CentOS7部署NFS存储服务
环境准备
-
主机
本文搭建的NFS存储服务需要两个主机,一台为NFS存储服务器,另一台充当NFS的客户端进行挂载。
主机名 | 网卡1(外网)非必须 | 网卡2(内网)必须 | 系统 | 其他 |
---|---|---|---|---|
nfs-server | 192.168.72.130 | 202.207.240.130 | CentOS7.5.1804 | MEM:2G 、CPU:2C/2P 、DISK:15G |
nfs-client | 192.168.72.131 | 202.207.240.131 | CentOS7.5.1804 | MEM:1G 、CPU:1C/1P 、DISK:15G |
- 关闭CentOS7相关安全组件(firewalld,selinux)
- 更改CentOS7的Base源
- 配置hosts主机解析
安装部署
nfs-server节点部署部分
- 安装
yum install nfs-utils rpcbind -y
- 启动服务
# 启动rpc
systemctl start rpcbind
systemctl enable rpcbind
# 启动nfs
systemctl start nfs
systemctl enable nfs
- 创建nfs共享目录、访问用户等
# 共享目录
mkdir -p /data
# 创建用户组、用户
groupadd -g 1111 nfs
useradd nfs -u 1111 -g 1111 -s /sbin/nologin -M
# 修改目录属组、属主
chown -R nfs:nfs /data
- 配置nfs共享目录配置文件
cat >/etc/exports <<EOF
/data 202.207.240.0/24(rw,sync,all_squash,anonuid=1111,anongid=1111)
EOF
参数说明:
ro 只读访问
rw 读写访问
sync 所有数据在请求时写入共享
all_squash 共享文件的 UID 和 GID 映射匿名用户 anoymous,适合公用目录。
no_all_squash 保留共享文件的 UID 和 GID(默认)
root_squash root 用户的所有请求映射成如 anoymous 用户一样的权限(默认)
no_root_squash root 用户具有根目录的完全管理访问权限
- 重启服务
systemctl restart rpcbind
systemctl restart nfs
- 查看挂载目录
[root@nfs-server ~]# showmount -e 202.207.240.130
Export list for 202.207.240.130:
/data 202.207.240.0/24
nfs-client节点部署部分
- 安装客户端
yum install nfs-utils -y
- 检查nfs-server节点挂载目录
[root@nfs-client ~]# showmount -e 202.207.240.130
Export list for 202.207.240.130:
/data 202.207.240.0/24
-
创建用户组,用户
说明:必须与客户端指定的用户和用户组保持一致
groupadd -g 1111 nfs
useradd nfs -u 1111 -g 1111 -s /sbin/nologin -M
- 创建挂载点,挂载nfs-server的目录
mkdir -p /data
mount -t nfs 202.207.240.130:/data /data