- A+
所属分类:WEB应用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
[root@master ~]# cat /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { 351937287@qq.com #配置管理员邮箱 } notification_email_from root #配置发件人 smtp_server 127.0.0.1 #配置邮件服务器 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_script chk_mantaince_down { #定义脚本检测 script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0" #检测文件是否存在,存在返回1,不存在0 interval 1 #1秒检测一次 weight -2 #失败后权重-2 fall 2 #失败判断2次 rise 1 #成功判断1次 } vrrp_instance VI_1 { state MASTER #配置模式 interface eth0 #vip绑定接口 virtual_router_id 51 #router_id priority 101 #配置优先级 advert_int 1 authentication { auth_type PASS #认证 auth_pass 1111 #认证密码 } virtual_ipaddress { 192.168.18.200 #配置虚拟IP地址 } track_script { #配置执行上面定义的脚本 chk_mantaince_down 上面定义的脚本 } notify_master "/etc/keepalived/notify.sh master" 当切换主节点执行 通常用于发邮件通知管理员 notify_backup "/etc/keepalived/notify.sh backup" 当切换备节点执行 notify_fault "/etc/keepalived/notify.sh fault" 当切无法连接执行 } virtual_server 192.168.18.200 80 { #lvs配置部分,设置IP 端口 delay_loop 6 lb_algo rr #设置权重模型 lb_kind DR #DR模型 nat_mask 255.255.255.0 #persistence_timeout 50 #长连接超时 protocol TCP real_server 192.168.18.201 80 { #配置rs weight 1 HTTP_GET { #监控配置 ,通过HTTP监控,还有ssl,tcp,smtp url { path / #监控网址 status_code 200 #检测状态码200 } connect_timeout 2 #检测时长 nb_get_retry 3 delay_before_retry 1 } } real_server 192.168.18.202 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 2 nb_get_retry 3 delay_before_retry 1 } } sorry_server 127.0.0.1 80 #增加一行sorry_server ,当所有节点挂掉就启用临时页面 } 下面是一个notify.sh脚本的简单示例: #!/bin/bash # # # vip=172.16.100.1 contact='root@localhost' notify() { mailsubject="`hostname` to be $1: $vip floating" mailbody="`date '+%F %H:%M:%S'`: vrrp transition, `hostname` changed to be $1" echo $mailbody | mail -s "$mailsubject" $contact } case "$1" in master) notify master /etc/rc.d/init.d/haproxy start exit 0 ;; backup) notify backup /etc/rc.d/init.d/haproxy stop exit 0 ;; fault) notify fault /etc/rc.d/init.d/haproxy stop exit 0 ;; *) echo 'Usage: `basename $0` {master|backup|fault}' exit 1 ;; esac |
- 我的微信
- 这是我的微信扫一扫
- 我的微信公众号
- 我的微信公众号扫一扫