I.保持存活
见上图->提前做好前提准备;保持基本设备的活力
第二,保持LVS的高可用性
Keepalived可以根据环境变量形成ipvs标准,还可以检查后端开发的每个RS的身心健康状况。
1.测试详情
目录1:节点1192.168.0.40
目录2:Nginx192.168.0.108
贵宾:192.168.0.80
RS1(httpd):192.168.0.100
RS2(httpd):192.168.0.101
2.环境变量
[root@Nginx ~]# cd /etc/keepalived/ [root@Nginx keepalived]# vim keepalived.conf ! Configuration File for keepalived global_defs { notification_email { root@localhost } notification_email_from kaadmin@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_script chk_mt { script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0" interval 1 weight -2 } vrrp_instance VI_1 { state MASTER #node1须改动为BACKUP interface eth0 virtual_router_id 51 priority 100 #node1减少优先 advert_int 1 authentication { auth_type PASS auth_pass 71988d704dcae985 } virtual_ipaddress { 192.168.0.80/32 } track_script { chk_mt } 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.0.80 80 { delay_loop 6 #网络服务器轮询6次请求超时 lb_algo rr #LVS生产调度优化算法 lb_kind DR #LVS分享方式 nat_mask 255.255.255.0 #掩码 persistence_timeout 50 #长连接時间 protocol TCP #tcp协议 ha_suspend #在无vip情况下,已不开展身心健康情况检验 sorry_server 127.0.0.1 80 #当RS全服务器宕机时,sorry_server出示不正确网页页面 real_server 192.168.0.100 80 { #RS的ip,端口号 weight 1 #权重值 HTTP_GET { #检验种类,这儿是HTTP_GET url { #检验要求的种类,这儿是情况检验 path / status_code 200 } connect_timeout 3 #网络连接超时時间 nb_get_retry 3 #再试频次 delay_before_retry 3 #再试前时间延迟 } } real_server 192.168.0.101 80 { weight 2 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }3.定义通知脚本的制作(来自Marco的文本文档),用于在情况发生变化后发送电子邮件。
#!/bin/bash # vip=192.168.0.80 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 exit 0 ;; backup) notify backup exit 0 ;; fault) notify fault exit 0 ;; *) echo 'Usage: `basename $0` {master|backup|fault}' exit 1 ;; esac二。高可用性Nginx
1.Nginx服务器配备了反向代理上游。
http路段配备 upstream nodeserver{ server 192.168.0.30; server 192.168.0.40; } server路段配备 location / { proxy_pass http://nodeserver; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; add_header X-Cache $upstream_cache_status; }2.配备keepalived,添加以下设备
global_defs { notification_email { root@localhost } notification_email_from kaadmin@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_script chk_nginx { script "killall -0 nginx &> /dev/null" interval 1 weight -10 } vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 71988d704dcae985 } virtual_ipaddress { 192.168.0.80/32 } track_script { chk_nginx } notify_master "/etc/keepalived/notify.sh master" notify_backup "/etc/keepalived/notify.sh backup" notify_fault "/etc/keepalived/notify.sh fault" }欢迎分享,转载请注明来源:内存溢出
评论列表(0条)