keepalived + nginx

本文主要介紹keepalived的安裝,Nginx自行解決,也能夠使用httpd.隨便任何服務均可以...html

keepalived 官網http://www.keepalived.org/index.html#linux

我不的不吐槽keepalived 官方文檔寫的...web

環境:oop

CentOS 6.6x64 minimal 禁用selinux iptablesspa

1.安裝環境包:3d

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

2.安裝keepalived:code

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

 (最新的包本身去官網下)router

安裝很簡單,可是裝完我不得不吐槽了..server

3.配置:htm

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
    }
}
相關文章
相關標籤/搜索