BACKUP的安装和Master的安装基本一致,只是一些参数略有变化。 变化的参数如下: 1、keepalived.conf文件中 原:state MASTER #标示状态为MASTER 备份机为BACKUP state BACKUP #标示状态改为BACKUP 原:priority 100 #MASTER权重要高于BACKUP 比如BACKUP为99 priority 99 #MASTER权重要高于BACKUP,MASTER为100,那么BACKUP略小于,比如99
8、开机启动HAProxy:为了方便系统在开机时加载,还可以创建启动脚本: # vim /etc/rc.d/init.d/haproxy 内容如下: #! /bin/sh set -e PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/haproxy/sbin PROGDIR=/usr/local/haproxy PROGNAME=haproxy DAEMON=$PROGDIR/sbin/$PROGNAME CONFIG=$PROGDIR/conf/$PROGNAME.conf PIDFILE=$PROGDIR/run/$PROGNAME.pid DESC="HAProxy daemon" SCRIPTNAME=/etc/init.d/$PROGNAME # Gracefully exit if the package has been removed. test -x $DAEMON || exit 0 start() { echo -n "Starting $DESC: $PROGNAME" $DAEMON -f $CONFIG echo "." } stop() { echo -n "Stopping $DESC: $PROGNAME" haproxy_pid=cat $PIDFILE kill $haproxy_pid echo "." } restart() { echo -n "Restarting $DESC: $PROGNAME" $DAEMON -f $CONFIG -p $PIDFILE -sf $(cat $PIDFILE) echo "." } case "$1" in start) start ;; stop) stop ;; restart) restart ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2 exit 1 ;; esac exit 0 保存后赐予可执行权限 # chmod +x /etc/rc.d/init.d/haproxy 就可以使用 service haproxy start|stop|restart 来控制服务的启动停止跟重启。 并通过以下命令加载到开机服务启动列表 # chkconfig --add haproxy
8、维护HAProxy和Keepalived: