keepAlived主备及双主

nginx用默认配置即可

1、主备配置

1、主keepAlived配置

vrrp_instance VI_1 {
    state MASTER   #主备区分
    interface eth0
    virtual_router_id 51  #主备一致
    priority 100   #主备区分
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
    track_script {
        chk_nginx
    }
}

2、备keepAlived配置

vrrp_instance VI_1 {
    state BACKUP  #主备区分
    interface eth0
    virtual_router_id 51   #主备一致
    priority 50     #主备区分
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
}

2、互为主备

1、第一台keepAlived配置

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface eth0
    virtual_router_id 52
    priority 50
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.244.201
    }
}

2、第二台keepAlived配置

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 50
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
}
vrrp_instance VI_2 {
    state MASTER
    interface eth0
    virtual_router_id 52
    priority 100
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.244.201
    }
}

3、检测nginx,实现主备高可用

1、第一台keepAlived配置

vrrp_script chk_nginx {
    script "/zjl/program/nginx/conf/checkNginxAlived.sh"
    interval 2
    weight 2
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
    track_script {
        chk_nginx
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface eth0
    virtual_router_id 52
    priority 50
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.244.201
    }
    track_script {
        chk_nginx
    }
}

2、第二台keepAlived配置

vrrp_script chk_nginx {
    script "/zjl/program/nginx/conf/checkNginxAlived.sh"
    interval 2
    weight 2
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 50
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
    track_script {
        chk_nginx
    }
}
vrrp_instance VI_2 {
    state MASTER
    interface eth0
    virtual_router_id 52
    priority 100
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.244.201
    }
    track_script {
        chk_nginx
    }
}

3、监测脚本

#!/bin/bash
psnginx=`ps -C nginx --no-heading|wc -l`
if [ $psnginx == 0 ] ; then
    echo "nginx服务已关闭,尝试重新启动..."
    /zjl/commond/nginxbegin-start.sh
    sleep 3
    if [ `ps -C nginx --no-heading|wc -l` -eq 0 ] ; then
        echo "nginx尝试启动失败关闭keepAlived"
        killall keepalived
    else
        echo "nginx重新启动成功"
    fi
else
    echo "nginx服务正常..."
fi

原文地址:https://www.cnblogs.com/happydreamzjl/p/10986237.html

时间: 2024-10-08 09:55:13

keepAlived主备及双主的相关文章

haproxy+keepalived主备与双主模式配置

Haproxy+Keepalived主备模式 主备节点设置 主备节点上各安装配置haproxy,配置内容且要相同 global log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon defaults #defaults段默认值对frontend和backend和listen段生效 mode http #运行模式

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高可用(双主模式)

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

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

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 

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互为主从 ,应用从客户端访问调

mysql主主复制(双主复制)配置步骤

以前我们介绍的都是主从复制,这里给各位介绍一个双主复制了,下面都希望两个主服务器数据自动复制的话可参考一下此文章. MySQL主主复制结构区别于主从复制结构.在主主复制结构中,两台服务器的任何一台上面的数据库存发生了改变都会同步到另一台服务器上,这样两台服务器互为主从,并且都能向外提供服务.有了上一节的主从复制,那么主主复制就很容易了. 一.先修改配置文件 服务器A(192.168.1.254)配置如下 log-bin   = mysql-binserver-id = 1 expire-logs

mysql 主主复制(双主复制)binlog-do-db

[[email protected] ~]# grep "binlog-do-db" /etc/my.cnf binlog-do-db = test [[email protected] ~]# grep "binlog-do-db" /etc/my.cnf binlog-do-db=test binlog-do-db=test2 DB: mysql> use test2; Database changed mysql> show tables; Emp