【CentOS 7LNMP架构31】,nginx负载均衡#

shallow丿ove


nginx负载均衡

多台代理服务器

  • vi /usr/local/nginx/conf/vhost/load.conf upstream qq_com { ip_hash; server 61.135.157.156:80; server 125.39.240.113:80; } server { listen 80; server_name www.qq.com; location / { proxy_pass http://qq.com; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
  • upstream来制定多个web server
[root@localhost ~]# yum install -y bind-utils
Loaded plugins: fastestmirror
base                                                                                               | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                                               | 7.8 kB  00:00:00     
extras                                                                                             | 3.4 kB  00:00:00     
updates                                                                                            | 3.4 kB  00:00:00     
updates/7/x86_64/primary_db                                                                        | 6.0 MB  00:00:11     
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: kartolo.sby.datautama.net.id
 * extras: mirrors.cqu.edu.cn
 * updates: mirrors.nju.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package bind-utils.x86_64 32:9.9.4-51.el7_4.2 will be installed
--> Processing Dependency: bind-libs = 32:9.9.4-51.el7_4.2 for package: 32:bind-utils-9.9.4-51.el7_4.2.x86_64
--> Processing Dependency: liblwres.so.90()(64bit) for package: 32:bind-utils-9.9.4-51.el7_4.2.x86_64
--> Processing Dependency: libisccfg.so.90()(64bit) for package: 32:bind-utils-9.9.4-51.el7_4.2.x86_64
--> Processing Dependency: libisccc.so.90()(64bit) for package: 32:bind-utils-9.9.4-51.el7_4.2.x86_64
--> Processing Dependency: libisc.so.95()(64bit) for package: 32:bind-utils-9.9.4-51.el7_4.2.x86_64
--> Processing Dependency: libdns.so.100()(64bit) for package: 32:bind-utils-9.9.4-51.el7_4.2.x86_64
--> Processing Dependency: libbind9.so.90()(64bit) for package: 32:bind-utils-9.9.4-51.el7_4.2.x86_64
--> Processing Dependency: libGeoIP.so.1()(64bit) for package: 32:bind-utils-9.9.4-51.el7_4.2.x86_64
--> Running transaction check
---> Package GeoIP.x86_64 0:1.5.0-11.el7 will be installed
---> Package bind-libs.x86_64 32:9.9.4-51.el7_4.2 will be installed
--> Processing Dependency: bind-license = 32:9.9.4-51.el7_4.2 for package: 32:bind-libs-9.9.4-51.el7_4.2.x86_64
--> Running transaction check
---> Package bind-license.noarch 32:9.9.4-14.el7 will be updated
--> Processing Dependency: bind-license = 32:9.9.4-14.el7 for package: 32:bind-libs-lite-9.9.4-14.el7.x86_64
---> Package bind-license.noarch 32:9.9.4-51.el7_4.2 will be an update
--> Running transaction check
---> Package bind-libs-lite.x86_64 32:9.9.4-14.el7 will be updated
---> Package bind-libs-lite.x86_64 32:9.9.4-51.el7_4.2 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================
 Package                        Arch                   Version                              Repository               Size
==========================================================================================================================
Installing:
 bind-utils                     x86_64                 32:9.9.4-51.el7_4.2                  updates                 203 k
Installing for dependencies:
 GeoIP                          x86_64                 1.5.0-11.el7                         base                    1.1 M
 bind-libs                      x86_64                 32:9.9.4-51.el7_4.2                  updates                 1.0 M
Updating for dependencies:
 bind-libs-lite                 x86_64                 32:9.9.4-51.el7_4.2                  updates                 733 k
 bind-license                   noarch                 32:9.9.4-51.el7_4.2                  updates                  84 k

Transaction Summary
==========================================================================================================================
Install  1 Package  (+2 Dependent packages)
Upgrade             ( 2 Dependent packages)

Total download size: 3.1 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/5): bind-libs-lite-9.9.4-51.el7_4.2.x86_64.rpm                                                  | 733 kB  00:00:01     
(2/5): bind-license-9.9.4-51.el7_4.2.noarch.rpm                                                    |  84 kB  00:00:01     
(3/5): GeoIP-1.5.0-11.el7.x86_64.rpm                                                               | 1.1 MB  00:00:01     
(4/5): bind-utils-9.9.4-51.el7_4.2.x86_64.rpm                                                      | 203 kB  00:00:04     
(5/5): bind-libs-9.9.4-51.el7_4.2.x86_64.rpm                                                       | 1.0 MB  00:00:09     
--------------------------------------------------------------------------------------------------------------------------
Total                                                                                     342 kB/s | 3.1 MB  00:00:09     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : GeoIP-1.5.0-11.el7.x86_64                                                                              1/7 
  Updating   : 32:bind-license-9.9.4-51.el7_4.2.noarch                                                                2/7 
  Installing : 32:bind-libs-9.9.4-51.el7_4.2.x86_64                                                                   3/7 
  Installing : 32:bind-utils-9.9.4-51.el7_4.2.x86_64                                                                  4/7 
  Updating   : 32:bind-libs-lite-9.9.4-51.el7_4.2.x86_64                                                              5/7 
  Cleanup    : 32:bind-libs-lite-9.9.4-14.el7.x86_64                                                                  6/7 
  Cleanup    : 32:bind-license-9.9.4-14.el7.noarch                                                                    7/7 
  Verifying  : 32:bind-license-9.9.4-51.el7_4.2.noarch                                                                1/7 
  Verifying  : GeoIP-1.5.0-11.el7.x86_64                                                                              2/7 
  Verifying  : 32:bind-libs-lite-9.9.4-51.el7_4.2.x86_64                                                              3/7 
  Verifying  : 32:bind-utils-9.9.4-51.el7_4.2.x86_64                                                                  4/7 
  Verifying  : 32:bind-libs-9.9.4-51.el7_4.2.x86_64                                                                   5/7 
  Verifying  : 32:bind-libs-lite-9.9.4-14.el7.x86_64                                                                  6/7 
  Verifying  : 32:bind-license-9.9.4-14.el7.noarch                                                                    7/7 

Installed:
  bind-utils.x86_64 32:9.9.4-51.el7_4.2                                                                                   

Dependency Installed:
  GeoIP.x86_64 0:1.5.0-11.el7                             bind-libs.x86_64 32:9.9.4-51.el7_4.2                            

Dependency Updated:
  bind-libs-lite.x86_64 32:9.9.4-51.el7_4.2                    bind-license.noarch 32:9.9.4-51.el7_4.2                   

Complete!
[root@localhost ~]# dig qq.com

; <<>> DiG 9.9.4-RedHat-9.9.4-51.el7_4.2 <<>> qq.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4432
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;qq.com.				IN	A

;; ANSWER SECTION:
qq.com.			561	IN	A	125.39.240.113
qq.com.			561	IN	A	61.135.157.156

;; Query time: 46 msec
;; SERVER: 119.29.29.29#53(119.29.29.29)
;; WHEN: Fri Mar 02 20:44:04 EST 2018
;; MSG SIZE  rcvd: 67

[root@localhost ~]# vi /usr/local/nginx/conf/vhost/load.conf
添加
      1 upstream qq_com
      2 {
      3     ip_hash;
      4     server 61.135.157.156:80;
      5     server 125.39.240.113:80;
      6 }
      7 
      8 server
      9 {
     10     listen 80;
     11     server_name www.qq.com;
     12 
     13     location /
     14     {
     15         proxy_pass http://qq_com;
     16         proxy_set_header Host $host;
     17         proxy_set_header X-Real-IP $remote_addr;
     18         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     19     }
     20 }

[root@localhost ~]# vi /usr/local/nginx/conf/vhost/load.conf
upstream qq_com
{
    ip_hash;
    server 61.135.157.156:80;
    server 125.39.240.113:80;
}

server
{
    listen 80;
    server_name www.qq.com;

    location /
    {
        proxy_pass http://qq_com;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload

[root@localhost ~]# curl -x 127.0.0.1:80 www.qq.com
	访问到qq.com主页

---

转载于:https://my.oschina.net/u/3892756/blog/3069416

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值