十四.nginx,web,反向代理,调用加权轮询算法,nfs服务

一.部署nginx反向代理web服务,调度算法使用加权轮询

1.首先配置一个nginx服务端,三个web客户端。用vmware 新建虚拟机完成,并用xshell连接

2.在服务端和3web客户端都下载epel_release nginx软件包;

yum install epel_release -y ;  yum install nginx -y

3.关闭服务端和web客户端的防火墙,在服务端和web客户端都开启nginx软件包并且查看是否开启; 如未开启重新启动nginx: systemctl restart nginx;

systemctl stop firewalld ; systemctl status nginx ;

4.在服务端编辑nginx配置文件:vim /etc/nginx/nginx.conf

http{ 下写入

     upstream yuan {

                 # 默认是轮询的方式访问web客户端

                 server 192.168.58.131:80 weight=3;# weight = 3 是加权访问

                 server 192.168.58.132:80;

                 server 192.168.58.134:80;

                  }

location / {

              proxy_pass http://yuan; #

                 }

5.在三个web服务端的 /etc/share/nginx/html 下新建文件并写入内容;

6.登入浏览器访问服务器持续刷新并且观察页面变化,结果是以web13,web2 1次,web31次的顺序加权轮询。

二.所有web服务使用共享nfs,保证所web都对其有读写权限,保证数据一致性:

1.首先配置1nginx服务端,3web客户端,1nfs服务端。用vmware完成,并用xshell连接。

2.nginx服务端,3web客户端上完成反向代理服务,调度算法用加权轮询;过程参考上述题目1答案。

3.nfs服务端,3web客户端上安装rpcbind.service nfs-utils.service 软件包.

 yum install rpcbind.service -y      yum install nfs-utils.service -y

4.nfs服务端/下建share目录 mkdir /share,然后将硬盘格式化  mkfs.ext4 /dev/sdb1 将 其挂载到 /share 目录下,mount /dev/sdb1 /share

 并且配置exports 文件, 写入 /share 192.168.58.0/24(rw,sync,fisd=0) 保存退出

 依次启动rpcbind.service nfs-server.servcie

5.在软件包都启动的情况下,在nfs服务器端查看共享是否成功,共享了哪个文件夹。

exportfs :  同样在web客户端也可以查看 showmount -e 192.168.58.134

 

6.在确定共享建立的情况下,将nfs服务器的 /share目录挂载到3web客户端的ngnixlocation 定义的root目录下,如果没有定义,则挂载到/usr/share/nginx/html 目录下。

:  mount  192.168.58.134:/share /usr/share/nginx/html  ,可用df查看挂载成功。

 

7.进行web服务测试:

一直刷新,数据不变,说明,3web客户端已经共享了nfs服务端的目录。

8.在终端上实验,在其中一个web客户端上新建文件,必须先给web客户端加w权限

 nfs服务端上修改权限:chmod -R o+w /share ,后在web端上的/usr/share/nginx/html 目录下建立文件python.txt ,并在其他web端上查看 和在nfs /share目录下查看,结果也存在。

 

原文地址:https://www.cnblogs.com/njzy-yuan/p/6813639.html