Openstack的mysql資料多主galera的錯誤

CL.TANG發表於2016-10-18

登入openstack的在dashboard,提示說許可權驗證錯誤,有2種情況: 1. 密碼被人改了。 2. 系統發生了問題。

密碼確認沒人改,所以檢視/var/log/keystone-all.log日誌,發現一堆錯誤:

File "/usr/lib/python2.6/site-packages/keystone/assignment/core.py", line 262, in get_domain
    return self.driver.get_domain(domain_id)
  File "/usr/lib/python2.6/site-packages/keystone/assignment/backends/sql.py", line 526, in get_domain
    return self._get_domain(session, domain_id).to_dict()
  File "/usr/lib/python2.6/site-packages/keystone/assignment/backends/sql.py", line 519, in _get_domain
    ref = session.query(Domain).get(domain_id)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/query.py", line 775, in get
    return self._load_on_ident(key)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/query.py", line 2512, in _load_on_ident
    return q.one()
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/query.py", line 2184, in one
    ret = list(self)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/query.py", line 2227, in __iter__
    return self._execute_and_instances(context)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/query.py", line 2240, in _execute_and_instances
    close_with_result=True)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/query.py", line 2231, in _connection_from_session
    **kw)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/session.py", line 777, in connection
    close_with_result=close_with_result)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/session.py", line 783, in _connection_for_bind
    return engine.contextual_connect(**kwargs)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/engine/base.py", line 2489, in contextual_connect
    self.pool.connect(),
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 236, in connect
    return _ConnectionFairy(self).checkout()
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/pool.py", line 474, in checkout
    self)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/event.py", line 377, in __call__
    fn(*args, **kw)
  File "/usr/lib/python2.6/site-packages/keystone/common/sql/core.py", line 204, in mysql_on_checkout
    dbapi_conn.cursor().execute('select 1')
  File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
OperationalError: (1047, 'Unknown command')

這裡可以看出,是mysqldb引擎連線mysql進行資料操作mysql返回的錯誤,所以,基本判斷是mysql出問題了,登入mysql,查詢admin的密碼,發現連mysql的use命令都無法使用。所以引出了mysql的galera的問題。

mysql的galera是一種多主的mysql的HA方案,由單獨開發一段程式在mysql底層實現資料的複製,而在各個伺服器操作mysql上基本和單機沒有區別。 但是線上上沒有做任何修改,一直執行的過程中,發生了一個錯誤:

[root@node-10 conf.d]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30631
Server version: 5.5.28

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use keystone;
ERROR 1047 (08S01): Unknown command

我們應該知道mysql的use命令肯定是存在的。如果我們真實輸入一個不存在的命令,提示也應該是這樣的:

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> test
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'test' at line 1

這裡先初步解決,讓伺服器執行起來,重啟服務即可

service mysql restart

注意,這裡/etc/init.d/mysql這個檔案是使用了galera的定製化的指令碼,理論上是將叢集中所有的mysql服務重啟,如果失敗,可以手動kill -9即可。

然後再登入openstack的HA環境,就可以成功了。

相關文章