本文是在vmware 上面进行的操作:
fdisk -l
Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000cf2c1
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 4812799 2098176 82 Linux swap / Solaris
/dev/sda3 4812800 125829119 60508160 83 Linux
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[root@Test02 ~]# fdisk sdb
fdisk: cannot open sdb: No such file or directory
[root@Test02 ~]# fdisk /dev/sdb
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
##
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
##
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
##lsblk -f 显示文件系统
# dumpe2fs /dev/sdb1 显示磁盘的uuid
#mkfs -t xfs /dev/sdb1 格式化
# 挂载磁盘比设置自动
[root@Test02 /]# mkdir data
[root@Test02 /]# mount /dev/sdb1 /data
在/etc/fstab 下面添加如下信息:
/dev/sdb1 /data xfs defaults 0 0
服务端和客户端必须软件nfs-utils,事实上在安装nfs-utils的同时,rpcbind作为依赖包被安装,因此无需再单独安装rpcbind。单独安装rpcbind时不会同时安装nfs-utils
(1)在服务器端设置:
[root@Test02 data]# cat /etc/exports
/data/ *(rw,no_root_squash)
(2)启动服务端的nfs和rpcbind服务,并将其设置为开机启动(作为服务器,应保证服务在每次重启之后都能迅速提供服务)
systemctl start nfs 、systemctl enable nfs、systemctl status nfs
systemctl start rpcbind 、systemctl enable rpcbind 、 systemctl status rpcbind
在服务端看下是否正确加载了设置的 /etc/exports
配置。 showmount -e localhost
(3)启动客户端nfs服务(客户端可以不启动rpcbind服务),挂载服务端nfs目录。
[root@Test01 ~]# systemctl start nfs
在客户端创建挂在目录 /nfs。
挂载远端目录到本地 /share
目录
mount 192.168.44.133:/data /nfs
在客户端设置开机自动挂载NFS服务:
echo “192.168.44.133:/data /nfs nfs defaults 0 0”>>/etc/fstab
在服务端及客户端分别写入数据,发现只能在服务端对/nfs目录进行读写,而在客户端只能读取。因为都是使用root账户进行操作的,在客户端看到的root是指服务端的root而并非客户端的root。为了尽快使用、体验nfs服务,在服务端将/nfs目录的权限设置为7,此时就能愉快的体验nfs带来的乐趣了。但这并不严谨,不是我们想要达到的目标。