Ubuntu16.04安装Keepalived

1.安装依赖包(主从服务器一致)

a) sudo apt-get install libssl-dev

                

b) sudo apt-get install openssl

                

c) sudo apt-get install libpopt-dev

                Ubuntu16.04安装Keepalived_第1张图片

2.安装keepalived(主从服务器一致)

sudo apt-get install keepalived

            Ubuntu16.04安装Keepalived_第2张图片

3.配置keepalived.conf(apt安装完后,程序创建了/etc/keepalived目录,但是没有生成keepalived.conf,自己手动写了一个)

a) 主服务器配置

    sudo vim /etc/keepalived/keepalived.conf

               Ubuntu16.04安装Keepalived_第3张图片

b) 主服务器配置

    sudo vim /etc/keepalived/keepalived.conf

               Ubuntu16.04安装Keepalived_第4张图片

c) 创建Nginx服务监控脚本/usr/local/nginx/check_nginx.sh(主从服务器上一致)

    sudo vim /usr/local/src/check_nginx_pid.sh

               Ubuntu16.04安装Keepalived_第5张图片

4.启动Nginx和Keepalived

a) 启动主服务

   sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

              

   sudo service keepalived start

              

b) 启动从服务

   sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

   sudo service keepalived start

5.测试

a) 修改主从服务器上Nginx的index.html

    sudo vim /usr/local/nginx/html/index.html

               Ubuntu16.04安装Keepalived_第6张图片

               Ubuntu16.04安装Keepalived_第7张图片

b) 通过虚拟IP访问Nginx服务

               Ubuntu16.04安装Keepalived_第8张图片

c) 关闭掉主服务器上Nginx和Keepavlived

    sudo killall keepalived

    sudo killall nginx

d) 再次通过虚拟IP访问Nginx服务

               Ubuntu16.04安装Keepalived_第9张图片

 

你可能感兴趣的:(keepalived)