说明: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