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

相关推荐

  • 初学者通过VMware安装CentOS7并实现本机windows端Xshell远程登陆

    这是我这个菜鸟在学习Linux过程中写的第一篇Blog。内容主要是通过VMware安装CentOS7系统,并且在本机的Windows端通过Xshell5来远程登陆安装好的虚拟机CentOS7系统。 首先通过VMware安装完CentOS7并进入系统。 使用root权限操作,通过 ~]#ifconfig or ~]#ip addr list 命令查询到虚拟机系…

    2017-10-11
  • grep的用法

    grep的用法 1、复制/etc/skel目录为/home/tuser1及其内容文件的属组和其它用户均没有任何访问权限。 cp -R /etc/skel /home/thuser1 #复制文件/etc/skel 到/home/目录下并改名为thuser1 chmod -R 700 /home/thuser1 #更改/home/thuser1目录权限为属主全部…

    Linux干货 2017-07-23
  • PXE自动化安装Centos7

    一、PXE介绍     PXE: Preboot Excution Environment,由Intel公司研发,可以使没有任何操作系统的主机能够基于网络完成系统的安装工作,实现服务器的自动化安装系统 二、PXE工作原理 Client向PXE Server上的DHCP发送IP地址请求消息,DHCP检测Client是否合…

    2017-07-24
  • bash脚本编程之数组、高级字符串处理、高级变量操作、用户环境配置

    概述:     承接之前脚本编程部分,本篇将介绍一下脚本编程基础语法的最后一部分内容,具体分为:         1、数组简介         2、高级字符串处…

    Linux干货 2016-08-24
  • CentOS7.3安装Jumpserver0.3.2

    CentOS7.3安装Jumpserver0.3.2 公司服务器前端增加堡垒机,选用开源的jumpserver 软件环境CentOS Linux release 7.3.1611 python 2.7.5 mysql5.7 安装git yum -y install git 克隆jumpserver # cd /opt # git clone https://…

    Linux干货 2017-07-11