026-Cinder服务-->使用NFS作为后端存储

以下将介绍如何使用NFS共享作为Openstack后端存储,本案例在计算节点上配置nfs

[root@linux-node2 ~]# yum install -y openstack-cinder python-keystone
[root@linux-node2 ~]# yum install -y nfs-utils rpcbind
[root@linux-node2 ~]# mkdir -p /data/nfs
[root@linux-node2 ~]# vim /etc/exports
/data/nfs *(rw,no_root_squash)
[root@linux-node2 ~]# systemctl start rpcbind
[root@linux-node2 ~]# systemctl start nfs


[root@linux-node1 ~]# scp /etc/cinder/cinder.conf 192.168.1.231:/etc/cinder
[root@linux-node2 ~]# vim /etc/cinder/cinder.conf
删除[lvm]的内容
[default]
enabled_backends = nfs

[nfs]
volume_driver = cinder.volume.drivers.nfs.NfsDriver
nfs_shares_config=/etc/cinder/nfs_shares
nfs_mount_point_base=$state_path/mnt
驱动查找:
查看在此文件:/usr/lib/pythone.27/site-packages/cinder/volume/drivers/nfs.py内是否有这样的类

[root@linux-node2 ~]# vim /etc/cinder/nfs_shares
192.168.1.231:/data/nfs


[root@linux-node2 ~]# chown root.cinder /etc/cinder/nfs_shares
[root@linux-node2 ~]# chmod 640 /etc/cinder/nfs_shares

[root@linux-node2 ~]# systemctl enable openstack-cinder-volume
[root@linux-node2 ~]# systemctl start openstack-cinder-volume

[root@linux-node1 ~]# openstack volume service list
+------------------+-----------------+------+---------+-------+----------------------------+
| Binary | Host | Zone | Status | State | Updated At |
+------------------+-----------------+------+---------+-------+----------------------------+
| cinder-scheduler | linux-node1 | nova | enabled | up | 2019-07-13T08:31:11.000000 |
| cinder-volume | linux-node1@lvm | nova | enabled | up | 2019-07-13T08:31:09.000000 |
| cinder-volume | linux-node2@nfs | nova | enabled | up | 2019-07-13T08:31:06.000000 |
+------------------+-----------------+------+---------+-------+----------------------------+

通过上面验证,nfs已注册成功,但是现在用不了,因为既有lvm也有nfs,不知道选哪个用,因此这时候需要去创建类型,就是创建一个存储叫lvm把linux-node1@lvm关联起来,另一个叫nfs关联起来
这样以后使用云硬盘就可以选择使用lvm还是nfs了

创建云硬盘类型NFS和ISCSI

[root@linux-node1 ~]# cinder type-create NFS
[root@linux-node1 ~]# cinder type-create ISCSI

 

将后端存储和云硬盘类型关联
[root@linux-node1 ~]# vim /etc/cinder/cinder.conf
使用lvm本地存储就需要在[lvm]加入
[lvm]
volume_backend_name = ISCSI-Storage #这个名称可以随便起,但是要与下面关联的命令中的名字对应,就是这里是什么名字,令名里就要写什么名字

[root@linux-node1 ~]# systemctl restart openstack-cinder-volume
[root@linux-node2 ~]# vim /etc/cinder/cinder.conf
使用NFS网络存储就需要在[nfs]加入
[nfs]
volume_backend_name = NFS-Storage

[root@linux-node2 ~]# systemctl restart openstack-cinder-volume

在配置文件cinder.conf加入volume_backend_name可以实现多类型的云硬盘挂载,如ISCSI,NFS

[root@linux-node1 ~]# cinder type-key NFS set volume_backend_name=NFS-Storage
[root@linux-node1 ~]# cinder type-key ISCSI set volume_backend_name=ISCSI-Storage

创建完NFS卷后
[root@linux-node2 ~]# cd /var/lib/cinder/
[root@linux-node2 cinder]# ls
groups mnt tmp
[root@linux-node2 cinder]# cd mnt/
[root@linux-node2 mnt]# ls
2f73be711d83c9a6279ce6ab95f36d74
[root@linux-node2 mnt]# ll
总用量 0
drwxr-xr-x 2 root root 6 7月 13 15:55 2f73be711d83c9a6279ce6ab95f36d74
[root@linux-node2 mnt]# cd 2f73be711d83c9a6279ce6ab95f36d74/
[root@linux-node2 2f73be711d83c9a6279ce6ab95f36d74]# ls
[root@linux-node2 2f73be711d83c9a6279ce6ab95f36d74]# ls
volume-9cecbcf4-0538-4e71-9726-cd23bac746ca
[root@linux-node2 2f73be711d83c9a6279ce6ab95f36d74]# ll volume-9cecbcf4-0538-4e71-9726-cd23bac746ca
-rw-rw-rw- 1 root root 1073741824 7月 13 17:03 volume-9cecbcf4-0538-4e71-9726-cd23bac746ca
[root@linux-node2 2f73be711d83c9a6279ce6ab95f36d74]# ll -h volume-9cecbcf4-0538-4e71-9726-cd23bac746ca
-rw-rw-rw- 1 root root 1.0G 7月 13 17:03 volume-9cecbcf4-0538-4e71-9726-cd23bac746ca
[root@linux-node2 2f73be711d83c9a6279ce6ab95f36d74]#

[root@linux-node2 ~]# clear
[root@linux-node2 ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=1918808k,nr_inodes=479702,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/centos-root on / type xfs (rw,relatime,attr2,inode64,noquota)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=35,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=23183)
mqueue on /dev/mqueue type mqueue (rw,relatime)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,noquota)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=386152k,mode=700)
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
192.168.1.231:/data/nfs on /var/lib/cinder/mnt/2f73be711d83c9a6279ce6ab95f36d74 type nfs4 (rw,relatime,vers=4.1,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.1.231,local_lock=none,addr=192.168.1.231)

 

  • 创建卷

"卷"-->"管理连接"-->"连接云主机"-->在云主机内fdisk -l进行查看

 小结:

cinder后端存储步骤:
(1)把存储准备好,如NFS,ISCSI
(2)安装cinder-volume
(3)vim /etc/cinder/cinder.conf
[xxx]
volume_driver=xxx
......
volume_backend_name=xxx-Storage
(4)创建类型:cinder type-create xxx
(5)关联类型:cinder type-key xxx set volume_backend_name=xxx-Storage

  

posted @ 2019-07-14 11:36  xuefy  阅读(423)  评论(0编辑  收藏  举报