主从模式 vm虚拟机下
主 192.168.157.137
从 129.168.157.138
虚拟ip 192.168.157.200
首先装包 yum -y isntall keepalived
配置文件的默认地址 /etc/keepalived/keepalived.conf
修改配置文件
! Configuration File for keepalived
global_defs {
notification_email { #邮件联系人
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id wang-A #本机的标示符
}
vrrp_instance VI_1 {
state MASTER #主为master 从为BACKUP
interface eth0 # 虚拟ip的网卡
virtual_router_id 51 #相同虚拟IP主从必须一样
priority 100 #优先级 从的优先级低于主优先级
advert_int 1
authentication {#加密方式
auth_type PASS
auth_pass 1111
}
virtual_ipaddress { #虚拟IP
192.168.157.200/24
}
}
virtual_server 192.168.157.2 80 {#虚拟IP的网关地址 用来监听?
delay_loop 6
lb_algo rr
lb_kind DR #路由器直连
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.157.137 80 {#第一个web服务器
weight 1 #权重
TCP_CHECK{
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.157.138 80 {
weight 1
TCP_CHECK{
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}