keepalived安装
keepalive 安装
https://www.keepalived.org/download.html
#环境安装
yum -y install kernel-devel* openssl-* popt-devel lrzsz openssh-clients libnl libnl-devel popt
#将keepalived-2.0.10.tar.gz上传到服务器/usr/local/下。
cd /usr/local
tar -zxvf keepalived-2.0.10.tar.gz
cd keepalived-2.0.10
#执行配置命令
./configure --prefix=/usr/local/keepalived
#编译
make
#安装
make install
配置开机启动
#拷贝执行文件
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
#将init.d文件拷贝到etc下,加入开机启动项 (错误:缺少rc.d 目录,1.2版本之后,这个目录编译后不再出现放在源码包里面)
cp /usr/local/keepalived-2.0.10/keepalived/etc/init.d/keepalived /etc/init.d/keepalived
#将keepalived文件拷贝到etc下,加入网卡配置
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
#创建keepalived文件夹
mkdir -p /etc/keepalived
#将keepalived配置文件拷贝到etc下
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
#添加可执行权限
chmod +x /etc/init.d/keepalived
#加入开机启动:
chkconfig --add keepalived #添加时必须保证/etc/init.d/keepalived存在
chkconfig keepalived on
#添加完可查询系统服务是否存在:
chkconfig --list
启动
#启动
service keepalived start
#停止
service keepalived stop
#重启
service keepalived restart
配置日志文件
#将keepalived日志输出到local0:
vi /etc/sysconfig/keepalived
KEEPALIVED_OPTIONS="-D -d -S 0"
#在/etc/rsyslog.conf里添加:
local0.* /var/log/keepalived.log
#重新启动keepalived和rsyslog服务:
service rsyslog restart
service keepalived restart
keepalive 主备配置文件
#####主
$ cat keepalived.conf
vrrp_instance VI_1 {
state MASTER
interface enp7s0f0
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
172.24.8.150
}
}
####备
vrrp_instance VI_1 {
state MASTER
interface enp7s0f0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
172.24.8.150
}
}
yum 安装的配置
检测docker容器的端口是否正常
# chk_mysql.sh
#!/bin/bash
counter=$(ss -tanlp |grep "LISTEN"|grep "3306"|wc -l)
if [ "${counter}" -eq 0 ]
then
systemctl stop keepalived
else
echo "running..." >> /opt/keepalived-running-info.log
#sleep 5000
fi
# 主keepalived 配置文件
! Configuration File for keepalived
global_defs {
script_user root
enable_script_security
router_id keep_89
}
vrrp_script chk_mysql {
script "/opt/chk_mysql.sh"
interval 2
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 57
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.169.135
}
track_script {
chk_mysql
}
}
# 备keepalived配置文件
! Configuration File for keepalived
global_defs {
script_user root
enable_script_security
router_id keep_88
}
vrrp_script chk_mysql {
script "/opt/chk_mysql.sh"
interval 2
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 57
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.169.135
}
track_script {
chk_mysql
}
}
可以参考的连接:
https://www.cnblogs.com/arjenlee/p/9258188.html 优先级策略
https://my.oschina.net/u/2347651/blog/3011012
https://blog.csdn.net/William0318/article/details/99595966 抢占模式
https://blog.csdn.net/harryxxxxx/article/details/81092263
https://www.cnblogs.com/xiaobaozi-95/p/11497295.html
https://www.jianshu.com/p/d9b6bbc7fd77 mysql 容器
镜像拉的慢配置阿里云加速仓库