首页 > 其他 > 详细

CentOS 7上安装NFS服务器

时间:2020-12-15 15:19:07      阅读:27      评论:0      收藏:0      [点我收藏+]

最近学习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表示启动成功

$ systemctl status rpcbind
● rpcbind.service - RPC bind service
   Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2020-06-01 17:31:08 CST; 2 days ago
 Main PID: 973 (rpcbind)
   CGroup: /system.slice/rpcbind.service
           └─973 /sbin/rpcbind -w

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
技术分享图片

启动nfs

$ systemctl start nfs
$ systemctl enable nfs
$ systemctl status nfs
技术分享图片

确认nfs状态,running表示启动成功

$ systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@k8s-master ~]# systemctl status nfs
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
   Active: active (exited) since Thu 2020-06-04 16:36:25 CST; 6s ago
 Main PID: 9628 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-server.service

Jun 04 16:36:25 k8s-master systemd[1]: Starting NFS server and services...
Jun 04 16:36:25 k8s-master systemd[1]: Started NFS server and services.

4. 配置NFS共享目录

创建nfs共享目录/nfs/nfsdisk1,修改该目录权限为777,

$ mkdir -p /nfs/nfsdisk
$ chmod 777 /nfs/nfsdisk
技术分享图片

修改nfs配置文件/etc/exports

$ vi /etc/exports
/nfs/nfsdisk *(rw,sync,no_root_squash)

配置文件说明

  • /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可挂载磁盘

$ showmount -e
技术分享图片

7. 挂载NFS磁盘

挂载nfs磁盘,可以在该安装NFS服务器的主机上挂载磁盘,也可以另外找一台和该主机通信的主机挂载磁盘

$ mkdir -p /mnt/nfsdisk
$ mount -t nfs 192.168.92.201:/nfs/nfsdisk /mnt/nfsdisk

测试文件写入

在挂载该磁盘的机器上写入hellonfs.txt

$ echo "Hello nfsdisk" > /mnt/nfsdisk/hellonfs.txt
$ ls -l /mnt/nfsdisk
total 4
-rw-r--r-- 1 root root 14 Jun  4 17:08 hellonfs.txt

在安装NFS服务器的主机上,确认hellonfs.txt是否写入到nfs共享目录

$ ll /nfs/nfsdisk/
total 4
-rw-r--r-- 1 root root 14 Jun  4 17:08 hellonfs.txt
$ cat /nfs/nfsdisk/hellonfs.txt 
Hello nfsdisk
技术分享图片

8. 卸载NFS磁盘

卸载nfs磁盘

$ umount /mnt/nfsdisk

 

CentOS 7上安装NFS服务器

原文:https://www.cnblogs.com/guoxiaobo/p/14138257.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!