码迷,mamicode.com
首页 > 其他好文 > 详细

Keepalived实现Nginx与LVS高可用

时间:2016-06-14 16:17:54      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:blank   border   target   style   title   

 

技术分享

在192.168.1.10和192.168.1.20分别安装:

#yum –y install keepalived

192.168.1.10的配置文件内容:

#vim keepalived.conf

! Configuration File for keepalived

global_defs {

notification_email {

root@localhost

}

notification_email_from keepalived@localhost

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id LVS_DEVEL

}

vrrp_script chk_nginx {

script "pidof nginx "

interval 1

weight -3

fall 2

rise 1

}

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.1.100

}

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 "

}

192.168.1.20的配置文件内容:

#vim keepalived.conf

! Configuration File for keepalived

global_defs {

notification_email {

root@localhost

}

notification_email_from keepalived@localhost

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id LVS_DEVEL

}

vrrp_script chk_nginx {

script "pidof nginx "

interval 1

weight -1

fall 2

rise 1

}

vrrp_instance VI_1 {

state BACKUP

interface eth0

virtual_router_id 51

priority 99

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.1.100

}

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 "

}

主备服务器上的脚本内容:

#vim /etc/keepalived/notify.sh notify.sh

#!/bin/bash

case "$1" in

master)

/etc/init.d/nginx start

exit 0

;;

backup)

/etc/init.d/nginx stop

exit 0

;;

fault)

/etc/init.d/nginx stop

exit 0

;;

*)

echo ‘Usage: `basename $0` {master|backup|fault}‘

exit 1

;;

esac

主备服务器上LVS配置内容:

virtual_server 192.168.1.100 80 {

delay_loop 6

lb_algo rr

lb_kind DR

nat_mask 255.255.255.0

persistence_timeout 0

protocol TCP

real_server 192.168.1.30 80 {

weight 1

HTTP_GET {

url {

path /demo.php

status_code 200

}

connect_timeout 3

nb_get_retry 3

delay_before_retry 3

}

}

real_server 192.168.1.40 80 {

weight 1

HTTP_GET {

url {

path /demo.php

status_code 200

}

connect_timeout 3

nb_get_retry 3

delay_before_retry 3

}

}

}

在nginx1和nginx2上分别运行一下命令:

ip addr add 192.168.1.100/32 label lo:0 brd 192.168.1.100 dev lo

echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore

echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce

echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore

echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce

Keepalived实现Nginx与LVS高可用

标签:blank   border   target   style   title   

原文地址:http://wjb10000.blog.51cto.com/9702295/1789074

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!