CentOS7 下配置Keepalived为系统服务,开机自动启动。

Posted 征服.刘华强

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7 下配置Keepalived为系统服务,开机自动启动。相关的知识,希望对你有一定的参考价值。

keepalived的安装以及基本配置


1.我的keepalived 安装在 /home/wangpl/mine/soft/keepalived-1.2.2目录下。

cd  /home/wangpl/mine/soft/keepalived-1.2.2
ls -l

drwxr-xr-x. 2 root root 20 7月   8 15:10 bin
drwxr-xr-x. 5 root root 50 7月   8 15:10 etc
drwxr-xr-x. 2 root root 23 7月   8 15:10 sbin
drwxr-xr-x. 3 root root 16 7月   8 15:10 share


keepalived启动后默认去这个(/etc/keepalived/keepalived.conf)位置读取配置文件,除非另行制定,需要将安装文件下带的配置文件拷贝过去。


2.创建keepalived.service文件。

vim /lib/systemd/system/keepalived.service

[Unit]
Description=Keepalived
After=syslog.target network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
PIDFile=/var/run/keepalived.pid
ExecStart=/home/wangpl/mine/soft/keepalived-1.2.2/sbin/keepalived -D
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

PIDFile=/var/run/keepalived.pid 这个路径是keepalived默认存放pid的位置。
<pre name="code" class="java">ExecStart=/home/wangpl/mine/soft/keepalived-1.2.2/sbin/keepalived  这个是keepalived的启动文件  -D的意思是 输出详细日志

 

3.配置systemctl

1;systemctl daemon-reload  重新加载

2:systemctl enable keepalived.service  设置开机自动启动

3:systemctl disable keepalived.service 取消开机自动启动

4:systemctl start keepalived.service 启动

5:systemctl stop keepalived.service停止


4.查看效果

systemctl status keepalived.service 
可以看到keep运行正常,并且已经绑定VIP到网卡en16777736


ip a  命令查看网卡已经绑定了VIP,说明已经成功。



以上是关于CentOS7 下配置Keepalived为系统服务,开机自动启动。的主要内容,如果未能解决你的问题,请参考以下文章

centos7下keepalived+nginx配置

Linux下 keepalived 的安装和配置

Centos7下安装keepalived

Centos7下安装keepalived

keepalived安装与配置,组建高可用服务器

centos7下配置LVS+KeepAlived高可用主备+2台tomcat负载图文篇