KeepAlived1.1.17安裝及配置說明

1.1  KeepAlived1.1.17安裝及配置說明

使用源碼方式安裝,

1.1.1   準備工作

tar -zxf keepalived-1.1.13.tar.gz

cp keepalived-1.1.13 /usr/local/src

cd /mnt/suse64/suse/x86_64

rpm -ivhopenssl-devel-0.9.8a-18.26.x86_64.rpm

rpm -ivh popt-devel-1.7-271.27.x86_64.rpm

1.1.2   正式安裝

cd /usr/local/src/keepalived-1.1.16/

./configure

make

make install

應有如下結果

make -C keepalived install

make[1]: Entering directory`/usr/local/src/keepalived-1.1.16/keepalived'

install -d /usr/local/sbin

install -m 700 ../bin/keepalived/usr/local/sbin/

install -d /usr/local/etc/rc.d/init.d

install -m 755 etc/init.d/keepalived.init/usr/local/etc/rc.d/init.d/keepalived

install -d /usr/local/etc/sysconfig

install -m 755etc/init.d/keepalived.sysconfig /usr/local/etc/sysconfig/keepalived

install -d/usr/local/etc/keepalived/samples

install -m 644etc/keepalived/keepalived.conf /usr/local/etc/keepalived/

install -m 644 ../doc/samples/*/usr/local/etc/keepalived/samples/

install -d /usr/local/share/man/man5

install -d /usr/local/share/man/man8

install -m 644../doc/man/man5/keepalived.conf.5 /usr/local/share/man/man5

install -m 644 ../doc/man/man8/keepalived.8/usr/local/share/man/man8

make[1]: Leaving directory `/usr/local/src/keepalived-1.1.16/keepalived'

make -C genhash install

make[1]: Entering directory`/usr/local/src/keepalived-1.1.16/genhash'

install -d /usr/local/bin

install -m 755 ../bin/genhash/usr/local/bin/

install -d /usr/local/share/man/man1

install -m 644 ../doc/man/man1/genhash.1/usr/local/share/man/man1

make[1]: Leaving directory`/usr/local/src/keepalived-1.1.16/genhash'

因爲系統使用suse,而該程序針對redhat系統,所以我們需要自行配置

1.1.3   服務配置

cd /usr/local/etc

mv keepalived /etc  (移動配置目錄到etc

cd sysconfig

mv keepalived /etc/sysconfig  (移動程序運行參數配置文件,缺省參數爲使用明細日誌)

/etc/init.d目錄下建立文件keepalived,內容如下:

 

 

#!/bin/sh

#

# Startup script for the Keepalived daemon

#

# processname: keepalived

# pidfile: /var/run/keepalived.pid

# config: /etc/keepalived/keepalived.conf

# chkconfig: - 21 79

# description: Start and stop Keepalived

 

# Source function library

. /etc/rc.status

 

# Source configuration file (we setKEEPALIVED_OPTIONS there)

. /etc/sysconfig/keepalived

 

rc_reset

 

prog="keepalived"

 

start() {

   echo -n $"Starting $prog: "

   $prog ${KEEPALIVED_OPTIONS}

   rc_status -v

   touch /var/lock/subsys/$prog

}

 

stop() {

   echo -n $"Stopping $prog: "

   killproc $prog

   rc_status -v

   rm -f /var/lock/subsys/$prog

}

 

reload() {

   echo -n $"Reloading $prog: "

   killproc $prog -1

   echo

}

 

# See how we were called.

case "$1" in

   start)

       start

       ;;

   stop)

       stop

       ;;

   reload)

       reload

       ;;

   restart)

       stop

       start

       ;;

   condrestart)

       if [ -f /var/lock/subsys/$prog ]; then

           stop

           start

       fi

       ;;

   status)

       /sbin/checkproc $prog

       rc_status -v

       ;;

   *)

       echo "Usage: $0{start|stop|reload|restart|condrestart|status}"

       exit 1

       ;;

esac

 

rc_exit

 

保證該文件的權限信息如下:

-rwxr-xr-x 1 root root 1.2K 2009-04-2014:13 keepalived

 

chkconfig --level 35 keepalived on  #set the keepalived service auto start whenthe system is booting

#copy the config which name iskeepalived.conf  to /etc/keepalived(dir)

#this config file declare the vrrp rule.

啓動/停止/重新裝載配置/當前運行狀態:

service keepalived start|stop|reload|status

診斷IP情況命令

ip addr

1.1.4   配置文件參考

文件在/etc/keepalived/目錄下

Master的配置文件

 

vrrp_instance VI_INET1 {

       state MASTER                   #(主機爲MASTER,備用機爲BACKUP)

       interface eth0                #(HA監測網絡接口)

       mcast_src_ip 192.168.7.191    #(VRRP Multicast廣播源地址,分別取主、備機地址,不能取與virtual_ipaddress相同)

     track_interface {

        Eth1                         #監測狀態的接口

     }  

       virtual_router_id 53            #(主、備機的virtual_router_id必須相同)

       priority 200                    #(主、備機取不同的優先級,主機值較大,備份機值較小,值越大優先級越高)

       advert_int 5                   #(VRRP Multicast廣播週期秒數)

       authentication {

                auth_type pass          #(VRRP認證方式)

                auth_pass yourpass      #(VRRP口令字)        

       }

      virtual_ipaddress {

              192.168.7.100              #(VRRP HA虛擬地址)

        }

}

Slave的配置文件

vrrp_instance VI_INET1 {

       state BACKUP

       interface eth0

       track_interface {

      eth1       

       }

      virtual_router_id 53

      priority 100

      advert_int 5

      authentication {

                auth_type pass

                auth_pass yourpass

      }

     virtual_ipaddress {

                192.168.7.100

       }

}

 

track_interface的意思是將Linux中你想監控的網絡接口卡監控起來,當其中的一塊出現故障是keepalived都將視爲路由器出現故障。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章