k8s 集群需要存储,本地测试环境懒得搞些复杂的,开始回忆回忆入门时学的 nfs 的搭建,记录下吧,方便查看

搭建服务器

1
sudo apt install -y nfs-kernel-server
1
sudo yum install -y nfs-utils
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 创建共享目录
sudo mkdir /nfs

# 删除权限限制
sudo chown -R nobody:nogroup /nfs

# RHEL 9 系统
# sudo chown -R nobody:nobody /nfs

# 修改配置文件
echo "/nfs *(rw,sync,no_subtree_check,no_root_squash)" >> /etc/exports

# 使配置生效
sudo exportfs -a

重启服务

1
2
sudo systemctl restart nfs-server
sudo systemctl enable nfs-server
1
2
3
# CentOS 7
sudo systemctl restart nfs
sudo systemctl enable nfs
1
2
sudo systemctl restart nfs-server
sudo systemctl enable nfs-server

搭建客户端

1
sudo apt install -y nfs-common
1
sudo yum install -y nfs-utils
1
2
3
4
5
6
7
8
# 创建待挂载的目录
mkdir /mnt/nfs

# 挂载
sudo mount 10.0.0.3:/nfs /mnt/nfs

# 修改 /etc/fstab 开机自动挂载
10.0.0.3:/nfs /mnt/nfs nfs defaults 0 0