lvs配置

一、安装相关软件包

建议yum安装:

yum install libnet

yum install ipvsadm

yum install heartbeat

如果自己手工下载rpm安装,可参考下面:

1LVS(ipvsadm)

ipvsadm-1.24-8.1.i386.rpm

2HAharetbeat

heartbeat-2.1.4-2.1.i386.rpm;heartbeat-ldirectord-2.1.4-2.1.i386.rpm;heartbeat-pils-2.1.4-2.1.i386.rpm; heartbeat-stonith-2.1.4-2.1.i386.rpm; libnet-1.1.2.1-2.1.i386.rpm;

perl-MailTools-2.04-1.el5.rf.noarch.rpm; perl-Net-SSLeay-1.30-4.fc6.i386.rpm

perl-TimeDate-1.16-1.c4.noarch.rpm

注意与操作系统对应的版本!这里只是一个参考

 

二、概念解释

1LVS最重要的是director(调度器)IPVSADM是最重要的主程序,这个包可以在RedHat5光盘下的Cluster文件夹下找到RPM的包.

2HA(haretbeat)主要是做两台调度服务器的热备份用,主服务器down机后,备服务器就会接替主服务器上的功能继续服务。三个主要配置文件ha.cfauthkeysharesources

3Ldirectordharetbeat的一个组件,主要是负责调度器后面的真实服务器的健康状况,可以通过http;pop;smtp;ftp等等的一些服务来确定后台真实服务器的情况,这里我们用http页面来测试真实服务器的健康状况。在/etc/ha.d/下面创建conf文件夹,此文件夹下创建Ldirectord的配置文件,文件名可以自己命名,后辍这里使用.cf

注:(如果使用了Ldirectord,那么就不需要用脚本来创建ipvsadm的规则,因为在ldirectord的配置文件里,已经添加了这些规则。)

4:最后用chmod 600 authkeys 把此文件改成只读属性

 注:在整个过程中,不需要手动添加子网卡与VIP地址。因为HA启动时,会跟据haresources文件里的VIP自动添加。

 

三、配置文件(ha.cf authkeys haresources 全部放在 /etc/ha.d/ 下面  /etc/ha.d/conf/下面放对应的调度配置文件)

1、ha.cf

#   File to write debug messages to 

#debugfile /var/log/ha-debug

 

#   File to write other messages to 

logfile /var/log/halog

 

#use_logd yes

 

# Keepalive:how long between heartbeats?

#The Default time unit is seconds

#10 means ten seconds

#1500ms means 1.5 seconds

keepalive 5

 

# Deadtime:how long to declare host dead

deadtime 15

 

# Warntime:how long before issuing "late heartbeat" warning?

warntime 10

 

# Very first dead time (initdead) 

# It should be at least twice the normal dead time.

initdead 120

 

# What UDP port to use for bcast/ucast communication?

udpport  694

 

# What interfaces to broadcast heartbeats over?

#bcast eth1 eth2   #Linux

bcast eth0    #Linux  为了省事,改成广播 其实单播比较合理

 

# auto_failback

auto_failback on

 

# Tell what machines are in th cluster

# node nodename ... -- must match uname -n

#主备节点,需要在主备配/etc/hosts

node lvs01

node lvs02

 

# If either 192.168.10.17 or 192.168.10.18 are up then group1 is up

# Used together with ipfail below .....

#心跳检查机制,当ping不通网关时,表示已经down了

ping 172.16.3.1

 

 

#                      Processes started and stopped with heartbeat.

#                      respawn means The process will be restarted whenever it terminates

#注意用户名与用户组 添加方式如下:

#groupadd haclient
#useradd -g haclient hacluster
#chown -R hacluster:haclient /var/lib/heartbeat

respawn hacluster /usr/lib/heartbeat/ipfail

 

# Access control for client api

apiauth ipfail gid=haclient uid=hacluster

 

 

#crm yes

2、authkeys 

#通信加密方式 这里选第二种

auth 2

#1 crc

2 sha1 HI!

#3 md5 Hello!

3、haresources(ld所用 比较重要)

lvs01  172.16.3.111/32/172.16.3.111 ldirectord::172.16.3.111.cf

#lv01是主服务器的机器名 uname n

#172.16.3.111 VIP

#32是子网掩码

#第二个172.16.3.111是广播地址

#ldirectord::172.16.3.111.cf  ldirectord程序将调用/etc/ha.d/conf/172.16.3.111.cf这个配置文件

 

4、/etc/ha.d/conf/172.16.3.111.cf

checktimeout = 10

 

negotiatetimeout = 5

 

checkinterval = 10

 

autoreload = yes

 

#fallback = 127.0.0.1:80

 

quiescent = no

#这个值为no时,ipvs表里将会把不健康的服务器删除掉,这个值为yes时,ipvs表里会保留这个不健康的服务器,但只是把权值设成0,并从表里删除,这样的话调度器还是会将请求发给这个不健康的服务器,当发现权值为0时,将请求再转给权值为1的服务器,这样虽然用户请求不会被丢,但是访问速度会变慢。相反如果从表里把不健康的服务器删除后,调度器就不会把请求再发给这台服务器了,用户访问速度不会明显变慢,但是之前调度器上对这台不健康服务器的访问请求将被丢弃,这样用户需重新访问站点创建新的连接会话。

virtual = 172.16.3.111:8888#在这行下面的行,前面都要有4个空格,如果没有会命令错误

    real = 172.16.3.105:8888 gate 1 "test","Hello,World."

    real = 172.16.3.38:8888 gate 1 "test","Hello,World."

#此处一定要注意路径,如果不是根路径,一定要加上上下文例如:crm/test

    service = http

    checkport = 8888

    scheduler = rr

    protocol = tcp

 

    checktype = negotiate

以上四个文件  主备节点保持一致

四:realserver配置

#!/bin/bash

#description : Start Real Server

VIP=172.16.3.111#注意此处为虚拟IP

/etc/rc.d/init.d/functions

case "$1" in

    start)

        echo " Start LVS  of  Real Server"

/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up

#/sbin/route add -host $VIP dev lo:0

        echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore

        echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce

        echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore

        echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

        ;;

    stop)

        /sbin/ifconfig lo:0 down

#/sbin/route del -host $VIP

        echo "close LVS Director server"

        echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore

        echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce

        echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore

        echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce

        ;;

    *)

        echo "Usage: $0 {start|stop}"

        exit 1

esac

将该脚本lvsrs放在/etc/rc.d/init.d下面

 

启动顺序:

service start heartbeat(主)

service start heartbeat(备)

/etc/rc.d/init.d/lvsrs start (realserver1)

/etc/rc.d/init.d/lvsrs start (realserver2)

监测:

wacth  ipvsadm -L -n

猜你喜欢

转载自andyaqu.iteye.com/blog/2026624
lvs