RHEL6.6
epel源
本地源
在搭建LVS负载均衡集群中,Director Server易成为单点故障所在,Director server故障,整个集群都会崩溃,因此要把Director Server做成高可用,提高其可用性。
在这里我们要用到ldirectord这个软件,ldirectord可以监控个集群节点的状态信息,若某节点出现故障,则会把它从集群系统中剔除,并在其回复正常后,将它重新加入集群系统。
ldirectord还可以调用ipvsadm命令创建LVS路由表信息,只需要在/etc/ha.d/ldirectord.cf配置文件中指明即可。
主Director server 192.168.1.3 主机名 node1.mingxiao.info node1
备Director server 192.168.1.4 主机名 node2.mingxiao.info node2
Real server1 192.168.1.5
Real server2 192.168.1.6
VIP 192.168.1.10
主备DS时间同步
主备DS双机互信
主备DS节点名称与 uname -n 相同
node1编辑/etc/hosts文件
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.1.3 node1.mingxiao.info node1 192.168.1.4 node2.mingxiao.info node2
# scp /etc/hosts node2:/etc/
双机互信
node1 # ssh-keygen -t rsa -f ~/.ssh/id_rsa # ssh-copy-id -i .ssh/id_rsa.pub node1 node2 # ssh-keygen -t rsa -f ~/.ssh/id_rsa # ssh-copy-id -i .ssh/id_rsa.pub node2
时间同步
# ntpdate time.windows.com # ssh node2 'ntpdate time.windows.com'
进入node1主机
安装ldirectord
# rpm -ivh ldirectord-3.9.5-3.1.x86_64.rpm # ssh node2 'rpm -ivh /root/ldirectord-3.9.5-3.1.x86_64.rpm'
# cp /usr/share/doc/ldirectord-3.9.5/ldirectord.cf /etc/ha.d/
vim /etc/ha.d/ldirectord.cf # Global Directives checktimeout=3 checkinterval=1 #fallback=127.0.0.1:80 #fallback6=[::1]:80 autoreload=no #logfile="/var/log/ldirectord.log" #logfile="local0" #emailalert="[email protected]" #emailalertfreq=3600 #emailalertstatus=all quiescent=no # Sample for an http virtual service virtual=192.168.1.10:80 real=192.168.1.5:80 gate real=192.168.1.6:80 gate fallback=127.0.0.1:80 gate service=http scheduler=rr #persistent=600 #netmask=255.255.255.255 protocol=tcp checktype=negotiate checkport=80 request=".test.html" receive="OK" #一定要与request=".test.html"内容一样,否则有错 virtualhost=www.x.y.z
node2主机配置与node1相同
RS1
# yum -y install httpd # echo RS1 > /var/www/html/index.html # echo OK > /var/www/html/.test.html # service httpd start # ifconfig lo:0 192.168.1.10 broadcast 192.168.1.10 netmask 255.255.255.255 up # route add �Chost 192.168.1.10 dev lo:0 # echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore # echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore # echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce # echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
RS2
配置同RS1
进node1主机
# yum install corosync pacemaker 红帽6去除了crmsh,因此需要另外安装,安装包可去rpmfind.net找到 # yum localinstall crmsh-2.1-1.6.x86_64.rpm
# vim /etc/corosync.conf compatibility: whitetank totem { version: 2 secauth: off threads: 0 interface { ringnumber: 0 bindnetaddr: 192.168.1.0 mcastaddr: 239.255.1.1 mcastport: 5405 ttl: 1 } } logging { fileline: off to_stderr: no to_logfile: yes logfile: /var/log/cluster/corosync.log to_syslog: yes debug: off timestamp: on logger_subsys { subsys: AMF debug: off } } service { ver: 0 name: pacemaker } aisexec { user: root group: root }
# service corosync start
node2 配置同node1
查看状态:
# crm status Last updated: Mon May 4 18:25:16 2015 Last change: Mon May 4 18:25:14 2015 Stack: classic openais (with plugin) Current DC: node2.mingxiao.info - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 2 Resources configured Online: [ node1.mingxiao.info node2.mingxiao.info ]
配置IP,ldirectord资源
crm(live)configure# property no-quorum-policy=ignore crm(live)configure# property stonith-enabled=false crm(live)configure# porperty resource-stickiness=100 crm(live)configure# primitive webip IPaddr2 params ip=192.168.1.10 nic=eth0 cidr_netmask=24 crm(live)configure# primitive ldirectord lsb:ldirectord op start timeout=15s interval=0 op stop timeout=15s interval=0 crm(live)configure# colocation webip_with_ldirectord inf: webip ldirectordcrm(live)configure# order ldirectord_after_webip inf: webip ldirectord crm(live)configure# verify crm(live)configure# commit
配置文件贴出
crm(live)configure# show node node1.mingxiao.info \ attributes standby=off node node2.mingxiao.info \ attributes standby=on primitive ldirectord lsb:ldirectord \ op start timeout=15s interval=0 \ op stop timeout=15s interval=0 primitive webip IPaddr \ params ip=192.168.1.10 nic=eth0 cidr_netmask=24 colocation webip_with_ldirectord inf: webip ldirectord order ldirectord_after_webip inf: webip ldirectord property cib-bootstrap-options: \ dc-version=1.1.11-97629de \ cluster-infrastructure="classic openais (with plugin)" \ expected-quorum-votes=2 \ stonith-enabled=false \ no-quorum-policy=ignore rsc_defaults rsc-options: \ resource-stickiness=100 #vim:set syntax=pcmk
查看状态:可看到资源都在node1节点上
# crm status Last updated: Mon May 4 18:33:31 2015 Last change: Mon May 4 18:25:14 2015 Stack: classic openais (with plugin) Current DC: node2.mingxiao.info - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 2 Resources configured Online: [ node1.mingxiao.info node2.mingxiao.info ] webip(ocf::heartbeat:IPaddr):Started node1.mingxiao.info ldirectord(lsb:ldirectord):Started node1.mingxiao.info
可看到VIP已配置成功
# ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:55:0d:82 brd ff:ff:ff:ff:ff:ff inet 192.168.1.3/24 brd 192.168.1.255 scope global eth0 inet 192.168.1.10/24 brd 192.168.1.255 scope global secondary eth0 inet6 fe80::20c:29ff:fe55:d82/64 scope link valid_lft forever preferred_lft forever
查看LVS路由表信息,可看到两个 RS已上线
# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.1.10:80 rr -> 192.168.1.5:80 Route 1 0 0 -> 192.168.1.6:80 Route 1 0 0
测试,将node1转为备用节点,看是否启动备用节点node2
# crm node standby #转为备用节点 # crm node online #上线 # crm status #可看到自动跳转到node2上 Last updated: Mon May 4 18:38:53 2015 Last change: Mon May 4 18:38:48 2015 Stack: classic openais (with plugin) Current DC: node2.mingxiao.info - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 2 Resources configured Online: [ node1.mingxiao.info node2.mingxiao.info ] webip(ocf::heartbeat:IPaddr):Started node2.mingxiao.info ldirectord(lsb:ldirectord):Started node2.mingxiao.info
进RS1 192.168.1.5 模拟RS1故障
# service httpd stop #停止httpd服务 进node2,可看到RS1已被剔除 # ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.1.10:80 rr -> 192.168.1.6:80 Route 1 0 0
进RS1 192.168.1.5 模拟故障回复
# service httpd start #启动httpd服务 进node2,可看到RS1已重新上线 # ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.1.10:80 rr -> 192.168.1.5:80 Route 1 0 0 -> 192.168.1.6:80 Route 1 0 0