一、承接上一篇文章,按上面拓扑做修改:
1.新增一台Director,eth1的IP 192.168.1.5
2.旧Director添加一起网卡eth0(IP 10.0.0.1/24)直连新Director的eth0(IP 10.0.0.2/24)
3.删除.旧Director的eth1:0
二、两台Director都进行以下操作:
1.关闭ipvsadm:
chkconfig ipvsadm off
service ipvsadm off
2..通过ssh-keygen互信(可省)
ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.5
3..安装keepalived
yum -i install keepalvied
4.设置配置文件
注意:
(1)红框是在backup的director上要进行修改的。
(2)所有大括号前必须有空格,否则会有异常,且不好排查。
vim /etc/keepalived/keepalived.conf
5.创建状态变化运行的脚本(可根据实际需要创建,这里只提供一个测试例子)
vim /etc/keepalived/status.sh
#!/bin/bash
echo "`date ‘+%F %T’`$1 change status to $2 " >>/etc/keepalived/status.txt
chmod +x /etc/keepalived/stauts.sh
6.启动服务
service keepalived start
chkconfig keepalived on
一开始旧Director为master
实验:
-
在旧Director上创建文件(touch /etc/keepalived/down)则会变成backup(优先级由原来的100变成了90),并且系统自动运行脚本 /etc/keepalived/status.sh 192.168.1.1 backup ,自动将状态改变写进status.txt文件里,就可通过tail -f /etc/keepalived/status.txt 查看当前keepalived的模式状态
-
rm -f /etc/keepalived/down ,则旧Director又变成master
-
将旧Director的eth1断开,则旧Director又变成master,而新Director变成fault
-
在httpd服务器上将主页移走:mv index.html index.html.bak ,Director的上ipvsadm可以看到将此httpd服务器移除。
原文出自:
http://blog.too2.net/?p=218
转载请注明转自:辛碌力成【http://blog.too2.net】
发表评论