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

keepalived的安装以及基本配置

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

  1. cd /home/wangpl/mine/soft/keepalived-1.2.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
  1. [Unit]
  2. Description=Keepalived
  3. After=syslog.target network.target remote-fs.target nss-lookup.target
  4. [Service]
  5. Type=forking
  6. PIDFile=/var/run/keepalived.pid
  7. ExecStart=/home/wangpl/mine/soft/keepalived-1.2.2/sbin/keepalived -D
  8. ExecReload=/bin/kill -s HUP $MAINPID
  9. ExecStop=/bin/kill -s QUIT $MAINPID
  10. PrivateTmp=true
  11. [Install]
  12. 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,说明已经成功。

发表评论

电子邮件地址不会被公开。 必填项已用*标注