积累经验
2014年(55)
分类: Mysql/postgreSQL
2014-06-27 11:27:52
Keepalived简介:Keepalived是Linux下面实现VRRP 备份路由的高可靠性运行件。基于Keepalived设计的服务模式能够真正做到主服务器和备份服务器故障时IP瞬间无缝交接,从而提高系统的可用性。
1、 keepalived的安装(amoeba、amoeba2上都要安装):
yum -y install kernel-devel openssl-devel popt-devel gcc
wget
tar zxvf keepalived-1.1.19.tar.gz
cd keepalived-1.1.19
./configure --prefix=/usr/local/keepalived
make
make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived
cd /etc/keepalived/
2、 keepalived的配置
配置amoeba的keepalived配置文件/etc/keepalived/keepalived.conf,内容如下:
bal_defs {
notification_email {
test@test.com.cn
}
notification_email_from test@test.com.cn
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id test1
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
smtp_alert
authentication {
auth_type PASS
auth_pass 123
}
virtual_ipaddress {
192.168.121.170
}
}
配置amoeba的keepalived配置文件/etc/keepalived/keepalived.conf,内容如下:
bal_defs {
notification_email {
test@test.com.cn
}
notification_email_from test@test.com.cn
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id test2
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 80
advert_int 1
smtp_alert
authentication {
auth_type PASS
auth_pass 123
}
virtual_ipaddress {
192.168.121.170
}
}
3、 keepalived的启动:
在amoeba、amoeba2上执行如下命令启动:
/etc/rc.d/init.d/keepalived start
看看amoeba上是否绑定了虚拟IP192.168.121.170
[root@amoeba ~]# ip add | grep 192.168.121.170
inet 192.168.1.170/32 scope global eth0
可以看到已经成功绑定了192.168.121.170。
4、 测试
停掉amoeba2,看看虚拟IP192.168.121.170会不会自动切换到amoeba2上。以及测试mysql -uroot -ppassword -h192.168.121.170登录,看看能否实现读写操作是否正常等等!