1. 程式人生 > 實用技巧 >搭建多OpenStack多節點私有云平臺)(八)(新增一個computer節點)

搭建多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:[email protected]/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/* [email protected]:/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)

image.png

上傳後檢視伺服器上的映象儲存位置:/var/lib/glance/image

2、建立例項:
專案-例項-啟用例項

image.png

qemu-img info .. #檢視映象資訊

啟動例項過程中檢視nova中資訊:從glance上下載映象到伺服器本地,並進行格式轉換。下載後存放的位置:
/var/lib/nova/instance/_base/
以後啟動的例項都是基於base目錄下的檔案做的連結克隆

檢視有沒有安裝到compute2

cd /var/lib/glance/images

檢視有沒有資料