想说的话
当一个运维高手初次踏入openstack的世界的时候,首先面临的问题就是快速安装一个openstack然后玩起来。 但是openstack安装过于庞杂,手动安装的学习路线比较漫长。自动化安装工具往往跑到一半就报错。 自动安装openstack往往有一下几个坑:
- 网络问题。openstack常见的安装工具,如kolla、devstack、rdo、TripleO等,这些工具都是由老外开发,他们在开发的时候没有考虑到不同国家的下载速度。自动安装的依赖包都是从github上下载,往往安装到一半就404了。
- 版本问题。openstack的每个版本都对应centos或者ubuntu的某几个版本。而且还要考虑到发行版的生命周期问题。有的发行版生命周期只有5年。如果过了生命周期,从官方的系统包下载源将无法下载到openstack。比如,你用centos7.9下载不了Mitaka版本的openstack,这在2020年以前都是可以的,这就是过期的问题。
- 学习资料问题。网上有很多openstack单节点或者多节点安装的教程。这些教程可能过半年就不能用了。有的教程是质量问题,有的教程是遇到了发行版过期的问题。反正我试了5篇最近一年的、不同安装工具的教程,没有一篇能让我成功安装openstack的。
所以以上这些问题导致安装openstack很恶心人,一度劝退95%的初学者。 如何破这个局:查看英文官方安装文档,下载Installation Guide的PDF反复阅读。注意是英文,不是中文。整个PDF只有100页。 openstack官网: https://docs.openstack.org/ 官网上能选择语言,但是中文文档最高只支持Mitaka。想要在最新的linux发行版安装较新的openstack,只能看英文的Installation Guide。英文的安装文档是持续更新的,所以靠谱。 综上,英语不好的同学,读英文文献费劲的同学,建议不要学openstack了,不然你会感受到举步维艰。这就是一个分水岭,把顶级人才和普通工程师区分开了。 网上教程和视频不能用,又看不懂英文文档。培训班不会教你如何安装,那么你想怎样搞定一个千台服务器级别的大型openstack集群的架构设计?
双节点手动安装openstack yoga版本
参考文献(官方文档):https://docs.openstack.org/install-guide/ 时间点:2022年4月25日
环境准备
宿主机系统任意,但是保证能安装KVM。 Debian安装KVM方法:
sudo apt update
sudo apt -y install qemu qemu-system qemu-kvm virt-manager bridge-utils vlan
网络配置
KVM安装成功后,创建两个NAT虚拟网卡。
- 设备名openstack,类型NAT,地址段10.0.0.0/24 ,网关10.0.0.1,ip范围从5-254。
- 设备名provider,类型NAT,地址段203.0.113.0/24,网关203.0.113.1,ip范围从5-254。
然后KVM安装两个虚拟机,操作系统是Ubuntu20.04 Desktop。安装时网络选择设备openstack,硬件要求: controller控制节点,主机名controller,CPU 2C ,4GB内存 , 50GB硬盘。 compute1控制节点,主机名compute1,CPU 4C ,8GB内存 , 50GB硬盘。 系统安装成功后,需要引入第二个网卡provider,所以两台节点先关机。 KVM下将两台虚拟机都添加网络设备provider,开机。 对controller的两个网口进行配置: 网口1调成静态ip,ip固定是10.0.0.11,子网掩码24,网关10.0.0.1 网口2调成静态ip,ip固定是203.0.113.11,子网掩码24,网关203.0.113.1 对compute1的两个网口进行配置 网口1调成静态ip,ip固定是10.0.0.31,子网掩码24,网关10.0.0.1 网口2调成静态ip,ip固定是203.0.113.31,子网掩码24,网关203.0.113.1
其他节点的ip配置: 如果你有一个Block Storage块存储,则把它加入到openstack的NAT网络中。 ip设置成10.0.0.41 如果你有一个Object storage对象存储,则把它加入到openstack的NAT网络中。 ip设置成10.0.0.51 注意:块存储和对象存储节点只需要一个网口就行了,不需要像控制节点和计算节点那样搞两个网口。(摘自Installation Guide)
hostname解析
两台机器都做。
vim /etc/hosts
-----------------
10.0.0.11 controller
10.0.0.31 compute1
10.0.0.41 block1
10.0.0.51 object1
10.0.0.52 object2
做完主机解析后,将controller和compute1重启。 reboot!
测试网络连通性
ping -c 4 www.baidu.com
ping -c 4 compute1
ping -c 4 www.baidu.com
ping -c 4 controller
NTP时间同步
在controller上执行以下命令,从阿里云的NTP服务器上同步时间
apt -y install chrony
mv /etc/chrony/chrony.conf /etc/chrony/chrony.conf.bak
vim /etc/chrony/chrony.conf
--------------------
server ntp.aliyun.com iburst
allow 10.0.0.0/24
service chrony restart
再配置ocmpute1的NTP服务,从controller上拉取时间。
apt -y install chrony
mv /etc/chrony/chrony.conf /etc/chrony/chrony.conf.bak
vim /etc/chrony/chrony.conf
--------------------
server controller iburst
service chrony restart
查看NTP服务是否连上正确的服务器 两台节点都执行一下命令
chronyc sources
如果你还有块存储节点和对象存储节点,则配置方法和compute1一样,都从controller上拉取时间。
所有节点安装openstack包
openstack每半年发布一个新版,版本号从A-Z,截止目前最新版本是yoga,简称Y版。 Ubuntu每两年出一个LTS版本,以下是各个LTS版本对应的可安装的openstack版本。 OpenStack for Ubuntu 20.04 LTS: yoga、xena、wallaby、victoria、Ussuri OpenStack for Ubuntu 18.04 LTS: ussuri、train、stein、rocky OpenStack for Ubuntu 16.04 LTS:queen、pike、mitaka 我们的虚拟机是Ubuntu20.04,所以安装最新的yoga版本 以下的命令请在controller和compute1上都执行(所有的openstack节点都要安装openstack包!!!) 官方文档是这样说明的。 Note: The archive enablement described here needs to be done on all nodes that run OpenStack services.
add-apt-repository cloud-archive:yoga
apt -y install nova-compute
apt -y install python3-openstackclient
controller节点安装SQL数据库
官方的安装指南让我们安装的是mariaDB,这一步安装操作只在controller上执行。
apt -y install mariadb-server python3-pymysql
安装完成后,为openstack在MariaDB中添加一个配置文件。
vim /etc/mysql/mariadb.conf.d/99-openstack.cnf
-----------------------------------------------
[mysqld]
bind-address = 10.0.0.11
default-storage-engine = innodb
innodb_file_per_table = on
max_connections = 4096
collation-server = utf8_general_ci
character-set-server = utf8
重启mariaDB并设置数据库的root用户密码
service mysql restart
mysql_secure_installation
controller节点安装消息队列
openstack支持3种消息队列。 OpenStack supports several message queue services including RabbitMQ, Qpid, and ZeroMQ. 推荐使用rabbitMQ。 以下命令在controller上面执行
apt -y install rabbitmq-server
rabbitmqctl add_user openstack 123456
rabbitmqctl set_permissions openstack ".*" ".*" ".*"
controller节点安装Memcached内存缓存
controller节点执行以下命令
apt -y install memcached python3-memcache
vim /etc/memcached.conf
----------------------------
-l 10.0.0.11
service memcached restart
controller节点安装etcd存储器
以下命令在controller节点上运行。
apt -y install etcd
vim /etc/default/etcd
-------------------------
ETCD_NAME="controller"
ETCD_DATA_DIR="/var/lib/etcd"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
ETCD_INITIAL_CLUSTER="controller=http://10.0.0.11:2380"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.0.0.11:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://10.0.0.11:2379"
ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
ETCD_LISTEN_CLIENT_URLS="http://10.0.0.11:2379"
systemctl restart etcd
systemctl enable etcd
至此,基本环境安装完毕。
yoga版本最小启动服务
想要安装一个可用的openstack,至少安装以下几个服务 ? Identity service keystone installation for Yoga(Keystone认证服务) ? Image service glance installation for Yoga(Glance镜像服务) ? Placement service placement installation for Yoga(Placement服务) ? Compute service nova installation for Yoga(Nova计算服务) ? Networking service neutron installation for Yoga(Neutron网络服务) 其他的推荐安装服务: ? Dashboard horizon installation for Yoga(Horizon用户网页面板服务) ? Block Storage service cinder installation for Yoga(Cinder块存储服务)
所以,以上七个服务我们依次安装完。
安装keystone
参考官方文档:https://docs.openstack.org/keystone/yoga/install/ 首先为keystone本身是个网站,网站就需要创建一个数据库。 所以在controller上面执行以下命令创建数据库
mysql -u root -p
Enter Password: 此处输入密码123456(之前安装mariaDB时设置的)
MariaDB [(none)]> CREATE DATABASE keystone;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY 'keystone';
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY 'keystone';
Query OK, 0 rows affected (0.001 sec)
exit;
Bye
安装keystone
apt -y install keystone
配置keystone,修改如下两处配置:
vim /etc/keystone/keystone.conf
-----------------------------------
[database]
connection = mysql+pymysql://keystone:keystone@controller/keystone
[token]
provider = fernet
同步配置到keystone数据库
su -s /bin/sh -c "keystone-manage db_sync" keystone
初始化fernet秘钥库
keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
keystone-manage credential_setup --keystone-user keystone --keystone-group keystone
运行keystone API
keystone-manage bootstrap --bootstrap-password admin \
--bootstrap-admin-url http://controller:5000/v3/ \
--bootstrap-internal-url http://controller:5000/v3/ \
--bootstrap-public-url http://controller:5000/v3/ \
--bootstrap-region-id RegionOne
到此,keystone的三个接口就运行起来了,web server是apache服务器。 还要设置apache
vim /etc/apache2/apache2.conf
---------------------------
ServerName controller
service apache2 restart
最后收尾操作: 设置以下环境变量
export OS_USERNAME=admin
export OS_PASSWORD=admin
export OS_PROJECT_NAME=admin
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_DOMAIN_NAME=Default
export OS_AUTH_URL=http://controller:5000/v3
export OS_IDENTITY_API_VERSION=3
配置域、项目、用户、角色
openstack domain create --description "An Example Domain" example
openstack project create --domain default --description "Service Project" service
openstack project create --domain default --description "Demo Project" myproject
openstack user create --domain default --password-prompt myuser
openstack role create myrole
openstack role add --project myproject --user myuser myrole
验证keystone是否安装成功
unset OS_AUTH_URL OS_PASSWORD
openstack --os-auth-url http://controller:5000/v3 --os-project-domain-name Default --os-user-domain-name Default --os-project-name admin --os-username admin token issue
+------------+-----------------------------------------------------------------+
| Field | Value |
+------------+-----------------------------------------------------------------+
| expires | 2016-02-12T20:14:07.056119Z |
| id | gAAAAABWvi7_B8kKQD9wdXac8MoZiQldmjEO643d-e_j-XXq9AmIegIbA7UHGPv |
| | atnN21qtOMjCFWX7BReJEQnVOAj3nclRQgAYRsfSU_MrsuWb4EDtnjU7HEpoBb4 |
| | o6ozsA_NmFWEpLeKy0uNn_WeKbAhYygrsmQGA49dclHVnz-OMVLiyM9ws |
| project_id | 343d245e850143a096806dfaefa9afdc |
| user_id | ac3377633149401296f6c0d92d79dc16 |
+------------+-----------------------------------------------------------------+
openstack --os-auth-url http://controller:5000/v3 --os-project-domain-name Default --os-user-domain-name Default --os-project-name myproject --os-username myuser token issue
+------------+-----------------------------------------------------------------+
| Field | Value |
+------------+-----------------------------------------------------------------+
| expires | 2016-02-12T20:15:39.014479Z |
| id | gAAAAABWvi9bsh7vkiby5BpCCnc-JkbGhm9wH3fabS_cY7uabOubesi-Me6IGWW |
| | yQqNegDDZ5jw7grI26vvgy1J5nCVwZ_zFRqPiz_qhbq29mgbQLglbkq6FQvzBRQ |
| | JcOzq3uwhzNxszJWmzGC7rJE_H0A_a3UFhqv8M4zMRYSbS2YF0MyFmp_U |
| project_id | ed0b60bf607743088218b0a533d5943f |
| user_id | 58126687cbcc4888bfa9ab73a2256f27 |
+------------+-----------------------------------------------------------------+
在controller上编写两个凭证文件
mkdir ~/openrc
vim ~/openrc/admin-openrc
------------------------------------
export OS_PROJECT_DOMAIN_NAME=Default
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=admin
export OS_AUTH_URL=http://controller:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
vim ~/openrc/demo-openrc
------------------------------------
export OS_PROJECT_DOMAIN_NAME=Default
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_NAME=myproject
export OS_USERNAME=myuser
export OS_PASSWORD=myuser
export OS_AUTH_URL=http://controller:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
尝试加载admin-openrc试试
. ~/openrc/admin-openrc
openstack token issue
+------------+-----------------------------------------------------------------+
| Field | Value |
+------------+-----------------------------------------------------------------+
| expires | 2022-04-24T16:48:29+0000 |
| id | gAAAAABWvjYj-Zjfg8WXFaQnUd1DMYTBVrKw4h3fIagi5NoEmh21U72SrRv2trl |
| | JWFYhLi2_uPR31Igf6A8mH2Rw9kv_bxNo1jbLNPLGzW_u5FC7InFqx0yYtTwa1e |
| | eq2b0f6-18KZyQhs7F3teAta143kJEWuNEYET-y7u29y0be1_64KYkM7E |
| project_id | 343d245e850143a096806dfaefa9afdc |
| user_id | ac3377633149401296f6c0d92d79dc16 |
+------------+-----------------------------------------------------------------+
到此,所有的keystone安装结束了,官方文档后面的部分是说明如何安装keystone的。
Glance安装
yoga版本的glance组件的官方安装文档: https://docs.openstack.org/glance/yoga/install/install-ubuntu.html 首先为Glance创建数据库
mysql -u root -p
Enter password: 123456
MariaDB [(none)]> CREATE DATABASE glance;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'glance';
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance';
Query OK, 0 rows affected (0.001 sec)
exit;
Bye
加载admin用户(这个用户在keystone安装时创建,所以不能跳)
. ~/openrc/admin-openrc
创建glance用户和项目
openstack user create --domain default --password-prompt glance
openstack role add --project service --user glance admin
openstack service create --name glance --description "OpenStack Image" image
openstack endpoint create --region RegionOne image public http://controller:9292
openstack endpoint create --region RegionOne image internal http://controller:9292
openstack endpoint create --region RegionOne image admin http://controller:9292
设置资源限制(这一步可做可不做,建议先跳过)
openstack --os-cloud devstack-system-admin registered limit create --service glance --default-limit 1000 --region RegionOne image_size_total
openstack --os-cloud devstack-system-admin registered limit create --service glance --default-limit 1000 --region RegionOne image_stage_total
openstack --os-cloud devstack-system-admin registered limit create --service glance --default-limit 100 --region RegionOne image_count_total
openstack --os-cloud devstack-system-admin registered limit create --service glance --default-limit 100 --region RegionOne image_count_uploading
下载安装并配置Glance
apt -y install glance
vim /etc/glance/glance-api.conf
------------------------------------
[DEFAULT]
use_keystone_quotas = True
[database]
connection = mysql+pymysql://glance:glance@controller/glance
[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 = glance
password = glance
[paste_deploy]
flavor = keystone
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
[oslo_limit]
auth_url = http://controller:5000
auth_type = password
user_domain_id = default
username = MY_SERVICE
system_scope = all
password = MY_PASSWORD
endpoint_id = ENDPOINT_ID
region_name = RegionOne
给MY_SERVICE添加读权限
openstack role add --user MY_SERVICE --user-domain Default --system all reader
这一步歇菜了,以后找原因
Placement安装
以下操作在controller节点上执行。 创建数据库
mysql -u root -p
Enter password: 123456
MariaDB [(none)]> CREATE DATABASE placement;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON placement.* TO 'placement'@'localhost' IDENTIFIED BY 'placement';
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON placement.* TO 'placement'@'%' IDENTIFIED BY 'placement';
Query OK, 0 rows affected (0.001 sec)
exit;
Bye
创建项目和用户
. ~/openrc/admin-openrc
openstack user create --domain default --password-prompt placement
openstack role add --project service --user placement admin
openstack service create --name placement --description "Placement API" placement
openstack endpoint create --region RegionOne placement public http://controller:8778
openstack endpoint create --region RegionOne placement internal http://controller:8778
openstack endpoint create --region RegionOne placement admin http://controller:8778
下载placement并配置
apt -y install placement-api
vim /etc/placement/placement.conf
------------------------------------
[placement_database]
connection = mysql+pymysql://placement:placement@controller/placement
[api]
auth_strategy = keystone
[keystone_authtoken]
auth_url = http://controller:5000/v3
memcached_servers = controller:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = placement
password = placement
同步配置到数据库
su -s /bin/sh -c "placement-manage db sync" placement
重启apache
service apache2 restart
验证placement是否安装成功
. ~/openrc/admin-openrc
placement-status upgrade check
+-------------------------------------------+
| Upgrade Check Results |
+-------------------------------------------+
| Check: Missing Root Provider IDs |
| Result: Success |
| Details: None |
+-------------------------------------------+
| Check: Incomplete Consumers |
| Result: Success |
| Details: None |
+-------------------------------------------+
| Check: Policy File JSON to YAML Migration |
| Result: Success |
| Details: None |
+-------------------------------------------+
apt -y install python3-pip
pip3 install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple/
pip3 install osc-placement -i https://mirrors.aliyun.com/pypi/simple/
openstack --os-placement-api-version 1.2 resource class list --sort-column name
+----------------------------------------+
| name |
+----------------------------------------+
| DISK_GB |
| FPGA |
| IPV4_ADDRESS |
| MEMORY_MB |
......
openstack --os-placement-api-version 1.6 trait list --sort-column name
+---------------------------------------+
| name |
+---------------------------------------+
| COMPUTE_ACCELERATORS |
| COMPUTE_ARCH_AARCH64 |
| COMPUTE_ARCH_MIPSEL |
| COMPUTE_ARCH_PPC64LE |
......
至此,placement安装成功。
Nova安装
Neutron安装
Horizon安装
Cinder安装
启动一个yoga实例
在安装之前,openstack安装指南给出了两种网络架构:公网网络架构option1、私网网络架构option2。 其中私网网络架构包含了公网网络架构的全部功能和组件,所以比公网的更复杂。 公网架构原文是这样的 Before launching an instance, you must create the necessary virtual network infrastructure. For networking option 1, an instance uses a provider (external) network that connects to the physical network infrastructure via layer-2 (bridging/switching). This network includes a DHCP server that provides IP addresses to instances. The admin or other privileged user must create this network because it connects directly to the physical network infrastructure. 私网架构option2介绍 If you chose networking option 2, you can also create a self-service (private) network that connects to the physical network infrastructure via NAT. This network includes a DHCP server that provides IP addresses to instances. An instance on this network can automatically access external networks such as the Internet. However, access to an instance on this network from external networks such as the Internet requires a floating IP address. 我们最初整了两张虚拟网卡就是为了实现私网架构的。
创建self-service私有网络
在controller上执行以下步骤
. ~/openrc/demo-openrc
openstack network create selfservice
|