OpenStack学习系列之五:安装部署compute服务

nova这一组件包含了许多的小组件,其中有API Server (nova-api)、Message Queue (rabbit-mq server)、Compute Workers (nova-compute)、Network Controller (nova-network)、Scheduler (nova-scheduler)、Conductor(nova-conductor)。
  • nova-api是一个交互接口,管理者可以通过这个接口来管理内部基础设施,也可以通过这个接口向用户提供服务。当然基于web的管理也是通过这个接口,然后向消息队列发送消息,达到资源调度的功能。
  • Rabbit-mqserver是计算资源中的一个消息队列,为各个组件传达消息实现资源调度。
  • nova-compute是用于处理管理实例生命周期。通过消息队列接收请求,并承担操作工作。
  • nova-network相当于云计算系统内部的一个路由器,他承担了IP地址的划分以及配置VLAN和安全组的划分。
  • nova-scheduler是一个拥有把nova-API调用映射为Open Stack功能的组件,会根据诸如CPU构架、可用域的物理距离、内存、负载等作出调度决定。
  • nova-conductor负责数据库的访问权限控制,避免nova-compute直接访问数据库。
综合对上面组件的介绍,可以看出Nova是一个非常重要的核心组件其功能覆盖了几乎所有的领域比如计算的控制器,用于管理用户的虚拟机实例,根据用户需求来实现对虚拟机的开关机、调配CPU、RAM等操作。
 

1.安装compute服务(控制节点node1部署nova)

---------------------------------------------#初始化数据库,nova连接mysql用户密码nova/nova
mysql -uroot -pmysql << EOF
CREATE DATABASE nova_api;
CREATE DATABASE nova;
CREATE DATABASE nova_cell0;
GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'localhost' \
  IDENTIFIED BY 'nova';
GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'%' \
  IDENTIFIED BY 'nova';
GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' \
  IDENTIFIED BY 'nova';
GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' \
  IDENTIFIED BY 'nova';
GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'localhost' \
  IDENTIFIED BY 'nova';
GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'%' \
  IDENTIFIED BY 'nova';
EOF

---------------------------------------------# 创建用户,node1执行
[root@node1 ~]# openstack user create --domain default --password-prompt nova # 输入nova密码为nova
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 3493b1c44a0b42899a9902ee3786e078 |
| name                | nova                             |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
[root@node1 ~]# openstack role add --project service --user nova admin
[root@node1 ~]# openstack service create --name nova --description "OpenStack Compute" compute
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Compute                |
| enabled     | True                             |
| id          | f3117d70d9824dbfa3c5210d9a704fff |
| name        | nova                             |
| type        | compute                          |
+-------------+----------------------------------+
[root@node1 ~]# openstack endpoint create --region RegionOne compute public http://node1:8774/v2.1
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | e82550944891484a9ee4dc48b573144b |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f3117d70d9824dbfa3c5210d9a704fff |
| service_name | nova                             |
| service_type | compute                          |
| url          | http://node1:8774/v2.1           |
+--------------+----------------------------------+
[root@node1 ~]# openstack endpoint create --region RegionOne compute internal http://node1:8774/v2.1
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 9ad51b3aece844baa4cbb1eb1523df58 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f3117d70d9824dbfa3c5210d9a704fff |
| service_name | nova                             |
| service_type | compute                          |
| url          | http://node1:8774/v2.1           |
+--------------+----------------------------------+
[root@node1 ~]# openstack endpoint create --region RegionOne compute admin http://node1:8774/v2.1
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 06a8806497634f1481cf751477211bba |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f3117d70d9824dbfa3c5210d9a704fff |
| service_name | nova                             |
| service_type | compute                          |
| url          | http://node1:8774/v2.1           |
+--------------+----------------------------------+

---------------------------------------------#安装配置组件
yum -y install openstack-nova-api openstack-nova-conductor \
  openstack-nova-novncproxy openstack-nova-scheduler
crudini --set /etc/nova/nova.conf DEFAULT enabled_apis osapi_compute,metadata
crudini --set /etc/nova/nova.conf DEFAULT transport_url rabbit://openstack:openstack@node1:5672/
crudini --set /etc/nova/nova.conf DEFAULT my_ip  192.168.31.101
crudini --set /etc/nova/nova.conf api_database connection mysql+pymysql://nova:nova@node1/nova_api
crudini --set /etc/nova/nova.conf database connection mysql+pymysql://nova:nova@node1/nova
crudini --set /etc/nova/nova.conf api auth_strategy keystone
crudini --set /etc/nova/nova.conf keystone_authtoken www_authenticate_uri http://node1:5000/
crudini --set /etc/nova/nova.conf keystone_authtoken auth_url http://node1:5000/
crudini --set /etc/nova/nova.conf keystone_authtoken memcached_servers node1:11211
crudini --set /etc/nova/nova.conf keystone_authtoken auth_type password
crudini --set /etc/nova/nova.conf keystone_authtoken project_domain_name Default
crudini --set /etc/nova/nova.conf keystone_authtoken user_domain_name Default
crudini --set /etc/nova/nova.conf keystone_authtoken project_name service
crudini --set /etc/nova/nova.conf keystone_authtoken username nova
crudini --set /etc/nova/nova.conf keystone_authtoken password nova
crudini --set /etc/nova/nova.conf vnc enabled  true
crudini --set /etc/nova/nova.conf vnc server_listen  \$my_ip
crudini --set /etc/nova/nova.conf vnc server_proxyclient_address \$my_ip
crudini --set /etc/nova/nova.conf glance api_servers http://node1:9292
crudini --set /etc/nova/nova.conf oslo_concurrency lock_path /var/lib/nova/tmp
crudini --set /etc/nova/nova.conf placement region_name RegionOne
crudini --set /etc/nova/nova.conf placement project_domain_name Default
crudini --set /etc/nova/nova.conf placement project_name service
crudini --set /etc/nova/nova.conf placement auth_type password
crudini --set /etc/nova/nova.conf placement user_domain_name Default
crudini --set /etc/nova/nova.conf placement auth_url http://node1:5000/v3
crudini --set /etc/nova/nova.conf placement username placement
crudini --set /etc/nova/nova.conf placement password placement

---------------------------------------------#初始化数据
su -s /bin/sh -c "nova-manage api_db sync" nova   # 相关日志在/var/log/nova/nova-manage.log
su -s /bin/sh -c "nova-manage cell_v2 map_cell0" nova
su -s /bin/sh -c "nova-manage cell_v2 create_cell --name=cell1 --verbose" nova
su -s /bin/sh -c "nova-manage db sync" nova
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:****@node1/nova_cell0 |  False   |
| cell1 | 54f65929-1071-443d-abd0-b4b34940b25f | rabbit://openstack:****@node1:5672/ |    mysql+pymysql://nova:****@node1/nova    |  False   |
+-------+--------------------------------------+-------------------------------------+--------------------------------------------+----------+

---------------------------------------------#启动服务
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

2.安装compute服务(计算节点,node2/node3/node4/node5)

---------------------------------------------# 安装配置组件
for i in $(seq 2 5);do ssh node$i "yum --enablerepo powertools -y install openstack-nova-compute" ;done # node1执行安装

# 在计算节点,node2/node3/node4/node5上分别配置,相关ip参数需要修改为对应节点的ip地址
crudini --set /etc/nova/nova.conf DEFAULT block_device_allocate_retries 120    # 默认60,间隔3,这样等待卷创建的时间为180秒,如果卷特别大,可以将时间改长一些
crudini --set /etc/nova/nova.conf DEFAULT enabled_apis osapi_compute,metadata
crudini --set /etc/nova/nova.conf DEFAULT transport_url rabbit://openstack:openstack@node1
crudini --set /etc/nova/nova.conf DEFAULT my_ip 192.168.31.102 # 每个计算节点的管理网络IP地址
crudini --set /etc/nova/nova.conf apiauth_strategy keystone
crudini --set /etc/nova/nova.conf keystone_authtoken www_authenticate_uri http://node1:5000/
crudini --set /etc/nova/nova.conf keystone_authtoken auth_url http://node1:5000/
crudini --set /etc/nova/nova.conf keystone_authtoken memcached_servers node1:11211
crudini --set /etc/nova/nova.conf keystone_authtoken auth_type password
crudini --set /etc/nova/nova.conf keystone_authtoken project_domain_name Default
crudini --set /etc/nova/nova.conf keystone_authtoken user_domain_name Default
crudini --set /etc/nova/nova.conf keystone_authtoken project_name service
crudini --set /etc/nova/nova.conf keystone_authtoken username nova
crudini --set /etc/nova/nova.conf keystone_authtoken password nova
crudini --set /etc/nova/nova.conf vnc enabled true
crudini --set /etc/nova/nova.conf vnc server_listen 0.0.0.0
crudini --set /etc/nova/nova.conf vnc server_proxyclient_address \$my_ip
crudini --set /etc/nova/nova.conf vnc novncproxy_base_url  http://node1:6080/vnc_auto.html      # 可以写IP地址,这样可以直接访问
crudini --set /etc/nova/nova.conf glance api_servers http://node1:9292
crudini --set /etc/nova/nova.conf oslo_concurrency lock_path /var/lib/nova/tmp
crudini --set /etc/nova/nova.conf placement region_name RegionOne
crudini --set /etc/nova/nova.conf placement project_domain_name Default
crudini --set /etc/nova/nova.conf placement project_name service
crudini --set /etc/nova/nova.conf placement auth_type password
crudini --set /etc/nova/nova.conf placement user_domain_name Default
crudini --set /etc/nova/nova.conf placement auth_url http://node1:5000/v3
crudini --set /etc/nova/nova.conf placement username placement
crudini --set /etc/nova/nova.conf placement password placement
crudini --set /etc/nova/nova.conf libvirt virt_type kvm     # 不支持虚拟化时设置为qemu,但是性能极低
crudini --set /etc/nova/nova.conf scheduler discover_hosts_in_cells_interval 300    # 自动发现,每隔5分钟发现一次

---------------------------------------------#启动服务
for i in $(seq 2 5);do ssh node$i 'systemctl enable libvirtd.service openstack-nova-compute.service';done
for i in $(seq 2 5);do ssh node$i 'systemctl start libvirtd.service openstack-nova-compute.service';done

---------------------------------------------#控制节点node1,手动执行发现节点,node1执行
 . admin-openrc
 su -s /bin/sh -c "nova-manage cell_v2 discover_hosts --verbose" nova
 
---------------------------------------------#控制节点验证,node1执行
[root@node1 ~]# . admin-openrc
[root@node1 ~]# openstack compute service list
+----+----------------+-------+----------+---------+-------+----------------------------+
| ID | Binary         | Host  | Zone     | Status  | State | Updated At                 |
+----+----------------+-------+----------+---------+-------+----------------------------+
|  1 | nova-conductor | node1 | internal | enabled | up    | 2022-03-01T07:35:54.000000 |
|  4 | nova-scheduler | node1 | internal | enabled | up    | 2022-03-01T07:35:55.000000 |
|  7 | nova-compute   | node2 | nova     | enabled | up    | 2022-03-01T07:35:52.000000 |
|  8 | nova-compute   | node3 | nova     | enabled | up    | 2022-03-01T07:35:57.000000 |
|  9 | nova-compute   | node4 | nova     | enabled | up    | 2022-03-01T07:35:52.000000 |
| 10 | nova-compute   | node5 | nova     | enabled | up    | 2022-03-01T07:35:56.000000 |
+----+----------------+-------+----------+---------+-------+----------------------------+
[root@node1 ~]# openstack catalog list
+-----------+-----------+------------------------------------+
| Name      | Type      | Endpoints                          |
+-----------+-----------+------------------------------------+
| keystone  | identity  | RegionOne                          |
|           |           |   public: http://node1:5000/v3/    |
|           |           | RegionOne                          |
|           |           |   admin: http://node1:5000/v3/     |
|           |           | RegionOne                          |
|           |           |   internal: http://node1:5000/v3/  |
|           |           |                                    |
| placement | placement | RegionOne                          |
|           |           |   public: http://node1:8778        |
|           |           | RegionOne                          |
|           |           |   internal: http://node1:8778      |
|           |           | RegionOne                          |
|           |           |   admin: http://node1:8778         |
|           |           |                                    |
| glance    | image     | RegionOne                          |
|           |           |   public: http://node1:9292        |
|           |           | RegionOne                          |
|           |           |   internal: http://node1:9292      |
|           |           | RegionOne                          |
|           |           |   admin: http://node1:9292         |
|           |           |                                    |
| nova      | compute   | RegionOne                          |
|           |           |   admin: http://node1:8774/v2.1    |
|           |           | RegionOne                          |
|           |           |   internal: http://node1:8774/v2.1 |
|           |           | RegionOne                          |
|           |           |   public: http://node1:8774/v2.1   |
|           |           |                                    |
+-----------+-----------+------------------------------------+
[root@node1 ~]# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 377a35ff-8674-4154-b7c9-707255c7474c | cirros | active |
+--------------------------------------+--------+--------+
[root@node1 ~]# nova-status upgrade check
......

---------------------------------------------# 实例热迁移需要的配置,在node2上修改然后拷贝到其它主机
vi /etc/sysconfig/libvirtd
LIBVIRTD_ARGS="--listen"
for i in $(seq 2 5); do scp /etc/sysconfig/libvirtd node$i:/etc/sysconfig/libvirtd;done

---
vi /etc/libvirt/libvirtd.conf
listen_tls = 0                                                                                                                                                       
listen_tcp = 1                                                                                                                                                       
unix_sock_group = "root"                                                                                                                                             
unix_sock_rw_perms = "0777"                                                                                                                                          
auth_unix_ro = "none"                                                                                                                                                
auth_unix_rw = "none"                                                                                                                                                
log_filters="2:qemu_monitor_json 2:qemu_driver"                                                                                                                      
log_outputs="2:file:/var/log/libvirt/libvirtd.log"                                                                                                                   
tcp_port = "16509"                                                                                                                                                   
listen_addr = "0.0.0.0"                                                                                                                                              
auth_tcp = "none"
for i in $(seq 2 5); do scp /etc/libvirt/libvirtd.conf node$i:/etc/libvirt/libvirtd.conf;done

---# 重启所有服务
for i in $(seq 2 5); do ssh node$i 'systemctl mask libvirtd.socket libvirtd-ro.socket libvirtd-admin.socket libvirtd-tls.socket libvirtd-tcp.socket';done
for i in $(seq 2 5); do ssh node$i  systemctl restart libvirtd;done

 

posted @ 2022-03-02 15:36  喝杯茶  阅读(637)  评论(0编辑  收藏  举报