kernel-devel需要的文件
以及需要的证书
lvs需要的文件
keepalived需要的文件
! Configuration File for keepalived global_defs { notification_email { 邮箱 } notification_email_from 邮箱 smtp_server 邮箱服务器地址 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER interface eth0 #eth0是要绑定的网卡 virtual_router_id 100 #同一个vrrp_instance中的值必须一样 priority 160 #master的值要高于backup的 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.0.5 #用于双机热备的虚拟ip } } virtual_server 192.168.0.5 6379 { delay_loop 3 lb_algo wrr lb_kind DR persistence_timeout 30 protocol TCP real_server 192.168.0.2 6379 { weight 8 notify_down redis服务失败后要执行的脚本的路径/脚本名 #服务失败后要执行的脚本 TCP_CHECK { connect_timeout 1 nb_get_retry 3 delay_before_retry 3 connect_port 6379 } } }
! Configuration File for keepalived global_defs { notification_email { 邮箱 } notification_email_from 邮箱 smtp_server 邮箱服务器地址 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER interface eth0 #eth0是要绑定的网卡 virtual_router_id 100 #同一个vrrp_instance中的值必须一样 priority 160 #master的值要高于backup的 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.0.5 #用于双机热备的虚拟ip } notify_master 将slave重新转换为slave的脚本 } vrrp_instance VI_2 { state MASTER #将此slave作为读数据的master interface eth0 virtual_router_id 101 priority 151 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.0.6 #用于读取数据的负载均衡的虚拟ip } } virtual_server 192.168.0.5 6379 { delay_loop 3 lb_algo wrr lb_kind DR persistence_timeout 30 protocol TCP real_server 192.168.0.2 6379 { weight 1 notify_down redis服务失败后要执行的脚本的路径/脚本名 #服务失败后要执行的脚本 TCP_CHECK { connect_timeout 1 nb_get_retry 2 delay_before_retry 1 connect_port 6379 } } real_server 192.168.0.3 6379 { weight 8 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 6379 } } } virtual_server 192.168.0.6 6379 { delay_loop 3 lb_algo wrr lb_kind DR persistence_timeout 30 protocol TCP real_server 192.168.0.2 6379 { weight 8 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 6379 } } real_server 192.168.0.3 6379 { weight 7 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 6379 } } }
! Configuration File for keepalived global_defs { notification_email { 邮箱 } notification_email_from 邮箱 smtp_server 邮箱服务器地址 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_2 { state BACKUP interface eth0 virtual_router_id 101 priority 149 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.0.6 } } virtual_server 192.168.0.6 6379 { delay_loop 3 lb_algo wrr lb_kind DR persistence_timeout 30 protocol TCP real_server 192.168.0.2 6379 { weight 8 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 6379 } } real_server 192.168.0.3 6379 { weight 7 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 6379 } } }
需要的脚本:
在master执行的脚本:
#!/usr/bin/env bash service keepalived stop #需要用户具有权限,不中断keepalived服务虚拟ip无法转移
#!/usr/bin/env bash /usr/local/bin/redis-cli -h 127.0.0.1 -p 6379 slaveof NO ONE #将slave1转换为redis的
#!/usr/bin/env bash /usr/local/bin/redis-cli slaveof 192.168.0.2 6379 #将slave1重新转换为redis的slave