控制节点controller
计算节点compute01、compute
2.1、创建nova数据库,并执行授权操作
[root@controller ~]# mysql -uroot -p123456
MariaDB [(none)]> CREATE DATABASE nova_api;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> CREATE DATABASE nova;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> CREATE DATABASE nova_cell0;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'localhost' IDENTIFIED BY 'NOVA_DBPASS';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'%' IDENTIFIED BY 'NOVA_DBPASS';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' IDENTIFIED BY 'NOVA_DBPASS';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' IDENTIFIED BY 'NOVA_DBPASS';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'localhost' IDENTIFIED BY 'NOVA_DBPASS';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'%' IDENTIFIED BY 'NOVA_DBPASS';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> exit
Bye
3.1、创建nova用户
[root@controller ~]# openstack user create --domain default --password NOVA_PASS nova
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| domain_id | default |
| enabled | True |
| id | f48e79cc9c4d4641b201243815e7228a |
| name | nova |
| options | {} |
| password_expires_at | None |
+---------------------+----------------------------------+
3.2、把nova用户添加到service项目,拥有admin权限
[root@controller ~]# openstack role add --project service --user nova admin
3.3、创建nova服务
[root@controller ~]# openstack service create --name nova --description "OpenStack Compute" compute
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Compute |
| enabled | True |
| id | 20a700bb16d143a0b47fb8826615480d |
| name | nova |
| type | compute |
+-------------+----------------------------------+
3.4、给Nova服务关联endpoint(端点)
[root@controller ~]# openstack endpoint create --region RegionOne compute public http://controller:8774/v2.1
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 893e9b69f5d640cdb7d0eccfbae7f17d |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 20a700bb16d143a0b47fb8826615480d |
| service_name | nova |
| service_type | compute |
| url | http://controller:8774/v2.1 |
+--------------+----------------------------------+
[root@controller ~]# openstack endpoint create --region RegionOne compute internal http://controller:8774/v2.1
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | fbe9c6b3fe4043d4bf8192919a3c9808 |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 20a700bb16d143a0b47fb8826615480d |
| service_name | nova |
| service_type | compute |
| url | http://controller:8774/v2.1 |
+--------------+----------------------------------+
[root@controller ~]# openstack endpoint create --region RegionOne compute admin http://controller:8774/v2.1
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | aa0e93196ab545fd93da5ebc960da36d |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 20a700bb16d143a0b47fb8826615480d |
| service_name | nova |
| service_type | compute |
| url | http://controller:8774/v2.1 |
+--------------+----------------------------------+
3.5、安装nova组件(nova-api、nova-conductor、nova-novncproxy、nova-scheduler)
[root@controller ~]# yum -y install openstack-nova-api openstack-nova-conductor openstack-nova-novncproxy openstack-nova-scheduler
3.6、修改nova配置文件(nova.conf)
[root@controller ~]# cp -a /etc/nova/nova.conf{,.bak}
[root@controller ~]# grep -Ev '^$|#' /etc/nova/nova.conf.bak > /etc/nova/nova.conf
[root@controller ~]# openstack-config --set /etc/nova/nova.conf DEFAULT enabled_apis osapi_compute,metadata
[root@controller ~]# openstack-config --set /etc/nova/nova.conf DEFAULT my_ip 192.168.100.11
[root@controller ~]# openstack-config --set /etc/nova/nova.conf DEFAULT use_neutron true
[root@controller ~]# openstack-config --set /etc/nova/nova.conf DEFAULT firewall_driver nova.virt.firewall.NoopFirewallDriver
[root@controller ~]# openstack-config --set /etc/nova/nova.conf DEFAULT transport_url rabbit://openstack:RABBIT_PASS@controller
[root@controller ~]# openstack-config --set /etc/nova/nova.conf api_database connection mysql+pymysql://nova:NOVA_DBPASS@controller/nova_api
[root@controller ~]# openstack-config --set /etc/nova/nova.conf database connection mysql+pymysql://nova:NOVA_DBPASS@controller/nova
[root@controller ~]# openstack-config --set /etc/nova/nova.conf placement_database connection mysql+pymysql://placement:PLACEMENT_DBPASS@controller/placement
[root@controller ~]# openstack-config --set /etc/nova/nova.conf api auth_strategy keystone
[root@controller ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken auth_url http://controller:5000/v3
[root@controller ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken memcached_servers controller:11211
[root@controller ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken auth_type password
[root@controller ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken project_domain_name Default
[root@controller ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken user_domain_name Default
[root@controller ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken project_name service
[root@controller ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken username nova
[root@controller ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken password NOVA_PASS
[root@controller ~]# openstack-config --set /etc/nova/nova.conf vnc enabled true
[root@controller ~]# openstack-config --set /etc/nova/nova.conf vnc server_listen ' $my_ip'
[root@controller ~]# openstack-config --set /etc/nova/nova.conf vnc server_proxyclient_address ' $my_ip'
[root@controller ~]# openstack-config --set /etc/nova/nova.conf glance api_servers http://controller:9292
[root@controller ~]# openstack-config --set /etc/nova/nova.conf oslo_concurrency lock_path /var/lib/nova/tmp
[root@controller ~]# openstack-config --set /etc/nova/nova.conf placement region_name RegionOne
[root@controller ~]# openstack-config --set /etc/nova/nova.conf placement project_domain_name Default
[root@controller ~]# openstack-config --set /etc/nova/nova.conf placement project_name service
[root@controller ~]# openstack-config --set /etc/nova/nova.conf placement auth_type password
[root@controller ~]# openstack-config --set /etc/nova/nova.conf placement user_domain_name Default
[root@controller ~]# openstack-config --set /etc/nova/nova.conf placement auth_url http://controller:5000/v3
[root@controller ~]# openstack-config --set /etc/nova/nova.conf placement username placement
[root@controller ~]# openstack-config --set /etc/nova/nova.conf placement password PLACEMENT_PASS
#查看nova.conf
[root@controller ~]# cat /etc/nova/nova.conf
[DEFAULT]
enabled_apis = osapi_compute,metadata # 指定支持的api类型
my_ip = 192.168.100.11 # 定义本地IP
use_neutron = true # 通过neutron获取IP地址
firewall_driver = nova.virt.firewall.NoopFirewallDriver
transport_url = rabbit://openstack:RABBIT_PASS@controller # 指定连接的rabbitmq
[api]
auth_strategy = keystone # 指定使用keystone认证
[api_database]
connection = mysql+pymysql://nova:NOVA_DBPASS@controller/nova_api
[barbican]
[cache]
[cinder]
[compute]
[conductor]
[console]
[consoleauth]
[cors]
[database]
connection = mysql+pymysql://nova:NOVA_DBPASS@controller/nova
[devices]
[ephemeral_storage_encryption]
[filter_scheduler]
[glance]
api_servers = http://controller:9292
[guestfs]
[healthcheck]
[hyperv]
[ironic]
[key_manager]
[keystone]
[keystone_authtoken] # 配置keystone的认证信息
auth_url = http://controller:5000/v3 # 到此url去认证
memcached_servers = controller:11211 # memcache数据库地址:端口
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = nova
password = NOVA_PASS
[libvirt]
[metrics]
[mks]
[neutron]
[notifications]
[osapi_v21]
[oslo_concurrency] # 指定锁路径
lock_path = /var/lib/nova/tmp # 锁的作用是创建虚拟机时,在执行某个操作的时候,需要等此步骤执行完后才能执行下一个步骤,不能并行执行,保证操作是一步一步的执行
[oslo_messaging_amqp]
[oslo_messaging_kafka]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
[oslo_middleware]
[oslo_policy]
[pci]
[placement]
region_name = RegionOne
project_domain_name = Default
project_name = service
auth_type = password
user_domain_name = Default
auth_url = http://controller:5000/v3
username = placement
password = PLACEMENT_PASS
[powervm]
[privsep]
[profiler]
[quota]
[rdp]
[remote_debug]
[scheduler]
[serial_console]
[service_user]
[spice]
[upgrade_levels]
[vault]
[vendordata_dynamic_auth]
[vmware]
[vnc] # 此处如果配置不正确,则连接不上虚拟机的控制台
enabled = true
server_listen = $my_ip # 指定vnc的监听地址
server_proxyclient_address = $my_ip # server的客户端地址为本机地址;此地址是管理网的地址
[workarounds]
[wsgi]
[xenserver]
[xvp]
[zvm]
[placement_database]
connection = mysql+pymysql://placement:PLACEMENT_DBPASS@controller/placement
3.7、初始化数据库(初始化nova_api数据库)
[root@controller ~]# su -s /bin/sh -c "nova-manage api_db sync" nova
3.8、注册cell0数据库;nova服务内部把资源划分到不同的cell中,把计算节点划分到不同的cell中;openstack内部基于cell把计算节点进行逻辑上的分组
[root@controller ~]# su -s /bin/sh -c "nova-manage cell_v2 map_cell0" nova
创建cell1单元格
[root@controller ~]# su -s /bin/sh -c "nova-manage cell_v2 create_cell --name=cell1 --verbose" nova # 输入
02a7b36d-e230-40cb-ae1a-df6e0fd1dc13
初始化nova数据库;可以通过 /var/log/nova/nova-manage.log 日志判断是否初始化成功
[root@controller ~]# su -s /bin/sh -c "nova-manage db sync" nova
/usr/lib/python2.7/site-packages/pymysql/cursors.py:170: Warning: (1831, u'Duplicate index `block_device_mapping_instance_uuid_virtual_name_device_name_idx`. This is deprecated and will be disallowed in a future release')
result = self._query(query)
/usr/lib/python2.7/site-packages/pymysql/cursors.py:170: Warning: (1831, u'Duplicate index `uniq_instances0uuid`. This is deprecated and will be disallowed in a future release')
result = self._query(query)
可使用以下命令验证cell0和cell1是否注册成功
[root@controller ~]# su -s /bin/sh -c "nova-manage cell_v2 list_cells" nova
+-------+--------------------------------------+------------------------------------+-------------------------------------------------+----------+
| 名称 | UUID | Transport URL | 数据库连接 | Disabled |
+-------+--------------------------------------+------------------------------------+-------------------------------------------------+----------+
| cell0 | 00000000-0000-0000-0000-000000000000 | none:/ | mysql+pymysql://nova:****@controller/nova_cell0 | False |
| cell1 | 02a7b36d-e230-40cb-ae1a-df6e0fd1dc13 | rabbit://openstack:****@controller | mysql+pymysql://nova:****@controller/nova | False |
+-------+--------------------------------------+------------------------------------+-------------------------------------------------+----------+
3.9、启动Nova服务
[root@controller ~]# systemctl enable openstack-nova-api.service openstack-nova-scheduler.service openstack-nova-conductor.service openstack-nova-novncproxy.service
[root@controller ~]# systemctl start openstack-nova-api.service openstack-nova-scheduler.service openstack-nova-conductor.service openstack-nova-novncproxy.service
3.10、检查nova服务端口
[root@controller ~]# netstat -tnlup|egrep '8774|8775'
tcp 0 0 0.0.0.0:8775 0.0.0.0:* LISTEN 51035/python2
tcp 0 0 0.0.0.0:8774 0.0.0.0:* LISTEN 51035/python2
[root@controller ~]# curl http://controller:8774
{"versions": [{"status": "SUPPORTED", "updated": "2011-01-21T11:33:21Z", "links": [{"href": "http://controller:8774/v2/", "rel": "self"}], "min_version": "", "version": "", "id": "v2.0"}, {"status": "CURRENT", "updated": "2013-07-23T11:33:21Z", "links": [{"href": "http://controller:8774/v2.1/", "rel": "self"}], "min_version": "2.1", "version": "2.79", "id": "v2.1"}]}
4.1、安装nova-compute组件
[root@compute01 ~]# yum -y install openstack-nova-compute
4.2、修改配置文件
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf DEFAULT enabled_apis osapi_compute,metadata
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf DEFAULT transport_url rabbit://openstack:RABBIT_PASS@controller
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf DEFAULT my_ip 192.168.100.12
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf DEFAULT use_neutron true
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf DEFAULT firewall_driver nova.virt.firewall.NoopFirewallDriver
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf api auth_strategy keystone
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken auth_url http://controller:5000/v3
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken memcached_servers controller:11211
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken auth_type password
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken project_domain_name Default
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken user_domain_name Default
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken project_name service
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken username nova
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf keystone_authtoken password NOVA_PASS
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf vnc enabled true
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf vnc server_listen 0.0.0.0
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf vnc server_proxyclient_address ' $my_ip'
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf vnc novncproxy_base_url http://192.168.100.11:6080/vnc_auto.html
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf glance api_servers http://controller:9292
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf oslo_concurrency lock_path /var/lib/nova/tmp
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf placement region_name RegionOne
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf placement project_domain_name Default
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf placement project_name service
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf placement auth_type password
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf placement user_domain_name Default
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf placement auth_url http://controller:5000/v3
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf placement username placement
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf placement password PLACEMENT_PASS
[root@compute01 ~]# openstack-config --set /etc/nova/nova.conf libvirt virt_type qemu
[root@compute01 ~]# cat /etc/nova/nova.conf
[DEFAULT]
enabled_apis = osapi_compute,metadata
transport_url = rabbit://openstack:RABBIT_PASS@controller
my_ip = 192.168.100.12
use_neutron = true
firewall_driver = nova.virt.firewall.NoopFirewallDriver
[api]
auth_strategy = keystone
[api_database]
[barbican]
[cache]
[cinder]
[compute]
[conductor]
[console]
[consoleauth]
[cors]
[database]
[devices]
[ephemeral_storage_encryption]
[filter_scheduler]
[glance]
api_servers = http://controller:9292
[guestfs]
[healthcheck]
[hyperv]
[ironic]
[key_manager]
[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 = nova
password = NOVA_PASS
[libvirt]
virt_type = qemu
[metrics]
[mks]
[neutron]
[notifications]
[osapi_v21]
[oslo_concurrency]
lock_path = /var/lib/nova/tmp
[oslo_messaging_amqp]
[oslo_messaging_kafka]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
[oslo_middleware]
[oslo_policy]
[pci]
[placement]
region_name = RegionOne
project_domain_name = Default
project_name = service
auth_type = password
user_domain_name = Default
auth_url = http://controller:5000/v3
username = placement
password = PLACEMENT_PASS
[powervm]
[privsep]
[profiler]
[quota]
[rdp]
[remote_debug]
[scheduler]
[serial_console]
[service_user]
[spice]
[upgrade_levels]
[vault]
[vendordata_dynamic_auth]
[vmware]
[vnc]
enabled = true
server_listen = 0.0.0.0
server_proxyclient_address = $my_ip
novncproxy_base_url = http://192.168.100.11:6080/vnc_auto.html # 比较特殊的地方,需要手动添加IP地址,否则之后搭建成功后,无法通过UI控制台访问到内部虚拟机
[workarounds]
[wsgi]
[xenserver]
[xvp]
[zvm]
4.3、开启服务
[root@compute01 ~]# systemctl enable libvirtd.service openstack-nova-compute.service
[root@compute01 ~]# systemctl start libvirtd.service openstack-nova-compute.service
4.4、【计算节点-compute02】与compute01相同(除了IP地址)
controller节点操作
[root@controller ~]# openstack compute service list --service nova-compute
+----+--------------+-----------+------+---------+-------+----------------------------+
| ID | Binary | Host | Zone | Status | State | Updated At |
+----+--------------+-----------+------+---------+-------+----------------------------+
| 7 | nova-compute | compute01 | nova | enabled | up | 2021-02-06T00:37:13.000000 |
| 8 | nova-compute | compute02 | nova | enabled | up | 2021-02-06T00:37:14.000000 |
+----+--------------+-----------+------+---------+-------+----------------------------+
[root@controller ~]# su -s /bin/sh -c "nova-manage cell_v2 discover_hosts --verbose" nova
Found 2 cell mappings.
Skipping cell0 since it does not contain hosts.
Getting computes from cell 'cell1': 02a7b36d-e230-40cb-ae1a-df6e0fd1dc13
Checking host mapping for compute host 'compute01': 44b689e5-c247-4bd8-b4ac-5f503e4f3d04
Creating host mapping for compute host 'compute01': 44b689e5-c247-4bd8-b4ac-5f503e4f3d04
Checking host mapping for compute host 'compute02': 71ead6b6-9d61-4fc9-9af6-51d0ad306232
Creating host mapping for compute host 'compute02': 71ead6b6-9d61-4fc9-9af6-51d0ad306232
Found 2 unmapped computes in cell: 02a7b36d-e230-40cb-ae1a-df6e0fd1dc13
[root@controller ~]# vim /etc/nova/nova.conf
[scheduler]
discover_hosts_in_cells_interval = 300 # 每300秒扫描一次
[root@controller ~]# systemctl restart openstack-nova-api.service
检查 nova 的各个服务是否都是正常,以及 compute 服务是否注册成功
[root@controller ~]# openstack compute service list
+----+----------------+------------+----------+---------+-------+----------------------------+
| ID | Binary | Host | Zone | Status | State | Updated At |
+----+----------------+------------+----------+---------+-------+----------------------------+
| 1 | nova-conductor | controller | internal | enabled | up | 2021-02-06T00:43:00.000000 |
| 4 | nova-scheduler | controller | internal | enabled | up | 2021-02-06T00:43:06.000000 |
| 7 | nova-compute | compute01 | nova | enabled | up | 2021-02-06T00:43:03.000000 |
| 8 | nova-compute | compute02 | nova | enabled | up | 2021-02-06T00:43:04.000000 |
+----+----------------+------------+----------+---------+-------+----------------------------+
查看各个组件的 api 是否正常
[root@controller ~]# openstack catalog list
+-----------+-----------+-----------------------------------------+
| Name | Type | Endpoints |
+-----------+-----------+-----------------------------------------+
| keystone | identity | RegionOne |
| | | internal: http://controller:5000/v3/ |
| | | RegionOne |
| | | admin: http://controller:5000/v3/ |
| | | RegionOne |
| | | public: http://controller:5000/v3/ |
| | | |
| nova | compute | RegionOne |
| | | public: http://controller:8774/v2.1 |
| | | RegionOne |
| | | admin: http://controller:8774/v2.1 |
| | | RegionOne |
| | | internal: http://controller:8774/v2.1 |
| | | |
| glance | image | RegionOne |
| | | admin: http://controller:9292 |
| | | RegionOne |
| | | internal: http://controller:9292 |
| | | RegionOne |
| | | public: http://controller:9292 |
| | | |
| placement | placement | RegionOne |
| | | public: http://controller:8778 |
| | | RegionOne |
| | | internal: http://controller:8778 |
| | | RegionOne |
| | | admin: http://controller:8778 |
| | | |
+-----------+-----------+-----------------------------------------+
查看是否能够拿到镜像
[root@controller ~]# openstack image list
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| ade29420-81eb-42ae-9ff3-a39fb365d10a | cirros | active |
+--------------------------------------+--------+--------+
查看cell的api和placement的api是否正常,只要其中一个有误,后期无法创建虚拟机
[root@controller ~]# nova-status upgrade check
+--------------------------------+
| Upgrade Check Results |
+--------------------------------+
| Check: Cells v2 |
| Result: Success |
| Details: None |
+--------------------------------+
| Check: Placement API |
| Result: Success |
| Details: None |
+--------------------------------+
| Check: Ironic Flavor Migration |
| Result: Success |
| Details: None |
+--------------------------------+
| Check: Cinder API |
| Result: Success |
| Details: None |
+--------------------------------+