通过 cinder 使用 lvm 卷提供后端存储:
官方部署文档:https://docs.openstack.org/ocata/zh_CN/install-guide-rdo/cinder.html
1、数据库准备:
#1:创建数据库并授权:
[root@linux-host5 ~]# mysql -uroot –p
MariaDB [(none)]> CREATE DATABASE cinder;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'cinder123';
MariaDB [(none)]> flush privileges;
#2:控制端验证数据访问:
[root@linux-host1 ~]# mysql -ucinder -h192.168.10.100 -pcinder123
2、控制端 cinder 服务注册:
#1:创建 cinder 用户并授权:
[root@linux-host1 ~]# source admin-ocata.sh
[root@linux-host1 ~]# openstack user create --domain default --password-prompt cinder
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| domain_id | 81672c29064942aea8fb754820ddb76a |
| enabled | True |
| id | f12af1d5583e4b179354c3b4d8d0d778 |
| name | cinder |
| options | {} |
| password_expires_at | None | +---------------------+----------------------------------+ #授权 admin 权限
[root@linux-host1 ~]# openstack role add --project service --user cinder admin
#2:创建服务: #v2 版本
[root@linux-host1 ~]# openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Block Storage |
| enabled | True |
| id | 8077b7de84fc4b32a288306459bad10b |
| name | cinderv2 |
| type | volumev2 |
+-------------+----------------------------------+ #v3 版本
[root@linux-host1 ~]# openstack service create --name cinderv3 --description "OpenStack Block Storage" volumev3
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Block Storage |
| enabled | True |
| id | 4234b69629ac4e6bbabcd72c8bb0ab81 |
| name | cinderv3 |
| type | volumev3 | +-------------+----------------------------------+
#3:注册 V2 版本 endpoint: #公共端点:
[root@linux-host1 ~]# openstack endpoint create --region RegionOne volumev2 public http://192.168.10.100:8776/v2/%\(project_id\)s
+--------------+----------------------------------------------+
| Field | Value |
+--------------+----------------------------------------------+
| enabled | True |
| id | cf87da53a7754996972b7ef2baf73933 |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 8077b7de84fc4b32a288306459bad10b |
| service_name | cinderv2 |
| service_type | volumev2 |
| url | http://192.168.10.100:8776/v2/%(project_id)s |
+--------------+----------------------------------------------+ #私有端点:
[root@linux-host1 ~]# openstack endpoint create --region RegionOne volumev2 internal
http://192.168.10.100:8776/v2/%\(project_id\)s
+--------------+----------------------------------------------+
| Field | Value |
+--------------+----------------------------------------------+
| enabled | True |
| id | 4d8cfb82cd4a4015876df6aafc8bb219 |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 8077b7de84fc4b32a288306459bad10b |
| service_name | cinderv2 |
| service_type | volumev2 |
| url | http://192.168.10.100:8776/v2/%(project_id)s |
+--------------+----------------------------------------------+ #管理端点:
[root@linux-host1 ~]# openstack endpoint create --region RegionOne volumev2 admin
http://192.168.10.100:8776/v2/%\(project_id\)s
+--------------+----------------------------------------------+
| Field | Value | +--------------+----------------------------------------------+
| enabled | True |
| id | 686d554b483a4a52b36c6b6a6c3a2feb |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 8077b7de84fc4b32a288306459bad10b |
| service_name | cinderv2 |
| service_type | volumev2 |
| url | http://192.168.10.100:8776/v2/%(project_id)s |
+--------------+----------------------------------------------+
#4:注册 V3 版本 endpoint: #公共端点:
[root@linux-host1 ~]# openstack endpoint create --region RegionOne volumev3 public
http://192.168.10.100:8776/v3/%\(project_id\)s
+--------------+----------------------------------------------+
| Field | Value |
+--------------+----------------------------------------------+
| enabled | True |
| id | 729e23316e964ff6bc6315f4d95e590a |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 4234b69629ac4e6bbabcd72c8bb0ab81 |
| service_name | cinderv3 |
| service_type | volumev3 |
| url | http://192.168.10.100:8776/v3/%(project_id)s |
+--------------+----------------------------------------------+ #私有端点:
[root@linux-host1 ~]# openstack endpoint create --region RegionOne volumev3 internal
http://192.168.10.100:8776/v3/%\(project_id\)s
+--------------+----------------------------------------------+
| Field | Value |
+--------------+----------------------------------------------+
| enabled | True |
| id | 0541cfdf2d99477fb4105aac045f0399 |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 4234b69629ac4e6bbabcd72c8bb0ab81 |
| service_name | cinderv3 |
| service_type | volumev3 |
| url | http://192.168.10.100:8776/v3/%(project_id)s |
+--------------+----------------------------------------------+ #管理端点:
[root@linux-host1 ~]# openstack endpoint create --region RegionOne volumev3 admin
http://192.168.10.100:8776/v3/%\(project_id\)s
+--------------+----------------------------------------------+
| Field | Value |
+--------------+----------------------------------------------+
| enabled | True |
| id | 3b45ed17bb724479a49df89e49a0e2ae |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 4234b69629ac4e6bbabcd72c8bb0ab81 |
| service_name | cinderv3 |
| service_type | volumev3 |
| url | http://192.168.10.100:8776/v3/%(project_id)s |
+--------------+----------------------------------------------+
3、配置 haproxy 负载:
[root@linux-host4 ~]# vim /etc/haproxy/haproxy.cfg
listen cinder
bind 192.168.10.100:8776
mode tcp
log global
balance source
server cinder-server 192.168.10.201:8776 check inter 5000 rise 3 fall 3
4、安装并配置 cinder 组件:
#1:控制端安装 cinder:
[root@linux-host1 ~]# yum install openstack-cinder –y
#2:编辑配置文件 cinder.conf:
[root@linux-host1 ~]# vim /etc/cinder/cinder.conf
3545 connection = mysql+pymysql://cinder:cinder123@192.168.10.100/cinder
3243 transport_url = rabbit://openstack:123456@192.168.10.205
376 auth_strategy = keystone
3767 [keystone_authtoken]
3768 auth_uri = http://192.168.10.100:5000
3769 auth_url = http://192.168.10.100:35357
3770 memcached_servers = 192.168.10.100:11211
3771 auth_type = password
3772 project_domain_name = default
3773 user_domain_name = default
3774 project_name = service
3775 username = cinder
3776 password = cinder
4012 lock_path = /var/lib/cinder/tmp
263 my_ip = 192.168.10.201
#当前配置:
[root@linux-host1 ~]# grep -n "^[a-Z\[]" /etc/cinder/cinder.conf
1:[DEFAULT]
263:my_ip = 192.168.10.201
376:auth_strategy = keystone
3243:transport_url = rabbit://openstack:123456@192.168.10.205
3518:[database]
3546:connection = mysql+pymysql://cinder:cinder123@192.168.10.100/cinder
3767:[keystone_authtoken]
3768:auth_uri = http://192.168.10.100:5000
3769:auth_url = http://192.168.10.100:35357
3770:memcached_servers = 192.168.10.100:11211
3771:auth_type = password
3772:project_domain_name = default
3773:user_domain_name = default
3774:project_name = service
3775:username = cinder
3776:password = cinder
3996:[oslo_concurrency]
4012:lock_path = /var/lib/cinder/tmp
#3:同步并验证数据库:
[root@linux-host1 ~]# su -s /bin/sh -c "cinder-manage db sync" cinder
#4:验证数据库同步成功:
[root@linux-host1 ~]# mysql -ucinder -h192.168.10.100 -pcinder123
#5:控制端重启 nova-api 服务:
[root@linux-host1 ~]# systemctl restart openstack-nova-api.service
#6:启动块存储服务 cinder:
[root@linux-host1 ~]# systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
[root@linux-host1 ~]# systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service
#7:验证 cinder 日志:
[root@linux-host1 ~]# tail -f /var/log/cinder/*.log
5、配置计算节点使用 cinder 存储:
#1:编辑配置文件 nova.conf:
[root@linux-host2 ~]# vim /etc/nova/nova.conf
3982 [cinder]
4031 os_region_name=RegionOne
#2:重启 nova 服务:
[root@linux-host2 ~]# systemctl restart libvirtd.service openstack-nova-compute.service
#3:验证 cinder 控制端:
[root@linux-host1 ~]# openstack volume service list
6、配置存储节点:
#1:添加磁盘: 在负载服务器(或其他指定服务器)新添加一块 50G 的磁盘然后点确定:
#2:安装 LVM 包:
[root@linux-host5 ~]# yum install lvm2 -y
#3:启动 LVM 并设置为开机启动:
[root@linux-host5 ~]# systemctl enable lvm2-lvmetad.service
[root@linux-host5 ~]# systemctl start lvm2-lvmetad.service
#4:动态识别新磁盘:
[root@linux-host5 ~]# ll /sys/class/scsi_host/host
host0/ host1/ host2/
[root@linux-host5 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@linux-host5 ~]# echo "- - -" > /sys/class/scsi_host/host1/scan
[root@linux-host5 ~]# echo "- - -" > /sys/class/scsi_host/host2/scan
#5:验证磁盘:
#6:创建物理卷和卷组:
[root@linux-host4 ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
[root@linux-host4 ~]# vgcreate cinder-volumes /dev/sdb
Volume group "cinder-volumes" successfully created
#7:配置只有实例可以访问存储卷组:
[root@linux-host4 ~]# vim /etc/lvm/lvm.conf
142 filter = [ "a/sdb/", "r/.*/"]
7、存储安装并配置组件:
#1:安装组件:
[root@linux-host4 ~]# yum install openstack-cinder targetcli python-keystone –y
#2:编辑配置文件 cinder.conf:
[root@linux-host4 ~]# vim /etc/cinder/cinder.conf
1210 transport_url = rabbit://openstack:123456@192.168.10.205
3749 connection = mysql+pymysql://cinder:cinder123@192.168.10.100/cinder
400 auth_strategy = keystone
3973 [keystone_authtoken]
3974 auth_uri = http://192.168.10.100:5000
3975 auth_url = http://192.168.10.100:35357
3976 memcached_servers = 192.168.10.100:11211
3977 auth_type = password
3978 project_domain_name = default
3979 user_domain_name = default
3980 project_name = service
3981 username = cinder
3982 password = cinde
283 my_ip = 192.168.10.205
4904:[lvm]
4905:volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
4906:volume_group = cinder-volumes
4907:iscsi_protocol = iscsi
4908:iscsi_helper = lioadm
4909:volume_backend_name=Openstack-lvm
404 enabled_backends = lvm #后端名字是任意的,这是驱动的名称
288 glance_api_servers = http://192.168.10.100:9292
4263 lock_path = /var/lib/cinder/tmp
#当前配置
[root@linux-host4 ~]# grep -n "^[a-Z\[]" /etc/cinder/cinder.conf
1:[DEFAULT]
283:my_ip = 192.168.10.205
288:glance_api_servers = http://192.168.10.100:9292
400:auth_strategy = keystone
404:enabled_backends = lvm
1210:transport_url = rabbit://openstack:123456@192.168.10.205
3730:[database]
3749:connection = mysql+pymysql://cinder:cinder123@192.168.10.100/cinder
3973:[keystone_authtoken]
3974:auth_uri = http://192.168.10.100:5000
3975:auth_url = http://192.168.10.100:35357
3976:memcached_servers = 192.168.10.100:11211
3977:auth_type = password
3978:project_domain_name = default
3979:user_domain_name = default
3980:project_name = service
3981:username = cinder
3982:password = cinder
4249:[oslo_concurrency]
4263:lock_path = /var/lib/cinder/tmp
4904:[lvm]
4905:volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
4906:volume_group = cinder-volumes
4907:iscsi_protocol = iscsi
4908:iscsi_helper = lioadm
4909:volume_backend_name=Openstack-lvm
#3:启动服务并设置为开机启动:
[root@linux-host4 ~]# systemctl enable openstack-cinder-volume.service target.service
[root@linux-host4 ~]# systemctl start openstack-cinder-volume.service target.service
#4:验证日志:
#5:控制端验证 cinder 注册:
[root@linux-host1 ~]# openstack volume service list
8、验证卷使用:
#1:创建卷:使用 admin 或者 demo 用户登录到管理界面,点击卷—创建卷:
#2:填写卷信息:
#3:查看卷状态:
#4:关联到虚拟机:
#5:关联到目标虚拟机:
#6:连接后的卷状态:
#7:虚拟机验证磁盘:
#8:格式化磁盘:
#9:挂载磁盘并复制数据:
#10:磁盘挂载至其他虚拟机: 新创建一个虚拟机,用于将上一步关联的卷分离后挂载到新的虚拟机上进行测试。
#10.1:卸载卷: 在之前的虚拟机将卷卸载。
#10.2:磁盘分离: 点击项目-卷-管理连接:
#10.3:分离卷:
#10.4:确认分离: #分离中:
#10.5:挂载至新实例: 在管理连接界面,将卷关联至test-vm2:
#10.6:关联中:
#10.7:关联成功:
#10.8:新实例验证磁盘: 验证可以挂载关联的磁盘并可以查看之前的数据