cinder以掛接的方式加入到現有的openstack環境中。
cinder塊存儲服務須要至少一個額外的存儲節點,該節點爲實例提供卷。
本實驗搭建一個專門的存儲節點及使用其之上的一塊空白磁盤(/dev/sdb),以卷的形式,向實例提供數據盤。python
安裝好存儲節點的centos系統,並配置好IP和主機名,編輯hosts文件加入主機解析等。
存儲節點的管理網絡的ip地址爲192.168.10.44,主機名是b1。mysql
安裝和配置控制器節點
建立數據庫
mysql -u root -plinux
建立cinder數據庫
MariaDB [(none)]> CREATE DATABASE cinder;sql
授予對cinder數據庫的適當訪問權限
MariaDB [(none)]> GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'localhost' IDENTIFIED BY 'CINDER_DBPASS';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'CINDER_DBPASS';
MariaDB [(none)]> exit;數據庫
建立服務憑證
. admin-openrc
建立cinder用戶
openstack user create --domain default --password CINDER_PASS cindervim
向cinder用戶添加admin角色
openstack role add --project service --user cinder admincentos
建立cinderv2和cinderv3服務實體
openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2
openstack service create --name cinderv3 --description "OpenStack Block Storage" volumev3api
建立塊存儲服務API端點
openstack endpoint create --region RegionOne volumev2 public http://ct:8776/v2/%(project_id)s
openstack endpoint create --region RegionOne volumev2 internal http://ct:8776/v2/%(project_id)s
openstack endpoint create --region RegionOne volumev2 admin http://ct:8776/v2/%(project_id)s
openstack endpoint create --region RegionOne volumev3 public http://ct:8776/v3/%(project_id)s
openstack endpoint create --region RegionOne volumev3 internal http://ct:8776/v3/%(project_id)s
openstack endpoint create --region RegionOne volumev3 admin http://ct:8776/v3/%(project_id)s網絡
安裝軟件包
yum install openstack-cinder
cp /etc/cinder/cinder.conf /etc/cinder/cinder.conf.bak
grep -Ev '#|^$' /etc/cinder/cinder.conf.bak>/etc/cinder/cinder.conf
vim /etc/cinder/cinder.conf
[database]
connection = mysql+pymysql://cinder:CINDER_DBPASS@ct/cinder
[DEFAULT]
transport_url = rabbit://openstack:RABBIT_PASS@ct
auth_strategy = keystone
my_ip = 192.168.10.41
[keystone_authtoken]
www_authenticate_uri = http://ct:5000
auth_url = http://ct:5000
memcached_servers = ct:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = cinder
password = CINDER_PASS
[oslo_concurrency]
lock_path = /var/lib/cinder/tmpapp
填充塊存儲數據庫
su -s /bin/sh -c "cinder-manage db sync" cinder
配置計算以使用塊存儲
vim /etc/nova/nova.conf
[oslo_concurrency]
os_region_name = RegionOne
從新啓動Compute API服務
systemctl restart openstack-nova-api.service
啓動塊存儲服務,並將其配置爲在系統啓動時啓動
systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service
安裝和配置存儲節點
存儲節點的管理網絡的ip地址爲192.168.10.44
安裝LVM軟件包
yum install lvm2 device-mapper-persistent-data
啓動LVM元數據服務,並將其配置爲在系統引導時啓動
systemctl enable lvm2-lvmetad.service
systemctl start lvm2-lvmetad.service
建立LVM物理卷/dev/sdb
pvcreate /dev/sdb
建立LVM卷組cinder-volumes
vgcreate cinder-volumes /dev/sdb
將LVM從新配置爲僅掃描包含cinder-volumes卷組的設備
vim /etc/lvm/lvm.conf
在devices部分中,添加一個接受/dev/sdb設備並拒絕全部其餘設備的過濾器:
devices {
filter = [ "a/sdb/", "r/.*/"]
a用於接受,r用於拒絕。
安裝軟件包
yum install centos-release-openstack-train -y
yum upgrade -y
yum install python-openstackclient -y
yum install openstack-selinux -y
yum install openstack-cinder targetcli python-keystone -y
修改配置文件
cp /etc/cinder/cinder.conf /etc/cinder/cinder.conf.bak
grep -Ev '#|^$' /etc/cinder/cinder.conf.bak>/etc/cinder/cinder.conf
vim /etc/cinder/cinder.conf
[database]
connection = mysql+pymysql://cinder:CINDER_DBPASS@ct/cinder
[DEFAULT]
transport_url = rabbit://openstack:RABBIT_PASS@ct
auth_strategy = keystone
my_ip = 192.168.10.44
enabled_backends = lvm
glance_api_servers = http://ct:9292
[keystone_authtoken]
www_authenticate_uri = http://ct:5000
auth_url = http://ct:5000
memcached_servers = ct:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = cinder
password = CINDER_PASS
[lvm]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-volumes
target_protocol = iscsi
target_helper = lioadm
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
啓動塊存儲卷服務及其相關,並將其配置爲在系統啓動時啓動:
systemctl enable openstack-cinder-volume.service target.service
systemctl start openstack-cinder-volume.service target.service
驗證cinder塊存儲服務
. admin-openrc
openstack volume service list
使用塊存儲服務向實例提供數據盤
建立卷(volume)
. ygj-openrc
建立一個10 GB的卷:
openstack volume create --size 10 volume1
很短的時間後,卷狀態應該從creating 到available
openstack volume list
將卷附加到實例
openstack server add volume INSTANCE_NAME VOLUME_NAME
將volume1卷附加到centos7-instance1實例:
openstack server add volume centos7-instance1 volume1
openstack volume list
使用SSH訪問實例,並使用如下fdisk命令驗證該卷是否做爲/dev/vdb塊存儲設備:sudo fdisk -l分區並格式化新添加的/dev/vdbfdisk /dev/vdbmk2fs.ext4 /dev/vdb1