https://www.keepalived.org/download.html
keepalived-1.4.5.tar.gz
yum install -y gcc openssl-devel libnl libnl3-devel libnfnetlink-devel tar -zxvf keepalived-1.4.5.tar.gz cd keepalived-1.4.5 ./configure prefix=/usr/local/keepalived make && make install
cd /usr/local/keepalived/ mkdir conf cp etc/keepalived/keepalived.conf conf/ vi conf/keepalived.conf
! Configuration File for keepalived # 定义用于实例执行的脚本内容 vrrp_script chk_http_nginx { script "/opt/nginx/check_nginx.sh" interval 10 weight 2 } # 全局配置 global_defs { router_id LVS_DEVEL } # 定义一个虚拟路由器的实例名称 vrrp_instance VI_1 { # 定义初始状态,可以是MASTER或者BACKUP state MASTER # 工作接口,通告选举使用哪个接口进行 interface eth0 # 优先级 priority 100 # 本地IP地址 unicast_src_ip 192.168.100.11 # 配置从节点的目标IP地址 unicast_peer { 192.168.100.12 } # ID还是虚拟MAC最后一段地址的信息,取值范围0-255 virtual_router_id 6 # 工作模式,nopreempt表示工作在非抢占模式,默认是抢占模式 preempt nopreempt # 通告频率,单位为秒 advert_int 1 # 通信认证机制,这里是明文认证还有一种是加密认证 authentication { auth_type PASS auth_pass 1111 } # 追踪脚本,通常用于去执行上面的vrrp_script定义的脚本内容 track_script { chk_http_nginx } # 设置虚拟VIP地址 virtual_ipaddress { 192.168.100.10 } }
/usr/local/keepalived/sbin/keepalived -f /usr/local/keepalived/conf/keepalived.conf