ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

cinder对接NFS后端存储

2022-08-30 22:00:58  阅读:431  来源: 互联网

标签:后端 share nfs controller NFS cinder tmpfs root


配置NFS服务

安装NFS服务

查询是否安装

[root@nfs ~]# rpm -qa |grep nfs
nfs-utils-1.3.0-0.8.el7.x86_64

如没有安装,执行以下命令

[root@nfs ~]# yum install -y nfs-utils

关闭防火墙及SELinux

[root@nfs ~]# setenforce 0
[root@nfs ~]# vi /etc/selinux/config
[root@nfs ~]# 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=disabled
[root@nfs ~]# systemctl stop firewalld
[root@nfs ~]# systemctl disable firewalld

创建共享目录

[root@nfs ~]# mkdir /nfs_share
[root@nfs ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0   50G  0 disk 
├─sda1          8:1    0  500M  0 part /boot
└─sda2          8:2    0 49.5G  0 part 
  ├─rhel-swap 253:0    0    2G  0 lvm  [SWAP]
  └─rhel-root 253:1    0 47.5G  0 lvm  /
sdb             8:16   0   50G  0 disk 
└─sdb1          8:17   0   30G  0 part 
sr0            11:0    1  3.6G  0 rom  
[root@nfs ~]# mount /dev/sdb1 /nfs_share/
[root@nfs ~]# df -hT
Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs        48G  1.1G   47G   3% /
devtmpfs              devtmpfs  985M     0  985M   0% /dev
tmpfs                 tmpfs     994M     0  994M   0% /dev/shm
tmpfs                 tmpfs     994M  8.4M  986M   1% /run
tmpfs                 tmpfs     994M     0  994M   0% /sys/fs/cgroup
/dev/sda1             xfs       497M  102M  395M  21% /boot
/dev/sdb1             xfs        30G   33M   30G   1% /nfs_share
[root@nfs ~]# chmod -R 777 /nfs_share/

修改配置文件

[root@nfs ~]# vi /etc/exports
[root@nfs ~]# cat /etc/exports
/nfs_share	192.168.100.0/24(rw)
## 重启服务
```bash
[root@nfs ~]# systemctl restart nfs-server.service

客户端测试挂载

使用控制节点测试挂载

[root@controller ~]# rpm -qa|grep nfs
nfs-utils-1.3.0-0.8.el7.x86_64
libnfsidmap-0.25-11.el7.x86_64
[root@controller ~]# systemctl start nfs
[root@controller ~]# mkdir /nfs_test
[root@controller ~]# mount -t nfs 192.168.100.40:/nfs_share /nfs_test
[root@controller ~]# df -hT
Filesystem                Type      Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root     xfs        50G  2.6G   48G   6% /
devtmpfs                  devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                     tmpfs     3.9G  4.0K  3.9G   1% /dev/shm
tmpfs                     tmpfs     3.9G   17M  3.9G   1% /run
tmpfs                     tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/loop0                ext4      1.9G   22M  1.7G   2% /srv/node/swiftloopback
/dev/mapper/rhel-home     xfs        42G   33M   42G   1% /home
/dev/sda1                 xfs       497M  104M  394M  21% /boot
tmpfs                     tmpfs     3.9G   17M  3.9G   1% /run/netns
192.168.100.40:/nfs_share nfs4       30G   32M   30G   1% /nfs_test
[root@controller ~]# cd /nfs_test/
[root@controller nfs_test]# touch {a,b}{1,2}.txt
[root@controller nfs_test]# ls
a1.txt  a2.txt  b1.txt  b2.txt
[root@controller ~]# umount /nfs_test/

控制节点配置NFS共享

创建文件并配置

[root@controller ~]# vim /etc/cinder/nfs_share
[root@controller ~]# cat /etc/cinder/nfs_share 
192.168.100.40:/nfs_share

修改文件权限

[root@controller ~]# chown root:cinder /etc/cinder/nfs_share 
[root@controller ~]# chmod 0640 /etc/cinder/nfs_share 
[root@controller ~]# ll /etc/cinder/
total 96
-rw------- 1 cinder cinder  2117 Aug 30 23:17 api-paste.ini
-rw------- 1 cinder cinder 79364 Aug 30 23:17 cinder.conf
-rw-r----- 1 root   cinder    26 Aug 31 21:17 nfs_share
-rw-r----- 1 root   cinder  3200 Feb  6  2015 policy.json
-rw-r----- 1 root   cinder   942 Feb  6  2015 rootwrap.conf
drwxr-xr-x 2 cinder root       6 Feb  7  2015 volumes

创建新的后端定义

增加 NFS 后端参数

增加 nfs 后端参数,其中 lvm 默认存在,nfs 为新增

[root@controller ~]# vim /etc/cinder/cinder.conf 
[root@controller ~]# cat /etc/cinder/cinder.conf 
enabled_backends=lvm,nfs

[lvm]
iscsi_helper=lioadm
volume_group=cinder-volumes
iscsi_ip_address=192.168.100.10
volume_driver=cinder.volume.drivers.lvm.LVMISCSIDriver
volume_backend_name=lvm

[nfs]
nfs_shares_config=/etc/cinder/nfs_share  
volume_driver=cinder.volume.drivers.nfs.NfsDriver  
volume_backend_name=nfsbackend

重启卷服务

[root@controller ~]# source keystonerc_admin 
[root@controller ~(keystone_admin)]# systemctl restart openstack-cinder-scheduler.service openstack-cinder-volume.service

创建云硬盘类型

创建云硬盘类型

[root@controller ~(keystone_admin)]# cinder type-create nfstype
+--------------------------------------+---------+
|                  ID                  |   Name  |
+--------------------------------------+---------+
| fb317c86-7941-4643-ba3b-c93491a80ada | nfstype |
+--------------------------------------+---------+
[root@controller ~(keystone_admin)]# cinder type-list 
+--------------------------------------+---------+
|                  ID                  |   Name  |
+--------------------------------------+---------+
| d172a274-12e0-4d04-ad9a-8ae6bbd0060c |  iscsi  |
| fb317c86-7941-4643-ba3b-c93491a80ada | nfstype |
+--------------------------------------+---------+

设置后端名称

[root@controller ~(keystone_admin)]# cinder type-key nfstype set volume_backend_name=nfsbackend

创建云硬盘

使用 NFS 类型创建云硬盘

[root@controller ~(keystone_admin)]# source keystonerc_user 
[root@controller ~(keystone_user)]# cinder create --display-name evs01 --volume-type nfstype 2
+---------------------+--------------------------------------+
|       Property      |                Value                 |
+---------------------+--------------------------------------+
|     attachments     |                  []                  |
|  availability_zone  |                 nova                 |
|       bootable      |                false                 |
|      created_at     |      2022-08-31T13:26:38.207154      |
| display_description |                 None                 |
|     display_name    |                evs01                 |
|      encrypted      |                False                 |
|          id         | 466c3fec-1cbd-403c-89cb-9cd2aefb9b65 |
|       metadata      |                  {}                  |
|         size        |                  2                   |
|     snapshot_id     |                 None                 |
|     source_volid    |                 None                 |
|        status       |               creating               |
|     volume_type     |               nfstype                |
+---------------------+--------------------------------------+

尝试挂载给主机

[root@controller ~(keystone_user)]# cinder list
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
|                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable | Attached to |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
| 9d31905f-6420-47e2-b75b-2b419882fa69 | available |    evs01     |  2   |   nfstype   |  false   |             |
+--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
[root@controller ~(keystone_user)]# nova list
+--------------------------------------+-------+--------+------------+-------------+--------------------+
| ID                                   | Name  | Status | Task State | Power State | Networks           |
+--------------------------------------+-------+--------+------------+-------------+--------------------+
| 26ac424c-7417-42a7-bbbc-016c5aab0ac4 | ecs01 | ACTIVE | -          | Running     | pri2=192.168.200.4 |
+--------------------------------------+-------+--------+------------+-------------+--------------------+
[root@controller ~(keystone_user)]# nova volume-attach ecs01 9d31905f-6420-47e2-b75b-2b419882fa69
+----------+--------------------------------------+
| Property | Value                                |
+----------+--------------------------------------+
| device   | /dev/vdb                             |
| id       | 9d31905f-6420-47e2-b75b-2b419882fa69 |
| serverId | 26ac424c-7417-42a7-bbbc-016c5aab0ac4 |
| volumeId | 9d31905f-6420-47e2-b75b-2b419882fa69 |
+----------+--------------------------------------+

标签:后端,share,nfs,controller,NFS,cinder,tmpfs,root
来源: https://www.cnblogs.com/kongshuo/p/16640943.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有