NFS安装(CentOS,Rocky)
服务器
| ip | 说明 |
|---|---|
| 10.0.0.110 | note1 |
| 10.0.0.111 | note2 |
| 10.0.0.112 | note3 |
| 10.0.0.113 | note4 |
| 10.0.0.114 | note5 |
| 10.0.0.115 | note6 |
| 10.0.0.116 | master |
安装NFS
所有节点都要安装
# CentOS
yum install -y nfs-utils
# Rocky
dnf install -y nfs-utils
初始化服务
[master节点],初始化服务,创建共享目录并且生效配置
# 编写配置信息
echo "/data1/nfs/data/ *(insecure,rw,sync,no_root_squash)" > /etc/exports
# 创建文件夹
mkdir -p /data1/nfs/data
# 启动服务
systemctl enable rpcbind
systemctl enable nfs-server
systemctl start rpcbind
systemctl start nfs-server
# 使配置生效
exportfs -r
# 检查配置是否生效
exportfs
/data1/nfs/data为共享目录位置
配置nfs-client
[note节点] (可选)
# 查看nfs服务器信息
showmount -e 10.0.3.6
# 创建本地文件夹并挂载nfs到本地
mkdir -p /data1/nfs/data
mount -t nfs 10.0.3.6:/data1/nfs/data /data1/nfs/data
# 卸载挂载点
umount -l /data1/nfs/data
# 查看nfs远程挂载信息
df -h
/data1/nfs/data为共享目录位置
如果报错需要关闭防火墙[systemctl stop firewalld && systemctl disable firewalld]或者开放对应端口
开机启动脚本
[note节点] (可选)
# 编辑
vi /etc/rc.local
# 添加
su - root -c 'mount -t nfs 10.0.3.6:/data1/nfs/data /data1/nfs/data'
# 赋予执行权限
chmod +x /etc/rc.local
个性化开机脚本
[note节点] (可选)
# 创建脚本存放文件夹
mkdir -p /data0/cmd
# 创建nfs启动脚本
tee /data0/cmd/nfs-init.sh <<-'EOF'
#!/bin/bash
# init
su - root -c 'mount -t nfs 10.0.3.6:/data1/nfs/data /data1/nfs/data'
EOF
# 创建startup启动脚本
tee /data0/cmd/startup.sh <<-'EOF'
#!/bin/bash
# nfs init
/data0/cmd/nfs-init.sh
EOF
# 赋予脚本执行权限
chmod +x /data0/cmd/*
# 添加脚本启动命令,并修改脚本执行权限
echo "# init start.sh" >> /etc/rc.local
echo "su - root -c '/data0/cmd/startup.sh'" >> /etc/rc.local
chmod +x /etc/rc.local && chmod +x /etc/rc.d/rc.local