第一步:在一台虚拟机中yum安装nfs服务端
#这是一台NAT链接的虚拟机,yum安装nfs
[root@localhost ~]# yum -y install rpcbind nfs-utils
[root@localhost ~]# mkdir /nfsshare
[root@localhost ~]# useradd nfsnobody
[root@localhost ~]# chown nfsnobody.nfsnobody /nfsshare
[root@localhost ~]# cat /etc/exports #因为虚拟机是NAT模式,若要宿主机能够挂载需要开通两个网段权限
/nfsshare 192.168.122.0(rw,sync) 192.168.200.0(rw,sync)
[root@localhost ~]# service rpcbind start
Starting rpcbind:
[ OK ]
[root@localhost ~]# service nfs start
Starting NFS services:
[ OK ]
Starting NFS mountd:
[ OK ]
Starting NFS daemon:
[ OK ]
Starting RPC idmapd:
[ OK ]
第二步:virt-manager创建基于NFS的存储池



#在宿主机中测试共享目录
[root@localhost ~]# df -h | grep nfsshare #已经自动挂载
192.168.122.123:/nfsshare 6.7G 899M 5.4G 14% /nfs1
[root@localhost ~]# mount | grep nfsshare #已经自动挂载
192.168.122.123:/nfsshare on /nfs1 type nfs4 (rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.1,local_lock=none,addr=192.168.122.123)
[root@localhost ~]# virsh pool-list --all
名称
状态
自动开始
-------------------------------------------
default
活动
是
iso
活动
是
nfs1
活动
是
#已经处于活动状态
VM
活动
是
[root@localhost ~]# cat /etc/libvirt/storage/nfs1.xml
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh pool-edit nfs1
or other application using the libvirt API.
-->
<pool type=\'netfs\'>
#类型为网络文件系统network file system
<name>nfs1</name>
<uuid>a662a36a-8927-4aa9-a73b-67bad0a378ef</uuid>
<capacity unit=\'bytes\'>0</capacity>
<allocation unit=\'bytes\'>0</allocation>
<available unit=\'bytes\'>0</available>
<source>
<host name=\'192.168.122.123\'/> #源共享主机IP
<dir path=\'/nfsshare\'/>
#源共享主机目录
<format type=\'auto\'/>
</source>
<target>
<path>/nfs1</path>
#目标挂载目录
</target>
</pool>
到这里就配置完毕了,同学们可以自动对共享目录进行写入测试
另外,glusterfs的配置方法也是类似的噢....
5.5 存储卷
5.5.1 存储卷概述
[x] 存储池被分割为存储卷(Storage Volume)
[x] 存储卷
文件
块设备(如物理分区,LVM逻辑卷等)
libvirt管理的其他类型存储的抽象