目標(biāo)
在《Ubuntu16手動安裝OpenStack——修改鏡像》一文中,我們通過修改鏡像,實(shí)現(xiàn)了ssh密碼訪問實(shí)例??瓷先ィ@個openstack系統(tǒng)已經(jīng)可以投入使用了,實(shí)際上,也確實(shí)可以投入使用了。
但是,我們總是追求更好更多的服務(wù)。所以接下來,我們繼續(xù)安裝openstack的服務(wù)組件。本文中要安裝配置的是cinder,主要參考OpenStack Queens : Configure Cinder和Cinder Installation Guide。
cinder簡介
塊存儲服務(wù)(cinder)為用戶實(shí)例提供塊存儲設(shè)備。配置和使用存儲的方法由塊存儲驅(qū)動程序確定,或者在多后端配置的情況下由驅(qū)動程序確定。有多種驅(qū)動程序可用:NAS / SAN,NFS,iSCSI,Ceph等。Block Storage API和調(diào)度程序服務(wù)通常在控制器節(jié)點(diǎn)上運(yùn)行。根據(jù)所使用的驅(qū)動程序,卷服務(wù)可以在控制器節(jié)點(diǎn),計(jì)算節(jié)點(diǎn)或獨(dú)立存儲節(jié)點(diǎn)上運(yùn)行。
控制節(jié)點(diǎn)
root用戶
為了避免權(quán)限問題,建議切換到root用戶進(jìn)行操作(否則要加很多sudo)。
sudo -i
數(shù)據(jù)庫
1、登錄數(shù)據(jù)庫
mysql -uroot -p,密碼為openstack。
2、創(chuàng)建cinder數(shù)據(jù)庫
create database cinder;
3、授權(quán)
grant all privileges on cinder.* to cinder@'localhost' identified by 'openstack';
grant all privileges on cinder.* to cinder@'%' identified by 'openstack';
4、退出數(shù)據(jù)庫
flush privileges;
exit;
證書和端點(diǎn)
1、使admin環(huán)境生效
. admin-openrc
2、創(chuàng)建cinder用戶,密碼為openstack
openstack user create --domain default --project service --password openstack cinder
3、給cinder用戶添加admin角色
openstack role add --project service --user cinder admin
4、創(chuàng)建cinder服務(wù)
openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2
openstack service create --name cinderv3 --description "OpenStack Block Storage" volumev3
5、創(chuàng)建cinder服務(wù)端點(diǎn)
openstack endpoint create --region RegionOne volumev2 public http://controller:8776/v2/%\(project_id\)s
openstack endpoint create --region RegionOne volumev2 internal http://controller:8776/v2/%\(project_id\)s
openstack endpoint create --region RegionOne volumev2 admin http://controller:8776/v2/%\(project_id\)s
openstack endpoint create --region RegionOne volumev3 public http://controller:8776/v3/%\(project_id\)s
openstack endpoint create --region RegionOne volumev3 internal http://controller:8776/v3/%\(project_id\)s
openstack endpoint create --region RegionOne volumev3 admin http://controller:8776/v3/%\(project_id\)s
安裝配置
1、下載安裝組件
apt-get -y install cinder-api cinder-scheduler python-cinderclient
2、備份cinder.conf
mv /etc/cinder/cinder.conf /etc/cinder/cinder.conf.bak
3、vi /etc/cinder/cinder.conf,新建cinder.conf內(nèi)容為:
# create new
[DEFAULT]
# define own IP address
my_ip = 172.16.0.105
rootwrap_config = /etc/cinder/rootwrap.conf
api_paste_confg = /etc/cinder/api-paste.ini
state_path = /var/lib/cinder
auth_strategy = keystone
# RabbitMQ connection info
transport_url = rabbit://openstack:openstack@controller
# MariaDB connection info
[database]
connection = mysql+pymysql://cinder:openstack@controller/cinder
# Keystone auth info
[keystone_authtoken]
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = cinder
password = openstack
[oslo_concurrency]
lock_path = $state_path/tmp
4、更改權(quán)限
chmod 644 /etc/cinder/cinder.conf
chown root:cinder /etc/cinder/cinder.conf
5、生成數(shù)據(jù)庫數(shù)據(jù)
su -s /bin/bash cinder -c "cinder-manage db sync"
6、重啟cinder-scheduler
systemctl restart cinder-scheduler
7、查看volume
openstack volume service list
存儲節(jié)點(diǎn)
本文中,我們的存儲節(jié)點(diǎn)和計(jì)算節(jié)點(diǎn)在同一個節(jié)點(diǎn),該節(jié)點(diǎn)的IP為172.16.0.106。已經(jīng)安裝的服務(wù)和virtualbox計(jì)算節(jié)點(diǎn)(192.168.56.111)相同,包括nova-compute和neutron。
root用戶
為了避免權(quán)限問題,建議切換到root用戶進(jìn)行操作(否則要加很多sudo)。
sudo -i
安裝配置
1、安裝cinder-volume
apt-get -y install cinder-volume python-mysqldb
2、備份cinder.conf
mv /etc/cinder/cinder.conf /etc/cinder/cinder.conf.bak
3、vi /etc/cinder/cinder.conf,新建cinder.conf內(nèi)容為:
# create new
[DEFAULT]
# define own IP address
my_ip = 172.16.0.106
rootwrap_config = /etc/cinder/rootwrap.conf
api_paste_confg = /etc/cinder/api-paste.ini
state_path = /var/lib/cinder
auth_strategy = keystone
# RabbitMQ connection info
transport_url = rabbit://openstack:openstack@controller
# Glance connection info
glance_api_servers = http://controller:9292
# OK with empty value now
enabled_backends =
# MariaDB connection info
[database]
connection = mysql+pymysql://cinder:openstack@controller/cinder
# Keystone auth info
[keystone_authtoken]
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = cinder
password = openstack
[oslo_concurrency]
lock_path = $state_path/tmp
4、更改權(quán)限
chmod 644 /etc/cinder/cinder.conf
chown root:cinder /etc/cinder/cinder.conf
5、重啟cinder-volume
systemctl restart cinder-volume
使用lvm卷
存儲節(jié)點(diǎn)
1、在存儲節(jié)點(diǎn)添加硬盤,保證至少有兩塊硬盤。
2、創(chuàng)建物理卷
ll /dev/sd*
pvcreate /dev/sdb
3、創(chuàng)建volume group
vgcreate -s 32M vg_volume01 /dev/sdb
4、安裝lvm相關(guān)組件
apt-get -y install tgt thin-provisioning-tools
5、vi /etc/cinder/cinder.conf,如下修改cinder.conf:
# add a value for enabled_backends
enabled_backends = lvm
# add follows to the end
[lvm]
iscsi_helper = tgtadm
# volume group name just created
volume_group = vg_volume01
# IP address of Storage Node
iscsi_ip_address = 172.16.0.106
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volumes_dir = $state_path/volumes
iscsi_protocol = iscsi
6、重啟服務(wù)
systemctl restart cinder-volume tgt
計(jì)算節(jié)點(diǎn)
1、vi /etc/nova/nova.conf,編輯nova.conf文件:
# add to the end
[cinder]
os_region_name = RegionOne
2、重啟compute服務(wù)
systemctl restart nova-compute
控制節(jié)點(diǎn)
以上,已經(jīng)準(zhǔn)備好了cinder服務(wù),我們在控制節(jié)點(diǎn)使用cinder服務(wù)(也可以在其他機(jī)器使用)。
1、假設(shè)我們已經(jīng)按照《Ubuntu16手動安裝OpenStack——創(chuàng)建實(shí)例》一文,創(chuàng)建了一個cirros0實(shí)例,ip為10.0.0.206。
2、登錄cirros0
ssh cirros@10.0.0.206,密碼默認(rèn)為gocubsgo。
3、在cirros0中查看硬盤
df -h
ls -l /dev/vd*
sudo fdisk -l
可以看到,當(dāng)前虛擬機(jī)只有一塊vda硬盤。
4、控制節(jié)點(diǎn)中修改voidking用戶環(huán)境,并使環(huán)境生效
echo "export OS_VOLUME_API_VERSION=2" >> ~/voidkingrc
. voidkingrc
5、創(chuàng)建卷disk01,大小為1G
openstack volume create --size 1 disk01
6、查看卷
openstack volume list
7、把卷disk01添加給cirros0實(shí)例
openstack server list
openstack server add volume cirros0 disk01
8、在cirros0中查看硬盤
ls -l /dev/vd*
發(fā)現(xiàn)cirros0中多出了一塊硬盤vdb。
9、在控制節(jié)點(diǎn)查看卷
openstack volume list
顯示disk01已經(jīng)attach到了cirros0的/dev/vdb,和我們在cirros0中看到的結(jié)果一致。
10、移除卷
openstack server remove volume cirros0 disk01
后記
關(guān)于NFS(網(wǎng)絡(luò)文件系統(tǒng))的使用,參考OpenStack Queens : Use Cinder Storage (NFS)。
關(guān)于LVM和NFS格式卷的混合使用,參考OpenStack Queens : Use Cinder Storage (Multi-BackEnds)。
關(guān)于使用cinder備份卷,參考OpenStack Queens : Configure Cinder Backup。