1.安装环境
操作系统:Suse 11.3 X86_64 版本(内核已经自带LVS,不需要安装重新编译内核)
内核版本: 2.6.27.19-5-default
用源代码安装包,安装的时候碰到很多基础依赖包,着实比较累,我安装了一天,一个个的下依赖包才搞定,所以建议配置zypper,让他来代替。
(注:zypper类似于yum或者apt-get)
zypper添加两个安装源
zypper ar http://packman.unixheads.com/suse/11.0/ My_Packman_USA
zypper ar http://download.opensuse.org/distribution/11.3/repo/oss/ opensuse11_3
刷新源 zypper ref
zypper设置完成
2.安装
zypper se ipvsadm 搜索 ipvsadm
列出搜索结果软件:
zypper in ipvsadm 安装ipvsadm
zypper se heartbeat
zypper in heartbeat
zypper in heartbeat-ldirectord
zypper in heartbeat-ldirectord
安装完成。
3.配置
服务器及IP为
虚拟ip : eth1:192.168.1.58 eth0:xxx.xxx.xxx.58
主LVS: eth1:192.168.1.52 eth0:xxx.xxx.xxx.52
备份LVS: eth1:192.168.1.53 eth0:xxx.xxx.xxx.53
真是服务器:eth1:192.168.1.54/55/56/57 eth0:xxx.xxx.xxx.54/55/56/57
配置/etc/ha.d/ha.cf
logfile /var/log/ha-log keepalive 2 deadtime 30 deadping 5 warntime 10 initdead 30 udpport 694 ucast eth0 192.168.1.52 #52上写53,53反过来 auto_failback on node linux-kwfx #主域名 node linux-1cb2 #次域名 ping_group group1 xxx.xxx.xxx.52 xxx.xxx.xxx.53 respawn root /usr/lib64/heartbeat/ipfail apiauth ipfail gid=root uid=root
配置/etc/ha.d/haresources
linux-kwfx LVSSyncDaemonSwap::master IPaddr::xxx.xxx.xxx.58/24/eth0:0/xxx.xxx.xxx.255 ldirectord
配置/etc/ha.d/ldirectord
checktimeout=30 checkinterval=5 #fallback=127.0.0.1:80 autoreload=yes logfile="/var/log/ldirectord.log" quiescent=no virtual=xxx.xxx.xxx.58:80 #虚拟ip地址 real=xxx.xxx.xxx.54:80 gate #真实ip地址 real=xxx.xxx.xxx.55:80 gate real=xxx.xxx.xxx.56:80 gate real=xxx.xxx.xxx.57:80 gate fallback=127.0.0.1:80 gate service=http #检查方式 request="lvs_check.html" #检查页面 receive="lvsok" #返回信息 scheduler=lc protocol=tcp
配置/etc/ha.d/authkeys
auth 1
1 crc
chmod 600 authkeys
lvs配置完后,配置真实服务器
http服务80端口跟目录添加一个lvs_check.html,内容为lvsok
然后浏览器输入 http://ip/lvs_check.html ,能正确看到lvsok
真实服务器/etc/init.d/lvs.real
#!/bin/bash #description:start realserver #chkconfig VIP1=xxx.xxx.xxx.58 #虚拟服务器ip case "$1" in start) echo " start LVS of REALServer" /sbin/ifconfig lo:0 $VIP1 broadcast $VIP1 netmask 255.255.255.255 up 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 echo "close LVS Directorserver" 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
然后
chmod u+x lvs.real
/etc/inid.d/lvs.real start
ifconfig 看看书否有虚拟ip,如果存在真实服务器ok
接下来启动heartbeat
service heartbeat start
启动成功后,用watch ipvsadm 看看能不能检查到真实ip,我这边安装的时候没有检查到,查看日志缺少2个包
zypper in perl-Socket6
zypper in perl-MailTools
然后service heartbeat stop
service heartbeat start
接下来就能看到54,55,56,57 这几个真实服务器了
lvs的DR配置完成,可以集群服务了