Nginx+Keepalived+rsync部署手册

1、Nginx编译部署

下载解压安装包
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar zxf /opt/nginx-1.16.1.tar.gz -C /opt/
cd nginx-1.16.1

添加用户
useradd -M -s /sbin/nologin nginx

编译安装
./configure --user=nginx --group=nginx --prefix=/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-pcre
make && make install

解决依赖关系
错误提示:./configure: error: C compiler cc is not found
#yum -y install gcc gcc-c++ autoconf automake make
错误提示:./configure: error: the HTTP cache module requires md5 functions from OpenSSL library.
#yum -y install openssl openssl-devel
错误提示:./configure: error: the HTTP rewrite module requires the PCRE library.
#yum -y install pcre-devel

初始化配置
ln -s /data/nginx/sbin/* /usr/local/sbin/
chown -R nginx:nginx /data/nginx/
chmod +x /etc/rc.d/rc.local
vim /etc/rc.d/rc.local
添加 /usr/local/sbin/nginx -c /data/nginx/conf/nginx.conf

2、Nginx主备配置
注:使用keepalived抢占模式,Nginx-1节点为更改nginx配置节点。
yum install -y keepalived
cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.init
vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived
global_defs {
   
   router_id lbh_nginx
   script_user root
   enable_script_security
}
vrrp_script chk_nginx {
   
    script "/etc/keepalived/check_nginx.sh"
    interval 2
}
vrrp_instance VI_1 {
   
    state MASTER			##两个节点都必须是BACKUP状态
    #nopreempt				##非抢占模式
    interface  eth0
    virtual_router_id 99
    priority 150
    advert_int 1
    authentication {
   
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
   
        10.130.1.244
    }
    track_script  {
   
    chk_nginx
    }
}

router_id nginx_master
script_user root ##解决WARNING告警

nginx-2 把priority 150 替换成 priority 100
把state MASTER 改成BACKUP

vim /etc/keepalived/chk_nginx.sh

#!/bin/bash
counter=`ps -C nginx --no-header |wc -l`
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值