LINUX之NFS服务器部署

主机IP
服务端192.168.201.131
客户端192.168.201.132

1.服务端配置

1.1 安装NFS和rpc

[root@hx1 ~]# yum install -y nfs-utils
[root@hx1 ~]# yum install -y rpcbind

1.2 启动服务和设置开启启动

[root@hx1 ~]# systemctl start rpcbind
[root@hx1 ~]# systemctl enable rpcbind
[root@hx1 ~]# systemctl start nfs-server
[root@hx1 ~]# systemctl enable nfs-server

1.3 配置防火墙放行nfs服务(防火墙关闭情况下忽略此步骤)

[root@hx1 ~]# firewall-cmd --permanent --add-service=nfs
[root@hx1 ~]# firewall-cmd --permanent --add-service=rpc-bind
[root@hx1 ~]# firewall-cmd --permanent --add-service=mountd
[root@hx1 ~]# firewall-cmd --reload
# 也可以放行端口
[root@hx1 ~]# firewall-cmd --permanent --add-port=111/tcp
[root@hx1 ~]# firewall-cmd --permanent --add-port=111/udp
[root@hx1 ~]# firewall-cmd --permanent --add-port=2049/tcp
[root@hx1 ~]# firewall-cmd --permanent --add-port=20048/tcp
[root@hx1 ~]# firewall-cmd --reload
# 如果使用的是 iptables,可以使用以下命令
[root@hx1 ~]# iptables -A INPUT -p tcp --dport 111 -j ACCEPT
[root@hx1 ~]# iptables -A INPUT -p udp --dport 111 -j ACCEPT
[root@hx1 ~]# iptables -A INPUT -p tcp --dport 2049 -j ACCEPT
[root@hx1 ~]# iptables -A INPUT -p tcp --dport 20048 -j ACCEPT
[root@hx1 ~]# service iptables save

1.4 配置共享文件目录,编辑配置文件

# 创建共享目录,然后在/etc/exports配置文件中编辑配置即可
[root@hx1 ~]# mkdir /test1
[root@hx1 ~]# vi /etc/exports
/test1 192.168.201.0/24(rw,no_root_squash)
[root@hx1 ~]# systemctl reload nfs
参数作用
ro只读
rw读写
root_squash当NFS客户端以root管理员访问时,映射为NFS服务器的匿名用户
no_root_squash当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员
all_squash无论NFS客户端使用什么账户访问,均映射为NFS服务器的匿名用户
sync同时将数据写入到内存与硬盘中,保证不丢失数据
no_all_squash保留共享文件的UID和GID(默认)
async优先将数据保存到内存,然后再写入硬盘;效率更高,但可能会丢失数据

2.客户端配置

2.1 安装NFS

[root@hx1 ~]# yum -y install nfs-utils

2.2 查看nfs服务器共享信息

[root@hx1 ~]# showmount -e 192.168.201.132
Export list for 192.168.201.132:
/test1 192.168.201.0/24

2.3 挂载文件系统(持久化挂载)

[root@hx1 ~]# vi /etc/fstab

192.168.201.132:/test1 /test1 nfs noatime,nodiratime,defaults,_netdev 0 0

[root@hx1 ~]# mount -a

[root@hx1 ~]# df -Th
文件系统                类型      容量  已用  可用 已用% 挂载点
devtmpfs                devtmpfs  1.9G     0  1.9G    0% /dev
tmpfs                   tmpfs     1.9G   68K  1.9G    1% /dev/shm
tmpfs                   tmpfs     1.9G   12M  1.9G    1% /run
tmpfs                   tmpfs     1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        50G  2.2G   48G    5% /
/dev/mapper/centos-home xfs        46G   33M   46G    1% /home
/dev/sda1               xfs      1014M  151M  864M   15% /boot
tmpfs                   tmpfs     378M     0  378M    0% /run/user/0
/dev/sr0                iso9660   4.4G  4.4G     0  100% /mnt
192.168.201.132:/test1  nfs4     1014M   32M  982M    4% /test1
  • 16
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值