keepalived實現主備切換


1.下載安裝keepalived,並且做成linux系統服務

wget http://www.keepalived.org/download.html
tar -zxvf keepalived-1.2.18.tar.gz -C /usr/local/
yum install -y openssl openssl-devel
cd keepalived-1.2.18/ && ./configure --prefix=/usr/local/keepalived
make && make install

將keepalived安裝成Linux系統服務

mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
ln -s /usr/local/sbin/keepalived /usr/sbin/
ln -s /usr/local/keepalived/sbin/keepalived /sbin/

可以設置開機啟動:
chkconfig keepalived on,
到此我們安裝完畢!
2.寫一個shell腳本,用於檢測nginx是否啟動,如果沒有啟動,嘗試重啟,如果還是不行,則關閉keepalived
腳本實例:


#!/bin/bash
a=`ps -C nginx --no-header | wc -l`
if [ $a -eq 0 ]
then
  /usr/local/nginx/sbin/nginx
  b=`ps -C nginx --no-header |wc -l`
  if [ $b -eq 0 ]
   then
     killall keepalived
  fi
fi

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com