• LNMP 之 Nginx负载均衡服务器


    Nginx负载均衡服务器


     参考教程:【千峰教育


     准备工作:

      三台服务器,每台服务器都需要安装nginx。


     1、关闭防火墙

      service iptables stop
    2、关闭Selinux
      setenforce 0
    3、安装基本依赖
      yum install -y gcc pcre-devel openssl-devel
    4、安装nginx
    useradd www -s /sbin/nologin #创建nginx运行账户www,不允许直接登录系统

    tar -zxvf nginx-1.14---
    cd nginx-1.14

    ./configure --prefix=/usr/local/nginx
    --without-http_memcached_module
    --user=www
    --group=www
    --with-http_stub_status_module
    --with-http_ssl_module

    make && make install

    设置nginx开机启动
    cp /lnmp/src/nginx /etc/rc.d/init.d/ #拷贝启动文件
    chmod 755 /etc/rc.d/init.d/nginx #赋予文件执行权限
    chkconfig nginx on #设置开机启动
    service nginx start #启动nginx

    5、配置nginx

    名称 IP 功能
    load balance: 10.0.166.17 负责任务的分配
    web server01 10.0.166.18 实际提供web服务
    web server02 10.0.166.19 实际提供web服务

    cd /usr/local/nginx/conf
    vim nginx.conf

    http {
      upstream lb{ #连接池,存放提供web服务的服务器地址
        server 10.0.166.18 weight=5; #权重为5
        server 10.0.166.19 weight=5; #权重也为5
      }
      server {
        location / {
          proxy_pass http://lb; #指定代理连接池
          proxy_set_header Host $host; #转发请求头信息
          proxy_set_header X-Forward-For $remote_addr; #转发请求IP地址、
          #root html; #这一行注释掉
          #index index.html index.htm; #这一行也注释掉
        }
      }
    }

    重启nginx:
    service nginx restart


  • 相关阅读:
    FEniCS 1.1.0 发布,计算算术模型
    Piwik 1.10 发布,增加社交网站统计
    淘宝褚霸谈做技术的心态
    CyanogenMod 10.1 M1 发布
    Druid 发布 0.2.11 版本,数据库连接池
    GNU Gatekeeper 3.2 发布
    Phalcon 0.9.0 BETA版本发布,新增大量功能
    EUGene 2.6.1 发布,UML 模型操作工具
    CVSps 3.10 发布,CVS 资料库更改收集
    Opera 移动版将采用 WebKit 引擎
  • 原文地址:https://www.cnblogs.com/gyfluck/p/10491014.html
Copyright © 2020-2023  润新知