搭建nginx代理服务器
- 原理:
- 1、在proxy-1的nginx.conf主配置文件后添加
- 2、修改proxy-1的子配置文件
- 3、修改存储服务器的一些配置
- 4、启动服务测试:
原理:
通过代理服务器进行访问,减小web1和web2的负担
资源是不直接放在web1和web2下的,而是由存储服务器进行调度。web1和web2通过挂载共享服务器的目录实现资源映射。

一台代理服务器+二台(或者多台)服务器+存储服务器
proxy-1代理服务器:192.168.33.161
【注意】proxy-1是web-1-service克隆后修改的
web-1-service服务器:192.168.33.171
web-2-service服务器:192.168.33.172
NFS-File:192.168.33.151
1、在proxy-1的nginx.conf主配置文件后添加
/etc/nginx/nginx.conf
#指定后端服务器集群,webServer为自定义集群名
#weight 为负载比例 代理请求失败最多尝试3次,3次之后15s内不在对它代理upstream webServer {server 192.168.88.100 weight=1 max_fails=3 fail_timeout=15s;server 192.168.88.101 weight=1 max_fails=3 fail_timeout=15s;}
2、修改proxy-1的子配置文件
location / {root /usr/share/nginx/html;index index.html index.htm;#指定该匹配项的后台服务器集群名proxy_pass http://webServer;#传递客户的ip信息给台服务器 在后台服务通过参数$http_x_real_ip取得该传递的IP信息proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#优化代理连接proxy_redirect off;proxy_connect_timeout 30;proxy_send_timeout 15;proxy_read_timeout 15;}
3、修改存储服务器的一些配置
(1)安装rpcbind 服务:
yum install rpcbind
设置rpcbind 服务开机自动启动:
systemctl start rpcbind
systemctl enable rpcbind
(2)安装nfs 服务:
yum install nfs-utils.x86_64
配置nfs服务共享目录:
配置文件为/etc/exports
vi /etc/exports
/webData *(rw,sync,all_squash,anonuid=99,anongid=99)
建立共享目录,授权:
mdkir /webData
chown nobody:nobody -R /webData/
4、启动服务测试:
确保:rpcbind服务处于运行状态,共享的目录存在
systemctl restart nfssystemctl enable nfs
systemctl status nfs
● nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
Active: active (exited) since 五 2020-11-06 15:00:50 CST; 1min 36s ago
关闭防火墙
iptables -F
setenforce 0
在任何可以通信的机器或者本机查看是否可以看得到共享的目录
showmount -e 192.168.33.151
Export list for 192.168.88.200:
/webData *
【注意】
showmount命令需要安装包nfs-utils-1.3.0-0.66.el7_8.x86_64
web-1-service,web-2-service需要安装nfs-utils-1.3.0-0.66.el7_8.x86_64
mount挂载使用:
注意:安装对应的nfs文件系统的格式支持
yum install -y nfs-utils-1.3.0-0.66.el7_8.x86_64
mount 192.168.33.151:/webData /mnt
df ----查看挂载信息
如果需要卸载:
umount /mnt
















