搭建多OpenStack多节点私有云平台)(八)(添加一个computer节点)

添加一个computer节点

1、添加一个computer节点

IP地址 主机名 内存 磁盘 用途
ens33: 192.168.25.145 10.0.0.21 compute2 4G 20G 计算节点

克隆一台虚拟机:根据节点不同分别进行修改,我以一台布置好网络和计算服务虚拟机为例子。

1、修改IP地址

[root@compute1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
IPADDR=192.168.25.145
[root@compute1 ~]# systemctl restart network

2、修改主机名,映射主机地址

[root@compute1 ~]# hostnamectl set-hostname compute2
[root@compute1 ~]# vim /etc/hosts
192.168.25.145 compute2

3、查看时间同步

[root@compute2 ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* controller                   10  10   377   762    -49us[  -83us] +/-  247us

4、修改文件 [root@compute2 ~]# vim /etc/nova/nova.conf(修改myid)

[DEFAULT]

my_ip = 192.168.25.145

5、确认数据库里有这计算机(控制节点)

[root@controller ~]# openstack compute service list --service nova-compute
+----+--------------+----------+------+---------+-------+----------------------------+
| ID | Binary       | Host     | Zone | Status  | State | Updated At                 |
+----+--------------+----------+------+---------+-------+----------------------------+
|  7 | nova-compute | compute1 | nova | enabled | up    | 2020-11-29T11:59:52.000000 |
|  8 | nova-compute | compute2 | nova | enabled | up    | 2020-11-29T11:59:50.000000 |
+----+--------------+----------+------+---------+-------+----------------------------+

6、验证安装

[root@controller ~]# openstack compute service list
+----+------------------+------------+----------+---------+-------+----------------------------+
| ID | Binary           | Host       | Zone     | Status  | State | Updated At                 |
+----+------------------+------------+----------+---------+-------+----------------------------+
|  1 | nova-consoleauth | controller | internal | enabled | up    | 2020-11-29T12:01:23.000000 |
|  2 | nova-scheduler   | controller | internal | enabled | up    | 2020-11-29T12:01:23.000000 |
|  3 | nova-conductor   | controller | internal | enabled | up    | 2020-11-29T12:01:20.000000 |
|  7 | nova-compute     | compute1   | nova     | enabled | up    | 2020-11-29T12:01:22.000000 |
|  8 | nova-compute     | compute2   | nova     | enabled | up    | 2020-11-29T12:01:20.000000 |
+----+------------------+------------+----------+---------+-------+----------------------------+

7、查看网络是否需要修改

[root@controller ~]# openstack network agent list
+--------------------------------------+--------------------+------------+-------------------+-------+-------+---------------------------+
| ID                                   | Agent Type         | Host       | Availability Zone | Alive | State | Binary                    |
+--------------------------------------+--------------------+------------+-------------------+-------+-------+---------------------------+
| 2515ae8e-0aa2-461b-a3d1-c4914f8b6b25 | Metadata agent     | controller | None              | :-)   | UP    | neutron-metadata-agent    |
| 47b8b775-31c6-4230-96e6-472527ae6907 | DHCP agent         | controller | nova              | :-)   | UP    | neutron-dhcp-agent        |
| 99386680-0335-4a55-8342-a8f12d1a23a7 | Linux bridge agent | compute1   | None              | :-)   | UP    | neutron-linuxbridge-agent |
| ca18ebd4-05de-4f70-9eb6-221e007e8daf | Linux bridge agent | controller | None              | :-)   | UP    | neutron-linuxbridge-agent |
| de80e993-d287-4cad-a8ed-732e8d661127 | Linux bridge agent | compute2   | None              | :-)   | UP    | neutron-linuxbridge-agent |
+--------------------------------------+--------------------+------------+-------------------+-------+-------+---------------------------+

8、在新节点创建实例,验证计算节点

  • 命令创建

     . admin-openrc 
    

    1、查看有效区域

    [root@controller ~]# openstack availability zone list
    +-----------+-------------+
    | Zone Name | Zone Status |
    +-----------+-------------+
    | internal  | available   |
    | nova      | available   |
    | nova      | available   |
    +-----------+-------------+
    

    2、查看有效主机列表

    [root@controller ~]# openstack host list
    +------------+-------------+----------+
    | Host Name  | Service     | Zone     |
    +------------+-------------+----------+
    | controller | consoleauth | internal |
    | controller | scheduler   | internal |
    | controller | conductor   | internal |
    | compute1   | compute     | nova     |
    | compute2   | compute     | nova     |
    +------------+-------------+----------+
    

    3、查看有效计算节点列表

    [root@controller ~]# openstack hypervisor list
    +----+---------------------+-----------------+----------------+-------+
    | ID | Hypervisor Hostname | Hypervisor Type | Host IP        | State |
    +----+---------------------+-----------------+----------------+-------+
    |  1 | compute1            | QEMU            | 192.168.16.143 | up    |
    |  2 | compute2            | QEMU            | 192.168.16.143 | up    |
    +----+---------------------+-----------------+----------------+-------+
    

    4、查询有网络列表

    [root@controller ~]# openstack network list 
    +--------------------------------------+------------+--------------------------------------+
    | ID                                   | Name       | Subnets                              |
    +--------------------------------------+------------+--------------------------------------+
    | 642e161d-f3f7-4dfa-abfc-d9a162dd9389 | myprovider | 8eeddf57-62ce-4f86-9dc7-1fc3f99069d4 |
    +--------------------------------------+------------+--------------------------------------+
    

    5、查看安全组

    [root@controller ~]# openstack security group list
    +--------------------------------------+---------+------------------------+----------------------------------+
    | ID                                   | Name    | Description            | Project                          |
    +--------------------------------------+---------+------------------------+----------------------------------+
    | d32b4ce4-5b2b-432f-8c1b-2af634676b23 | default | Default security group | 13c57ce9dd154c5fa3d9e3e1c75abc87 |
    +--------------------------------------+---------+------------------------+----------------------------------+
    

    6同步数据库

     su -s /bin/sh -c "nova-manage cell_v2 discover_hosts --verbose" nova
    

    7、创建网络实例

    $ openstack server create --flavor m1.nano --image cirros  --nic net-id=642e161d-f3f7-4dfa-abfc-d9a162dd9389  --security-group default  --availability-zone nova:compute2:compute2 --key-name mykey computer2
    

    界面创建

    1、管理员->计算->主机聚集->创建主机聚集group1,可用域group1->单独选择computer2

    2、创建实例->可用域“group1”

2、glance镜像服务迁移

1、在控制节点停止glance服务

[root@controller ~]# systemctl stop openstack-glance-api.service openstack-glance-registry.service
[root@controller ~]# systemctl disable openstack-glance-api.service openstack-glance-registry.service

2、glance数据迁移

  • 在computer2上安装数据库mariadb,启动服务

    [root@compute2 ~]# yum install mariadb mariadb-server python2-PyMySQL -y
    [root@controller ~]# vi /etc/my.cnf.d/openstack.cnf
    [mysqld]
    bind-address = 192.168.25.145
    default-storage-engine = innodb
    innodb_file_per_table
    max_connections = 4096
    collation-server = utf8_general_ci
    character-set-server = utf8
    [root@compute2 ~]# systemctl enable mariadb.service
    [root@compute2 ~]# systemctl start mariadb.service
    
  • 安全初始化 mysql_secure_installation (回车,n,y,y,y,y)

3、恢复glance数据库的数据

  • 到控制节点备份数据库的数据 mysqldump -B glance >glance.sql

  • 将备份文件推送到computer2 scp glance.sql 192.168.25.145:/root

  • 在computer2导入数据库库文件 mysql < glance.sql

  • 确认导入文件 mysql glance -e 'show tables;'

  • 登录数据库创建授权命令

    mysql -u root -p
    GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
      IDENTIFIED BY 'GLANCE_DBPASS';
    GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
      IDENTIFIED BY 'GLANCE_DBPASS';
        退出数据库
    

4、在compute2上安装配置glance服务

  • 安装glance服务 yum install openstack-glance -y

  • 获取配置文件(在控制节点上将配置文件发送至compute2上:)

    [root@controller ~]# scp -rp /etc/glance/glance-api.conf 192.168.25.145:/etc/glance/glance-api.conf
    [root@controller ~]# scp -rp /etc/glance/glance-registry.conf 192.168.25.145:/etc/glance/glance-registry.conf
    
  • 修改配置文件 vim /etc/glance/glance-api.confvim /etc/glance/glance-registry.conf的一下配置

    [database]
    ...
    connection = mysql+pymysql://glance:GLANCE_DBPASS@192.168.25.145/glance
    
  • 启动服务

    # systemctl start openstack-glance-api.service openstack-glance-registry.service
    # systemctl enable openstack-glance-api.service openstack-glance-registry.service
    
  • 验证端口 netstat -lntup的9191和9292端口

5、镜像文件迁移(将控制节点上的镜像文件迁移到新的节点)

# scp -rp /var/lib/glance/images/* root@192.168.25.145:/var/lib/glance/images/

修改权限

chown glance:glance /var/lib/glance/images/*

6、修改keystone里的glance的服务命令(这一步的操作都在控制节点控制节点)

# openstack endpoint list|grep image(先查看,发现地址还是以前的,于是输入下面的代码修改地址)
[root@controller ~]# openstack endpoint list|grep image
| 7c16509eac794239945b9168a7321ad9 | RegionOne | glance       | image        | True    | public    | http://controller:9292      |
| d33ab9c8dec8441fb0b28c4eedcf331b | RegionOne | glance       | image        | True    | internal  | http://controller:9292      |
| facb6ee1c4544facafd52c2c995e1ae0 | RegionOne | glance       | image        | True    | admin     | http://controller:9292      |
-- 备份endpoint表(控制节点)
# mysqldump keystone endpoint >endpoint.sql
修改数据库配置文件:
sed -i 's#http://controller:9292#http://192.168.25.145:9292#g' endpoint.sql
# mysql keystone < endpoint.sql
# openstack endpoint list|grep image
| 7c16509eac794239945b9168a7321ad9 | RegionOne | glance       | image        | True    | public    | http://192.168.25.145:9292  |
| d33ab9c8dec8441fb0b28c4eedcf331b | RegionOne | glance       | image        | True    | internal  | http://192.168.25.145:9292  |
| facb6ee1c4544facafd52c2c995e1ae0 | RegionOne | glance       | image        | True    | admin     | http://192.168.25.145:9292  |
# openstack image list

7、修改所有节点nova配置文件里面的glance地址(每一个机子,包括controller,compute1,compute2)

# sed -i 's#http://controller:9292#http://192.168.25.145:9292#g' /etc/nova/nova.conf
# grep '9292'  /etc/nova/nova.conf;

8、重启服务

控制节点:

systemctl restart openstack-nova-api.service

计算节点(2台计算节点都要)

systemctl restart openstack-nova-compute.service 

9、验证:上传镜像,然后基于镜像创建实例
1、上传镜像:
项目-镜像-创建镜像(centos-cloud)

img

image.png

上传后查看服务器上的镜像存储位置:/var/lib/glance/image

2、创建实例:
项目-实例-启用实例

img

image.png

qemu-img info .. #查看镜像信息

启动实例过程中查看nova中信息:从glance上下载镜像到服务器本地,并进行格式转换。下载后存放的位置:
/var/lib/nova/instance/_base/
以后启动的实例都是基于base目录下的文件做的链接克隆

查看有没有安装到compute2

cd /var/lib/glance/images

查看有没有数据

posted @ 2021-01-07 20:30  龙吟九枭  阅读(468)  评论(0)    收藏  举报