NFS部署
显示内核信息:uname -a
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
NFS依赖于RPC
安装依赖包rpcbind
[root@localhost ~]# yum install nfs-utils rpcbind -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
查看nfsnobody用户是否存在
[root@localhost ~]# id nfsnobody
uid=65534(nfsnobody) gid=65534(nfsnobody) groups=65534(nfsnobody)
启动rpc服务并设置为开机自启
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl enable rpcbind
启动nfs服务并设置为开机自启
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# systemctl enable nfs
关闭防火墙及规则
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# setenforce 0
查看rpc端口
[root@localhost ~]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 18540/rpcbind
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 18594/rpc.mountd
tcp 0 0 0.0.0.0:44726 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1492/sshd
tcp 0 0 0.0.0.0:55159 0.0.0.0:* LISTEN 18584/rpc.statd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2002/master
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp6 0 0 :::111 :::* LISTEN 18540/rpcbind
tcp6 0 0 :::20048 :::* LISTEN 18594/rpc.mountd
tcp6 0 0 :::21 :::* LISTEN 18333/vsftpd
tcp6 0 0 :::22 :::* LISTEN 1492/sshd
以上两台虚拟机都需进行操作
在20节点创建共享目录
[root@localhost ~]# mkdir /data
更改共享目录权限
[root@localhost ~]# chown -R nfsnobody.nfsnobody /data
[root@localhost ~]# chmod 755 -R /data
添加磁盘并重启虚拟机
设置磁盘分区
[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xfea90052.
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-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G
Partition 1 of type Linux and of size 5 GiB is set
Command (m for help): W
The partition table has been altered!
格式化分区
[root@localhost ~]# mkfs.ext4 /dev/sdb1
并自动挂载[root@localhost ~]# vi /etc/fstab
添加 /dev/sdb1 /data ext4 defaults 0 0
刷新[root@localhost ~]# mount -a
查看挂载是否成功
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 879M 17G 5% /
devtmpfs 903M 0 903M 0% /dev
tmpfs 913M 0 913M 0% /dev/shm
tmpfs 913M 8.6M 904M 1% /run
tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/sda1 497M 125M 373M 25% /boot
tmpfs 183M 0 183M 0% /run/user/0
/dev/sdb1 4.8G 20M 4.6G 1% /data
配置nfs共享目录
[root@localhost ~]# vi /etc/exports
/data 192.168.200.0/24(rw,no_root_squash,async)
生效配置与检验
[root@localhost ~]# exportfs -rv
exporting 192.168.200.0/24:/data
[root@localhost ~]# showmount -e localhost
Export list for localhost:
/data 192.168.200.0/24
此处重启后需要再次开启RPC和nfs
检测nfs共享目录创建成果
[root@localhost ~]# showmount -e 192.168.200.20
Export list for 192.168.200.20:
/data 192.168.200.0/24
将data目录挂载到/mnt并查看
[root@localhost ~]# mount -t nfs 192.168.200.20:/data /mnt
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 879M 17G 5% /
devtmpfs 903M 0 903M 0% /dev
tmpfs 913M 0 913M 0% /dev/shm
tmpfs 913M 8.6M 904M 1% /run
tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/sda1 497M 125M 373M 25% /boot
tmpfs 183M 0 183M 0% /run/user/0
/dev/sr0 4.1G 4.1G 0 100% /opt/cdrom
192.168.200.20:/data 4.8G 20M 4.6G 1% /mnt
显示格式
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 18G 879M 17G 5% /
devtmpfs devtmpfs 903M 0 903M 0% /dev
tmpfs tmpfs 913M 0 913M 0% /dev/shm
tmpfs tmpfs 913M 8.6M 904M 1% /run
tmpfs tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 125M 373M 25% /boot
tmpfs tmpfs 183M 0 183M 0% /run/user/0
/dev/sr0 iso9660 4.1G 4.1G 0 100% /opt/cdrom
192.168.200.20:/data nfs4 4.8G 20M 4.6G 1% /mnt