Nginx+keepalived负载均衡及高可用

说明:node1,node2作为负载服务器,安装nginx (实现负载均衡), keepalived(实现高可用),node3,node4作为后端真实服务器(real server),node5作为客户端进行测试。

node1:192.168.129.131        node2:192.168.129.132

node3:192.168.129.133        node4:192.168.129.134        node5:192.168.129.135

1.使用rpm包方式安装安装Nginx:   (node1,node2)

1.将httpd服务停止(都是web服务器,端口都是80)

[root@localhost ~]# systemctl stop httpd

2.配置扩展源:

[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

3.使用yum方式安装,启动:

[root@localhost ~]# yum install nginx -y
[root@localhost ~]# systemctl start nginx

rpm包安装,网页默认放在此文件:

[root@localhost ~]# ls /usr/share/nginx/html/
404.html  50x.html  en-US  icons  img  index.html  nginx-logo.png  poweredby.png

关闭防火墙,可在网页直接访问默认页面

[root@localhost ~]# systemctl stop firewalld

2.node3,node4提供两个测试的静态页面:(使用的apache服务)

[root@localhost ~]# yum install httpd -y
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# cd /var/www/html/
[root@localhost ~]# echo "web test page, ip `hostname -I`." > /var/www/html/index.html
[root@localhost ~]# systemctl stop firewalld        #关闭防火墙
[root@localhost ~]# systemctl restart httpd        #重启服务

3.nginx负载均衡配置 :

[root@node1 ~]# cd /etc/nginx/conf.d/
[root@node1 conf.d]# vim www.conf

upstream websrvs {
	server 192.168.129.133:80 weight=1;        #node1地址,端口,轮询算法1:1
	server
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值