NFS服务
NFS(Network File System )简称网络文件系统,基于内核的文件系统。通过使用NFS,用户和程序可以像访问本地文件一样访问远端系统上的 文件,基于RPC(Remote Procedure Call Protocol远程过程调用)实现,可以通过网络访问,本地终端可减少自身存储系统的使用,接下来让我们一起通过实验来简单的认识一下NFS服务吧!
实验一 简单实现NFS服务
1、启动NFS服务
[root@localhost ~]#systemctl restart nfs
2、设置NFS服务开机自启
[root@localhost ~]#systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
3、配置相关文件
[root@localhost ~]#vim /etc/exports
/app/nfsdir1 *(sync)
[root@localhost ~]#vim /etc/exports.d/*.exports
/app/nfsdir2 172.18.254.64(sync)
编辑配置文件的相关配置中选项:
ro 只读
rw 可读可写
all_squash 所有人(除root)都被镇压
no_all_squash 所有人(除root)都不被镇压,默认
root_squash root被镇压为nfsnobody,默认
no_root_squash root不被镇压
sync 立即同步
async 异步
anonuid=48 如被镇压,则uid被镇压为指定的uid
anongid=48 如被镇压,则gid被镇压为指定的gid
4、配置完成后在客服端测试并进行挂载
[root@localhost ~]# showmount -e 172.18.250.243
Export list for 172.18.250.243:
/app/nfsdir1 *
/app/nfsdir2 172.18.254.64
[root@localhost mnt]# mount 172.18.250.243:/app/nfsdir1 /mnt/nfs1 挂载
[root@localhost mnt]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 20511356 4360464 15102316 23% /
tmpfs 502056 72 501984 1% /dev/shm
/dev/sda3 10190136 49524 9616324 1% /app
/dev/sda1 194241 35107 148894 20% /boot
172.18.250.243:/app/nfsdir1
10475520 33024 10442496 1% /mnt/nfs1
[root@localhost nfs1]# cat t 检测
hello
实验二 使用NFS,NIS,AUTOFS实现用户帐号及家目录的漫游
- 配置NIS服务
1.安装相关软件
[root@localhost nfsdir1]#yum -y install ypserv ypbind yp-tools
2.配置nisdomain
[root@localhost nfsdir1]#vim /etc/sysconfig/network NISDOMAIN=nv
[root@localhost nfsdir1]#nisdomainname nv
3.配置nis服务的主配置文件
[root@localhost nfsdir1]# vim /etc/ypserv.conf
127.0.0.1:*:*:none
192.168.153.0/255.255.255.0:*:*:none
*:*:*:deny
4.启动nis服务
[root@localhost nfsdir1]# systemctl restart ypserv
[root@localhost nfsdir1]# systemctl enable ypserv
5.创建用户
[root@localhost nfsdir1]#useradd -u 2001 -d /app/homedir/li li
[root@localhost nfsdir1]# useradd -u 2000 -d /app/homedir/hao hao
[root@localhost nfsdir1]#for n in {1..5};do useradd -d /app/homedir/nisuser$n nisuser$n;echo centos |passwd --stdin nisuser$n;done
并设置密码
[root@localhost nfsdir1]# echo centos |passwd --stdin hao; echo centos |passwd --stdin passwd li
6.nis生成数据库
[root@localhost nfsdir1]#/usr/lib64/yp/ypinit -m
ctrl+d
y
7.在客户端用setup配置来连接到nis服务,客户端需要确保ypbind安装
- 配置NFS服务
[root@localhost nfsdir1]#vim /etc/exports.d/mage.exports
[root@localhost nfsdir1]#systemctl restart nfs
- autofs相关配置
1.安装autofs
[root@localhost ~]#yum -y install autofs
2.配置主配置文件
[root@localhost ~]#vim /etc/auto.master
/app/homedir /etc/auto.mage --timeout=10
[root@localhost ~]# vim /etc/auto.mage
* -fstype=nfs 192.168.153.7:/app/homedir/&
3.重启autofs服务
[root@localhost ~]#service autofs restart
实验三 在centos7中autofs 可以使用绝对路径以避免基名的上一级目录的原始内容被覆盖
[root@localhost ~]#vim /etc/auto.master
/- /etc/auto.home
[root@localhost ~]# vim /etc/auto.home
/home/cdrom -fstype=iso9660 :/dev/cdrom
[root@localhost ~]# systemctl restart autofs
配置伪根
创建伪装目录
[root@localhost ~]# mkdir -p /nfsroot/dir{1..2}
进行bind的挂载
[root@localhost ~]# mount -B /app/nfsdir1 /nfsroot/dir1/
[root@localhost ~]# mount -B /app/nfsdir2 /nfsroot/dir2/
编辑NFS相关配置文件,实现指定目录共享
[root@localhost ~]# vim /etc/exports
/nfsroot *(rw,fsid=0,crossmnt)
/nfsroot/dir1 *(rw)
/nfsroot/dir2 *(ro)
启动服务并进行挂载
[root@localhost ~]# systemctl restart autofs
[root@localhost ~]#mount 172.18.250.243:/nfsroot/dir1 /mnt/nfs1/
这样配置完成后,原目录下的原有文件就不会被遮挡住了。