keepalived高可用基础配置
(准备三台Linux服务器,两台做Web服务器,并部署Keepalived高可用软件,一台作为客户端主机)(关闭SElinux、防火墙)
一、配置网络环境
# yum -y install keepalived
# yum -y install keepalived
lm_sensors-libsnet-snmp-libs 依赖包
# rpm -qc keepalived
/etc/keepalived/keepalived.conf
/etc/sysconfig/keepalived
# cp /etc/keepalived/keepalived.conf /root/ 最好备份一份
1.1编写网络文件
#echo '192.168.4.53' > /var/www/html/test.html
#echo '192.168.4.54' > /var/www/html/test.html
2、修改配置文件
#vim /etc/keepalived/keepalived.conf
global_defs {
4 notification_email { 工作邮箱
15 vrrp_instance webha {
16 state MASTER 主服务器
17 interface eth0 网卡
18 virtual_router_id 51
19 priority 150 优先级
20 advert_int 1
21 authentication {
22 auth_type PASS
23 auth_pass 123456 主从密码一致
24 }
25 virtual_ipaddress { vip地址
26 192.168.4.251
27 }
28 }
#vim /etc/keepalived/keepalived.conf
15 vrrp_instance webha {
16 state BACKUP 从服务器
17 interface eth0
18 virtual_router_id 51
19 priority 100
20 advert_int 1
21 authentication {
22 auth_type PASS
23 auth_pass 123456
24 }
25 virtual_ipaddress { vip地址
26 192.168.4.251
3、开启服务并验证(53 54)
# ip addr show 查看本机的虚拟ip
# service keepalived start
# ip addr show | grep 192.168.4.* 优先级高的先获取虚拟ip
inet 192.168.4.53/24 brd 192.168.4.255 scope global eth0
inet 192.168.4.251/32 scope global eth0
# elinks --dump http://192.168.4.251/test.html 显示53的网页内容
‘192.168.4.53’
# service keepalived stop 关闭53虚拟ip会被54抢走
# ip addr show | grep 192.168.4.*
inet 192.168.4.54/24 brd 192.168.4.255 scope global eth0
inet 192.168.4.251/32 scope global eth0
# elinks --dump http://192.168.4.251/test.html 在访问就会显示54
‘192.168.4.54’
页:
[1]