Mysql

MySQL ERROR 1045 Access denied for ’nova’@‘controller’

  • October 10, 2021

描述

我使用OpenStack 安裝指南安裝了 Openstack Wallaby ,所有命令和配置都在我的Github上。這個 LAB 在 VirtualBox 上執行,我在 ESXi 上有另一個具有相同配置和 Openstack 版本的 LAB,沒有任何問題。

此時一個控制器帶有兩個計算節點。

在下一節中,改進正確配置的數據庫權限

數據庫已正確創建:

user@controller001:~$ sudo mysql
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| glance             |
| information_schema |
| keystone           |
| mysql              |
| nova               |
| nova_api           |
| nova_cell0         |
| performance_schema |
| placement          |
+--------------------+

授予這些數據庫的所有權限:

MariaDB [(none)]> SHOW GRANTS FOR nova;
+-----------------------------------------------------------------------------------------------------+
| Grants for nova@%                                                                                   |
+-----------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `nova`@`%` IDENTIFIED BY PASSWORD '*3A4A03AC22526F6B591010973A741D59A71D728E' |
| GRANT ALL PRIVILEGES ON `nova`.* TO `nova`@`%`                                                      |
| GRANT ALL PRIVILEGES ON `nova_cell0`.* TO `nova`@`%`                                                |
| GRANT ALL PRIVILEGES ON `nova_api`.* TO `nova`@`%`                                                  |
+-----------------------------------------------------------------------------------------------------+

可以從計算節點遠端訪問數據庫:

user@compute001:~$ mysql -unova -popenstack -h controller001

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| nova               |
| nova_api           |
| nova_cell0         |
+--------------------+

重啟nova服務後的mysql日誌:

user@controller001:~$ sudo systemctl restart nova-*

user@controller001:~$ sudo tail -f /var/log/mysql/error.log
2021-10-02 12:52:12 112 [Warning] Aborted connection 112 to db: 'nova' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:12 118 [Warning] Aborted connection 118 to db: 'nova_api' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:12 116 [Warning] Aborted connection 116 to db: 'nova' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:12 119 [Warning] Aborted connection 119 to db: 'nova_api' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:12 115 [Warning] Aborted connection 115 to db: 'nova' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:12 113 [Warning] Aborted connection 113 to db: 'nova' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:12 114 [Warning] Aborted connection 114 to db: 'nova' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:12 117 [Warning] Aborted connection 117 to db: 'nova' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:12 109 [Warning] Aborted connection 109 to db: 'nova' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:12 110 [Warning] Aborted connection 110 to db: 'nova' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:12 111 [Warning] Aborted connection 111 to db: 'nova' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:12 108 [Warning] Aborted connection 108 to db: 'nova_cell0' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:12 103 [Warning] Aborted connection 103 to db: 'nova_api' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:12 102 [Warning] Aborted connection 102 to db: 'nova_api' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:12 105 [Warning] Aborted connection 105 to db: 'nova_cell0' user: 'nova' host: 'controller001' (Got an error reading communication packets)
2021-10-02 12:52:16 141 [Warning] Access denied for user 'nova'@'controller001' (using password: YES)
2021-10-02 12:52:16 142 [Warning] Access denied for user 'nova'@'controller001' (using password: YES)
2021-10-02 12:52:17 147 [Warning] Access denied for user 'nova'@'controller001' (using password: YES)

讀取通信數據包時出錯

以下是解決此錯誤的一些建議:

SET GLOBAL max_allowed_packet = 1024 * 1024 * 256; 
set @@global.max_connections = 400;
SET GLOBAL interactive_timeout=6000;
SET GLOBAL innodb_buffer_pool_size = 1024 * 1024 * 2;

任何嘗試發現新主機都會導致以下錯誤:

user@controller001:~$ sudo su -s /bin/sh -c "nova-manage cell_v2 discover_hosts --verbose" nova
....
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1045, "Access denied for user 'nova'@'controller001' (using password: YES)")
(Background on this error at: http://sqlalche.me/e/13/e3q8)

而且,但我不確定這是否是一個錯誤

user@controller001:~$ os hypervisor list
Unexpected API Error. Please report this at http://bugs.launchpad.net/nova/ and attach the Nova API log if possible.
<class 'sqlalchemy.exc.OperationalError'> (HTTP 500) (Request-ID: req-d6edcfa3-ccf2-4eb8-80f8-041cb55e772d)

名稱配置:

user@controller001:~$ . admin-openrc 
user@controller001:~$ os endpoint list
+----------------------------------+-----------+--------------+--------------+---------+-----------+--------------------------------+
| ID                               | Region    | Service Name | Service Type | Enabled | Interface | URL                            |
+----------------------------------+-----------+--------------+--------------+---------+-----------+--------------------------------+
| 1e2f0fc829f84a53a337bbb70e7679af | RegionOne | nova         | compute      | True    | internal  | http://controller001:8774/v2.1 |
| 38e967a4c87f4464ba6ac965c889f6a4 | RegionOne | placement    | placement    | True    | admin     | http://controller001:8778      |
| 398d51ab439f4afc8fb7c71adc1bf3a9 | RegionOne | keystone     | identity     | True    | internal  | http://controller001:5000/v3/  |
| 4aaf9ac0ccec41978e541a0de0e55ed4 | RegionOne | nova         | compute      | True    | public    | http://controller001:8774/v2.1 |
| 52ba2047ed864b9aa6ad352ba2fe59dc | RegionOne | nova         | compute      | True    | admin     | http://controller001:8774/v2.1 |
| 659ed7ae84074b30a6a4941648b994c3 | RegionOne | placement    | placement    | True    | internal  | http://controller001:8778      |
| 9cd126c1f07e4b13946edcdc80f9f215 | RegionOne | placement    | placement    | True    | public    | http://controller001:8778      |
| aec5b18b834b4a9cad8a4efb83b1b1d7 | RegionOne | glance       | image        | True    | internal  | http://controller001:9292      |
| b1a13f51438c40b8b74ec25b89efebab | RegionOne | glance       | image        | True    | public    | http://controller001:9292      |
| c35c703090f3478aa7d960293fde1bf0 | RegionOne | keystone     | identity     | True    | admin     | http://controller001:5000/v3/  |
| ca231e48c3ad406c8ec757c765b651a6 | RegionOne | glance       | image        | True    | admin     | http://controller001:9292      |
| ff927678f6634475bd80bdba7effc3fc | RegionOne | keystone     | identity     | True    | public    | http://controller001:5000/v3/  |
+----------------------------------+-----------+--------------+--------------+---------+-----------+--------------------------------+
user@controller001:~$ sudo 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:****@controller001/nova_cell0 |  False   |
| cell1 | e62ffdc8-5f28-43ef-9bcb-404812faaeae | rabbit://openstack:****@controller001:5672/ |    mysql+pymysql://nova:****@controller001/nova    |  False   |
+-------+--------------------------------------+---------------------------------------------+----------------------------------------------------+----------+
user@controller001:~$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 controller001

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

172.16.50.41    controller001
172.16.50.42    compute011

這與 MariaDB 權限或數據庫 URL 無關。

使用此錯誤描述解決了問題,還有另一個對我不起作用的解決方案。創建與nova 安裝 guied完全相同的單元格對我有用,將transport-urldatabase-connection添加到nova-mange命令是我的錯,儘管它過去對我有用。

“如果你不指定 –database_connection 那麼 nova-manage 將使用

$$ database $$/connection 配置文件中的值,並將數據庫名稱修改為具有 _cell0 後綴。” 和:

“如果您的數據庫位於不同的主機上,那麼您應該指定 –database_connection 或確保正在使用的 nova.conf 具有

$$ database $$/connection 值指向與 cell0 數據庫相同的使用者/密碼/主機。如果 cell0 映射創建不正確,可以使用 nova-manage cell_v2 delete_cell 命令將其刪除,然後使用正確的數據庫連接值再次執行 map_cell0。” 所以我認為可能發生的情況是,當您執行 map_cell0 時,它使用錯誤的數據庫連接 URL 創建了 nova_api.cell_mappings 記錄,因為現在依賴 cell_mappings 表記錄連接到 cell0 數據庫的 db sync 失敗了,因為它正在尋找 nova_api_cell0 但你有 nova_cell0。

如果您在執行 map_cell0 時未指定 –database-connection,則這是創建預設 cell0 連接 URL 的確切程式碼:

因此,我認為您可能只想(1)刪除 cell0 映射(2)再次執行 map_cell0 並確保它使用正確的數據庫連接 URL 創建一個 cell0 條目,然後(3)再次執行 nova-manage db sync。

sudo su -s /bin/sh -c "nova-manage cell_v2 map_cell0" nova
sudo su -s /bin/sh -c "nova-manage cell_v2 create_cell --name=cell1 --transport-url rabbit://openstack:****@controller001:5672/ --database_connection mysql+pymysql://nova:****@controller001/nova  --verbose" nova 


user@controller001:~$ sudo 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:****@controller001/nova_cell0 |  False   |
| cell1 | 553970ef-335a-4cf1-90fb-8268c49d5fad | rabbit://openstack:****@controller001:5672/ |    mysql+pymysql://nova:****@controller001/nova    |  False   |
+-------+--------------------------------------+-------------------------------------------+--------------------------------------------------+----------+

user@controller001:~$ sudo su -s /bin/sh -c "nova-manage cell_v2 delete_cell --cell_uuid  00000000-0000-0000-0000-000000000000" nova
user@controller001:~$ sudo su -s /bin/sh -c "nova-manage cell_v2 delete_cell --cell_uuid  553970ef-335a-4cf1-90fb-8268c49d5fad" nova



user@controller001:~$ sudo su -s /bin/sh -c "nova-manage api_db sync" nova
user@controller001:~$ sudo su -s /bin/sh -c "nova-manage cell_v2 map_cell0" nova
user@controller001:~$ sudo  su -s /bin/sh -c "nova-manage cell_v2 create_cell --name=cell1 --verbose" nova
--transport-url not provided in the command line, using the value [DEFAULT]/transport_url from the configuration file
--database_connection not provided in the command line, using the value [database]/connection from the configuration file
d448f914-53fa-410c-8f89-407e33c96c3f
user@controller001:~$ sudo su -s /bin/sh -c "nova-manage db sync" nova
user@controller001:~$ sudo 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:****@controller001/nova_cell0 |  False   |
| cell1 | d448f914-53fa-410c-8f89-407e33c96c3f | rabbit://openstack:****@controller001:5672/ |    mysql+pymysql://nova:****@controller001/nova    |  False   |
+-------+--------------------------------------+-------------------------------------------+--------------------------------------------------+----------+

user@controller001:~$ openstack compute service list --service nova-compute
+----+--------------+-----------+------+---------+-------+----------------------------+
| ID | Binary       | Host      | Zone | Status  | State | Updated At                 |
+----+--------------+-----------+------+---------+-------+----------------------------+
|  5 | nova-compute | compute21 | nova | enabled | up    | 2021-10-09T13:59:32.000000 |
+----+--------------+-----------+------+---------+-------+----------------------------+

引用自:https://serverfault.com/questions/1079096