Keepalived 的script及双主

环境:

K1:192.168.11.26

K2:192.168.11.28

VIP1:192.168.11.17

VIP2:192.168.11.18

一、vrrp_script

1、K1配置

[[email protected] keepalived]# cat keepalived.conf                        #配置内容
! Configuration File for keepalived

global_defs {
   notification_email {
	[email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
  # vrrp_mcast_group4 224.0.100.18
}

vrrp_script  chk_down {                             #定义vrrp_script脚本扩展
   script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"     #判断文件是否存在,也可以定义脚本
   interval 3                                 #检查周期
   weight -10                                 #文件存在权重-10 根据上面script定义
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 6Nb6zjWB
    }
    virtual_ipaddress {
	192.168.11.17
    }
    track_script {                              #跟踪script,如果不写,则不调用也就是不会执行我们是定义的vrrp_script定义的内容
	chk_down
    }
	notify_master "/etc/keepalived/notify.sh master"
	notify_backup "/etc/keepalived/notify.sh backup"
	notify_fault "/etc/keepalived/notify.sh fault"
}

2、K2配置

[[email protected] keepalived]# cat keepalived.conf                          #配置内容
! Configuration File for keepalived

global_defs {
   notification_email {
	[email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
  # vrrp_mcast_group4 224.0.100.18
}

vrrp_script  chk_down {                             #定义vrrp_script脚本扩展
   script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"     #判断文件是否存在,也可以定义脚本   
   interval 3                                                                   #检查周期
   weight -10                                                                   #文件存在权重-10 根据上面script定义
}
}

vrrp_instance VI_1 {
    state BAKCUP                                #填写BACKUP,因为K1是MASTER
    interface eth0
    virtual_router_id 51
    priority 98                                 #优先级也需要设定比K1小
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 6Nb6zjWB
    }
    virtual_ipaddress {
	192.168.11.17
    }
    track_script {                               #跟踪script,如果不写,则不调用也就是不会执行我们是定义的vrrp_script定义的内容
	chk_down
    }
	notify_master "/etc/keepalived/notify.sh master"
	notify_backup "/etc/keepalived/notify.sh backup"
	notify_fault "/etc/keepalived/notify.sh fault"
}

3、测试

#启动keepalived服务,这里就不演示了
[[email protected] keepalived]# touch down                                                     #在K1MASTER上touche down文件
[[email protected] keepalived]# ls                                                             #查看是否存在,发现有down文件
down  keepalived.conf  keepalived.conf.bak  keepalived.conf.real  notify.sh
[[email protected] keepalived]# tail -f /var/log/messages                                      #在另外一个K1的session tail -f
Jun 24 17:43:57 web2 Keepalived_vrrp[9530]: VRRP_Script(chk_down) failed             #发现我们定义的track_script(chk_down) failed ,自动权限-10
Jun 24 17:43:58 web2 Keepalived_vrrp[9530]: VRRP_Instance(VI_1) Received higher prio advert  #发现更高优先级的
Jun 24 17:43:58 web2 Keepalived_vrrp[9530]: VRRP_Instance(VI_1) Entering BACKUP STATE        #自己转为BACKUP STATE
Jun 24 17:43:58 web2 Keepalived_vrrp[9530]: VRRP_Instance(VI_1) removing protocol VIPs.      #迁移VIPs协议
Jun 24 17:43:58 web2 Keepalived_healthcheckers[9529]: Netlink reflector reports IP 192.168.11.17 removed  #宣布删除IP 192.168.11.17

[[email protected] keepalived]# rm -f down                                                      #删除down文件
You have new mail in /var/spool/mail/root                                             #查看,down的确被删除
[[email protected] keepalived]# ls
keepalived.conf  keepalived.conf.bak  keepalived.conf.real  notify.sh
[[email protected] keepalived]# tail -f /var/log/messages                                       #切换回刚刚的session
Jun 24 17:43:57 web2 Keepalived_vrrp[9530]: VRRP_Script(chk_down) failed              #发现我们定义的track_script(chk_down) failed ,自动权限-10,此时权限为90
Jun 24 17:43:58 web2 Keepalived_vrrp[9530]: VRRP_Instance(VI_1) Received higher prio advert  #发现更高优先级的
Jun 24 17:43:58 web2 Keepalived_vrrp[9530]: VRRP_Instance(VI_1) Entering BACKUP STATE        #自己转为BACKUP STATE
Jun 24 17:43:58 web2 Keepalived_vrrp[9530]: VRRP_Instance(VI_1) removing protocol VIPs.      #迁移VIPs协议
Jun 24 17:43:58 web2 Keepalived_healthcheckers[9529]: Netlink reflector reports IP 192.168.11.17 removed  #宣布删除IP 192.168.11.17

========================================================割了,实际是连在一起的,只不过为了方便解释,割了==============================================

Jun 24 17:50:00 web2 Keepalived_vrrp[9530]: VRRP_Script(chk_down) succeeded           #发现我们定义的tarck_script(chk_down) succeeded,此时权限为100,就是把之前-10的加回来了
Jun 24 17:50:00 web2 Keepalived_vrrp[9530]: VRRP_Instance(VI_1) forcing a new MASTER election    #推选了一个新的MATER
Jun 24 17:50:00 web2 Keepalived_vrrp[9530]: VRRP_Instance(VI_1) forcing a new MASTER election    #推选了一个新的MASTER
Jun 24 17:50:01 web2 Keepalived_vrrp[9530]: VRRP_Instance(VI_1) Transition to MASTER STATE       #正在进入MASTER状态中
Jun 24 17:50:02 web2 Keepalived_vrrp[9530]: VRRP_Instance(VI_1) Entering MASTER STATE            #进入MASTER状态
Jun 24 17:50:02 web2 Keepalived_vrrp[9530]: VRRP_Instance(VI_1) setting protocol VIPs.           #设定VIPs协议
Jun 24 17:50:02 web2 Keepalived_vrrp[9530]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.11.17     #从eth0发送192.168.11.17免费的ARPs
Jun 24 17:50:02 web2 Keepalived_healthcheckers[9529]: Netlink reflector reports IP 192.168.11.17 added                #添加192.168.11.17
Jun 24 17:50:07 web2 Keepalived_vrrp[9530]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.11.17     #从eth0发送192.168.11.17免费的ARPs

4、通过vrrp_script简单检查服务并设定漂移

[[email protected] keepalived]# cat keepalived.conf                               #查看修改后的配置文件内容
! Configuration File for keepalived

global_defs {
   notification_email {
	[email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
  # vrrp_mcast_group4 224.0.100.18
}

vrrp_script  chk_down {
   script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
   interval 3
   weight -10
}

vrrp_script chk_httpd {                                                  #增加一个新的vrrp_script,为chk_httpd
  script "killall -0 httpd"                                              #killall -0 信号,如果服务存在返回0
  interval 3                                                             #检查周期
  weight -10                                                             #httpd服务存在权重-10
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 98
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 6Nb6zjWB
    }
    virtual_ipaddress {
	192.168.11.17
    }
    track_script {
	chk_down
        chk_httpd                                                        #增加了一个新的track_script chk_httpd
    }
	notify_master "/etc/keepalived/notify.sh master"
	notify_backup "/etc/keepalived/notify.sh backup"
	notify_fault "/etc/keepalived/notify.sh fault"
}
[[email protected] keepalived]# service keepalived  stop                                     #在K2停止keepalived
Stopping keepalived:                                       [  OK  ]
[[email protected] keepalived]# netstat -tnlp| grep httpd                                    #查看httpd服务是否启动
tcp        0      0 :::80                       :::*                        LISTEN      19187/httpd         
[[email protected] keepalived]# service keepalived start                                     #启动keepalived服务
Starting keepalived:                                       [  OK  ]
[[email protected] keepalived]# ip add sh                                                    #查看IP,发现:inet 192.168.11.17/32 scope global eth0
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:2d:ba:b0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.28/24 brd 192.168.11.255 scope global eth0
    inet 192.168.11.17/32 scope global eth0
    inet6 fe80::20c:29ff:fe2d:bab0/64 scope link 
       valid_lft forever preferred_lft forever
     
[[email protected] keepalived]# service keepalived stop                                     #在K1停止keepalived
正在启动 keepalived:                                      [确定]
[[email protected] keepalived]# netstat -tunlp | grep httpd                                 #查看httpd是否启动
tcp        0      0 :::80                       :::*                        LISTEN      5457/httpd 
[[email protected] keepalived]# service keepalived start                                    #启动keepalived    
[[email protected] keepalived]# ip add sh                                                   #查看IP,发现:192.168.11.17被抢占过来了
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:ad:98:5c brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.26/24 brd 192.168.11.255 scope global eth0
    inet 192.168.11.17/32 scope global eth0
    inet6 fe80::20c:29ff:fead:985c/64 scope link 
       valid_lft forever preferred_lft forever     
       
[[email protected] keepalived]# service httpd stop                                         #在K1停止httpd服务
停止 httpd:                                               [确定]
You have new mail in /var/spool/mail/root
[[email protected] keepalived]# ip add sh                                                  #查看IP,发信192.168.11.17不见了
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:ad:98:5c brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.26/24 brd 192.168.11.255 scope global eth0
    inet6 fe80::20c:29ff:fead:985c/64 scope link 
       valid_lft forever preferred_lft forever     
   
[[email protected] keepalived]# tail -f /var/log/messages                                   #在K1停止httpd服务器前,开启的一个新session
Jun 24 18:26:43 web2 Keepalived_vrrp[11701]: VRRP_Script(chk_httpd) failed        #定义的trackscript(chk_httpd)faileld
Jun 24 18:26:44 web2 Keepalived_vrrp[11701]: VRRP_Instance(VI_1) Received higher prio advert    #发现更高的优先级
Jun 24 18:26:44 web2 Keepalived_vrrp[11701]: VRRP_Instance(VI_1) Entering BACKUP STATE          #进入BACKUP状态
Jun 24 18:26:44 web2 Keepalived_vrrp[11701]: VRRP_Instance(VI_1) removing protocol VIPs.        #迁移VIPs协议
Jun 24 18:26:44 web2 Keepalived_healthcheckers[11700]: Netlink reflector reports IP 192.168.11.17 removed      #宣布删除IP 192.168.11.17 

[[email protected] keepalived]# service httpd start                                         #启动httpd服务
正在启动 httpd:httpd: apr_sockaddr_info_get() failed for K1
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName
                                                           [确定]
You have new mail in /var/spool/mail/root
[[email protected] keepalived]# ip add sh                                                   #查看IP,发现:192.168.11.17被抢占过来了
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:ad:98:5c brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.26/24 brd 192.168.11.255 scope global eth0
    inet 192.168.11.17/32 scope global eth0
    inet6 fe80::20c:29ff:fead:985c/64 scope link 
       valid_lft forever preferred_lft forever
       
[[email protected] keepalived]#tail -f /var/log/messages                                   #在K1停止httpd服务器前,开启的一个新session 
Jun 24 18:26:43 web2 Keepalived_vrrp[11701]: VRRP_Script(chk_httpd) failed       #定义的trackscript(chk_httpd)faileld
Jun 24 18:26:44 web2 Keepalived_vrrp[11701]: VRRP_Instance(VI_1) Received higher prio advert    #发现更高的优先级
Jun 24 18:26:44 web2 Keepalived_vrrp[11701]: VRRP_Instance(VI_1) Entering BACKUP STATE          #进入BACKUP状态
Jun 24 18:26:44 web2 Keepalived_vrrp[11701]: VRRP_Instance(VI_1) removing protocol VIPs.        #迁移VIPs协议
Jun 24 18:26:44 web2 Keepalived_healthcheckers[11700]: Netlink reflector reports IP 192.168.11.17 removed      #宣布删除IP 192.168.11.17 

========================================================割了,实际是连在一起的,只不过为了方便解释,割了==============================================
Jun 24 18:31:10 web2 Keepalived_vrrp[11701]: VRRP_Script(chk_httpd) succeeded                        #发现我们定义的tarck_script(chk_httpd) succeeded,此时权限为100,就是把之前-10的加回来了    
Jun 24 18:31:10 web2 Keepalived_vrrp[11701]: VRRP_Instance(VI_1) forcing a new MASTER election       #推选了一个新的MATER
Jun 24 18:31:10 web2 Keepalived_vrrp[11701]: VRRP_Instance(VI_1) forcing a new MASTER election       #推选了一个新的MATER
Jun 24 18:31:11 web2 Keepalived_vrrp[11701]: VRRP_Instance(VI_1) Transition to MASTER STATE          #正在进入MASTER状态中      
Jun 24 18:31:12 web2 Keepalived_vrrp[11701]: VRRP_Instance(VI_1) Entering MASTER STATE               #进入MASTER状态       
Jun 24 18:31:12 web2 Keepalived_vrrp[11701]: VRRP_Instance(VI_1) setting protocol VIPs.              #设定VIPs协议
Jun 24 18:31:12 web2 Keepalived_vrrp[11701]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.11.17    #从eth0发送192.168.11.17免费的ARPs
Jun 24 18:31:12 web2 Keepalived_healthcheckers[11700]: Netlink reflector reports IP 192.168.11.17 added               #添加192.168.11.17
Jun 24 18:31:17 web2 Keepalived_vrrp[11701]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.11.17    #从eth0发送192.168.11.17免费的ARPs

二、双主模型

[[email protected] keepalived]# cat keepalived.conf                                 #查案配置内容,K1的就不贴上来了,新增段配置改为相反的
! Configuration File for keepalived

global_defs {
   notification_email {
	[email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
  # vrrp_mcast_group4 224.0.100.18
}

vrrp_script  chk_down {
   script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
   interval 3
   weight -10
}

vrrp_script chk_httpd {
  script "killall -0 httpd"
  interval 3
  weight -10
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 98
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 6Nb6zjWB
    }
    virtual_ipaddress {
	192.168.11.17
    }
    track_script {
	chk_down
        chk_httpd
    }
	notify_master "/etc/keepalived/notify.sh master"
	notify_backup "/etc/keepalived/notify.sh backup"
	notify_fault "/etc/keepalived/notify.sh fault"
}

vrrp_instance VI_2 {                                                     #相对上面的复制了VI_1内容并改为VI_2,配置也做了相应的修改
    state MASTER                                                         #由复制BACKUP改为MASTER
    interface eth0
    virtual_router_id 52                                                 #由51改为52
    priority 100                                                         #由98改为100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 6Nb6zjWB
    }
    virtual_ipaddress {
	192.168.11.18                                                    #地址192.168.11.17改为192.168.11.18
    }
    track_script {
	chk_down
        chk_httpd
    }
	notify_master "/etc/keepalived/notify.sh master"
	notify_backup "/etc/keepalived/notify.sh backup"
	notify_fault "/etc/keepalived/notify.sh fault"
}
[[email protected] keepalived]# service keepalived stop                            #停止keepalived服务
Stopping keepalived:                                       [  OK  ]
[[email protected] keepalived]# service keepalived start                           #启动keepalived服务【需要等待两边都stop keepalived 服务,不然会出现一些小问题】
[[email protected] keepalived]# ip add sh                                          #查看VIP地址都在这台,因为另外一台没有开启
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:2d:ba:b0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.28/24 brd 192.168.11.255 scope global eth0
    inet 192.168.11.18/32 scope global eth0
    inet 192.168.11.17/32 scope global eth0
    inet6 fe80::20c:29ff:fe2d:bab0/64 scope link 
       valid_lft forever preferred_lft forever
       
[[email protected] keepalived]# service keepalived stop                            #停止keepalived服务
停止 keepalived:                                          [确定]    
[[email protected] keepalived]# service keepalived start                           #启动keepalived服务
正在启动 keepalived:                                      [确定]
[[email protected] keepalived]# ip add sh                                          #哈哈,我胡三又回来了(192.168.11.17)
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:ad:98:5c brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.26/24 brd 192.168.11.255 scope global eth0
    inet 192.168.11.17/32 scope global eth0
    inet6 fe80::20c:29ff:fead:985c/64 scope link 
       valid_lft forever preferred_lft forever
[[email protected] keepalived]# ip add sh                                          #在K2查看,192.168.11.17 没了
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:2d:ba:b0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.28/24 brd 192.168.11.255 scope global eth0
    inet 192.168.11.18/32 scope global eth0
    inet6 fe80::20c:29ff:fe2d:bab0/64 scope link 
       valid_lft forever preferred_lft forever
You have new mail in /var/spool/mail/root

#测试就不测试了 ^-^ 不管是httpd访问停止还是在/etc/keepalived/下touch down 服务都会跑到另外一边去
时间: 2024-10-14 12:44:42

Keepalived 的script及双主的相关文章

keepalived + haproxy 实现web 双主模型的高可用负载均衡

1.本文的架构图: 阐述各服务器用途: 1.haproxy在本构架中实现的是:负载均衡 2.keepalived实现对haproxy的高可用 3.apache static 实现静态页面的访问 4.aoache dynamic实现动态页面的访问,图中有两个是实现负载均衡的 配置各功能模块: 一.配置haproxy和keepalived 验证: 1.当一台keepalived宕机后,VIP会不会转移到另外一台服务器 2.当一台haproxy服务出故障,VIP会不会转移到另外一台服务器 注意: 那如

nginx+keepalived高可用及双主模式

高可用有2中方式. 1.Nginx+keepalived 主从配置 这种方案,使用一个vip地址,前端使用2台机器,一台做主,一台做备,但同时只有一台机器工作,另一台备份机器在主机器不出现故障的时候,永远处于浪费状态,对于服务器不多的网站,该方案不经济实惠. 2.Nginx+keepalived 双主配置 这种方案,使用两个vip地址,前端使用2台机器,互为主备,同时有两台机器工作,当其中一台机器出现故障,两台机器的请求转移到一台机器负担,非常适合于当前架构环境. 1.Nginx+keepali

keepalived基于nginx实现双主模型

准备环境 Director 1 Director 2 Web Server Nginx1 Web Server Nginx DIP:172.18.42.100 DIP:172.18.42.22 RIP:172.18.42.111 RIP:172.18.42.222 VIP:172.18.42.119(MASTER) VIP:172.18.42.120(BACKUP) VIP:172.18.42.119(BACKUP) VIP:172.18.42.120(MASTER) VIP:172.18.42

Mysql HA-Install Keepalived+LVS+Mysql(双主) On Redhat 6.3

主机信息: 调度节点: Name:lvs OS:Redhat 6.3 IP:192.168.56.235 VIP:192.168.56.236 数据节点1: Name:zbdba1 OS:Redhat 6.3 IP:192.168.56.230 数据节点2: Name:zbdba2 OS:Redhat 6.3 IP:192.168.56.231 客户端: Name:ogg2 OS:Redhat 6.3 IP:192.168.56.231 描述:数据节点1跟数据节点2互为主从 ,应用从客户端访问调

Nginx+keepalived高可用(双主模式)

负载均衡技术对于一个网站尤其是大型网站的web服务器集群来说是至关重要的!做好负载均衡架构,可以实现故障转移和高可用环境,避免单点故障,保证网站健康持续运行.由于业务扩展,网站的访问量不断加大,负载越来越高.现需要在web前端放置nginx负载均衡,同时结合keepalived对前端nginx实现HA高可用.介绍下Nginx和keepalive1.Nginx Nginx 是一个很强大的高性能Web和反向代理服务器,它具有很多非常优越的特性:Nginx作为负载均衡服务器:Nginx 既可以在内部直

KeepAlived双主模式高可用集群

一.keepalived简介 keepalived是vrrp协议的实现,原生设计目的是为了高可用ipvs服务,keepalived能够配置文件中的定义生成ipvs规则,并能够对各RS的健康状态进行检测:通过共用的虚拟IP地址对外提供服务:每个热备组内同一时刻只有一台主服务器提供服务,其他服务器处于冗余状态,若当前在线的服务器宕机,其虚拟IP地址将会被其他服务器接替(优先级决定接替顺序),实现高可用为后端主机提供服务.   二.keepalived组件 Keepalived组件介绍 core:ke

KeepAlived实现HAProxy双主并实现资源的动静分离

KeepAlived实现HAProxy双主并实现资源的动静分离 大纲 前言 HAProxy介绍 实验拓扑 实验环境 实验步骤 配置后端httpd服务器 配置HAProxy实现backend负载均衡 测试动静分离效果 配置KeepAlived 测试KeepAlived 配置DNS DNS测试 最终测试 总结 前言 我们这次使用HAProxy作为负载均衡调度器来实现后端httpd服务的负载均衡和动静分离,并使用KeepAlived让HAproxy实现双主高可用, 再使用DNS轮询将用户对www.an

keepalived基于双主模型实现nginx的高可用(2)

Keepalived: keepalived是基于vrrp协议实现的一个高可用集群解决方案,可以利用keepalived来解决单点故障问题,使用keepalived实现的高可用集群方案中,一般有两台服务器,一个是MASTER(主服务器),另一个是BACKUP(备用服务器),这个集群中对外提供一个虚拟IP,MASTER服务器会定时发送特定信息给BACKUP服务器,当BACKUP服务器接收不到MASTER发送的消息时,BACKUP服务器会接管虚拟IP,继续提供服务. 当keepalived基于主备模

keepalived+mysql双主复制高可用方案

MySQL双主复制,即互为Master-Slave(只有一个Master提供写操作),可以实现数据库服务器的热备,但是一个Master宕机后不能实现动态切换.而Keepalived通过虚拟IP,实现了双主对外的统一接口以及自动检查.失败切换机制.联合使用,可以实现MySQL数据库的高可用方案. 实验环境:OS:centos 6.x x86_64系统MySQL版本: :mysql 5.6.22   64 位A: master :192.168.79.3 3306B: slave :192.168.