Nginx反向代理功能-实现动静分离

             Nginx反向代理功能-实现动静分离

                                          作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

 

 

一.试验架构准备

1>.试验架构说明

node101.yinzhengjie.org.cn:
  Nginx服务器  

node105.yinzhengjie.org.cn:
  NFS服务器

node106.yinzhengjie.org.cn:
  Apache Httpd服务器

node107.yinzhengjie.org.cn:
  Apache Httpd服务器

node108.yinzhengjie.org.cn:
  Apache Httpd服务器

2>.安装nfs软件

[root@node105.yinzhengjie.org.cn ~]# yum -y install nfs-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
base                                                                                                                                                 | 3.6 kB  00:00:00     
extras                                                                                                                                               | 2.9 kB  00:00:00     
updates                                                                                                                                              | 2.9 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package nfs-utils.x86_64 1:1.3.0-0.65.el7 will be installed
--> Processing Dependency: libtirpc >= 0.2.4-0.7 for package: 1:nfs-utils-1.3.0-0.65.el7.x86_64
--> Processing Dependency: gssproxy >= 0.7.0-3 for package: 1:nfs-utils-1.3.0-0.65.el7.x86_64
--> Processing Dependency: rpcbind for package: 1:nfs-utils-1.3.0-0.65.el7.x86_64
--> Processing Dependency: quota for package: 1:nfs-utils-1.3.0-0.65.el7.x86_64
--> Processing Dependency: libnfsidmap for package: 1:nfs-utils-1.3.0-0.65.el7.x86_64
--> Processing Dependency: libevent for package: 1:nfs-utils-1.3.0-0.65.el7.x86_64
--> Processing Dependency: keyutils for package: 1:nfs-utils-1.3.0-0.65.el7.x86_64
--> Processing Dependency: libtirpc.so.1()(64bit) for package: 1:nfs-utils-1.3.0-0.65.el7.x86_64
--> Processing Dependency: libnfsidmap.so.0()(64bit) for package: 1:nfs-utils-1.3.0-0.65.el7.x86_64
--> Processing Dependency: libevent-2.0.so.5()(64bit) for package: 1:nfs-utils-1.3.0-0.65.el7.x86_64
--> Running transaction check
---> Package gssproxy.x86_64 0:0.7.0-26.el7 will be installed
--> Processing Dependency: libini_config >= 1.3.1-31 for package: gssproxy-0.7.0-26.el7.x86_64
--> Processing Dependency: libverto-module-base for package: gssproxy-0.7.0-26.el7.x86_64
--> Processing Dependency: libref_array.so.1(REF_ARRAY_0.1.1)(64bit) for package: gssproxy-0.7.0-26.el7.x86_64
--> Processing Dependency: libini_config.so.3(INI_CONFIG_1.2.0)(64bit) for package: gssproxy-0.7.0-26.el7.x86_64
--> Processing Dependency: libini_config.so.3(INI_CONFIG_1.1.0)(64bit) for package: gssproxy-0.7.0-26.el7.x86_64
--> Processing Dependency: libref_array.so.1()(64bit) for package: gssproxy-0.7.0-26.el7.x86_64
--> Processing Dependency: libini_config.so.3()(64bit) for package: gssproxy-0.7.0-26.el7.x86_64
--> Processing Dependency: libcollection.so.2()(64bit) for package: gssproxy-0.7.0-26.el7.x86_64
--> Processing Dependency: libbasicobjects.so.0()(64bit) for package: gssproxy-0.7.0-26.el7.x86_64
---> Package keyutils.x86_64 0:1.5.8-3.el7 will be installed
---> Package libevent.x86_64 0:2.0.21-4.el7 will be installed
---> Package libnfsidmap.x86_64 0:0.25-19.el7 will be installed
---> Package libtirpc.x86_64 0:0.2.4-0.16.el7 will be installed
---> Package quota.x86_64 1:4.01-19.el7 will be installed
--> Processing Dependency: quota-nls = 1:4.01-19.el7 for package: 1:quota-4.01-19.el7.x86_64
--> Processing Dependency: tcp_wrappers for package: 1:quota-4.01-19.el7.x86_64
---> Package rpcbind.x86_64 0:0.2.0-48.el7 will be installed
--> Running transaction check
---> Package libbasicobjects.x86_64 0:0.1.1-32.el7 will be installed
---> Package libcollection.x86_64 0:0.7.0-32.el7 will be installed
---> Package libini_config.x86_64 0:1.3.1-32.el7 will be installed
--> Processing Dependency: libpath_utils.so.1(PATH_UTILS_0.2.1)(64bit) for package: libini_config-1.3.1-32.el7.x86_64
--> Processing Dependency: libpath_utils.so.1()(64bit) for package: libini_config-1.3.1-32.el7.x86_64
---> Package libref_array.x86_64 0:0.1.5-32.el7 will be installed
---> Package libverto-libevent.x86_64 0:0.2.5-4.el7 will be installed
---> Package quota-nls.noarch 1:4.01-19.el7 will be installed
---> Package tcp_wrappers.x86_64 0:7.6-77.el7 will be installed
--> Running transaction check
---> Package libpath_utils.x86_64 0:0.2.1-32.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================
 Package                                        Arch                                Version                                         Repository                         Size
============================================================================================================================================================================
Installing:
 nfs-utils                                      x86_64                              1:1.3.0-0.65.el7                                base                              412 k
Installing for dependencies:
 gssproxy                                       x86_64                              0.7.0-26.el7                                    base                              110 k
 keyutils                                       x86_64                              1.5.8-3.el7                                     base                               54 k
 libbasicobjects                                x86_64                              0.1.1-32.el7                                    base                               26 k
 libcollection                                  x86_64                              0.7.0-32.el7                                    base                               42 k
 libevent                                       x86_64                              2.0.21-4.el7                                    base                              214 k
 libini_config                                  x86_64                              1.3.1-32.el7                                    base                               64 k
 libnfsidmap                                    x86_64                              0.25-19.el7                                     base                               50 k
 libpath_utils                                  x86_64                              0.2.1-32.el7                                    base                               28 k
 libref_array                                   x86_64                              0.1.5-32.el7                                    base                               27 k
 libtirpc                                       x86_64                              0.2.4-0.16.el7                                  base                               89 k
 libverto-libevent                              x86_64                              0.2.5-4.el7                                     base                              8.9 k
 quota                                          x86_64                              1:4.01-19.el7                                   base                              179 k
 quota-nls                                      noarch                              1:4.01-19.el7                                   base                               90 k
 rpcbind                                        x86_64                              0.2.0-48.el7                                    base                               60 k
 tcp_wrappers                                   x86_64                              7.6-77.el7                                      base                               78 k

Transaction Summary
============================================================================================================================================================================
Install  1 Package (+15 Dependent packages)

Total download size: 1.5 M
Installed size: 4.3 M
Downloading packages:
(1/16): libbasicobjects-0.1.1-32.el7.x86_64.rpm                                                                                                      |  26 kB  00:00:00     
(2/16): gssproxy-0.7.0-26.el7.x86_64.rpm                                                                                                             | 110 kB  00:00:00     
(3/16): libcollection-0.7.0-32.el7.x86_64.rpm                                                                                                        |  42 kB  00:00:00     
(4/16): libini_config-1.3.1-32.el7.x86_64.rpm                                                                                                        |  64 kB  00:00:00     
(5/16): libnfsidmap-0.25-19.el7.x86_64.rpm                                                                                                           |  50 kB  00:00:00     
(6/16): libpath_utils-0.2.1-32.el7.x86_64.rpm                                                                                                        |  28 kB  00:00:00     
(7/16): libevent-2.0.21-4.el7.x86_64.rpm                                                                                                             | 214 kB  00:00:00     
(8/16): libref_array-0.1.5-32.el7.x86_64.rpm                                                                                                         |  27 kB  00:00:00     
(9/16): libtirpc-0.2.4-0.16.el7.x86_64.rpm                                                                                                           |  89 kB  00:00:00     
(10/16): nfs-utils-1.3.0-0.65.el7.x86_64.rpm                                                                                                         | 412 kB  00:00:00     
(11/16): libverto-libevent-0.2.5-4.el7.x86_64.rpm                                                                                                    | 8.9 kB  00:00:00     
(12/16): quota-4.01-19.el7.x86_64.rpm                                                                                                                | 179 kB  00:00:00     
(13/16): quota-nls-4.01-19.el7.noarch.rpm                                                                                                            |  90 kB  00:00:00     
(14/16): rpcbind-0.2.0-48.el7.x86_64.rpm                                                                                                             |  60 kB  00:00:00     
(15/16): tcp_wrappers-7.6-77.el7.x86_64.rpm                                                                                                          |  78 kB  00:00:00     
(16/16): keyutils-1.5.8-3.el7.x86_64.rpm                                                                                                             |  54 kB  00:00:05     
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                       267 kB/s | 1.5 MB  00:00:05     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libbasicobjects-0.1.1-32.el7.x86_64                                                                                                                     1/16 
  Installing : libref_array-0.1.5-32.el7.x86_64                                                                                                                        2/16 
  Installing : libcollection-0.7.0-32.el7.x86_64                                                                                                                       3/16 
  Installing : libevent-2.0.21-4.el7.x86_64                                                                                                                            4/16 
  Installing : libtirpc-0.2.4-0.16.el7.x86_64                                                                                                                          5/16 
  Installing : rpcbind-0.2.0-48.el7.x86_64                                                                                                                             6/16 
  Installing : libverto-libevent-0.2.5-4.el7.x86_64                                                                                                                    7/16 
  Installing : 1:quota-nls-4.01-19.el7.noarch                                                                                                                          8/16 
  Installing : tcp_wrappers-7.6-77.el7.x86_64                                                                                                                          9/16 
  Installing : 1:quota-4.01-19.el7.x86_64                                                                                                                             10/16 
  Installing : keyutils-1.5.8-3.el7.x86_64                                                                                                                            11/16 
  Installing : libnfsidmap-0.25-19.el7.x86_64                                                                                                                         12/16 
  Installing : libpath_utils-0.2.1-32.el7.x86_64                                                                                                                      13/16 
  Installing : libini_config-1.3.1-32.el7.x86_64                                                                                                                      14/16 
  Installing : gssproxy-0.7.0-26.el7.x86_64                                                                                                                           15/16 
  Installing : 1:nfs-utils-1.3.0-0.65.el7.x86_64                                                                                                                      16/16 
  Verifying  : libtirpc-0.2.4-0.16.el7.x86_64                                                                                                                          1/16 
  Verifying  : libverto-libevent-0.2.5-4.el7.x86_64                                                                                                                    2/16 
  Verifying  : 1:quota-4.01-19.el7.x86_64                                                                                                                              3/16 
  Verifying  : gssproxy-0.7.0-26.el7.x86_64                                                                                                                            4/16 
  Verifying  : libpath_utils-0.2.1-32.el7.x86_64                                                                                                                       5/16 
  Verifying  : libnfsidmap-0.25-19.el7.x86_64                                                                                                                          6/16 
  Verifying  : libevent-2.0.21-4.el7.x86_64                                                                                                                            7/16 
  Verifying  : keyutils-1.5.8-3.el7.x86_64                                                                                                                             8/16 
  Verifying  : 1:nfs-utils-1.3.0-0.65.el7.x86_64                                                                                                                       9/16 
  Verifying  : tcp_wrappers-7.6-77.el7.x86_64                                                                                                                         10/16 
  Verifying  : libcollection-0.7.0-32.el7.x86_64                                                                                                                      11/16 
  Verifying  : libref_array-0.1.5-32.el7.x86_64                                                                                                                       12/16 
  Verifying  : libbasicobjects-0.1.1-32.el7.x86_64                                                                                                                    13/16 
  Verifying  : rpcbind-0.2.0-48.el7.x86_64                                                                                                                            14/16 
  Verifying  : libini_config-1.3.1-32.el7.x86_64                                                                                                                      15/16 
  Verifying  : 1:quota-nls-4.01-19.el7.noarch                                                                                                                         16/16 

Installed:
  nfs-utils.x86_64 1:1.3.0-0.65.el7                                                                                                                                         

Dependency Installed:
  gssproxy.x86_64 0:0.7.0-26.el7           keyutils.x86_64 0:1.5.8-3.el7             libbasicobjects.x86_64 0:0.1.1-32.el7        libcollection.x86_64 0:0.7.0-32.el7      
  libevent.x86_64 0:2.0.21-4.el7           libini_config.x86_64 0:1.3.1-32.el7       libnfsidmap.x86_64 0:0.25-19.el7             libpath_utils.x86_64 0:0.2.1-32.el7      
  libref_array.x86_64 0:0.1.5-32.el7       libtirpc.x86_64 0:0.2.4-0.16.el7          libverto-libevent.x86_64 0:0.2.5-4.el7       quota.x86_64 1:4.01-19.el7               
  quota-nls.noarch 1:4.01-19.el7           rpcbind.x86_64 0:0.2.0-48.el7             tcp_wrappers.x86_64 0:7.6-77.el7            

Complete!
[root@node105.yinzhengjie.org.cn ~]# 
[root@node105.yinzhengjie.org.cn ~]# yum -y install nfs-utils

3>.配置NFS共享并设置为开机启动

[root@node105.yinzhengjie.org.cn ~]# mkdir -pv /data/static
mkdir: created directory ‘/data’
mkdir: created directory ‘/data/static’
[root@node105.yinzhengjie.org.cn ~]# 
[root@node105.yinzhengjie.org.cn ~]# vim /etc/exports
[root@node105.yinzhengjie.org.cn ~]# 
[root@node105.yinzhengjie.org.cn ~]# cat /etc/exports
/data/static *(rw,no_root_squash)
[root@node105.yinzhengjie.org.cn ~]# 
[root@node105.yinzhengjie.org.cn ~]# systemctl start nfs
[root@node105.yinzhengjie.org.cn ~]# 
[root@node105.yinzhengjie.org.cn ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@node105.yinzhengjie.org.cn ~]# 
[root@node105.yinzhengjie.org.cn ~]# 

4>.测试NFS是否可用

[root@node101.yinzhengjie.org.cn ~]# showmount -e node105.yinzhengjie.org.cn          #查看NFS挂载是否可用
Export list for node105.yinzhengjie.org.cn:
/data/static *
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# mount -t nfs node105.yinzhengjie.org.cn:/data/static /yinzhengjie/data/web/nginx/static    #尝试挂载NFS
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# df -TH
Filesystem                              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root                 xfs        54G  1.9G   52G   4% /
devtmpfs                                devtmpfs  4.1G     0  4.1G   0% /dev
tmpfs                                   tmpfs     4.2G     0  4.2G   0% /dev/shm
tmpfs                                   tmpfs     4.2G  9.1M  4.1G   1% /run
tmpfs                                   tmpfs     4.2G     0  4.2G   0% /sys/fs/cgroup
/dev/mapper/centos-home                 xfs       1.1T  3.2G  1.1T   1% /home
/dev/sda1                               xfs       1.1G  153M  912M  15% /boot
tmpfs                                   tmpfs     821M     0  821M   0% /run/user/0
node105.yinzhengjie.org.cn:/data/static nfs4       54G  1.5G   53G   3% /yinzhengjie/data/web/nginx/static
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# umount  /yinzhengjie/data/web/nginx/static        #卸载NFS,我们需要让它开机自动挂载
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# df -TH
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        54G  1.9G   52G   4% /
devtmpfs                devtmpfs  4.1G     0  4.1G   0% /dev
tmpfs                   tmpfs     4.2G     0  4.2G   0% /dev/shm
tmpfs                   tmpfs     4.2G  9.1M  4.1G   1% /run
tmpfs                   tmpfs     4.2G     0  4.2G   0% /sys/fs/cgroup
/dev/mapper/centos-home xfs       1.1T  3.2G  1.1T   1% /home
/dev/sda1               xfs       1.1G  153M  912M  15% /boot
tmpfs                   tmpfs     821M     0  821M   0% /run/user/0
[root@node101.yinzhengjie.org.cn ~]# 

5>.Nginx服务器挂载NFS目录

[root@node101.yinzhengjie.org.cn ~]# df -TH
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        54G  1.9G   52G   4% /
devtmpfs                devtmpfs  4.1G     0  4.1G   0% /dev
tmpfs                   tmpfs     4.2G     0  4.2G   0% /dev/shm
tmpfs                   tmpfs     4.2G  9.1M  4.1G   1% /run
tmpfs                   tmpfs     4.2G     0  4.2G   0% /sys/fs/cgroup
/dev/mapper/centos-home xfs       1.1T  3.2G  1.1T   1% /home
/dev/sda1               xfs       1.1G  153M  912M  15% /boot
tmpfs                   tmpfs     821M     0  821M   0% /run/user/0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# vim /etc/fstab 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Mon Jul  8 16:22:49 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=343e9f9c-8324-4918-a10d-541627af8e04 /boot                   xfs     defaults        0 0
/dev/mapper/centos-home /home                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
node105.yinzhengjie.org.cn:/data/static /yinzhengjie/data/web/nginx/static nfs defaults,_netdev 0 0
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# mount -a
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# df -TH
Filesystem                              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root                 xfs        54G  1.9G   52G   4% /
devtmpfs                                devtmpfs  4.1G     0  4.1G   0% /dev
tmpfs                                   tmpfs     4.2G     0  4.2G   0% /dev/shm
tmpfs                                   tmpfs     4.2G  9.1M  4.1G   1% /run
tmpfs                                   tmpfs     4.2G     0  4.2G   0% /sys/fs/cgroup
/dev/mapper/centos-home                 xfs       1.1T  3.2G  1.1T   1% /home
/dev/sda1                               xfs       1.1G  153M  912M  15% /boot
tmpfs                                   tmpfs     821M     0  821M   0% /run/user/0
node105.yinzhengjie.org.cn:/data/static nfs4       54G  1.5G   53G   3% /yinzhengjie/data/web/nginx/static
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

温馨提示:
  设置开机自动挂载网络设备时必须要添加"_netdev",这样可用避免操作系统在没有获取IP地址之前对网络服务进行挂载的情况。若不配置该参数在服务器未配置IP地址时会一直尝试挂载导致操作系统无法正常启动,当配置了该参数后可用让操作系统正常启动并获得IP地址后才会挂载。

 

二.Nginx配置动静分离

1>.编辑主配置文件

[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/nginx/conf/nginx.conf
worker_processes  4;
worker_cpu_affinity 00000001 00000010 00000100 00001000; 
 
events {
   worker_connections  100000;
   use epoll;
   accept_mutex on;
   multi_accept on; 
}
   
http {
     include       mime.types;
       
     default_type  text/html;
    
     server_tokens off; 
      
     charset utf-8;
   
     log_format my_access_json '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",' '"clientip":"$remote_addr",' '"size":$body_bytes_sent,' '"responsetime":$request_ti
me,' '"upstreamtime":"$upstream_response_time",' '"upstreamhost":"$upstream_addr",' '"http_host":"$host",' '"uri":"$uri",' '"domain":"$host",' '"xff":"$http_x_forwarded_for",' '"referer":"$http_referer",' '"tcp_xff":"$proxy_protocol_addr",' '"http_user_agent":"$http_user_agent",' '"status":"$status"}';   
    access_log logs/access_json.log my_access_json;
 
    ssl_certificate /yinzhengjie/softwares/nginx/certs/www.yinzhengjie.org.cn.crt;
    ssl_certificate_key /yinzhengjie/softwares/nginx/certs/www.yinzhengjie.org.cn.key;
    ssl_session_cache shared:sslcache:20m;
    ssl_session_timeout 10m;
  
    include /yinzhengjie/softwares/nginx/conf.d/*.conf;
}
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nginx -t
nginx: the configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf test is successful
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

2>.编辑子配置文件

[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/nginx/conf.d/node101_yinzhengjie_org.cn.conf 
upstream webserver {
    server 172.30.1.106:80 weight=1 fail_timeout=5s max_fails=3;
    server 172.30.1.107:80 weight=1 fail_timeout=5s max_fails=3;
    server 172.30.1.108:80 weight=1 fail_timeout=5s max_fails=3 backup;
    #ip_hash;
    #least_conn;
    hash $request_uri consistent;
}


server {
    listen 80;
    listen 443 ssl;
    server_name node101.yinzhengjie.org.cn;
 
    access_log /yinzhengjie/softwares/nginx/logs/node101_yinzhengjie_org_cn_access.log my_access_json;
    error_log /yinzhengjie/softwares/nginx/logs/node101_yinzhengjie_org_cn_error.log;

    location / {
       root /yinzhengjie/data/web/nginx;
       index index.html;
    }

    location = /favicon.ico {
       root /yinzhengjie/data/web/nginx/images/jd;
    }

    location /app01 {
        proxy_pass http://webserver;
        proxy_connect_timeout 60s;
    }

    #将访问图片之类的静态资源直接访问NFS共享目录服务器
    location ~* \.(gif|jpg|jpeg|bmp|png|tiff|tif|ico|wmf|js)$ {
        root /yinzhengjie/data/web/nginx/static;
    }
}
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nginx -t
nginx: the configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf test is successful
[root@node101.yinzhengjie.org.cn ~]# 

3>.重新加载nginx的配置文件

[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep nginx | grep -v grep
root     22837     1  0 Dec27 ?        00:00:00 nginx: master process nginx
nginx    23047 22837  0 Dec27 ?        00:00:19 nginx: worker process
nginx    23048 22837  0 Dec27 ?        00:00:05 nginx: worker process
nginx    23049 22837  0 Dec27 ?        00:00:13 nginx: worker process
nginx    23050 22837  0 Dec27 ?        00:00:19 nginx: worker process
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nginx -s reload
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep nginx | grep -v grep
root     22837     1  0 Dec27 ?        00:00:00 nginx: master process nginx
nginx    23700 22837  0 08:42 ?        00:00:00 nginx: worker process
nginx    23701 22837  0 08:42 ?        00:00:00 nginx: worker process
nginx    23702 22837  0 08:42 ?        00:00:00 nginx: worker process
nginx    23703 22837  0 08:42 ?        00:00:00 nginx: worker process
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

4>.在node105.yinzhengjie.org.cn节点添加测试数据

[root@node105.yinzhengjie.org.cn ~]# ll
total 1004
-rw-r--r-- 1 root root 1025154 Dec 24 18:05 01.png
[root@node105.yinzhengjie.org.cn ~]# 
[root@node105.yinzhengjie.org.cn ~]# 
[root@node105.yinzhengjie.org.cn ~]# mv 01.png /data/static/
[root@node105.yinzhengjie.org.cn ~]# 
[root@node105.yinzhengjie.org.cn ~]# ll /data/static/
total 1004
-rw-r--r-- 1 root root 1025154 Dec 24 18:05 01.png
[root@node105.yinzhengjie.org.cn ~]# 

5>.在Nginx服务器上查看是否有相应的数据

[root@node101.yinzhengjie.org.cn ~]# df -TH
Filesystem                              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root                 xfs        54G  1.9G   52G   4% /
devtmpfs                                devtmpfs  4.1G     0  4.1G   0% /dev
tmpfs                                   tmpfs     4.2G     0  4.2G   0% /dev/shm
tmpfs                                   tmpfs     4.2G  9.1M  4.1G   1% /run
tmpfs                                   tmpfs     4.2G     0  4.2G   0% /sys/fs/cgroup
/dev/mapper/centos-home                 xfs       1.1T  3.2G  1.1T   1% /home
/dev/sda1                               xfs       1.1G  153M  912M  15% /boot
tmpfs                                   tmpfs     821M     0  821M   0% /run/user/0
node105.yinzhengjie.org.cn:/data/static nfs4       54G  1.5G   53G   3% /yinzhengjie/data/web/nginx/static
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /yinzhengjie/data/web/nginx/static/
total 1004
-rw-r--r-- 1 root root 1025154 Dec 24 18:05 01.png
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

6>.浏览器访问Nginx的静态资源(http://node101.yinzhengjie.org.cn/01.png)时会自动返回NFS共享的数据

 

posted @ 2019-12-27 01:12  尹正杰  阅读(375)  评论(0编辑  收藏  举报