Keepalived 安装配置
版本信息
Linux version 3.10.0-514.el7.x86_64
keepalived-1.3.6
mkdir /usr/local/keepalived/
cd /keepalived/keepalived-1.3.6
yum install gcc -y
yum install openssl-devel -y
./configure --prefix=/usr/local/keepalived/
make&&make install
mkdir /etc/keepalived
vim /etc/init.d/keepalived
chmod +x /etc/init.d/keepalived
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
vi /etc/keepalived/keepalived.conf
vim /usr/local/keepalived/bin/mysql.sh
service keepalived start
chkconfig --add keepalived
chkconfig --level 35 keepalived on
systemctl enable keepalived.service
#配置文件keepalived.conf#
#! Configuration File for keepalived
global_defs {
router_id mysql-ha1 #修改为自己的主机名
}
##################第一部分###################
vrrp_instance VI_1 {
state BACKUP #都修改成BACKUP
interface ens160
virtual_router_id 60 #默认51 主从都修改为60
priority 80 #在mysql-ha2上LVS上修改成80
advert_int 1
nopreempt #不抢占资源,意思就是它活了之后也不会再把主抢回来
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.80.148
}
}
##################第二部分###################
virtual_server 10.0.80.148 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 10.0.80.135 3306 {
weight 1
notify_down /usr/local/mysql/bin/mysql.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
connect_port 3306
}
}
}
#配置文件/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.d/init.d/functions
# Source configuration file (we set KEEPALIVED_OPTIONS there)
. /etc/sysconfig/keepalived
RETVAL=0
prog="keepalived"
start() {
echo -n $"Starting $prog: "
daemon keepalived ${KEEPALIVED_OPTIONS}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
}
stop() {
echo -n $"Stopping $prog: "
killproc keepalived
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
}
reload() {
echo -n $"Reloading $prog: "
killproc keepalived -1
RETVAL=$?
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)
status keepalived
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|reload|restart|condrestart|status}"
RETVAL=1
esac
#配置文件 /usr/local/keepalived/bin/mysql.sh#
#!/bin/bash
pkill keepalived