欢迎各位兄弟 发布技术文章
这里的技术是共享的
yum安装
以下为离线安装
1.下载地址:
http://www.keepalived.org/software/keepalived-2.0.6.tar.gz
https://share.weiyun.com/5NNQ15a
linux下载
没有wget 先安装 yum -y install wget
wget http://www.keepalived.org/software/keepalived-2.0.6.tar.gz
解压:
tar -zxvf keepalived-2.0.6.tar.gz
1
编译:
cd keepalived-2.0.6
./configure --prefix=/usr/local/keepalived #prefix 指定安装的目录
1
2
报错了:configure: error: libnfnetlink headers missing
参考:https://blog.yoodb.com/yoodb/article/detail/1378
解决方案一:(在线安装)
执行yum命令yum install -y libnfnetlink-devel解决上述错误问题
1
解决方案二:(离线安装)
Linux执行wget下载rpm包(离线安装libnfnetlink包时所需rpm包,执行wget下载libnfnetlink rpm包命令,此步可以忽略,只是为大家提供个下载libnfnetlink地址),具体命令如下:
wget ftp://mirror.switch.ch/mirror/centos/6/os/x86_64/Packages/libnfnetlink-1.0.0-1.el6.x86_64.rpm
wget ftp://mirror.switch.ch/mirror/centos/6/os/x86_64/Packages/libnfnetlink-devel-1.0.0-1.el6.x86_64.rpm
1
2
或者从官网下载 https://pkgs.org/download/libnfnetlink-devel
rpm -ivh libnfnetlink-devel-1.0.1-4.el7.x86_64.rpm
1
阿偶 忘了昨天已经安装了
cd keepalived-2.0.6
./configure --prefix=/usr/local/keepalived
1
2
make && make instal #编译keepalive 不知道为啥我执行了两边才在/usr/local/keepalived
1
cp /usr/local/keepalived/sbin/keepalived /etc/init.d/
cp /usr/local/keepalived/sbin/keepalived /etc/sysconfig/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
1
2
3
打开
/usr/local/keepalived/etc/keepalived/keepalived.conf
参考:
https://blog.yoodb.com/yoodb/article/detail/1378
https://blog.csdn.net/liurui_wuhan/article/details/81910882
cd /usr/local/src
wget http://www.keepalived.org/software/keepalived-2.0.7.tar.gz
tar xvf keepalived-2.0.7.tar.gz
cd keepalived-2.0.7
./configure --prefix=/usr/local/keepalived
make && make install
完成后会在以下路径生成:
/usr/local/etc/keepalived/keepalived.conf
/usr/local/etc/sysconfig/keepalived
/usr/local/sbin/keepalived
# keepalived启动脚本变量引用文件,默认文件路径是/etc/sysconfig/,也可以不做软链接,直接修改启动脚本中文件路径即可(安装目录下)
[root@localhost /]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived
# 将keepalived主程序加入到环境变量(安装目录下)
[root@localhost /]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/keepalived
# keepalived启动脚本(源码目录下),放到/etc/init.d/目录下就可以使用service命令便捷调用
[root@localhost /]# cp /usr/local/src/keepalived-2.0.7/keepalived/etc/init.d/keepalived /etc/init.d/keepalived
# 将配置文件放到默认路径下
[root@localhost /]# mkdir /etc/keepalived
[root@localhost /]# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
service keepalived start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
加为系统服务:chkconfig –add keepalived
开机启动:chkconfig keepalived on
查看开机启动的服务:chkconfig –list
启动、关闭、重启service keepalived start|stop|restart
查看当前网卡
nmcli connection show
1
2
参考重命名网卡
https://www.cnblogs.com/feiquan/p/9228066.html
MASTER
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
admin@test.com
}
notification_email_from admin@test.com
smtp_server xxx.smtp.com
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script Monitor_Nginx {
script "/root/monitor_nginx.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER #(主机为MASTER,备用机为BACKUP)
interface ens33 #(HA监测网络接口)
virtual_router_id 61 #(主、备机的virtual_router_id必须相同)
#mcast_src_ip 192.168.0.99 #(多播的源IP,设置为本机外网IP,与VIP同一网卡)此项可不设置
priority 90 #(主、备机取不同的优先级,主机值较大,备份机值较小,值越大优先级越高)
advert_int 1 #(VRRP Multicast广播周期秒数)
authentication {
auth_type PASS #(VRRP认证方式)
auth_pass 1234 #(密码)
}
track_script {
Monitor_Nginx #(调用nginx进程检测脚本)
}
virtual_ipaddress {
192.168.0.101 #(VRRP HA虚拟地址)
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
BACKUP方面只需要修改state为BACKUP , priority比MASTER稍低即可
monitor_nginx.sh 内容如下:
vim /root/monitor_nginx.sh
当检测到nginx进程不存在的时候,就干掉所有的keepalived,这时候,请求将会由keepalived的backup接管!!
#!/bin/bash
if [ "$(ps -ef | grep "nginx: master process"| grep -v grep )" == "" ]
then
killall keepalived
fi
1
2
3
4
5
监控docker脚本
#!/bin/bash
if [ "$(docker ps | grep "nginx" )" == "" ]
then
killall keepalived
fi
1
2
3
4
5
~
chmod +x /root/monitor_nginx.sh
都重新启动keepalived:
service keepalived restart
这里请注意,当keepalived启动后,我们可以用命令:
ip add show ens33来看我们的eth66网卡确实被添加了虚拟IP,如下图:
参考
https://blog.csdn.net/bbwangj/article/details/80346428
https://blog.csdn.net/l1028386804/article/details/52577875
http://www.178linux.com/56850
第二次安装遇到的一些问题
缺少 yum -y install openssl-devel
问题 Keepalived PID file ///**//var/run/keepalived.pid not readable (yet?) after start.
1;systemctl daemon-reload 重新加载
2:systemctl enable keepalived.service 设置开机自动启动
3:systemctl disable keepalived.service 取消开机自动启动
4:systemctl start keepalived.service 启动
5:systemctl stop keepalived.service停止
换错了
chmod 644 keepalived.conf 改成644
来自 https://blog.csdn.net/qq_22041375/article/details/103479317