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
智能推荐

注意!

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



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

赞助商广告