服務(wù)端
# 1、安裝nfs-utils 和 rpcbind
# yum -y install nfs-utils rpcbind
# 2、創(chuàng)建要共享的目錄(可能要一步一步的創(chuàng)建)
# mkdir /data/report/nfs
# 3、修改/etc/exports 10.111.74.247 不是本機ip,是要共享的ip,對誰開放就是誰
# /data/report/nfs 10.111.74.247(rw,no_root_squash)
#參數(shù)no_root_squash的其作用是:NFS客戶端使用共享目錄的用戶,如果是root 的話,所有的操作均在服務(wù)器端映射為root用戶,擁有共享目錄的root權(quán)限!
# 4、開啟nfs
# systemctl start nfs
# 5、如果報錯,可能要先開啟rpcbind
# systemctl start rpcbind
# 6、查看共享目錄
# showmount -e localhost
# 7、設(shè)置開機自啟動
# systemctl enable rpcbind
# systemctl enable nfs-server.server
客戶端
# 客戶端安裝在另外一臺機器上,就是對誰開放的那個誰
# 1、安裝nfs-utils
# yum -y intall nfs-utils
# 2、顯示服務(wù)端可掛載的目錄
# showmount -e 10.111.74.248
# 這個IP是服務(wù)端的IP
# 3、將服務(wù)端的/data/report/nfs 掛載到本地的 /data/report/nfs。實際上是互相共享,無論修改哪一邊,另外一邊也會相應(yīng)的被修改
# mount -t nfs 10.111.74.248:/data/report/nfs /data/report/nfs
# 設(shè)置開機自動掛載
# vi /etc/fstab
# 這個IP是服務(wù)端的IP
# 10.111.74.248:/data/report/nfs/ /data/report/nfs/ nfs defaults,_rnetdev 1 1
文件服務(wù)器
# 一、安裝PCRE
#
# 文檔:菜鳥教程 https://www.runoob.com/linux/Nginx-install-setup.html
# 安裝編譯工具及庫文件
# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
# 首先要安裝 PCRE PCRE 作用是讓 Nginx 支持 Rewrite 功能。
# cd /usr/local/src/
# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
# 解壓
# tar zxvf pcre-8.35.tar.gz
# 進(jìn)入安裝包目錄
# cd pcre-8.35
# ./configure
# make && make install
# 查看pcre版本
# pcre-config --version
# 二、安裝Nginx
# cd /usr/local/src/
# wget http://nginx.org/download/nginx-1.6.2.tar.gz
# tar zxvf nginx-1.6.2.tar.gz
# 進(jìn)入安裝包目錄
# cd nginx-1.6.2
# 編譯安裝
# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
# make
# make install
# 查看nginx版本
# /usr/local/webserver/nginx/sbin/nginx -v
# 修改配置文件
vi /etc/nginx/conf.d/default.conf
# 內(nèi)容
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
# 添加這個
location ~ ^/report/ {
root /data;
#autoindex on;
}
# 添加這個
location ^~/opt/{
alias /data/report/nfs/opt/;
autoindex on;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the php scripts to Apache listening on 127.0.0.1:80
#
#location ~ .php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ .php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /.ht {
# deny all;
#}
# }
# 就可以以ip的形式訪問這個目錄下的文件
# 例如: http://10.111.74.248/data/report/nfs/xxx/xxx.txt
# 例如: http://10.111.74.248:80/data/report/nfs/xxx/xxx.txt
# 非80 端口號監(jiān)聽
server {
listen 8080;
server_name localhost;
location / {
proxy_pass http://192.168.1.100:8081;
proxy_set_header Host $host:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}