共计 1915 个字符,预计需要花费 5 分钟才能阅读完成。
下载 keepalived
http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
解压以及编译
tar xzf keepalived-1.2.7.tar.gz
./configure –prefix=/opt/keepalived make && make install
配置 keepalived
创建 keepalived 配置文件 keepalived.conf(只有虚拟 ip 功能,其他功能,例如监控服务、发送邮件等功能由其他脚本完成)
PS:网卡必须是内网网卡
主机配置
! 主机配置
vrrp_instance VI_1 {
state MASTER /* 设置为主 */
interface eth0 /* 监控网卡 */
virtual_router_id 51 /* 这个两台服务器必须一样 */
mcast_src_ip 192.168.0.100 /* 多播的源 IP,设置为本机 IP,与 VIP 同一网卡 */
priority 100 /* 权重值 MASTRE 一定要高于 BAUCKUP */
advert_int 1 /* VRRP Multicast 广播周期秒数 */
smtp_alert
authentication {
auth_type PASS /* 加密 */
auth_pass 123456 /* 加密的密码,两台服务器一定要一样,不然会出错 */
}
virtual_ipaddress {
192.168.0.119
}
}
备机配置
! 备机配置
vrrp_instance VI_1 {
state BACKUP /* 设置为备 */
interface eth0 /* 监控网卡 */
virtual_router_id 51 /* 这个两台服务器必须一样 */
mcast_src_ip 192.168.0.101 /* 多播的源 IP,设置为本机 IP,与 VIP 同一网卡 */
priority 50 /* 权重值 BACKUP 一定要低于 MASTER */
advert_int 1 /* VRRP Multicast 广播周期秒数 */
smtp_alert
authentication {
auth_type PASS /* 加密 */
auth_pass 123456 /* 加密的密码,两台服务器一定要一样,不然会出错 */
}
virtual_ipaddress {
192.168.0.119
}
}
启动 keepalived
将 keepalived 设置成为服务式启动及停止
#!/bin/bash
MY_ROOT=$(cd “$(dirname “$0″)”; pwd)
ln -s $MY_ROOT/sbin/keepalived /usr/sbin/keepalived
ln -s $MY_ROOT/etc/sysconfig/keepalived /etc/sysconfig/keepalived
ln -s $MY_ROOT/etc/rc.d/init.d/keepalived /etc/init.d/keepalived
mkdir /etc/keepalived
ln -s $MY_ROOT/keepalived.conf /etc/keepalived/keepalived.conf
启动 keepalived
/etc/init.d/keepalived start
可以 tail 系统日志 /var/log/messages 来查看服务启动状态
Keepalived 的详细介绍 :请点这里
Keepalived 的下载地址 :请点这里
推荐阅读:
CentOS 6.3 下 Haproxy+Keepalived+Apache 配置笔记 http://www.linuxidc.com/Linux/2013-06/85598.htm
Haproxy + KeepAlived 实现 WEB 群集 on CentOS 6 http://www.linuxidc.com/Linux/2012-03/55672.htm
Keepalived+Haproxy 配置高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/56748.htm
Haproxy+Keepalived 构建高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/55880.htm