keepalived单主模型和nginx双主模型

主程序:keepalived

主配置文件:/etc/keepalived/keepalived.conf

单主模型ipvs:

global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node1
vrrp_mcast_group4 224.0.100.19
}
vrrp_instance VI_1 {
state MASTER
interface eno16777736
virtual_router_id 14
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 571f97b2
}
virtual_ipaddress {
10.1.0.93/16 dev eno16777736
}
notify_master “/etc/keepalived/notify.sh master”
notify_backup “/etc/keepalived/notify.sh backup”
notify_fault “/etc/keepalived/notify.sh fault”
}
virtual_server 10.1.0.93 80 {
delay_loop 3
lb_algo rr
lb_kind DR
protocol TCP
sorry_server 127.0.0.1 80
real_server 10.1.0.69 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 1
nb_get_retry 3
delay_before_retry 1
}
}
real_server 10.1.0.71 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 1
nb_get_retry 3
delay_before_retry 1
}
}
}

双主模型nginx:

global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node1
vrrp_mcast_group4 224.0.100.19
}
vrrp_script chk_down {
script “[[ -f /etc/keepalived/down ]] && exit 1 || exit 0”
interval 1
weight -5
}
vrrp_script chk_nginx {
script “killall -0 nginx && exit 0 || exit 1”
interval 1
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 14
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 571f97b2
}
virtual_ipaddress {
172.16.0.99/16 dev ens33
}
track_script {
chk_down
chk_nginx
}
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 {
state MASTER
interface ens33
virtual_router_id 24
priority 96
advert_int 1
authentication {
auth_type PASS
auth_pass 571errrb2
}
virtual_ipaddress {
172.16.0.98/16 dev ens33
}
track_script {
chk_down
chk_nginx
}
notify_master “/etc/keepalived/notify.sh master”
notify_backup “/etc/keepalived/notify.sh backup”
notify_fault “/etc/keepalived/notify.sh fault”
}

示例通知脚本:

#!/bin/bash
#
contact=’root@localhost’
notify() {
mailsubject=”$(hostname) to be $1, vip floating”
mailbody=”$(date +’%F %T’): vrrp transition, $(hostname) changed to be $1″
echo “$mailbody” | mail -s “$mailsubject” $contact
}
case $1 in
master)
notify master
;;
backup)
notify backup
;;
fault)
notify fault
;;
*)
echo “Usage: $(basename $0) {master|backup|fault}”
exit 1
;;
esac

原创文章,作者:z long,如若转载,请注明出处:http://www.178linux.com/84220

(1)
z longz long
上一篇 2017-08-08
下一篇 2017-08-08

相关推荐

  • Hello World

    随笔

    Linux干货 2018-03-26
  • shell编程循环语法作业

    判断/var/目录下所有文件的类型 [root@www sh.log]# cat typefile.sh  #!/bin/bash #author:DYW #显示目录下文件类型 if [ $# -lt 1 ];then echo "Please&nb…

    Linux干货 2016-08-21
  • N-28作业第一周

    N-28作业第一周小结:以前看存储视频里面讲存储架构里不清楚的部分居然开始清晰。基础命令需要多花时间熟悉。

    2017-12-05
  • 文本处理工具和shell脚本基本编程

    文本处理工具 grep 对文本进行搜索获取我们想要的行(关键信息) egrep 支持扩展正则表达式的grep fgrep 快速搜索不支持正则    -v 取反  找出不包含“pattern”的行  -i 忽略字符的大小写  -n 显示行号  -c 显示统计到的行数,等同于wc -l  -o…

    2017-04-09
  • 数据库的备份和恢复

    数据库的备份和恢复 一 (理论篇)、数据库备份与恢复基础 1、数据库的备份与恢复 备份:存储的数据副本; 原始数据:持续改变; 恢复:把副本应用到线上系统; 仅能恢复至备份操作时刻的数据状态; 时间点恢复: binary logs; 2、为什么备份? 灾难恢复: 硬件故障(冗余)、软件故障(bug)、自然灾害、黑客攻击、误操作、…&nb…

    2016-11-22
  • 在Centos系统上安装EPEL扩展源以及安装htop工具

        Htop是一个强大的进程管理前端工具,但这是一个扩展工具,一般在Centos系统源中并没有,所有我们需要到fedora-epel源中下载。         EPEL即Extra Packages for Enterprise Lin…

    Linux干货 2016-02-14