【五】Openstack-Nova

部署Nova控制节点和计算节点

Nova组件

使用OpenStack Compute托管和管理云计算系统。OpenStack计算是基础设施即服务(IaaS)系统的主要组成部分。主要模块用Python实现。
OpenStack Compute与用于身份验证的OpenStack Identity、用于资源清单跟踪和选择的OpenStack Placement、用于磁盘和服务器映像的OpenStack Image service以及用于用户和管理界面的OpenStack Dashboard进行交互。图像访问受到项目和用户的限制;每个项目的配额是有限的(例如,实例的数量)。OpenStack Compute可以在标准硬件上水平扩展,并下载映像来启动实例。

##OpenStack计算由以下区域及其组件组成:
#nova-api service
接受并响应最终用户计算API调用。该服务支持OpenStack计算API。它执行一些策略并启动大多数编排活动,比如运行一个实例。

#nova-api-metadata service
接受来自实例的元数据请求。这nova-api-metadata服务通常在多主机模式下运行时使用nova-network装置。有关详细信息,请参见元数据服务在计算机管理员指南中。

#nova-compute service
通过虚拟机管理程序API创建和终止虚拟机实例的工作守护程序。例如:
XenServer/XCP的XenAPI
KVM或QEMU的libvirt
VMware的VMwareAPI
处理相当复杂。基本上,守护进程接受来自队列的动作,并执行一系列系统命令,比如启动KVM实例并更新其在数据库中的状态。

#nova-scheduler service
从队列中获取虚拟机实例请求,并确定它在哪个计算服务器主机上运行。

#nova-conductor module
协调之间的交互nova-compute服务和数据库。它消除了nova-compute服务。这nova-conductor模块水平扩展。
但是,不要将其部署在nova-compute服务运行。有关更多信息,请参见conductor中的部分配置选项.

#nova-novncproxy daemon
为通过VNC连接访问正在运行的实例提供代理。支持基于浏览器的novnc客户端。

#nova-spicehtml5proxy daemon
为通过SPICE连接访问正在运行的实例提供代理。支持基于浏览器的HTML5客户端。

#nova-xvpvncproxy daemon
为通过VNC连接访问正在运行的实例提供代理。支持特定于OpenStack的Java客户端。

 自19.0.0版起已弃用:nova-xvpvnxproxy自19.0.0 (Stein)起已被弃用,并将在即将发布的版本中删除。

#The queue
在守护进程之间传递消息的中心枢纽。通常用实现兔子q但是还有其他选择.

#SQL数据库
存储云基础架构的大多数构建时和运行时状态,包括:

可用的实例类型
正在使用的实例
可用网络
项目

理论上,OpenStack Compute可以支持SQLAlchemy支持的任何数据库。
常见的数据库有用于测试和开发工作的SQLite3、MySQL、MariaDB和PostgreSQL。

一、配置openstack-controller1节点

#Compute service – nova installation for Train
https://docs.openstack.org/nova/train/install/compute-install-rdo.html

#先controller进行配置
#创建数据库
mysql -u root -p

MariaDB [(none)]> CREATE DATABASE nova_api;
MariaDB [(none)]> CREATE DATABASE nova;
MariaDB [(none)]> CREATE DATABASE nova_cell0;

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'localhost' IDENTIFIED BY 'nova123';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'%' IDENTIFIED BY 'nova123';

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' IDENTIFIED BY 'nova123';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%'  IDENTIFIED BY 'nova123';

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'localhost' IDENTIFIED BY 'nova123';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'%' IDENTIFIED BY 'nova123';


source admin-openrc.sh
#Create the nova user
[root@openstack-controller1 ~]# openstack user create --domain default --password-prompt nova
User Password:nova
Repeat User Password:nova
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 1b708bd3438e4aaa8cfa60b8cc839834 |
| name                | nova                             |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

#Add the admin role to the nova user
openstack role add --project service --user nova admin

#Create the nova service entity
[root@openstack-controller1 ~]# openstack service create --name nova --description "OpenStack Compute" compute
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Compute                |
| enabled     | True                             |
| id          | 48efaf2b284a4aa1acd745b2a083cc8e |
| name        | nova                             |
| type        | compute                          |
+-------------+----------------------------------+

#Create the Compute API service endpoints
openstack endpoint create --region RegionOne compute public http://openstack-vip.xks.local:8774/v2.1
openstack endpoint create --region RegionOne compute internal http://openstack-vip.xks.local:8774/v2.1
openstack endpoint create --region RegionOne compute admin http://openstack-vip.xks.local:8774/v2.1

[root@openstack-controller1 ~]# openstack endpoint list | grep compute
| 36df7ee06e8e4a5fa4e3bd08051a9f88 | RegionOne | nova         | compute      | True    | public    | http://openstack-vip.xks.local:8774/v2.1 |
| 7f4a7baa344542cd9b5c33dbbd4521af | RegionOne | nova         | compute      | True    | admin     | http://openstack-vip.xks.local:8774/v2.1 |
| f9971392a0b346dbaedae4edcaf3dcf1 | RegionOne | nova         | compute      | True    | internal  | http://openstack-vip.xks.local:8774/v2.1 |

#配置Haproxy
[root@openstack-haproxy1 glance]# cat /etc/haproxy/haproxy.cfg
listen openstack-nova-8774
  bind 192.168.40.248:8774
  mode tcp
  server 192.168.40.101 192.168.40.101:8774 check inter 3s fall 3 rise 5
[root@openstack-haproxy1 glance]# systemctl restart haproxy
[root@openstack-haproxy1 glance]# netstat -ntlp | grep 8774
tcp        0      0 192.168.40.248:8774     0.0.0.0:*               LISTEN      26260/haproxy

#Install and configure components
#Install the package
yum install -y openstack-nova-api openstack-nova-conductor openstack-nova-novncproxy openstack-nova-scheduler

#Edit the /etc/nova/nova.conf file and complete the following actions
vim /etc/nova/nova.conf
[DEFAULT]
# ...
enabled_apis = osapi_compute,metadata

[api_database]
# ...
connection = mysql+pymysql://nova:nova123@openstack-vip.xks.local/nova_api

[database]
# ...
connection = mysql+pymysql://nova:nova123@openstack-vip.xks.local/nova

[DEFAULT]
# ...
transport_url = rabbit://openstack:openstack123@openstack-vip.xks.local:5672/

[api]
# ...
auth_strategy = keystone

[keystone_authtoken]
# ...
www_authenticate_uri = http://openstack-vip.xks.local:5000/
auth_url = http://openstack-vip.xks.local:5000/
memcached_servers = openstack-vip.xks.local:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = nova
password = nova

[DEFAULT]
# ... #此配置可以不配置 后面变量自己配置本机地址
my_ip = 192.168.40.101

#nova.virt.firewall.NoopFirewallDriver:在/usr/lib/python2.7/site-packages/nova/virt/firewall.py中的模块class NoopFirewallDriver(object):
[DEFAULT]
# ...
use_neutron = true
firewall_driver = nova.virt.firewall.NoopFirewallDriver

[vnc]
enabled = true
# ... #这里$my_ip可以改为 本机地址 192.168.40.101
server_listen = $my_ip
server_proxyclient_address = $my_ip

[glance]
# ...
api_servers = http://openstack-vip.xks.local:9292

[oslo_concurrency]
# ...
lock_path = /var/lib/nova/tmp

[placement]
# ...
region_name = RegionOne
project_domain_name = Default
project_name = service
auth_type = password
user_domain_name = Default
auth_url = http://openstack-vip.xks.local:5000/v3
username = placement
password = placement

#Populate the nova-api database:
su -s /bin/sh -c "nova-manage api_db sync" nova

#Register the cell0 database
su -s /bin/sh -c "nova-manage cell_v2 map_cell0" nova

#Create the cell1 cel
su -s /bin/sh -c "nova-manage cell_v2 create_cell --name=cell1 --verbose" nova

#Populate the nova databas-报错不要紧
[root@openstack-controller1 ~]# 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 deprec                                                 ated 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 rele                                                 ase')
  result = self._query(query)

#Verify nova cell0 and cell1 are registered correctly
[root@openstack-controller1 ~]# su -s /bin/sh -c "nova-manage cell_v2 list_cells" nova
+-------+--------------------------------------+-------------------------------------------------------+--------------------------------------------------------------+----------+
|  Name |                 UUID                 |                     Transport URL                     |                     Database Connection                      | Disabled |
+-------+--------------------------------------+-------------------------------------------------------+--------------------------------------------------------------+----------+
| cell0 | 00000000-0000-0000-0000-000000000000 |                         none:/                        | mysql+pymysql://nova:****@openstack-vip.xks.local/nova_cell0 |  False   |
| cell1 | 5a2d8e44-4b01-4d26-a3d3-f04088ad1688 | rabbit://openstack:****@openstack-vip.xks.local:5672/ |    mysql+pymysql://nova:****@openstack-vip.xks.local/nova    |  False   |
+-------+--------------------------------------+-------------------------------------------------------+--------------------------------------------------------------+----------+

#Finalize installation
systemctl enable \
    openstack-nova-api.service \
    openstack-nova-scheduler.service \
    openstack-nova-conductor.service \
    openstack-nova-novncproxy.service
systemctl start \
    openstack-nova-api.service \
    openstack-nova-scheduler.service \
    openstack-nova-conductor.service \
    openstack-nova-novncproxy.service
    
#查看日志是否有报错
[root@openstack-controller1 ~]# cd /var/log/nova/
#并且会启动一个6080端口
[root@openstack-controller1 nova]# tail -f nova-*.log

==> nova-novncproxy.log <==
2023-07-23 11:11:12.977 12399 INFO nova.console.websocketproxy [-] WebSocket server settings:
2023-07-23 11:11:12.978 12399 INFO nova.console.websocketproxy [-]   - Listen on 0.0.0.0:6080
2023-07-23 11:11:12.978 12399 INFO nova.console.websocketproxy [-]   - Flash security policy server
2023-07-23 11:11:12.978 12399 INFO nova.console.websocketproxy [-]   - Web server (no directory listings). Web root: /usr/share/novnc
2023-07-23 11:11:12.978 12399 INFO nova.console.websocketproxy [-]   - No SSL/TLS support (no cert file)
2023-07-23 11:11:12.978 12399 INFO nova.console.websocketproxy [-]   - proxying from 0.0.0.0:6080 to None:None
[root@openstack-controller1 nova]# netstat -ntlp |grep 6080
tcp        0      0 0.0.0.0:6080            0.0.0.0:*               LISTEN      12399/python2

#添加Haproxy6080
[root@openstack-haproxy1 glance]# vim /etc/haproxy/haproxy.cfg

listen openstack-nova-novncproxy-6080
  bind 192.168.40.248:6080
  mode tcp
  server 192.168.40.101 192.168.40.101:6080 check inter 3s fall 3 rise 5

[root@openstack-haproxy1 glance]# systemctl restart haproxy
[root@openstack-haproxy1 ~]# netstat -nltp | grep 6080
tcp        0      0 192.168.40.248:6080     0.0.0.0:*               LISTEN      26348/haproxy

#添加重启nova脚本
vim nova-restart.sh
#!/bin/bash
systemctl restart openstack-nova-api.service openstack-nova-scheduler.service openstack-nova-conductor.service openstack-nova-novncproxy.service
 
[root@openstack-controller1 ~]# chmod +x nova-restart.sh

#优化Haproxy 超时时间调整长点 日志报错会少
[root@openstack-haproxy1 ~]# vim /etc/haproxy/haproxy.cfg
    timeout client          5m
    timeout server          5m
    timeout http-keep-alive 5m
    timeout check           10s
    maxconn                 30000

[root@openstack-haproxy1 ~]# systemctl restart haproxy

二、配置openstack-node1节点

##配置node
#https://docs.openstack.org/nova/train/install/compute-install-rdo.html

#创建虚拟机-参考  第一个步骤创建服务器
#启用OpenStack库
yum install -y centos-release-openstack-train.noarch
yum install -y https://rdoproject.org/repos/rdo-release.rpm

#Finalize the installation
yum install -y python-openstackclient openstack-selinux

#Install the packages
yum install -y openstack-nova-compute

#/etc/nova/nova.conf
vim /etc/nova/nova.conf
[DEFAULT]
# ...
enabled_apis = osapi_compute,metadata

[DEFAULT]
# ...
transport_url = rabbit://openstack:openstack123@openstack-vip.xks.local

[api]
# ...
auth_strategy = keystone

[keystone_authtoken]
# ...
www_authenticate_uri = http://openstack-vip.xks.local:5000/
auth_url = http://openstack-vip.xks.local:5000/
memcached_servers = openstack-vip.xks.local:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = nova
password = nova

[DEFAULT]
# ...
#这个可以先不配置 直接在下面配置 node节点IP
my_ip = MANAGEMENT_INTERFACE_IP_ADDRESS

[DEFAULT]
# ...
use_neutron = true
firewall_driver = nova.virt.firewall.NoopFirewallDriver

[vnc]
# ...
enabled = true
server_listen = 0.0.0.0
server_proxyclient_address = 192.168.40.107
novncproxy_base_url = http://openstack-vip.xks.local:6080/vnc_auto.html

[glance]
# ...
api_servers = http://openstack-vip.xks.local:9292

[oslo_concurrency]
# ...
lock_path = /var/lib/nova/tmp

[placement]
# ...
region_name = RegionOne
project_domain_name = Default
project_name = service
auth_type = password
user_domain_name = Default
auth_url = http://openstack-vip.xks.local:5000/v3
username = placement
password = placement

#Finalize installation
#如果返回不是0 可以不用配置下面【libvirt】,如果是0需要配置加速硬件虚拟机参数
egrep -c '(vmx|svm)' /proc/cpuinfo
[libvirt]
# ...
virt_type = qemu

systemctl enable libvirtd.service openstack-nova-compute.service
systemctl start libvirtd.service openstack-nova-compute.service

#Add the compute node to the cell database
source  admin-openrc.sh

#Source the admin credentials to enable admin-only CLI commands, then confirm there are compute hosts in the database:
[root@openstack-controller1 ~]# openstack compute service list --service nova-compute
+----+--------------+---------------------------+------+---------+-------+----------------------------+
| ID | Binary       | Host                      | Zone | Status  | State | Updated At                 |
+----+--------------+---------------------------+------+---------+-------+----------------------------+
| 13 | nova-compute | openstack-node1.xks.local | nova | enabled | up    | 2023-07-23T08:15:31.000000 |
+----+--------------+---------------------------+------+---------+-------+----------------------------+

#Discover compute hosts:
[root@openstack-controller1 ~]# 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': 5a2d8e44-4b01-4d26-a3d3-f04088ad1688
Found 0 unmapped computes in cell: 5a2d8e44-4b01-4d26-a3d3-f04088ad1688
[root@openstack-controller1 ~]#

#When you add new compute nodes, you must run nova-manage cell_v2 discover_hosts on the controller node to register those new compute nodes.
#Alternatively, you can set an appropriate interval in /etc/nova/nova.conf:
[root@openstack-controller1 nova]# vim /etc/nova/nova.conf
[scheduler]
discover_hosts_in_cells_interval = 300

[root@openstack-controller1 nova]# bash /root/nova-restart.sh

#Verify operation
source admin-openrc.sh

[root@openstack-controller1 ~]# openstack compute service list
+----+----------------+---------------------------------+----------+---------+-------+----------------------------+
| ID | Binary         | Host                            | Zone     | Status  | State | Updated At                 |
+----+----------------+---------------------------------+----------+---------+-------+----------------------------+
|  4 | nova-conductor | openstack-controller1.xks.local | internal | enabled | up    | 2023-07-23T08:19:40.000000 |
|  7 | nova-scheduler | openstack-controller1.xks.local | internal | enabled | up    | 2023-07-23T08:19:41.000000 |
| 13 | nova-compute   | openstack-node1.xks.local       | nova     | enabled | up    | 2023-07-23T08:19:41.000000 |
+----+----------------+---------------------------------+----------+---------+-------+----------------------------+


[root@openstack-controller1 ~]# openstack catalog list
+-----------+-----------+------------------------------------------------------+
| Name      | Type      | Endpoints                                            |
+-----------+-----------+------------------------------------------------------+
| nova      | compute   | RegionOne                                            |
|           |           |   public: http://openstack-vip.xks.local:8774/v2.1   |
|           |           | RegionOne                                            |
|           |           |   admin: http://openstack-vip.xks.local:8774/v2.1    |
|           |           | RegionOne                                            |
|           |           |   internal: http://openstack-vip.xks.local:8774/v2.1 |
|           |           |                                                      |
| keystone  | identity  | RegionOne                                            |
|           |           |   internal: http://openstack-vip.xks.local:5000/v3/  |
|           |           | RegionOne                                            |
|           |           |   public: http://openstack-vip.xks.local:5000/v3/    |
|           |           | RegionOne                                            |
|           |           |   admin: http://openstack-vip.xks.local:5000/v3/     |
|           |           |                                                      |
| glance    | image     | RegionOne                                            |
|           |           |   admin: http://openstack-vip.xks.local:9292         |
|           |           | RegionOne                                            |
|           |           |   public: http://openstack-vip.xks.local:9292        |
|           |           | RegionOne                                            |
|           |           |   internal: http://openstack-vip.xks.local:9292      |
|           |           |                                                      |
| placement | placement | RegionOne                                            |
|           |           |   admin: http://openstack-vip.xks.local:8778         |
|           |           | RegionOne                                            |
|           |           |   internal: http://openstack-vip.xks.local:8778      |
|           |           | RegionOne                                            |
|           |           |   public: http://openstack-vip.xks.local:8778        |
|           |           |                                                      |
+-----------+-----------+------------------------------------------------------+

[root@openstack-controller1 ~]# openstack image list

[root@openstack-controller1 ~]# 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                  |
+--------------------------------+

[root@openstack-controller1 ~]# nova service-list
+--------------------------------------+----------------+---------------------------------+----------+---------+-------+----------------------------+-----------------+-------------+
| Id                                   | Binary         | Host                            | Zone     | Status  | State | Updated_at                 | Disabled Reason | Forced down |
+--------------------------------------+----------------+---------------------------------+----------+---------+-------+----------------------------+-----------------+-------------+
| 79cb22e1-a8db-4267-92c6-77351e8d0373 | nova-conductor | openstack-controller1.xks.local | internal | enabled | up    | 2023-07-23T08:21:40.000000 | -               | False       |
| 5d974f43-5081-4340-b954-a5b3ce06740c | nova-scheduler | openstack-controller1.xks.local | internal | enabled | up    | 2023-07-23T08:21:41.000000 | -               | False       |
| 6428a4a4-02ad-4ac0-a0bd-8ad22ce03f08 | nova-compute   | openstack-node1.xks.local       | nova     | enabled | up    | 2023-07-23T08:21:41.000000 | -               | False       |
+--------------------------------------+----------------+---------------------------------+----------+---------+-------+----------------------------+-----------------+-------------+

 

posted @ 2023-07-27 08:54  しみずよしだ  阅读(51)  评论(0)    收藏  举报