CentOS 7上安装NFS服务器
最近学习kubernetes,需要搭建NFS服务器,就查了下如何安装NFS服务器,具体步骤如下。
1. 关闭防火墙
关闭防火墙,并设置开机禁止启动
$ systemctl stop firewalld $ systemctl disable firewalld
2. 安装NFS
安装NFS服务器,需要安装nfs-utils和rpcbind两个包,安装nfs-utils时会自动安装rpcbind
$ yum install nfs-utils -y
3. 启动NFS
启动NFS服务,并设置开机自启
启动rpcbind
$ systemctl start rpcbind $ systemctl enable rpcbind $ systemctl status rpcbind
确认rpcbind状态,running表示启动成功
启动nfs
确认nfs状态,running表示启动成功
4. 配置NFS共享目录
创建nfs共享目录/nfs/nfsdisk1,修改该目录权限为777,
修改nfs配置文件/etc/exports
配置文件说明
- /nfs/disk1: NFS共享目录
- *:允许任何IP连接
- rw:访问权限为读写权限
- sync:同步写入硬盘和内存
- no_root_squash:当使用者是root用户是,权限变为匿名使用者nobody
5. 重启NFS
重启nfs并确认状态
$ systemctl restart rpcbind $ systemctl status rpcbind $ systemctl restart nfs $ systemctl status nfs
6. 查看NFS可挂载磁盘
7. 挂载NFS磁盘
挂载nfs磁盘,可以在该安装NFS服务器的主机上挂载磁盘,也可以另外找一台和该主机通信的主机挂载磁盘
测试文件写入
在挂载该磁盘的机器上写入hellonfs.txt
在安装NFS服务器的主机上,确认hellonfs.txt是否写入到nfs共享目录
8. 卸载NFS磁盘
卸载nfs磁盘
欢迎各位光临郭小波的博客,请在此留下您的脚印。