Openstack的HA解決方案【mysql叢集配置】

CL.TANG發表於2016-10-18

使用mysql的galera做多主叢集配置,galera的叢集優勢網路上面有對比,這裡不在敘述。

1. 新建3臺虛擬機器(centos6.5)

  node1:172.17.44.163
  node2:172.17.44.164
  node3:172.17.44.165
  他們沒有主從關係,所有配置都應該一樣。

2. 建立軟體源

  我們有一個內部的軟體yum 源,至於怎麼建立源伺服器,可參考網路上的介紹,我們的原始檔的nailgun.repo
[nailgun]
name=Nailgun
baseurl=http://172.17.44.2:8080/centos/fuelweb/x86_64/
gpgcheck=0
 將這個檔案放在/etc/yum.repo.d/目錄下

3. 搜尋和mysql galera有關的軟體安裝包 執行結果:

[root@ha1 yum.repos.d]# yum search wsrep
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * epel: mirrors.ustc.edu.cn
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
===================================================================================== N/S Matched: wsrep ======================================================================================
MySQL-client-wsrep.x86_64 : MySQL - Client
MySQL-server-wsrep.x86_64 : MySQL: a very fast and reliable SQL database server
MySQL-shared-wsrep.x86_64 : MySQL - Shared libraries
galera.x86_64 : Galera: a synchronous multi-master wsrep provider (replication engine)

  Name and summary matches only, use "search all" for everything.
[root@ha1 yum.repos.d]# 

主要就是安裝這4個包。

4.安裝後基本配置: 安裝後正常應該會有/etc/my.cnf檔案。但是不夠,因為my.cnf檔案是普通版本的mysql配置,而galera的mysql需要更多配置。

a.增加目錄
  <pre>
    mkdir -p /etc/mysql/conf.d
  </pre>
b.在/etc/mysql/conf.d/新增檔案wsrep.cnf
  內容是:
     
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
bind-address=172.17.44.163
port=3307
max_connections=2048
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_provider_options="pc.ignore_sb = no;ist.recv_addr=172.17.44.163;gmcast.listen_addr=tcp://172.17.44.163:4567;gcache.size=1G"
wsrep_cluster_name="openstack"
wsrep_cluster_address="gcomm://172.17.44.164:4567,172.17.44.164:4567,172.17.44.165:4567?pc.wait_prim=no"
wsrep_node_address=172.17.44.163
wsrep_slave_threads=4
wsrep_certify_nonPK=1
wsrep_max_ws_rows=131072
wsrep_max_ws_rows=131072
wsrep_max_ws_size=1073741824
wsrep_debug=0
wsrep_convert_LOCK_to_trx=0
wsrep_retry_autocommit=1
wsrep_auto_increment_control=1
wsrep_drupal_282555_workaround=0
wsrep_causal_reads=0
wsrep_notify_cmd=
wsrep_sst_method=mysqldump
wsrep_sst_receive_address=172.17.44.163:3307
wsrep_sst_auth=wsrep_sst:password
skip-name-resolve
innodb_buffer_pool_size=563M
innodb_thread_concurrency=0
innodb_write_io_threads=8
innodb_read_io_threads=8
innodb_io_capacity=500
table_cache=10000
innodb_file_per_table=1
innodb_file_format=Barracuda
   

3臺機器都應該有上面的配置。需要對IP進行部分修改,上面配置的IP是44.163機器的,如果是164,需要將bind-address,wsrep_sst_receive_address做出修改。

c.修改my.cnf檔案
[mysqld_safe]
syslog
!includedir /etc/mysql/conf.d/

其他都註釋.

5.啟動叢集。

第一次啟動是有問題的。因為我們還沒有設定我們的叢集底層使用者,sst_auth,主要在配置檔案wsrep_sst_auth選項。我們需要給每一臺主機都設定上這麼一個使用者才可以。
我們需要先將wsrep_cluster_address="gcomm://172.17.44.164:4567,172.17.44.164:4567,172.17.44.165:4567?pc.wait_prim=no"註釋(所有機器),改為

wsrep_cluster_address="gcomm://",即當前機器是一個單一的mysql galera

然後建立使用者:

grant all on *.* to wsrep_sst@"%" identified by "password";
grant all on *.* to wsrep_sst@"localhost" identified by "password";

建立後測試該使用者是否可用。注意我們的埠使用的是3307.


然後將配置wsrep_cluster_address改到所有使用者,重新啟動mysql galera.然後進入mysql,檢視其狀態:

mysql> show status like "wsrep_%";
+----------------------------+----------------------------------------------------------+
| Variable_name              | Value                                                    |
+----------------------------+----------------------------------------------------------+
| wsrep_local_state_uuid     | f0e10cb3-249a-11e4-0800-2666f281655b                     |
| wsrep_protocol_version     | 4                                                        |
| wsrep_last_committed       | 4                                                        |
| wsrep_replicated           | 0                                                        |
| wsrep_replicated_bytes     | 0                                                        |
| wsrep_received             | 23                                                       |
| wsrep_received_bytes       | 2118                                                     |
| wsrep_local_commits        | 0                                                        |
| wsrep_local_cert_failures  | 0                                                        |
| wsrep_local_bf_aborts      | 0                                                        |
| wsrep_local_replays        | 0                                                        |
| wsrep_local_send_queue     | 0                                                        |
| wsrep_local_send_queue_avg | 0.000000                                                 |
| wsrep_local_recv_queue     | 0                                                        |
| wsrep_local_recv_queue_avg | 0.000000                                                 |
| wsrep_flow_control_paused  | 0.000000                                                 |
| wsrep_flow_control_sent    | 0                                                        |
| wsrep_flow_control_recv    | 0                                                        |
| wsrep_cert_deps_distance   | 1.000000                                                 |
| wsrep_apply_oooe           | 0.000000                                                 |
| wsrep_apply_oool           | 0.000000                                                 |
| wsrep_apply_window         | 0.000000                                                 |
| wsrep_commit_oooe          | 0.000000                                                 |
| wsrep_commit_oool          | 0.000000                                                 |
| wsrep_commit_window        | 0.000000                                                 |
| wsrep_local_state          | 4                                                        |
| wsrep_local_state_comment  | Synced                                                   |
| wsrep_cert_index_size      | 2                                                        |
| wsrep_causal_reads         | 0                                                        |
| wsrep_incoming_addresses   | 172.17.44.163:3307,172.17.44.164:3307,172.17.44.165:3307 |
| wsrep_cluster_conf_id      | 13                                                       |
| wsrep_cluster_size         | 3                                                        |
| wsrep_cluster_state_uuid   | f0e10cb3-249a-11e4-0800-2666f281655b                     |
| wsrep_cluster_status       | Primary                                                  |
| wsrep_connected            | ON                                                       |
| wsrep_local_index          | 0                                                        |
| wsrep_provider_name        | Galera                                                   |
| wsrep_provider_vendor      | Codership Oy <info@codership.com>                        |
| wsrep_provider_version     | 23.2.2(r137)                                             |
| wsrep_ready                | ON                                                       |
+----------------------------+----------------------------------------------------------+
40 rows in set (0.00 sec)

這裡的incoming_addresses地址是3個,wsrep_ready 為ON就表示正常了。

不正常原因。 1. 網路防火牆。 2. 使用者許可權。 3. 其他。

我們來看一下我們的成果。 基本測試就是一臺機器上建立一個資料庫,要再其他機器上也能看到。 163的:

| wsrep_provider_version     | 23.2.2(r137)                                             |
| wsrep_ready                | ON                                                       |
+----------------------------+----------------------------------------------------------+
40 rows in set (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| aa                 |
| mysql              |
| performance_schema |
| tangcl             |
| test               |
+--------------------+
6 rows in set (0.00 sec)

mysql> 

164的:

mysql> show databses;
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 'databses' at line 1
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| aa                 |
| mysql              |
| performance_schema |
| tangcl             |
| test               |
+--------------------+
6 rows in set (0.00 sec)

165的:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| aa                 |
| mysql              |
| performance_schema |
| tangcl             |
| test               |
+--------------------+
6 rows in set (0.00 sec)

相關文章