• Nginx web proxy NFS服务


      

    1.nginx web 安装 配置 

    #systemctl stop firewalld
    #systemctl disabled firewalld
    #wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 
    #yum install nginx -y
    #echo "welcome to china" >/usr/share/nginx/html/index.html
    #systemctl start nginx.service
    #curl 192.168.16.95
      welcome to china
    

    2.nginx proxy

    proxy              192.168.16.95
    web01             192.168.16.186
    web02             192.168.16.187
     
    #web01操作
    [root@web01 ~]# yum install nginx -y
    [root@web01 ~]# echo "welcome to web01" >/usr/share/nginx/html/index.html
    [root@web01 ~]# systemctl start nginx.service
    [root@web01 ~]# curl 192.168.16.186
    welcome to web01
     
    #web02操作
    [root@web02 ~]# systemctl stop firewalld
    [root@web02 ~]# echo "welcome to web02" >/usr/share/nginx/html/index.html
    [root@web02 ~]# systemctl start nginx.service
    [root@web02 ~]# curl 192.168.16.187
    welcome to web02
     
     
    #proxy 操作
    [root@proxy ~]# vim /etc/nginx/nginx.conf
    http {
        upstream web {
            server 192.168.16.186;
            server 192.168.16.187;
        }
     
        server {
            listen 80;
     
            location / {
                proxy_pass http://web;
            }
        }
    }
    [root@proxy ~]# systemctl reload nginx.service
     
     
    #其它服务器curl
    bogon:~ centos$ curl 192.168.16.95
    welcome to web01
    bogon:~ centos$ curl 192.168.16.95
    welcome to web02
    

    2.nginx 调度  轮询  权重  hash

    #轮询
    http {
        upstream myapp1 {
            server srv1.example.com;
            server srv2.example.com;
            server srv3.example.com;
        }
    
        server {
            listen 80;
    
            location / {
                proxy_pass http://myapp1;
            }
        }
    }
    
    
    #权重
    http {
        upstream myapp1 {
            server srv1.example.com weight=3;
            server srv2.example.com;
            server srv3.example.com;
        }
        server {
            listen 80;
    
            location / {
                proxy_pass http://myapp1;
            }
        }
    }
    
    
    #hash
    
    http {
        upstream myapp1 {
           ip_hash;
            server srv1.example.com;
            server srv2.example.com;
            server srv3.example.com;
        }
        server {
            listen 80;
    
            location / {
                proxy_pass http://myapp1;
            }
        }
    }

    4.nfs服务

    #环境准备
    nfs服务端                   192.168.16.95
    web01                      192.168.16.186
    web02                      192.168.16.187
    
    #nfs服务端
    [root@proxy ~]# cat /etc/exports
    /share 192.168.16.0/24(rw,sync,fsid=0)
    [root@proxy ~]# mkdir  /share
    [root@proxy ~]# chmod o+w /share
    [root@proxy ~]# cat /etc/exports
    /share 192.168.16.0/24(rw,sync,fsid=0)
    [root@proxy ~]# mkdir  /share
    [root@proxy ~]# chmod o+w /share
    [root@proxy ~]#  systemctl start rpcbind.service
    [root@proxy ~]# systemctl start nfs-server.service
    [root@proxy ~]# echo "192.168.16.95 proxy" >>/etc/hosts
    [root@proxy ~]# exportfs
    /share        	192.168.16.0/24
    [root@proxy ~]# showmount -e
    Export list for proxy:
    /share 192.168.16.187/24,192.168.16.186/24
    
    #web01 操作
    [root@bogon ~]# yum install rpcbind nfs-utils -y
    [root@web01 ~]#  systemctl start rpcbind.service
    [root@web01 ~]# systemctl start nfs-server.service
    [root@web01 ~]# showmount -e 192.168.16.95
    Export list for 192.168.16.95:
    /share 192.168.16.187/24,192.168.16.186/24
    [root@web01 ~]# mount -t nfs 192.168.16.95:/share /usr/share/nginx/html/
    [root@web01 ~]# df -h
    文件系统              容量  已用  可用 已用% 挂载点
    /dev/mapper/cl-root    18G  4.6G   13G   26% /
    devtmpfs              473M     0  473M    0% /dev
    tmpfs                 489M     0  489M    0% /dev/shm
    tmpfs                 489M  7.1M  482M    2% /run
    tmpfs                 489M     0  489M    0% /sys/fs/cgroup
    /dev/sda1             509M  169M  341M   34% /boot
    tmpfs                  98M     0   98M    0% /run/user/0
    192.168.16.95:/share   18G  5.0G   13G   29% /usr/share/nginx/html
    
    
    #web02 操作
    [root@bogon ~]# yum install rpcbind nfs-utils -y
    [root@web02 ~]#  systemctl start rpcbind.service
    [root@web02 ~]# systemctl start nfs-server.service
    [root@web02 ~]# showmount -e 192.168.16.95
    Export list for 192.168.16.95:
    /share 192.168.16.187/24,192.168.16.186/24
    [root@web01 ~]# mount -t nfs 192.168.16.95:/share /usr/share/nginx/html/
    [root@web02 ~]# mount -t nfs 192.168.16.95:/share /usr/share/nginx/html/
    [root@web02 ~]# df -h
    文件系统              容量  已用  可用 已用% 挂载点
    /dev/mapper/cl-root    18G  4.6G   13G   26% /
    devtmpfs              473M     0  473M    0% /dev
    tmpfs                 489M     0  489M    0% /dev/shm
    tmpfs                 489M  7.1M  482M    2% /run
    tmpfs                 489M     0  489M    0% /sys/fs/cgroup
    /dev/sda1             509M  169M  341M   34% /boot
    tmpfs                  98M     0   98M    0% /run/user/0
    192.168.16.95:/share   18G  5.0G   13G   29% /usr/share/nginx/html
    
    
    #proxy创建文件 web01  web02 查看
    [root@proxy share]# echo "Nginx" >/share/index.html
    
    [root@web01 html]# cat /usr/share/nginx/html/index.html
    Nginx
    
    [root@web02 ~]# cat /usr/share/nginx/html/index.html
    Nginx
    

    5.nginx反向代理+两台web+nfs共享存储实现集群配置

    #在实验2和3的基础上
    
    #在浏览器上访问proxy 192.168.16.95
    
    #在web01上查看
    [root@web01 html]# tail -f /var/log/nginx/access.log
    192.168.16.95 - - [20/Mar/2017:17:10:21 +0800] "GET / HTTP/1.0" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36" "-"
    
    
    #在web02上查看
    [root@web02 html]# tail -f /var/log/nginx/access.log
    192.168.16.95 - - [20/Mar/2017:17:10:17 +0800] "GET / HTTP/1.0" 200 6 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36" "-"
    
    
    
    #浏览器访问proxy,后端的两台nginx会轮询得到nfs服务器的文件
    

      

    6. 源码安装nginx

    [root@web01 html]#yum remove nginx
    [root@web01 html]#useradd -s /sbin/nologin -M www
    [root@web01 html]#yum -y install  pcre pcre-devel openssl openssl-devel
    [root@web01 html]#wget http://nginx.org/download/nginx-1.10.3.tar.gz
    [root@web01 ~]# tar xf nginx-1.10.3.tar.gz
    [root@web01 nginx-1.10.3]# cd nginx-1.10.3/
    [root@web01 nginx-1.10.3]#./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-stream
    [root@web01]#make && make install
    [root@web01~]#/usr/local/nginx/sbin/nginx -t
    [root@web01~]#nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    [root@web01~]#nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
    [root@web01 ~]# echo "Hello Word" > /usr/local/nginx/html/index.html
    [root@web01 ~]# /usr/local/nginx/sbin/nginx
    [root@web01 ~]# curl 192.168.16.186
    Hello Word
    

      

     

  • 相关阅读:
    MVC中使用Ajax提交数据 Jquery Ajax方法传值到action
    Jquery获取select,dropdownlist,checkbox下拉列表框的值
    mvc Attribute NotMapped DisplayName Required 等介绍
    asp.net mvc Controller控制器返回类型
    蓝桥杯必备算法模板
    解决vant-weapp组件库的example的导入问题
    JAVA学习之路(多线程)---模拟售票(细解)
    【位运算,异或】“只出现一次的数字” 的一类问题解决方法
    【蓝桥杯2016第七届比赛题目】JAVA A组
    【API】151. 翻转字符串里的单词
  • 原文地址:https://www.cnblogs.com/golangav/p/6589040.html
Copyright © 2020-2023  润新知