赞
踩
实验环境准备两台机器,支持多节点同时挂载以及并发写入
服务端:nfs-server 192.168.221.136
客户端:web1 192.168.221.138
centos7(服务端和客户端都关闭防火墙和selinux内核防火墙)
#systemctl stop firewalld
#systemctl disable firewalld
#setenforce 0
[root@nfs-server ~]# yum -y install rpcbind //安装rpc协议的包
[root@nfs-server ~]# yum -y install nfs-utils //安装nfs服务。
启动服务
[root@nfs-server ~]# systemctl start nfs && systemctl enable nfs
[root@nfs-server ~]# systemctl start rpcbind && systemctl enable rpcbind
[root@nfs-server ~]# mkdir /nfs-dir //创建存储目录
[root@nfs-server ~]# vim /etc/exports //编辑共享文件
/nfs-dir 192.168.221.0/24(rw,no_root_squash,sync)
这里表示共享给192.168.221.0/24网络地址段的所有IP读写的权限。
可选参数注释:
ro:只读
rw:读写
* :表示共享给所有网段。
sync:所有数据在请求时写入共享
root_squash: 对于使用分享目录的使用者,如果是root用户,那么这个使用者的权限将被压缩成为匿名使用者。
no_root_squash:使用分享目录的使用者,如果是 root 的话,那么对于这个分享的目录来说,他就具有 root 的权限。
[root@nfs-server ~]# exportfs -rv //刷新并输出详细配置。
[root@nfs-server ~]# systemctl enable nfs-server //制作开机启动
[root@web1 ~]# yum -y install rpcbind nfs-utils [root@web1 ~]# mkdir /qf //创建挂载点 [root@web1 ~]# mount -t nfs 192.168.221.136:/nfs-dir /qf //挂载 -t:指定文件系统类型 [root@web1 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 17G 1.1G 16G 7% / tmpfs tmpfs 98M 0 98M 0% /run/user/0 192.168.221.136:/nfs-dir nfs4 36G 1.9G 34G 6% /qf [root@web1 ~]# touch /qf/test.txt [root@web1 ~]# umount /qf //取消挂载 制作开机挂载(fstab开机挂载) [root@web1 ~]# cat >>/etc/fstab<<EOF 192.168.221.136:/nfs-dir /qf nfs defaults 0 0 EOF [root@web1 ~]# mount -a rc.local开机自启动挂载(推荐) [root@web1 ~]# chmod o+x /etc/rc.local [root@web1 ~]# echo '/usr/bin/mount -t nfs 192.168.221.136:/nfs-dir /qf' >>/etc/rc.local [root@web1 ~]# systemctl enable rc-local [root@web1 ~]# df -Th 查看rpc信息 [root@web1 ~]# rpcinfo -p 查看NFS共享目录 [root@web1 ~]# showmount -e 192.168.221.136
FTP和NFS是两种不同的网络文件传输协议,具有以下区别:
FTP是一种基于客户端—服务器的协议,用于文件传输。NFS则是一种分布式文件系统协议,作为本地操作系统和远程文件系统之间的桥梁,可以实现跨平台文件共享。
由于FTP是基于客户端—服务器的协议,所以需要进行连接的建立和关闭,因此相对于NFS,FTP传输的速度较慢,效率也较低。而NFS则是通过一些标准和规定管理远程文件系统的,直接访问远程文件系统,传输速度和效率更高。
FTP协议的安全性比较差,数据传输时通常不加密,可能会被非法获取。而NFS使用一些安全机制来实现远程文件系统的访问和传输,因此相对于FTP,NFS更加安全可靠。
FTP协议是通过FTP客户端和FTP服务器进行文件传输。而NFS通过共享文件系统的方式使用本地文件系统来挂载远程文件系统,实现文件共享。
FTP协议是一种常见的文件传输协议,广泛应用于所有操作系统平台。而NFS多用于UNIX和Linux中,虽然现在也有一些移植到其他平台的版本,但是还是没有FTP使用广泛。
nfs-server:存放代码应用
安装组件:rpcbind
,nfs-utils
IP:192.168.221.136
[root@nfs-server ~]# yum -y install rpcbind nfs-utils
启动服务
[root@nfs-server ~]# systemctl start nfs && systemctl enable nfs
[root@nfs-server ~]# systemctl start rpcbind && systemctl enable rpcbind
[root@nfs-server ~]# mkdir /nfs-data //创建存储目录
[root@nfs-server ~]# vim /etc/exports //编辑共享文件
/nfs-data 192.168.221.0/24(rw,no_root_squash,sync)
[root@nfs-server ~]#exportfs -rv
安装组件:nginx
,rpcbind
,nfs-utils
IP: 192.168.221.138
上传nginx源码包
[root@web1 ~]# yum -y install gcc make zlib-devel pcre pcre-devel openssl-devel
[root@web1 ~]# tar xzf nginx-1.22.1.tar.gz && cd nginx-1.22.1
[root@web1 ~]# ./configure --prefix=/usr/local/nginx
[root@web1 ~]# make && make install
[root@web1 ~]# /usr/local/nginx/sbin/nginx
[root@web1 ~]# yum -y install rpcbind nfs-utils
[root@web1 ~]# mkdir -p /data/wwwroot
[root@web1 ~]# showmount -e 192.168.221.136
[root@web1 ~]# mount -t nfs 192.168.221.136:/nfs-data /data/wwwroot
rc.local开机自启动挂载
[root@web1 ~]#chmod o+x /etc/rc.local
[root@web1 ~]#echo '/usr/bin/mount -t nfs 192.168.221.136:/nfs-data /data/wwwroot' >>/etc/rc.local
[root@web1 ~]#systemctl enable rc-local
[root@nfs-server ~]# cat >>/data/wwwroot/index.html<<EOF
hello
EOF
[root@web1 ~]# vim /usr/local/nginx/conf/nginx.conf
修改root html;为 root /data/wwwroot;
location / {
root html;
index index.html index.htm;
}
如下:
location / {
root /data/wwwroot;
index index.html index.htm;
}
[root@web1 ~]# /usr/local/nginx/sbin/nginx -t
[root@web1 ~]# /usr/local/nginx/sbin/nginx -s reload
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。