centos下安装nfs

centos下安装nfs

1.安装

nfs服务器ip:192.168.44.12

# yum install nfs-utils rpcbind

安装完以后先不急着启动,先来了解一下nfs服务运行在哪些端口上,它默认需要使用5个端口,其中有4个端口是动态的,所以如果服务器和客户端之间有iptables,就要先把这4个动态端口设置成静态的,查看iptables是否开启了,然后加入进防火墙规则里,需要修改的端口有如下四个(端口可以根据需求改,不一定就和我这一样)

2.编辑nfs配置文件

# vi /etc/sysconfig/nfs

LOCKD_TCPPORT=30001 #TCP锁使用端口
LOCKD_UDPPORT=30002 #UDP锁使用端口
MOUNTD_PORT=30003 #挂载使用端口
STATD_PORT=30004 #状态使用端口

# service iptables status

除了以上四个端口要通过iptables,还有nfs协议端口2049以及rpc的111端口,这样才能顺利的使用nfs服务

# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m tcp --dport 111 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 2049 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3001 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3002 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3003 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 3004 -j ACCEPT

# service iptables reload

3.创建测试文件

# mkdir /home/wwwroot/default/upload
# touch /home/wwwroot/default/upload/test

4.添加客户端机器

# vi /etc/exports

把/home/wwwroot/default目录共享给192.168.44.13 主机,可以写主机名、域名等,使用默认参数(ro,sync,wdelay,root_squash)

/home/wwwroot/default/upload 192.168.44.13(rw,sync,no_root_squash)
/home/wwwroot/default/upload 192.168.44.11(rw,sync,no_root_squash)

5.参数详解

  • ro #只读共享
  • rw #读写共享
  • sync #同步写操作
  • async #异步写操作
  • wdelay #延迟写操作
  • root_squash #屏蔽远程root权限
  • no_root_squash #不屏蔽远程root权限
  • all_squash #屏蔽所有远程用户的权限

6.启动nfs服务

# service nfs start
# service rpcbind start
# chkconfig nfs on
# chkconfig rpcbind on

1.客户端安装nfs

# yum install nfs-utils

2.挂载

查看挂载的情况

# mount -l

挂载nfs服务器的共享目录到/home/wwwroot/default/

# mount -t nfs 192.168.44.12:/home/wwwroot/default/upload  /home/wwwroot/default/upload

取消挂载

# umount  -l /home/wwwroot/default/upload

3.开机自动挂载,添加在客户端机器

 # echo "192.168.44.12:/home/wwwroot/default/upload  /home/wwwroot/default/upload nfs defaults 0 0" >> /etc/fstab

其它的客户端的nfs安装一样,并且需要在nfs服务器的/etc/exports下新增下ip。

你可能感兴趣的:(centos下安装nfs)