nginx+keepalived搭建

nginx+keepalived搭建
搭建环境
系统版本:CentOS Linux release 7.9.2009 (Core)
nginx版本:nginx-1.12.2.tar.gz
keepalived版本:keepalived-1.2.13.tar.gz

服务器4台
设备1:192.168.217.15 安装nginx keepalived
设备2:192.168.217.16 安装 nginx keepalived
设备3:192.168.217.17 安装httpd*
设备4:192.168.217.18 安装httpd*

设备1、设备2
安装ngixn keepalived

nginx

[root@localhost ~]#  yum -y install gcc gcc-c++ zlib zlib-devel pcre pcre-devel openssl openssl-devel
[root@localhost ~]#  tar -zxf nginx-1.12.2.tar.gz -C /usr/src
[root@localhost ~]# cd /usr/src/nginx-1.12.2/
[root@localhost nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
[root@localhost nginx-1.12.2]# make && make install
[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@localhost nginx-1.12.2]# vim /usr/local/nginx/conf/nginx.conf
35行添加  (反向代理)
upstream apache{
        server 192.168.217.17 max_fails=2 fail_timeout=30; #两台Apache的IP
        server 192.168.217.18 max_fails=2 fail_timeout=30;
    }
    ……
     location / {
           # root   html;   #注释掉
           # index  index.html index.htm;    #注释掉
           proxy_pass http://apache;    #添加此信息   (负载均衡)
        }
 [root@localhost nginx-1.12.2]# vim /etc/rc.d/init.d/nginx
 #!/bin/bash
 #chkconfig: 35 85 21
case $1 in
start)
 /usr/local/sbin/nginx
 ;;
stop)
 killall -9 nginx
 rm -f /var/run/nginx.pid
 ;;
restart)
 $0 stop
 $0 start
 ;;
*)
 echo "start|stop|restart"
 ;;
esac
[root@localhost nginx-1.12.2]# chmod +x /etc/rc.d/init.d/nginx
[root@localhost nginx-1.12.2]# chkconfig --add nginx
[root@localhost nginx-1.12.2]# chkconfig nginx on 
[root@localhost nginx-1.12.2]# systemctl restart nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
此处如有报错  检查配置文件或杀掉进程
root@localhost nginx-1.12.2]# killall -9 nginx
检查配置文件
[root@localhost nginx-1.12.2]# nginx -t
重启
[root@localhost nginx-1.12.2]# nginx  
或	
[root@localhost nginx-1.12.2]# systemctl restart nginx
查看状态
root@localhost nginx-1.12.2]# systemctl status nginx.service
[root@localhost keepalived-1.2.13]# systemctl stop firewalld

安装keepalived依赖

[root@localhost ~]# yum -y install popt
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值