欢迎来到CloudService文涵的博客

人生三从境界:昨夜西风凋碧树,独上高楼,望尽天涯路。 衣带渐宽终不悔,为伊消得人憔悴。 众里寻他千百度,蓦然回首,那人却在灯火阑珊处。

搭建NFS服务

搭建NFS服务

1. 保证两台主机能够相互通信

[root@localhost ~]# ping 10.10.10.111
PING 10.10.10.111 (10.10.10.111) 56(84) bytes of data.
64 bytes from 10.10.10.111: icmp_seq=1 ttl=64 time=0.258 ms
64 bytes from 10.10.10.111: icmp_seq=2 ttl=64 time=1.57 ms
64 bytes from 10.10.10.111: icmp_seq=3 ttl=64 time=0.262 ms

2.配置yum源

[root@localhost ~]# cat /etc/yum.repos.d/local.repo 
[centos]
name=centos
baseurl=file:///media
gpgcheck=0
enabled=1

[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: centos
Cleaning up list of fastest mirrors
[root@localhost ~]# yum repolist 
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
centos | 3.6 kB  00:00:00 
(1/2): centos/group_gz | 166 kB  00:00:00 
(2/2): centos/primary_db   | 3.1 MB  00:00:00 
repo id repo name   status
centos  centos  4,021
repolist: 4,021

3.安装rpcbind和nfs-utils

[root@localhost ~]# yum -y install rpcbind nfs-utils
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package rpcbind-0.2.0-47.el7.x86_64 already installed and latest version
Package 1:nfs-utils-1.3.0-0.61.el7.x86_64 already installed and latest version
Nothing to do

4.在/opt下创建wenhan文件夹并在里面创建一个测试文件

[root@localhost ~]# mkdir -p /opt/wenhan/
[root@localhost ~]# cd /opt/wenhan/
[root@localhost wenhan]# touch wenhan
[root@localhost wenhan]# ls
wenhan

5.关闭防火墙和selinux

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0

[root@localhost ~]# cat /etc/selinux/config   
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=diasbled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected. 
# mls - Multi Level Security protection.
SELINUXTYPE=targeted 

6.进入配置文件写入以下信息

[root@localhost ~]# cat /etc/exports
/opt/wenhan  10.10.10.0/24(ro,sync)

7.重启nfs服务

[root@localhost ~]# systemctl restart nfs
[root@localhost ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.

8.到client客户端进行挂载

[root@localhost ~]# mount -t nfs 10.10.10.123:/opt/wenhan /mnt/

[root@localhost ~]# df -hT
Filesystem   Type  Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  xfs17G  4.5G   13G  27% /
devtmpfs devtmpfs  974M 0  974M   0% /dev
tmpfstmpfs 991M 0  991M   0% /dev/shm
tmpfstmpfs 991M   11M  981M   2% /run
tmpfstmpfs 991M 0  991M   0% /sys/fs/cgroup
/dev/sda1xfs  1014M  166M  849M  17% /boot
tmpfstmpfs 199M  4.0K  199M   1% /run/user/42
tmpfstmpfs 199M   20K  199M   1% /run/user/0
/dev/sr0 iso9660   4.3G  4.3G 0 100% /run/media/root/CentOS 7 x86_64
10.10.10.123:/opt/wenhan nfs4   17G  4.5G   13G  27% /mnt

[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls
wenhan

posted on 2022-04-15 10:16  Cloudservice  阅读(63)  评论(0编辑  收藏  举报