一、安装环境:
系统:
centos5.2 32位(自带内核默认支持lvs,不需要重新编译内核)
lvs:
VIP:10.129.60.199
DIP:192.168.23.200
主LVS:
主机名:l1
eth0:10.129.60.188 掩码:255.255.255.128
eth1:192.168.23.128 掩码:255.255.255.0
缺省网关:10.129.60.129
从LVS:
主机名:l2
eth0: 10.129.60.185 掩码:255.255.255.128
eth1:192.168.23.129 掩码:255.255.255.0
缺省网关:10.129.60.129
realserver:
192.168.23.130 掩码:255.255.255.0 缺省网关:192.168.23.200
192.168.23.135 掩码:255.255.255.0 缺省网关:192.168.23.200
二、lvs服务器安装
2.1 软件安装
#yum install ipvsadm
#yum install heartbeat
#yum install heartbeat-ldirectord
2.1 realserver软件安装
使用系统自带的apache测试
#yum install httpd
2.2 编辑LVS服务器配置文件
两台lvs服务器除了ha.cf中的ucast配置不同外,其余配置文件完全相同
#vi /etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
#udpport 694
ucast eth1 192.168.23.129 #从LVS配192.168.23.128
auto_failback off
node l1 #主要node的名字必须和uname -a看到的名字一致
node l2
ping 10.129.60.129 #网关
respawn hacluster /usr/lib/heartbeat/ipfail
#vi /etc/ha.d/haresources
l1 IPaddr::10.129.60.199/25/eth0:0 IPaddr::192.168.23.200/24/eth1:0 ldirectord::ldirectord.cf LVSSyncDaemonSwap::master
l2
#vi /etc/ha.d/authkeys
auth 3
3 md5 J2hjS2rf9M4j#la[wue$vxGw&h(m3T6No$f
#mkdir /etc/ha.d/conf
#vi /etc/ha.d/conf/ldirectord.cf
checktimeout=3
checkinterval=1
autoreload=yes
logfile="/var/log/ldirectord.log"
logfile="local0"
emailalert="admin@domain.com"
emailalertfreq=3600
emailalertstatus=all
quiescent=no
virtual=10.129.60.199:80
real=192.168.23.135:80 masq
real=192.168.23.130:80 masq
fallback=127.0.0.1:80 masq #realserver全部失败,vip指向本机80端口。在VIP维护的时候非常有用
service=http
request="hb.html" #用于健康检测的url,realserver上需要建立此文件,内容需要包含work
receive="work" #用于健康检测的url包含的关键字
scheduler=rr
persistent=600
#netmask=255.255.255.255
protocol=tcp
checktype=negotiate
checkport=80
request="hb.html"
receive="work"
2.3 编辑/etc/rc.local
#cat /etc/rc.local
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/default/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/eth0/send_redirects
三、real server配置文件
配置网关地址为LVS DIP的IP:192.168.23.200
四、启动
4.1 lvs服务器
#/etc/init.d/heartbeat start
4.2 real server
#source /etc/rc.local
#/etc/init.d/httpd start
五、测试
主从lvs的切换命令
#/usr/lib/heartbeat/hb_takeover
有s问题注意查看heartbeat的日志文件:/var/log/ha-log
(责任编辑:admin)
系统:
centos5.2 32位(自带内核默认支持lvs,不需要重新编译内核)
lvs:
VIP:10.129.60.199
DIP:192.168.23.200
主LVS:
主机名:l1
eth0:10.129.60.188 掩码:255.255.255.128
eth1:192.168.23.128 掩码:255.255.255.0
缺省网关:10.129.60.129
从LVS:
主机名:l2
eth0: 10.129.60.185 掩码:255.255.255.128
eth1:192.168.23.129 掩码:255.255.255.0
缺省网关:10.129.60.129
realserver:
192.168.23.130 掩码:255.255.255.0 缺省网关:192.168.23.200
192.168.23.135 掩码:255.255.255.0 缺省网关:192.168.23.200
二、lvs服务器安装
2.1 软件安装
#yum install ipvsadm
#yum install heartbeat
#yum install heartbeat-ldirectord
2.1 realserver软件安装
使用系统自带的apache测试
#yum install httpd
2.2 编辑LVS服务器配置文件
两台lvs服务器除了ha.cf中的ucast配置不同外,其余配置文件完全相同
#vi /etc/ha.d/ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
#udpport 694
ucast eth1 192.168.23.129 #从LVS配192.168.23.128
auto_failback off
node l1 #主要node的名字必须和uname -a看到的名字一致
node l2
ping 10.129.60.129 #网关
respawn hacluster /usr/lib/heartbeat/ipfail
#vi /etc/ha.d/haresources
l1 IPaddr::10.129.60.199/25/eth0:0 IPaddr::192.168.23.200/24/eth1:0 ldirectord::ldirectord.cf LVSSyncDaemonSwap::master
l2
#vi /etc/ha.d/authkeys
auth 3
3 md5 J2hjS2rf9M4j#la[wue$vxGw&h(m3T6No$f
#mkdir /etc/ha.d/conf
#vi /etc/ha.d/conf/ldirectord.cf
checktimeout=3
checkinterval=1
autoreload=yes
logfile="/var/log/ldirectord.log"
logfile="local0"
emailalert="admin@domain.com"
emailalertfreq=3600
emailalertstatus=all
quiescent=no
virtual=10.129.60.199:80
real=192.168.23.135:80 masq
real=192.168.23.130:80 masq
fallback=127.0.0.1:80 masq #realserver全部失败,vip指向本机80端口。在VIP维护的时候非常有用
service=http
request="hb.html" #用于健康检测的url,realserver上需要建立此文件,内容需要包含work
receive="work" #用于健康检测的url包含的关键字
scheduler=rr
persistent=600
#netmask=255.255.255.255
protocol=tcp
checktype=negotiate
checkport=80
request="hb.html"
receive="work"
2.3 编辑/etc/rc.local
#cat /etc/rc.local
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/default/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/eth0/send_redirects
三、real server配置文件
配置网关地址为LVS DIP的IP:192.168.23.200
四、启动
4.1 lvs服务器
#/etc/init.d/heartbeat start
4.2 real server
#source /etc/rc.local
#/etc/init.d/httpd start
五、测试
主从lvs的切换命令
#/usr/lib/heartbeat/hb_takeover
有s问题注意查看heartbeat的日志文件:/var/log/ha-log
(责任编辑:admin)