单节点nginx为两台apache服务器提供负载均衡(转载)

需求:本实验为单节点nginx为两台apache服务器提供负载均衡,所有配置为最简单

1.初始化3台测试server,该关的关了

1
2
3
4
5
6
7
8
9
[root@host101 ~] # vim /etc/hosts
192.168.1.101   ng-master
192.168.1.161   web1
192.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 httpd
ln  -s  '/usr/lib/systemd/system/httpd.service'  '/etc/systemd/system/multiuser.target.wants/httpd.service'
[root@host161 ~] # cat /var/www/html/index.html
hello 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 repo
baseurl=http: //nginx .org /packages/centos/7/x86_64/
gpgcheck=0
enabled=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

转载于:https://www.cnblogs.com/xingkong001/p/7017712.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值