keepalived + nginx

本文主要介绍keepalived的安装,Nginx自行解决,也可以使用httpd.随便任何服务都可以...

keepalived 官网http://www.keepalived.org/index.html#

我不的不吐槽keepalived 官方文档写的...

环境:

CentOS 6.6x64 minimal 禁用selinux iptables

1.安装环境包:

yum install openssl-devel gcc popt wget  libnl-devel -y

2.安装keepalived:

wget http://www.keepalived.org/software/keepalived-1.2.19.tar.gz
tar xvf  keepalived-1.2.19.tar.gz
cd keepalived-1.2.19
./configure
make
make install

 (最新的包自己去官网下)

安装很简单,但是装完我不得不吐槽了..

3.配置:

mkdir /etc/keepalived
ln -s /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
ln -s /usr/local/etc/sysconfig/keepalived  /etc/sysconfig/keepalived
ln -s /usr/local/etc/rc.d/init.d/keepalived  /etc/rc.d/init.d/keepalived
ln -s /usr/local/sbin/keepalived /usr/bin/

 

主要用ln是为了方便管理.这个keepalived都安装在/etc/user/local 而他却需要的配置文件又是从/开始的 所以搞不懂....

4.真正的配置keepalived.conf

cd /usr/local/etc/keepalived/
vi keepalived.conf

 

 Master(样例):  

[root@web2 ~]# cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    mcast_src_ip 192.168.6.25
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.6.20
    }

 

解释一下:
因为我没有使用LVS所以virtual server段都被删除了....
global_defs{ #块全局的配置(也没发现能配置什么)
notification_email {} #通知邮件的收件人,下边from 就是发件人
支持SMTP.但是不支持用户登录(找了好多文档也没找到用户登陆的user和passwd 谁知道可以留言)
route_id #不知道什么估计就是keepalived的iD名字吧,或者和LVS有关系

}

VRRP_instance VI_1{ #VRRP实例段,关键地方 VI_1 也可以有VI_2,不同的VRRP实例 需要不同的 virtual_router_id

 

state  #标记主备的 MASTER主BACKUP是备
interface #VIP绑定在哪个网卡上
virtual_router_id # VRRP实例的ID用来区分不同的VRRP
mcast_src_ip #VRRP包的封装IP,真实网卡IP
priority #权重,主备之间值不一样,值越大越优先,做实验的时候忘记改了..结果 VIP回不到主上..
advert_int #指定VRRP广播包发送间隔
authentication #VRRP实例之间的认证
virtual_ipaddress #VIP 就是用户要访问的IP地址.这个ip地址会在不同的keepalived实例上飞来飞去

}

5.查看IP

[root@web2 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:35:cb:3d brd ff:ff:ff:ff:ff:ff
inet 192.168.6.25/24 brd 192.168.6.255 scope global eth0
inet 192.168.6.20/32 scope global eth0
inet6 fe80::5054:ff:fe35:cb3d/64 scope link
valid_lft forever preferred_lft forever

6.监控

这个东西不会主动去监控服务是否正常.自己写脚本监控主机上的服务如果服务不正常就把keepalived停掉就好了...

 

BACKUP(样例):

[root@we1 ~]# cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 99
    mcast_src_ip 192.168.6.26
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.6.20
    }
}

 

posted on 2015-07-16 16:21  Mo-_-!  阅读(491)  评论(0编辑  收藏  举报

导航