这是本人的一些学习笔记,如果有错误的地方或者更好的解决方法,欢迎提出!!
nova服务是负责虚拟机创建、删除、启动、停止、挂起、恢复等全生命周期管理的核心服务。通过nova-scheduler组件,根据资源使用情况、调度策略和用户请求,将虚拟机调度到最合适的计算节点上运行。同时,nova服务与OpenStack的其他服务紧密集成,共同提供完整的云服务功能。
1.安装nova软件包
[root@openstack01 ~]# yum install -y openstack-nova-api openstack-nova-conductor openstack-nova-scheduler openstack-nova-novncproxy
检查nova服务有没有成功安装
[root@openstack01 ~]# cat /etc/passwd | grep nova
nova:x:162:162:OpenStack Nova Daemons:/var/lib/nova:/sbin/nologin
[root@openstack01 ~]# cat /etc/group | grep nova
nobody:x:99:nova
nova:x:162:nova
2.修改nova配置文件
备份配置文件
[root@openstack01 ~]# cp /etc/nova/nova.conf /etc/nova/nova.conf.bak
去除空行注释,生成新的配置文件,方便修改
[root@openstack01 ~]# grep -Ev '^$|#' /etc/nova/nova.conf.bak > /etc/nova/nova.conf
编辑配置文件
在[DEFAULT]部分配置以下内容
#[DEFAULT]
enabled_apis=osapi_compute,metadata
transport_url=rabbit://openstack01:000000@openstack01:5672
my_ip=192.168.238.100
use_neutron=true
firewall_driver=nova.virt.firewall.NoopFirewallDriver
在[api_database]和[database]部分配置以下内容
[api_database]
connection=mysql+pymysql://nova:000000@openstack01/nova_api
[database]
connection=mysql+pymysql://nova:000000@openstack01/nova
修改[api]部分
[api]
auth_strategy=keystone
修改[keystone_authtoken]部分
[keystone_authtoken]
auth_url=http://openstack01:5000
memcached_servers=openstack01:11211
auth_type=password
username=nova
password=000000
project_name=project
user_domain_name=Default
project_domain_name=Default
修改[placement]部分
[placement]
auth_url=http://openstack01:5000
region_name=RegionOne
auth_type=password
username=placement
password=000000
project_name=project
user_domain_name=Default
project_domain_name=Default
修改[glance]部分
[glance]
api_servers=http://openstack01:9292
修改[oslo_concurrency]部分
[oslo_concurrency]
lock_path=/var/lib/nova/tmp
修改[vnc]部分
[vnc]
enabled=true
server_listen=192.168.238.100
server_proxyclient_address=192.168.238.100
3.创建nova数据库并授权
MariaDB [(none)]> create database nova;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> create database nova_api;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> create database nova_cell0;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> grant all privileges on nova.* to 'nova'@'localhost' identified by '000000';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all privileges on nova.* to 'nova'@'%' identified by '000000';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all privileges on nova_api.* to 'nova'@'localhost' identified by '000000';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all privileges on nova_api.* to 'nova'@'%' identified by '000000';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> grant all privileges on nova_cell0.* to 'nova'@'localhost' identified by '000000';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all privileges on nova_cell0.* to 'nova'@'%' identified by '000000';
Query OK, 0 rows affected (0.001 sec)
4.初始化数据库
初始化nova_api数据库
[root@openstack01 ~]# su nova -s /bin/sh -c 'nova-manage api_db sync'
创建cell1单元,该单元将使用nova数据库
[root@openstack01 ~]# su nova -s /bin/sh -c 'nova-manage cell_v2 create_cell --name=cell1'
映射nova到cell0数据库,使cell0的表结构和nova的表结构保持一致
[root@openstack01 ~]# su nova -s /bin/sh -c 'nova-manage cell_v2 map_cell0'
初始化nova数据库
[root@openstack01 ~]# su nova -s /bin/sh -c 'nova-manage db sync'
验证是否都正确注册
[root@openstack01 ~]# nova-manage cell_v2 list_cells
+-------+--------------------------------------+-----------------------------------------+--------------------------------------------------+----------+
| Name | UUID | Transport URL | Database Connection | Disabled |
+-------+--------------------------------------+-----------------------------------------+--------------------------------------------------+----------+
| cell0 | 00000000-0000-0000-0000-000000000000 | none:/ | mysql+pymysql://nova:****@openstack01/nova_cell0 | False |
| cell1 | 29634ff6-dec2-47fa-b81d-ef657ae9e556 | rabbit://rabbitmq:****@openstack01:5672 | mysql+pymysql://nova:****@openstack01/nova | False |
+-------+--------------------------------------+-----------------------------------------+--------------------------------------------------+----------+
[root@openstack01 ~]#
4.nova组件初始化
导入环境变量
[root@openstack01 ~]# . admin-login
在openstack平台中创建nova用户
[root@openstack01 ~]# openstack user create nova --domain default --password 000000
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| domain_id | default |
| enabled | True |
| id | 3390e6f431e947fb83760af42ed33fff |
| name | nova |
| options | {} |
| password_expires_at | None |
+---------------------+----------------------------------+
赋予nova用户管理员角色
[root@openstack01 ~]# openstack role add admin --project project --user nova
创建nova服务
[root@openstack01 ~]# openstack service create --name nova compute
+---------+----------------------------------+
| Field | Value |
+---------+----------------------------------+
| enabled | True |
| id | d5546bc1311f472da5a1edc28abc88a3 |
| name | nova |
| type | compute |
+---------+----------------------------------+
创建nova对外服务端点
[root@openstack01 ~]# openstack endpoint create --region RegionOne nova public http://openstack01:8774/2.1
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | e2c74cb9ea984190885a7689b3bbc7a7 |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | d5546bc1311f472da5a1edc28abc88a3 |
| service_name | nova |
| service_type | compute |
| url | http://openstack01:8774/v2.1 |
+--------------+----------------------------------+
创建nova对内服务端点
[root@openstack01 ~]# openstack endpoint create --region RegionOne nova internal http://openstack01:8774/v2.1
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | db7288e85532427ca8c9775a9f915f6a |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | d5546bc1311f472da5a1edc28abc88a3 |
| service_name | nova |
| service_type | compute |
| url | http://openstack01:8774/v2.1 |
+--------------+----------------------------------+
创建nova对管理员服务端点
[root@openstack01 ~]# openstack endpoint create --region RegionOne nova admin http://openstack01:8774/v2.1
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 8e309990754c40448483201ce96d9826 |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | d5546bc1311f472da5a1edc28abc88a3 |
| service_name | nova |
| service_type | compute |
| url | http://openstack01:8774/v2.1 |
+--------------+----------------------------------+
5.启动控制节点openstack01的nova服务
[root@openstack01 ~]# systemctl start openstack-nova-api openstack-nova-scheduler openstack-nova-conductor openstack-nova-novncproxy
[root@openstack01 ~]# systemctl enable openstack-nova-api openstack-nova-scheduler openstack-nova-conductor openstack-nova-novncproxy
检查服务是否正确开启
[root@openstack01 ~]# ss -lntpu | grep 8778
tcp LISTEN 0 128 :::8778 :::* users:(("httpd",pid=6282,fd=6),("httpd",pid=6280,fd=6),("httpd",pid=6270,fd=6),("httpd",pid=6222,fd=6),("httpd",pid=5609,fd=6),("httpd",pid=2498,fd=6),("httpd",pid=2494,fd=6),("httpd",pid=2493,fd=6),("httpd",pid=2492,fd=6),("httpd",pid=2491,fd=6),("httpd",pid=1158,fd=6))
[root@openstack01 ~]#
6.在计算节点openstack02配置nova服务
[root@openstack02 ~]# yum install -y openstack-nova-compute
如果安装过程中遇到报错
Error: Package: 1:openstack-nova-compute-20.6.0-1.el7.noarch (centos-openstack-train) Requires: qemu-kvm-rhev >= 2.10.0 You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest
这是因为在虚拟机内遇到了依赖问题。具体来说,需要一个依赖包,名为: qemu-kvm-rhev,
版本至少为 2.10.0
解决方法:
在/etc/yum.repos.d/目录下新建一个repo文件,文件内容如以下所示:
[root@openstack02 yum.repos.d]# cat CentOS-QEMU-EV.repo
[CentOS-QEMU-EV]
name=CentOS-7 - QEMU EV
baseurl=https://mirrors.aliyun.com/centos/7/virt/x86_64/kvm-common/
gpgcheck=0
enabled=1
请注意:baseurl内容可能会变动,请参考网站:centos安装包下载_开源镜像站-阿里云进行手动修正。
7.修改计算节点nova服务的配置文件
备份配置文件
[root@openstack02 ~]# cd /etc/nova
[root@openstack02 nova]# ls
api-paste.ini nova.conf policy.json release rootwrap.conf
[root@openstack02 nova]# mv nova.conf nova.conf.bak
将控制节点openstack01的配置文件传输到计算节点openstack02指定目录下
[root@openstack01 nova]# scp nova.conf root@openstack02:/etc/nova/
将文件的数据库连接语句注释或者删除
[api_database]
#connection=mysql+pymysql://nova:000000@openstack01/nova_api
[database]
#connection=mysql+pymysql://nova:000000@openstack01/nova
修改[DEFAULT]部分,将ip改成计算节点openstack02的ip
[DEFAULT]
enabled_apis=osapi_compute,metadata
transport_url=rabbit://openstack:000000@openstack01:5672
my_ip=192.168.238.200
use_neutron=true
firewall_driver=nova.virt.firewall.NoopFirewallDriver
修改[VNC]部分,配置vnc的连接方式,注意将IP地址改成openstack02计算节点的IP地址
[vnc]
enabled=true
server_listen=0.0.0.0
server_proxyclient_address=192.168.238.200
novncproxy_base_url=http://192.168.238.100:6080/vnc_auto.html
修改[libvirt]部分,设置虚拟化类型
[libvirt]
virt_type=qemu
8.启动计算节点openstack02的nova服务
[root@openstack02 nova]# systemctl start openstack-nova-compute libvirtd
[root@openstack02 nova]# systemctl enable openstack-nova-compute libvirtd
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-nova-compute.service to /usr/lib/systemd/system/openstack-nova-compute.service.
9.控制节点openstack01发现计算节点openstack02
[root@openstack01 nova]# su nova -s /bin/sh -c 'nova-manage cell_v2 discover_hosts --verbose'
Found 2 cell mappings.
Getting computes from cell 'cell1': 2b5d6520-4384-4844-880b-d4956b1fb743
Checking host mapping for compute host 'openstack02': 4ff0acd7-b3b3-4351-91c8-cd1688a3b29a
Creating host mapping for compute host 'openstack02': 4ff0acd7-b3b3-4351-91c8-cd1688a3b29a
Found 1 unmapped computes in cell: 2b5d6520-4384-4844-880b-d4956b1fb743
Skipping cell0 since it does not contain hosts.
在控制节点openstack01设置自动发现功能,每60秒自动执行一次发现命令
[scheduler]
discover_hosts_in_cells_interval=60
重启服务
[root@openstack01 ~]# systemctl restart openstack-nova-api
10.验证nova服务
查看计算服务中各个模块的服务状态
[root@openstack01 ~]# openstack compute service list
+----+----------------+-------------+----------+---------+-------+----------------------------+
| ID | Binary | Host | Zone | Status | State | Updated At |
+----+----------------+-------------+----------+---------+-------+----------------------------+
| 4 | nova-conductor | openstack01 | internal | enabled | up | 2024-07-31T12:07:32.000000 |
| 6 | nova-scheduler | openstack01 | internal | enabled | up | 2024-07-31T12:07:35.000000 |
| 7 | nova-compute | openstack02 | nova | enabled | up | 2024-07-31T12:07:32.000000 |
+----+----------------+-------------+----------+---------+-------+----------------------------+
查看OpenStack现有的服务和对应的端点列表
[root@openstack01 ~]# openstack catalog list
+-----------+-----------+------------------------------------------+
| Name | Type | Endpoints |
+-----------+-----------+------------------------------------------+
| glance | image | RegionOne |
| | | admin: http://openstack01:9292 |
| | | RegionOne |
| | | public: http://openstack01:9292 |
| | | RegionOne |
| | | internal: http://openstack01:9292 |
| | | |
| placement | placement | RegionOne |
| | | public: http://openstack01:8778 |
| | | RegionOne |
| | | admin: http://openstack01:8778 |
| | | RegionOne |
| | | internal: http://openstack01:8778 |
| | | |
| keystone | identity | RegionOne |
| | | public: http://openstack01:5000/v3 |
| | | RegionOne |
| | | internal: http://openstack01:5000/v3 |
| | | RegionOne |
| | | admin: http://openstack01:5000/v3 |
| | | |
| nova | compute | RegionOne |
| | | internal: http://openstack01:8774/v2.1 |
| | | RegionOne |
| | | admin: http://openstack01:8774/v2.1 |
| | | RegionOne |
| | | public: http://openstack01:8774/v2.1 |
| | | |
+-----------+-----------+------------------------------------------+
使用Nova状态检测工具“nova-status”
[root@openstack01 ~]# 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 |
+--------------------------------+
至此,openstack组件nova服务配置完成