需求:本实验为单节点nginx为两台apache服务器提供负载均衡,所有配置为最简单
1.初始化3台测试server,该关的关了
|
1
2
3
4
5
6
7
8
9
|
[root@host101 ~]# vim /etc/hosts192.168.1.101 ng-master192.168.1.161 web1192.168.1.162 web2[root@host101 ~]# yum clean all[root@host101 ~]# systemctl stop firewalld.service[root@host101 ~]# systemctl disable firewalld.service[root@host101 ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config |
2.配置web1,web2的apache服务
|
1
2
3
4
5
6
|
[root@host161 ~]# yum -y install httpd[root@host161 ~]# systemctl start httpd[root@host161 ~]# systemctl enable httpdln -s ‘/usr/lib/systemd/system/httpd.service‘ ‘/etc/systemd/system/multiuser.target.wants/httpd.service‘[root@host161 ~]# cat /var/www/html/index.htmlhello this lvs-web1 |
3.通过yum安装配置nginx节点
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
[root@host101 ~]# vim /etc/yum.repos.d/nginx.repo[nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/7/x86_64/gpgcheck=0enabled=1[root@host101 ~]# yum clean all[root@host101 ~]# yum -y install nginx[root@host101 ~]# vim /usr/share/nginx/html/index.html<h1>Welcome to ng-master!</h1>[root@host101 ~]# cd /etc/nginx/conf.d/[root@host101 conf.d]# mv default.conf default.conf.1[root@host101 ~]# vim /etc/nginx/conf.d/web.conf upstream myapp1 { server web1; server web2; } server { listen 80; location / { proxy_pass http://myapp1; } }[root@host101 ~]# systemctl restart nginx.service |
4.查看nginx相关日志
|
1
2
3
|
[root@host101 conf.d]# tail -f /var/log/messages[root@host101 conf.d]# tail -f /var/log/nginx/access.log[root@host101 conf.d]# tail -f /var/log/nginx/error.log |
5.通过浏览器访问测试http://192.168.1.101/ 或者 http://myapp1/ 可发现流量在web1和web2之间跳转
参考:
http://www.linuxdiyf.com/linux/12955.html
http://nginx.org/en/linux_packages.html
http://blog.csdn.net/e421083458/article/details/30086413
单节点nginx为两台apache服务器提供负载均衡(转载)
原文:http://www.cnblogs.com/xingkong001/p/7017712.html