544323 发表于 2016-9-22 09:22:03

KeepAlived1.1.17安装及配置说明

1.1KeepAlived1.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: 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: Leaving directory `/usr/local/src/keepalived-1.1.16/keepalived'
make -C genhash install
make: 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: 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.confto /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都将视为路由器出现故障。

页: [1]
查看完整版本: KeepAlived1.1.17安装及配置说明