搭建nfs服务器
1、nfs服务器安装软件包nfs-utils
[root@nfs ~]yum install -y nfs-utils
2、启动nfs服务
[root@nfs ~]systemctl restart nfs
3、设置nfs开机启动
[root@nfs ~]systemctl enable nfs
4、查看nfs启动情况
[root@nfs ~]# ps aux|grep nfs
root 14320 0.0 0.0 0 0 ? S< 17:24 0:00 [nfsd4_callbacks]
root 14326 0.0 0.0 0 0 ? S 17:24 0:00 [nfsd]
root 14327 0.0 0.0 0 0 ? S 17:24 0:00 [nfsd]
root 14328 0.0 0.0 0 0 ? S 17:24 0:00 [nfsd]
root 14329 0.0 0.0 0 0 ? S 17:24 0:00 [nfsd]
root 14330 0.0 0.0 0 0 ? S 17:24 0:00 [nfsd]
root 14331 0.0 0.0 0 0 ? S 17:24 0:00 [nfsd]
root 14332 0.0 0.0 0 0 ? S 17:24 0:00 [nfsd]
root 14333 0.0 0.0 0 0 ? S 17:24 0:00 [nfsd]
root 14375 0.0 0.0 112824 984 pts/3 S+ 17:25 0:00 grep --color=auto nfs
[root@nfs ~]# ss -anplut |grep rpcbind
udp UNCONN 0 0 *:111 *:* users:(("rpcbind",pid=14295,fd=6))
udp UNCONN 0 0 *:902 *:* users:(("rpcbind",pid=14295,fd=7))
udp UNCONN 0 0 [::]:111 [::]:* users:(("rpcbind",pid=14295,fd=9))
udp UNCONN 0 0 [::]:902 [::]:* users:(("rpcbind",pid=14295,fd=10))
tcp LISTEN 0 128 *:111 *:* users:(("rpcbind",pid=14295,fd=8))
tcp LISTEN 0 128 [::]:111 [::]:* users:(("rpcbind",pid=14295,fd=11))
nfsd进程将监听端口的活外包给了rpcbind进程
5、nfs服务器创建共享文件夹/web
[root@nfs ~]# mkdir /web
[root@nfs ~]# cd /web
[root@nfs web]# echo "welcome to changsha,nongda" > index.html
[root@nfs web]# ls
index.html
6、编辑/etc/exports 文件
[root@nfs web]# vim /etc/exports
/web 192.168.175.0/24(rw,sync,all_squash)
/web——共享的目录的路径
192.168.175.0/24——允许能访问的机器的网段
(rw,sync,all_squash)——拥有的权限 rw:可以读写 sync:在host上修改了数据,里面同步到nfs服务器 all_squash:任何连接的用户都视为普通用户
7、让共享目录生效
[root@nfs web]# exportfs -av
exporting 192.168.175.0/24:/web
8、设置共享目录权限
[root@nfs web]# chown nfsnobody:nfsnobody /web
[root@nfs web]# ll -d /web
drwxr-xr-x 2 nfsnobody nfsnobody 24 8月 26 17:28 /web
9、客户机安装软件nfs-utils
[root@client /]#yum install nfs-utils -y
10、客户机创建挂载目录挂载nfs服务器
[root@client web]# mkdir /nfs-web
[root@client web]# cd /nfs-web/
[root@client nfs-web]# mount 192.168.175.138:/web /nfs-web
11、验证
[root@client nfs-web]# df -Th|grep web
192.168.175.138:/web nfs4 17G 4.8G 13G 28% /nfs-web
[root@client /]# cd /nfs-web
[root@client nfs-web]# ls
index.html
[root@client nfs-web]# cat index.html
welcome to changsha,nongda
12、创建一个nfs-web-6的卷挂载到nfs服务器 共享nfs服务器的/web目录
[root@client nfs-web]# docker volume create --driver local --opt type=nfs --opt o=addr=192.168.175.138,nolock,soft,rw.sync --opt device=:/web nfs-web-6
13、查看nfs-service卷详细信息
[root@client nfs-web]# docker volume inspect nfs-web-6
[
{
"CreatedAt": "2022-08-29T10:47:22+08:00",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/nfs-web-6/_data",
"Name": "nfs-web-6",
"Options": {
"device": ":/web",
"o": "addr=192.168.175.138,nolock,soft,rw,sync",
"type": "nfs"
},
"Scope": "local"
}
]
14、创建一个容器使用nfs-web-6卷
[root@client nfs-web]# docker run -d -p 8818:80 -v nfs-web-6:/usr/share/nginx/html --name siyx-nginx-8 nginx
b0809f0fba02a7961c1b952550f213e8aece246ed0b079104ab55dd411ac7707
扩展:
nfs容易丢失数据,网络不稳定很容易丢失数据
NAS 网络附加存储:网络存储基于标准网络协议实现数据传输,为网络中的windows/linux/Mac os等各种不同的操作系统的计算机提供文件共享和数据备份
需要专业的存储设备——》NAS——》NFS
使用传统的tcp/ip网络
其他的电脑/手机/pad等设备都可以使用