Linux for CentOS 下的 keepalived 安装与卸载以及相关命令操作之详细教程
Posted 畅聊科技
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux for CentOS 下的 keepalived 安装与卸载以及相关命令操作之详细教程相关的知识,希望对你有一定的参考价值。
百度百科解释:
keepalived 是一个类似于 layer3, 4 & 7 交换机制的软件,也就是我们平时说的第 3 层、第 4 层和第 7 层交换。Keepalived 的作用是检测 web 服务器的状态,如果有一台 web服务器死机,或工作出现故障,keepalived 将检测到,并将有故障的 web 服务器从系统中剔除,当web服务器工作正常后 keepalived 自动将 web 服务器加入到服务器群中,这些工作全部自动完成,不需要人工干涉,需要人工做的只是修复故障的 web 服务器。
1、安装
- 方法一:yum 方式
- yum 安装
#安装依赖包 yum install -y curl gcc openssl-devel libnl3-devel net-snmp-devel #yum安装软件 yum install -y keepalived
- yum 安装
- 初始化及启动
systemctl start keepalived //启动 keepalived systemctl enable keepalived //加入开机启动 keepalived systemctl restart keepalived //重新启动 keepalived systemctl status keepalived //查看 keepalived 状态
- 初始化及启动
方法二:源码包
1.mkdir /opt/software #建立一个目录,用来存放软件包
2.cd /opt/software #切换到该目录下
3.wget https://www.keepalived.org/software/keepalived-2.0.20.tar.gz #联网下载,也可以windows下载好,上传进来
4.tar xvf keepalived-2.0.20.tar.gz
5.mv keepalived-2.0.20.tar.gz /usr/local/src
6.cd /usr/local/src/keepalived-2.0.20
7.
yum install -y curl gcc openssl-devel libnl3-devel net-snmp-devel
yum -y install openssl openssl-devel
yum -y install libnl libnl-devel
yum -y install libnfnetlink-devel
8.完成后会在以下路径生成:
/usr/local/keepalived/ /usr/local/keepalived/bin /usr/local/keepalived/etc /usr/local/keepalived/sbin /usr/local/keepalived/share --------------- --------------- /usr/local/keepalived/etc/keepalived/keepalived.conf /usr/local/keepalived/etc/sysconfig/ /usr/local/keepalived/sbin/keepalived
9.初始化启动
# 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.20/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
- 加为系统服务: chkconfig --add keepalived
- 开机启动: chkconfig keepalived on
- 查看开机启动的服务:chkconfig --list
- 启动、关闭、重启 : service keepalived start|stop|restart
卸载
卸载keeplived工作路径
[root@localhost /]# cd /usr/local/src/keepalived #源码所在目录(根据实际情况进入对应目录)
[root@localhost keepalived]#make uninstall
删除相关文件,有时系统版本差异,删除的时候,先查看该路径是否存在文件,以免删除错误,要仔细了。不要复制我的路径
#删除keepalived [root@localhost /]# rm -f /usr/local/keepalived/sbin/keepalived [root@localhost /]# rm -f /usr/local/keepalived/etc/rc.d/init.d/keepalived [root@localhost /]# rm -f /usr/local/keepalived/etc/sysconfig/keepalived [root@localhost /]# rm -rf /usr/local/keepalived/etc/keepalived [root@localhost /]# rm -f /usr/local/keepalived/bin/genhash [root@localhost /]# rm -rf /usr/local/keepalived [root@localhost /]# rm -rf /etc/keepalived [root@localhost /]# rm -f /etc/rc.d/init.d/keepalived [root@localhost /]# rm -f /usr/sbin/keepalived [root@localhost /]# rm -f /etc/sysconfig/keepalived [root@localhost /]# rm -f /etc/systemd/system/multi-user.target.wants/keepalived.service
测试是否卸载成功
[root@localhost /]# serive keepalived satrt [root@localhost /]# systemctl start keepalived 当命令无效时,证明卸载成功。 相关操作命令 centOs: [root@localhost /]# systemctl start keepalived -- 启动 [root@localhost /]# systemctl stop keepalived --关闭 [root@localhost /]# ps aux|grep keepalived --查看进程 linux: [root@localhost /]# service keepalived start -- 启动 [root@localhost /]# service keepalived stop --关闭 [root@localhost /]# ps aux|grep keepalived --查看进程
以上是关于Linux for CentOS 下的 keepalived 安装与卸载以及相关命令操作之详细教程的主要内容,如果未能解决你的问题,请参考以下文章