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


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

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

    [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服务

    [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节点

    [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相关日志

    [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

  • 相关阅读:
    FZU-2087 统计树边(最小生成树)
    HDU-1599 find the mincost route(floyd求最小环)
    BZOJ-1191 [HNOI2006]超级英雄Hero(二分图匹配)
    FZU-2020 组合(Lucas定理)
    FZU-2232 炉石传说(二分图匹配)
    NOIP2016模拟 拼接mf(模拟)
    2016年11月10日00:26:08
    BZOJ2986 Non-Squarefree Numbers
    BZOJ3624 [Apio2008]免费道路
    BZOJ3224 Tyvj 1728 普通平衡树
  • 原文地址:https://www.cnblogs.com/oskb/p/5634057.html
Copyright © 2020-2023  润新知