对Director的高可用分为两部分完成:
- 主机 IP类型 IP地址 网络连接
- rs1 RIP172.16.14.10 桥接
- lo:0 172.16.14.2
- rs2 RIP172.16.14.11 桥接
- lo:0 172.16.14.2
- dr1 DIP 172.16.14.100 桥接
- VIP eth0:0 172.16.14.2
- dr2 VIP 172.16.14.99 桥接
- DIP eth0:0 172.16.14.2
- CIP 192.168.0.243
- ifconfig eth0 172.16.14.10/16
- ifconfig lo:0 172.16.14.2 broadcast 172.16.14.2
- netmask 255.255.255.255
- route add -host 172.16.14.2 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
- yum -y insatll httpd
- vim /var/www/html/index.html
- 添加:<h1>real server1</h1>
- service httpd start
- ifconfig eth0 172.16.14.11/16
- 添加lo:0使客户端访问VIP,让VIP来响应客户端:
- ifconfig lo:0 172.16.14.2 broadcast 172.16.14.2
- netmask 255.255.255.255
- route add -host 172.16.14.2 dev lo:0
- 隐藏rs2的RIP:
- 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
- 安装httpd
- yum -y insatll httpd
- 为了测试结果的明显,将rs2的测试页面为:
- vim /var/www/html/index.html
- 添加:<h1>real server2</h1>
- 启动服务,测试页面
- ifconfig eth0 172.16.14.100/16
- ifconfig lo:0 172.16.14.2 broadcast 172.16.14.2
- netmask 255.255.255.255
- route add -host 172.16.14.2 dev lo:0
- echo 1 > /proc/sys/net/ipv4/ip_forward
- yum -y insatll ipvsadm
- ipvsadm -A -t 172.16.14.2:80 -s rr
- ipvsadm -a -t 172.16.14.2:80 -r 172.16.14.10 -g
- ipvsadm -a -t 172.16.14.2:80 -r 172.16.14.11 -g
- ipvsadm -Ln
- ifconfig eth0 172.16.14.99/16
- ifconfig lo:0 172.16.14.2 broadcast 172.16.14.2
- netmask 255.255.255.255
- route add -host 172.16.14.2 dev lo:0
- 开启内核转发功能:
- echo 1 > /proc/sys/net/ipv4/ip_forward
- 安装ipvsadm:
- yum -y insatll ipvsadm
- ipvsadm -C
- 添加规则:
- ipvsadm -A -t 172.16.14.2:80 -s rr
- ipvsadm -a -t 172.16.14.2:80 -r 172.16.14.10 -g
- ipvsadm -a -t 172.16.14.2:80 -r 172.16.14.11 -g
- ipvsadm -Ln
- 使dr1,dr2的uname -n分别为:
- dr1.magedu.com
- dr2.magedu.com
- hostname dr1.magedu.com
- vim /etc/sysconfig/network
- HOSTNAME=dr1.magedu.com
- hostname dr2.magedu.com
- vim /etc/sysconfig/network
- HOSTNAME=dr2.magedu.com
- vim /etc/hosts添加:
- 172.16.14.10 dr1.magedu.com dr1
- 172.16.14.11 dr2.magedu.com dr2
- dr1:
- # ssh-keygen -t rsa
- # ssh-copy-id -i ~/.ssh/id_rsa.pub root@dr2
- dr2
- # ssh-keygen -t rsa
- # ssh-copy-id -i ~/.ssh/id_rsa.pub root@dr1
- # date 112322022012;ssh dr2 'date 112322022012'
- yum -y --nogpgcheck localinstall
- heartbeat-2.1.4-9.el5.i386.rpm
- heartbeat-pils-2.1.4-10.el5.i386.rpm
- heartbeat-stonith-2.1.4-10.el5.i386.rpm
- libnet-1.1.4-3.el5.i386.rpm
- cd /usr/share/doc/heartbeat-2.1.4/
- cp ha.cf haresources authkeys /etc/ha.d/
- cd /etc/ha.d/
- ##ha.cf 主配置文件
- ##haresources 资源配置文件
- ##authkeys 认证文件
- 把authkeys权限改为600
- chmod 600 authkeys
- vim authkeys
- auth 3 ##启用加密方式3
- 3 md5 Hello!
- 生成一串密码,把md5后的hello!替换掉:
- dd if=/dev/urandom count=1 bs=512 |md5sum
- 5bd1ebacb939d34261ff2b2e6730a8d9 -
- ##用该行替换Hello!
- vim ha.cf ##启用如下项:
- keepalive 2 ##两个心跳信息的间隔时间
- deadtime 30 ##多长认为主机dead
- warntime 6 ##在发出最后一个心跳信息的警告时间
- initdead 120 ##开机时等待时间;用于增强容错能力
- udpport 694 ##默认使用的端口(单播)
- mcast eth0 224.2.2.14 694 1 0 ##组播地址
- auto_failback on ##当主节点重新上线后,是否回到主节点
- crm on ##启用crm
- node dr1.magedu.com ##添加两个节点信息
- node dr2.magedu.com
- ping 172.16.0.1 ##两个节点集群时的仲裁设备
- compression bz2 ##压缩类型
- compression_threshod 2 ##大于多少KB才压缩
- yum -y --nogpgcheck localinstall
- perl-MailTools-1.77 heartbeat-ldirectord-2.1.4.9
- 查看信息:
- rpm -ql heartbeat-ldirectord
- chkconfig --list|grep ldirectord
- 显示3,5级别为on,需要关闭
- chkconfig ldirectord off
- cd /usr/share/doc/heartbeat-ldirector-2.1.4/
- cp ldirectord.cf /etc/ha.d/
- vim ldirectord.cf 做如下修改:
- checktimeout=3 ##检测时间
- checkinterval=1 ##平均检测间隔时间
- logfile="/var/log/ldirectord.log" ##启用日志
- virtual=172.16.14.2:80 ##定义虚拟主机服务 VIP的地址
- real=172.16.14.10:80 gate ##节点IP;gate表示DR模型
- real=172.16.14.11:80 gate
- service=http ##服务类型
- request=".health.html" ##健康检测页面;必须在节点上
- receive="OK" ##检测页面内容
- scheduler=rr
- #persistent=600
- #netmask=255.255.255.255
- protocol=tcp ##协议
- checktype=negotiate ##检测类型
- checkport=80 ##检测端口
- 然后启动ldirectord测试
- service ldirector start
- 将上述操作同步到dr2上:
- /usr/lib/heartbeat/ha_propagete
- 在两个节点主机上建立测试页面:
- cd /var/www/htdocs
- vim .health.html
- 写入:OK
- hb_gui ##打开gui界面
- 为hacluster设置一个密码