环境说明
1、操作系统:linux
2、Keepalived软件版本:keepalived-1.1.20.tar.gz
3、安装环境
yum install -y openssl openssl-devel
yum install libnl* libpopt* popt-static
环境配置
1、主Keepalived服务器IP地址 192.168.1.xx1
2、备Keepalived服务器IP地址 192.168.1.xx2
3、Keepalived虚拟IP地址 192.168.1.165
安装流程
1、上传Keepalived到/usr/local/keepalived(如果文件夹不存在创建:mkdir /usr/local/keepalived)或者直接下载
wget http://www.keepalived.org/software/keepalived-1.1.20.tar.gz
2、进入文件夹
cd /usr/local/keepalived
3、解压Keepalived软件
tar -zxvf keepalived-1.1.20.tar.gz
4、进入安装包文件夹
cd keepalived-1.1.20
5、编译
./configure –prefix=/usr/local/keepalived
6、安装
make
make install
7、修改配置文件路径
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp -r /usr/local/keepalived/etc/keepalived/ /etc/
8、设置为服务,开机启动, 编辑vi /etc/rc.local,添加一行启动指令
vi /etc/rc.local
/etc/init.d/keepalived start
保存退出,启动/停止
service keepalived start/stop
安装完成。
主Keepalived配置
打开以下配置文件:
vi /etc/keepalived/keepalived.conf
修改以下内容(红色内容为变动的内容):
vrrp_instance VI_1 {
state MASTER #主服务器的这个值为MASTER
interface eth2
virtual_router_id 51 #主服务器和备份服务器这个值必须相等
priority 100 #主服务器的这个值必须大于备份服务器
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.232.165 #虚拟ip,主服务器和备份服务器一致,外网访问的ip
}
track_script {
chk_http_port
}
}
备Keepalived配置
打开以下配置文件:
vi /etc/keepalived/keepalived.conf
修改以下内容(红色内容为变动的内容):
vrrp_instance VI_1 {
state BACKUP #备份服务器的这个值为BACKUP
interface eth2
virtual_router_id 51 #主服务器和备份服务器这个值必须相等
priority 50 #主服务器的这个值必须大于备份服务器
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.232.165 #虚拟ip,主服务器和备份服务器一致,外网访问的ip
}
track_script {
chk_http_port
}
}
重启Keepalived服务
service keepalived restart
查看网卡信息
主Keepalived网卡信息,ip add指令查看:
ip add
验证测试
1、在主服务器上新建一个网页,内容为:192.168.111.223
2、在备用服务器上新建一个网页,内容为:192.168.111.100
3、启动主备服务器的http服务和Keepalived服务
4、通过浏览器,输入虚拟IP地址 192.168.111.165,页面显示为 192.168.111.223
5、关闭主服务器的Keepalived服务,通过浏览器输入IP地址192.168.111.165,页面显示为 192.168.111.100
6、再次启动主服务器的Keepalived服务,通过浏览器输入IP地址192.168.111.165,页面显示为:192.168.111.223
说明keepalived配置成功。