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,說明已經成功。