软件部署在不同linux上,如何在Linux中安装和部署keepalived
如何在Linux中安装和部署keepalived
发布时间:2020-05-27 13:56:19
来源:亿速云
阅读:407
作者:鸽子
keepalived的部署
keepalived在很多高可用的集群都会用到,一般前端放置的会是nginx、ipvs、haproxy
比如我们在使用rabbitmq的时候做了这么一个集群,一般做了集群的话,那肯定就需要这么一个高可用的负载均衡器来实现流量的分发,如果使用的是haproxy,比如一台rebbitmq的节点突然宕机或者网卡失效,那么虽然RabbitMQ集群没有任何故障,但是对于外界的客户端来说所有的连接都会被断开,结果将是灾难性的。确保负载均衡服务的可靠性同样显得十分的重要。这里就引入Keepalived工具,它能够通过自身健康检查、资源接管功能做高可用(双机热备),实现故障转移。
Keepalived采用VRRP(Virtual Router Redundancy Protocol,虚拟路由冗余协议),以软件的形式实现服务器热备功能。通常情况下是将两台Linux服务器组成一个热备组(Master和Backup),同一时间热备组内只有一台主服务器Master提供服务,同时Master会虚拟出一个公用的虚拟IP地址,简称VIP。这个VIP只存在在Master上并对外提供服务。如果Keepalived检测到Master宕机或者服务故障,备份服务器Backup会自动接管VIP称为Master,Keepalived并将原Master从热备组中移除。当原Master恢复后,会自动加入到热备组,默认再抢占称为Master,起到故障转移的功能。
Keepalived工作在OSI模型中的第3层、第4层和第7层。
工作在第3层是指Keepalived会定期向热备组中的服务器发送一个ICMP数据包来判断某台服务器是否故障,如果故障则将这台服务器从热备组移除。
工作在第4层是指Keepalived以TCP端口的状态判断服务器是否故障,比如检测RabbitMQ的5672端口,如果故障则将这台服务器从热备组中移除。
工作在第7层是指Keepalived根据用户设定的策略(通常是一个自定义的检测脚本)判断服务器上的程序是否正常运行,如果故障将这台服务器从热备组移除。
首先需要去Keepalived的官网下载Keepalived的安装文件,目前最新的版本为:keepalived-2.0.20.tar.gz,下载地址为http://www.keepalived.org/download.html
可以找到最新版[root@VM_0_8_centos ~]# mkdir keepalived
[root@VM_0_8_centos ~]# cd keepalived/
[root@VM_0_8_centos keepalived]# wget https://www.keepalived.org/software/keepalived-2.0.20.tar.gz
--2020-02-27 10:46:37-- https://www.keepalived.org/software/keepalived-2.0.20.tar.gz
Resolving www.keepalived.org (www.keepalived.org)... 37.59.63.157, 2001:41d0:8:7a9d::1
Connecting to www.keepalived.org (www.keepalived.org)|37.59.63.157|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1036063 (1012K) [application/x-gzip]
Saving to: ‘keepalived-2.0.20.tar.gz’
100%[==================================================================================================================================>] 1,036,063 13.7KB/s in 1m 43s
2020-02-27 10:48:37 (9.80 KB/s) - ‘keepalived-2.0.20.tar.gz’ saved [1036063/1036063]
解压[root@VM_0_8_centos keepalived]# ls
keepalived-2.0.20.tar.gz
[root@VM_0_8_centos keepalived]# tar xf keepalived-2.0.20.tar.gz
[root@VM_0_8_centos keepalived]# cd keepalived-2.0.20/
[root@VM_0_8_centos keepalived-2.0.20]# ls
aclocal.m4 AUTHOR build_setup compile configure.ac COPYING doc INSTALL keepalived lib Makefile.in README.md TODO
ar-lib bin_install ChangeLog configure CONTRIBUTORS depcomp genhash install-sh keepalived.spec.in Makefile.am missing snap
[root@VM_0_8_centos keepalived-2.0.20]# ./configure --prefix=/opt/keepalived --with-init=SYSV
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
出现报错:缺少openssl-develconfigure: error:
!!! OpenSSL is not properly installed on your system. !!!
!!! Can not include OpenSSL headers files. !!!
[root@VM_0_8_centos keepalived-2.0.20]# yum -y install openssl-devel
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
Resolving Dependencies
--> Running transaction check
---> Package openssl-devel.x86_64 1:1.0.2k-19.el7 will be installed
安装后重新再执行
[root@VM_0_8_centos keepalived-2.0.20]# ./configure --prefix=/opt/keepalived --with-init=SYSV
再次报错,说这个版本不支持ipv6,需要安装依赖包
*** WARNING - this build will not support IPVS with IPv6. Please install libnl/libnl-3 dev libraries to support IPv6 with IPVS.[root@VM_0_8_centos keepalived-2.0.20]# yum -y install libnl libnl-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package libnl-1.1.4-3.el7.x86_64 already installed and latest version
安装完依赖包再次执行[root@VM_0_8_centos keepalived-2.0.20]# ./configure --prefix=/opt/keepalived --with-init=SYSV
编译[root@VM_0_8_centos keepalived-2.0.20]# make && make install
将启动文件放到/etc/init.d下,可以使用service来启动keepalived[root@VM_0_8_centos keepalived-2.0.20]# cp /opt/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
[root@VM_0_8_centos keepalived-2.0.20]# cp /opt/keepalived/etc/sysconfig/keepalived /etc/sysconfig
[root@VM_0_8_centos keepalived-2.0.20]# cp /opt/keepalived/sbin/keepalived /usr/sbin
[root@VM_0_8_centos keepalived-2.0.20]# chmod +x /etc/init.d/keepalived
[root@VM_0_8_centos keepalived-2.0.20]# chkconfig --add keepalived
[root@VM_0_8_centos keepalived-2.0.20]# chkconfig keepalived on
[root@VM_0_8_centos keepalived-2.0.20]# cp /opt/keepalived/etc/keepalived/keepalived.conf /etc/keepalived.conf
启动失败,查看报错,这里提示 Unable to find configuration file /etc/keepalived/keepalived.conf,没有发现我们的配置文件的地址,这里是因为我们在安装的时候指定了自己的安装路径[root@VM_0_8_centos keepalived-2.0.20]# service keepalived start
Starting keepalived (via systemctl): Job for keepalived.service failed because the control process exited with error code. See "systemctl status keepalived.service" and "journalctl -xe" for details.
[FAILED]
[root@VM_0_8_centos keepalived-2.0.20]# journalctl -xe
找出放置我们配置文件的地方,修改文件地址[root@VM_0_8_centos ~]# find / -name keepalived.conf
/opt/keepalived/etc/keepalived/keepalived.conf
/etc/keepalived.conf
/root/keepalived/keepalived-2.0.20/keepalived/etc/keepalived/keepalived.conf
在最后一行添加我们配置文件的地址[root@VM_0_8_centos ~]# vim /etc/sysconfig/keepalived
[root@VM_0_8_centos ~]# tail -1 /etc/sysconfig/keepalived
KEEPALIVED_OPTIONS="-f /etc/keepalived.conf -D -S 0"
使用systemctl启动成功[root@VM_0_8_centos ~]# systemctl restart keepalived
[root@VM_0_8_centos ~]# systemctl status keepalived
● keepalived.service - SYSV: Start and stop Keepalived
Loaded: loaded (/etc/rc.d/init.d/keepalived; bad; vendor preset: disabled)
Active: active (running) since Thu 2020-02-27 11:02:22 CST; 10s ago
Docs: man:systemd-sysv-generator(8)
Process: 30129 ExecStart=/etc/rc.d/init.d/keepalived start (code=exited, status=0/SUCCESS)
Main PID: 30136 (keepalived)
CGroup: /system.slice/keepalived.service
├─30136 keepalived -f /etc/keepalived.conf -D -S 0
├─30138 keepalived -f /etc/keepalived.conf -D -S 0
└─30139 keepalived -f /etc/keepalived.conf -D -S 0
Feb 27 11:02:31 VM_0_8_centos Keepalived_vrrp[30139]: Sending gratuitous ARP on eth0 for 192.168.200.18
Feb 27 11:02:31 VM_0_8_centos Keepalived_vrrp[30139]: Sending gratuitous ARP on eth0 for 192.168.200.16
Feb 27 11:02:31 VM_0_8_centos Keepalived_vrrp[30139]: Sending gratuitous ARP on eth0 for 192.168.200.17
Feb 27 11:02:31 VM_0_8_centos Keepalived_vrrp[30139]: Sending gratuitous ARP on eth0 for 192.168.200.18
Feb 27 11:02:31 VM_0_8_centos Keepalived_healthcheckers[30138]: HTTP_CHECK on service [192.168.200.3]:tcp:1358 failed after 3 retry.
Feb 27 11:02:31 VM_0_8_centos Keepalived_healthcheckers[30138]: Removing service [192.168.200.3]:tcp:1358 to VS [10.10.10.2]:tcp:1358
Feb 27 11:02:31 VM_0_8_centos Keepalived_healthcheckers[30138]: Lost quorum 1-0=1 > 0 for VS [10.10.10.2]:tcp:1358
Feb 27 11:02:31 VM_0_8_centos Keepalived_healthcheckers[30138]: Adding sorry server [192.168.200.200]:tcp:1358 to VS [10.10.10.2]:tcp:1358
Feb 27 11:02:31 VM_0_8_centos Keepalived_healthcheckers[30138]: Removing alive servers from the pool for VS [10.10.10.2]:tcp:1358
Feb 27 11:02:31 VM_0_8_centos Keepalived_healthcheckers[30138]: Remote SMTP server [192.168.200.1]:25 connected.
使用service进行启动停止[root@VM_0_8_centos ~]# service keepalived stop
Stopping keepalived (via systemctl): [ OK ]
[root@VM_0_8_centos ~]# service keepalived start
Starting keepalived (via systemctl): [ OK ]
[root@VM_0_8_centos ~]# service keepalived status
● keepalived.service - SYSV: Start and stop Keepalived
Loaded: loaded (/etc/rc.d/init.d/keepalived; bad; vendor preset: disabled)
Active: active (running) since Thu 2020-02-27 11:03:27 CST; 10s ago
Docs: man:systemd-sysv-generator(8)
Process: 30394 ExecStop=/etc/rc.d/init.d/keepalived stop (code=exited, status=0/SUCCESS)
Process: 30469 ExecStart=/etc/rc.d/init.d/keepalived start (code=exited, status=0/SUCCESS)
Main PID: 30476 (keepalived)
CGroup: /system.slice/keepalived.service
├─30476 keepalived -f /etc/keepalived.conf -D -S 0
├─30478 keepalived -f /etc/keepalived.conf -D -S 0
└─30479 keepalived -f /etc/keepalived.conf -D -S 0
Feb 27 11:03:36 VM_0_8_centos Keepalived_vrrp[30479]: Sending gratuitous ARP on eth0 for 192.168.200.18
Feb 27 11:03:36 VM_0_8_centos Keepalived_vrrp[30479]: Sending gratuitous ARP on eth0 for 192.168.200.16
Feb 27 11:03:36 VM_0_8_centos Keepalived_vrrp[30479]: Sending gratuitous ARP on eth0 for 192.168.200.17
Feb 27 11:03:36 VM_0_8_centos Keepalived_vrrp[30479]: Sending gratuitous ARP on eth0 for 192.168.200.18
Feb 27 11:03:37 VM_0_8_centos Keepalived_healthcheckers[30478]: HTTP_CHECK on service [192.168.200.3]:tcp:1358 failed after 3 retry.
Feb 27 11:03:37 VM_0_8_centos Keepalived_healthcheckers[30478]: Removing service [192.168.200.3]:tcp:1358 to VS [10.10.10.2]:tcp:1358
Feb 27 11:03:37 VM_0_8_centos Keepalived_healthcheckers[30478]: Lost quorum 1-0=1 > 0 for VS [10.10.10.2]:tcp:1358
Feb 27 11:03:37 VM_0_8_centos Keepalived_healthcheckers[30478]: Adding sorry server [192.168.200.200]:tcp:1358 to VS [10.10.10.2]:tcp:1358
Feb 27 11:03:37 VM_0_8_centos Keepalived_healthcheckers[30478]: Removing alive servers from the pool for VS [10.10.10.2]:tcp:1358
Feb 27 11:03:37 VM_0_8_centos Keepalived_healthcheckers[30478]: Remote SMTP server [192.168.200.1]:25 connected.
软件部署在不同linux上,如何在Linux中安装和部署keepalived相关推荐
- ubuntu安装linux deepin,如何在Ubuntu中安装Deepin终端 | MOS86
Deepin终端是一个基于python的终端仿真器,专为中国Linux发行版开发,名为"Deepin"."它有许多有用的功能,其中一些,如"地震模式" ...
- linux卸载crossover,CrossOver Linux版如何在Ubuntu中安装?Ubuntu安装CrossOver Linux版教程...
CrossOver这款系统兼容软件不仅有着Mac版本,还有Linux版本可供大家选择,也可以让Linux用户在其电脑上运行Windows应用,那么CrossOver Linux是如何安装的呢?今天小编 ...
- 如何在Linux上的命令行中设置Google Chrome浏览器的代理设置?
How to set Google Chrome's proxy settings in command line on Linux? I am using Google Chrome on Linu ...
- linux动画制作软件,如何在Ubuntu中安装2D动画软件OpenToonz
OpenToonz,开源2D动画软件,现在可以通过Snap软件包轻松安装在Ubuntu 16.04,Ubuntu 18.04及更高版本中. OpenToonz基于Toonz Studio Ghibli ...
- aws中部署防火墙_如何在AWS中设置自动部署
aws中部署防火墙 by Harry Sauers 哈里·绍尔斯(Harry Sauers) 如何在AWS中设置自动部署 (How to set up automated deployment in ...
- 如何在VMware中安装Linux系统(带界面)~新手向
如何在VMware中安装Linux系统(带界面)~新手向 1.打开VMware虚拟机 2.创建新的虚拟机 3.加载ISO 4.命名虚拟机 5.指定磁盘容量 6.自定义硬件 7.启动虚拟机 1.打开VM ...
- 如何在 Ubuntu 中安装和删除软件
文章目录 1.Ubuntu Software 1.1.使用Ubuntu软件中心安装软件[推荐] 1.2.使用Ubuntu软件中心删除软件[推荐] 2..deb 文件 2.1.使用 .deb 文件在 U ...
- 文件系统层次结构标准和Linux上下载源代码配置编译安装
一.文件系统层次结构标准 FHS_3.0 标准文档 /bin 存储一些二进制可执行命令文件, /usr/bin 也存放了一些基于用户的命令文件. /sbin 存储了很多系统命令, /usr/sbin ...
- 如何在 IDEA 中创建并部署 JavaWeb 程序
前言 在之前 Java 的学习中,我们可能更多地是和控制台程序打交道,也就是我们日常说的黑框框程序. 现在既然完成了 Java SE 部分的基础知识,是时候来学习 JavaWeb 部分.而随着 IDE ...
最新文章
- python怎么发送代码文件_python 通过 socket 发送文件的实例代码
- WF4.0实战(四):博客申请流程
- Linux下C/C++开发工具注意事项
- hadoop关键进程
- C++实践参考——数组类运算的实现
- mpu 配置内存空间_mpu内存保护单元功能及工作原理
- 鸿蒙唯独没有手机,想用鸿蒙OS,却没有华为手机?华为高层:还有1亿台设备可体验...
- 华为p40论坛_华为高端旗舰继续发力!麒麟990 5G+超感知三摄,256GB降价799元
- python判断一个日期对应的节假日名
- 达摩院发布AI Earth地球科学云平台
- 使用spss求标准化的线性回归方程
- 网络信息安全模型概述
- 《JavaScript百炼成仙》第三次送书活动~
- linux设备驱动模型-linux驱动开发第5部分-朱有鹏-专题视频课程
- Android 原生支持 Opus、AV1!但你真正要了解的还有更多
- PDF转Word+转Html+英文论文轻松翻译+屏幕取词
- 计算机网络的主要红木有,报关员第4章练习题2
- 50个最受网友欢迎的HTML5资源下载列表
- 腾讯技术直播预告|不要怂,一起上!关于******,我们有话要说
- nginx 负载均衡502问题