您的位置:首页 > 其它

nfs服务,autofs自动挂载

2017-12-12 21:22 447 查看

cifs—-nfs(文件系统的共享)

注意:服务器的版本要与镜像一致

服务端:
yum install nfs-utils -y
15  systemctl start nfs
16  firewall-cmd --get-services
17  firewall-cmd --permanent --add-service=nfs  ##添加火墙策略
18  firewall-cmd --permanent --add-service=rpc-bind
19  firewall-cmd --permanent --add-service=mountd     ##给了服务,客户端才能使用
20  firewall-cmd --reload    ##加载火墙策略
21  mkdir /westos/nfs -p     ##建立共享目录
22  vim /etc/exports

/westos/nfs    *(sync)  ##将/westos/nfs文件共享出去,所有人都可以看,sync内存中数据写入磁盘,即数据共享

23  exportfs -rv      ##相当于重起,Reexport,每次更改此文件都需要刷新,r--重新挂载,v--共享的目录




客户端:
105  showmount -e 172.25.254.109
106  mount 172.25.254.109:/westos/nfs /mnt    ##挂载共享目录
107  df




部分基本配置:

服务端:
[root@server ~]# useradd westos
[root@server ~]# id westos
uid=1001(westos) gid=1001(westos) groups=1001(westos)
chmod 777 /westos/nfs    ##使文件可写
vim /etc/exports

/westos/nfs    *(sync,rw,anonuid=1001,anongid=1001)    ##指定已存在的id,可以看见是谁更改了共享文件,未更改时默认nobody
/westos/nfs    *(sync,rw,no_root_squash)    ##默认任何人更改身份都为超户
/westos/nfs    172.25.254.209(sync,rw,no_root_squash) *(sync,ro)   ##指定只有209可以更改,其他只读

exportfs -rv

客户端:
vim /etc/auto.nfs
nfs    -rw    172.25.254.109:/westos/nfs     ##挂载可写

[root@client nfs]# touch file2
[root@client nfs]# ls -l
total 0
-rw-r--r-- 1 root   root   0 Dec  8 22:14 file
-rw-r--r-- 1 westos westos 0 Dec  8 22:22 file1
-rw-r--r-- 1 root   root   0 Dec  8 22:25 file2










autofs自动挂载器

客户端:
108  yum install autofs.x86_64  -y    ##此服务是自动挂载和卸载
109  systemctl start autofs
110  ls -ld /net
111  rpm -qc autofs    ##查询安装文件位置
112  vim /etc/sysconfig/autofs

TIMEOUT=5   ##5秒之后自动卸载

113  systemctl restart autofs.service
114  cd /net/172.25.254.109/westos/nfs  ##只有进入这个目录之后才会自动挂载
115  ls








注意看两次的时间变化



客户端:
修改自动挂载目录:
vim /etc/auto.master    ##最终挂在点的上层目录和子配置文件

/westos/linux        /etc/auto.nfs
|                       |
最终挂在点的上层目录       子配置文件

vim /etc/auto.nfs

nfs    -ro    172.25.254.109:/westos/nfs     ##需要挂载的目录,-ro为只读,也可添加其他,例:notime,访问时不改变时间

systemctl restart autofs.service

检测:cd /westos/linux/nfs   df   head -n 10 /etc/auto.master   ##查看挂载状况




/etc/auto.master



/etc/auto.nfs

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: