> CentOS > CentOS服务器 > 环境配置 >

在RHEL/CENTOS7上安装NFS

NFS serverclient安装在RHEL/CENTOS7
Server RHEL7server1.example.com and IP as 192.168.0.100
Client RHEL7client1.example.com and IP as  192.168.0.101
Server
安装:
yum install nfs-utils
配置:
mkdir /var/nfsshare
chmod -R 777 /var/nfsshare/
       *:这里使用/var/nfsshare作为共享目录,如果使用其他比如/home作为共享目录,请不要更改权限,会造成权限问题和破坏系统层次结构。
启动服务并加到启动目录:
systemctl enable rpcbind
systemctl enable nfs-server
systemctl enable nfs-lock
systemctl enable nfs-idmap
systemctl start rpcbind
systemctl start nfs-server
systemctl start nfs-lock
systemctl start nfs-idmap
修改配置文件共享/var/nfsshare和/home:
Vi /etc/exports
写入:
/var/nfsshare    192.168.0.101(rw,sync,no_root_squash,no_all_squash)
/home            192.168.0.101(rw,sync,no_root_squash,no_all_squash)
如果任何人都能访问,将192.168.0.101改成“*”。
重启nfs服务:
systemctl restart nfs-server
防火墙:
firewall-cmd --permanent --zone=public --add-service=nfs
firewall-cmd –reload
 
 
Client
安装:
yum install nfs-utils
创建挂载目录:
mkdir -p /mnt/nfs/home
mkdir -p /mnt/nfs/var/nfsshare
启动服务:systemctl enable rpcbind
systemctl enable nfs-server
systemctl enable nfs-lock
systemctl start rpcbind
systemctl start nfs-lock
最后挂载:
mount -t nfs 192.168.0.100:/home /mnt/nfs/home/
mount -t nfs 192.168.0.100:/var/nfsshare /mnt/nfs/var/nfsshare/
无错:
df –kh
[root@client1 ~]# df -kh
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/centos-root        39G  1.1G   38G   3% /
devtmpfs                      488M     0  488M   0% /dev
tmpfs                         494M     0  494M   0% /dev/shm
tmpfs                         494M  6.7M  487M   2% /run
tmpfs                         494M     0  494M   0% /sys/fs/cgroup
/dev/mapper/centos-home        19G   33M   19G   1% /home
/dev/sda1                     497M  126M  372M  26% /boot
192.168.0.100:/var/nfsshare   39G  980M   38G   3% /mnt/nfs/var/nfsshare
192.168.0.100:/home           19G   33M   19G   1% /mnt/nfs/home
[root@client1 ~]#
测试一下:
touch /mnt/nfs/var/nfsshare/test_nfs
OK!!!!!!!!
PS:
开机挂载:
Vi /etc/fstab
Add:
192.168.0.100:/home    /mnt/nfs/home   nfs defaults 0 0
192.168.0.100:/var/nfsshare    /mnt/nfs/var/nfsshare   nfs defaults 0 0


(责任编辑:IT)