mysql galera 集群

MySQL 和 Galera
Rather than starting with a vanilla version of MySQL, and then adding Galera, you will want
to install a version of MySQL patched for wsrep (Write Set REPlication) from
https://
launchpad.net/codership-mysql/0.7
. The wsrep API is suitable for configuring MySQL High
Availability in OpenStack because it supports synchronous replication.
Note that the installation requirements call for careful attention. Read the guide
https://launchpadlibrarian.net/66669857/README-wsrep to ensure you follow all the
required steps.
为已经加上 wresp 补丁的 MySQL 数据库安装 Galera :
1. Download Galera from https://launchpad.net/galera/+download, and install the *.rpms
or *.debs, which takes care of any dependencies that your system doesn't already have
installed.
2. 调整配置文件:
在 MySQL 数据库的全局配置文件 my.conf 中,修改 mysqld 服务的监听地址( mysqld 不应
只监听 127.0.0.1 ),另外确保 mysqld 启动也会读取 /etc/mysql/conf.d/ 目录下的配置文
件。通常,MySQL 数据库的全局配置文件的系统路径是 /etc/my.cnf :
[mysqld]
...
!includedir /etc/mysql/conf.d/
...
#bind-address = 127.0.0.1

OpenStack高可用指南 January 24, 2015 current
31
增加节点服务器时,需要配置一个 MySQL 帐户,使用该帐户可以访问各节点的数据库实
例。新增节点必须具备从已有节点服务器获取一份状态快照的权限:
3. 在 /etc/mysql/conf.d/wsrep.cnf 配置用于同步的 MySQL 帐户信息:
wsrep_sst_auth=wsrep_sst:wspass
4. 使用 root 帐户登陆数据库,为该帐户分配权限:
$ mysql -e "SET wsrep_on=OFF; GRANT ALL ON *.* TO wsrep_sst@'%' IDENTIFIED BY 'wspass'";
5. 删除所有用户名为空的 MySQL 帐户(这些帐户会产生安全隐患):
$ mysql -e "SET wsrep_on=OFF; DELETE FROM mysql.user WHERE user='';"
6. 另外下列关于 MySQL 自身的配置是 Galera 的强制要求:
query_cache_size=0
binlog_format=ROW
default_storage_engine=innodb
innodb_autoinc_lock_mode=2
innodb_doublewrite=1
7. 检查各节点之间的网络通信有没有被防火墙拦截。根据布署环境的不同,检查方法也各
不相同。如,某些环境中,这一步只需要对 iptables 进行配置:
# iptables --insert RH-Firewall-1-INPUT 1 --proto tcp \
--source <my IP>/24 --destination <my IP>/32 --dport 3306 \
-j ACCEPT
# iptables --insert RH-Firewall-1-INPUT 1 --proto tcp \
--source <my IP>/24 --destination <my IP>/32 --dport 4567 \
-j ACCEPT
在某些环境中,可能还需要对 NAT 防火墙进行配置,以保证节点服务器之间可以直接通
信。另外,可能需要禁用 SELinux,或者允许 mysqld 监听非特权端口。
现在可以开始创建数据库集群。
创建数据库集群
创建数据库集群时,首先启动一个数据库实例,它会建立这个集群,其它的实例启动后连接
到该集群:
创建数据库集群示例:
1. 在 IP 地址为 10.0.0.10 的节点服务器上启动第一个数据库实例:
# service mysql start wsrep_cluster_address=gcomm://
1. 在其它节点服务器上启动数据库实例,通对指定第一台节点服务器的 IP 地址,连接到已
经创建的集群:
# service mysql start wsrep_cluster_address=gcomm://10.0.0.10
在各节点的配置文件 /etc/mysql/conf.d/wsrep.cnf 中配置 wsrep_cluster_address 参数,
或者在命令行客户端工具中进行配置(对于使用 MariaDB 或者 Percona 数据库的系统来说,
后一种方法可能是唯一的选择)。

OpenStack高可用指南 January 24, 2015 current
32
检查数据库集群状态的示例:
1. 运行 MySQL 客户端工具,检查各项参数:
mysql> SET GLOBAL wsrep_cluster_address='<cluster address string>';
mysql> SHOW STATUS LIKE 'wsrep%';
可以获取类似下面输出结果的集群状态:
mysql> show status like 'wsrep%';
+----------------------------+--------------------------------------+
| Variable_name | Value |
+----------------------------+--------------------------------------+
| wsrep_local_state_uuid | 111fc28b-1b05-11e1-0800-e00ec5a7c930 |
| wsrep_protocol_version | 1 |
| wsrep_last_committed | 0 |
| wsrep_replicated | 0 |
| wsrep_replicated_bytes | 0 |
| wsrep_received | 2 |
| wsrep_received_bytes | 134 |
| 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 | 0.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 (6) |
| wsrep_cert_index_size | 0 |
| wsrep_cluster_conf_id | 1 |
| wsrep_cluster_size | 1 |
| wsrep_cluster_state_uuid | 111fc28b-1b05-11e1-0800-e00ec5a7c930 |
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
| wsrep_local_index | 0 |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy |
| wsrep_provider_version | 21.1.0(r86) |
| wsrep_ready | ON |
+----------------------------+--------------------------------------+
38 rows in set (0.01 sec)



参考:

1 mysql wsrep options:http://galeracluster.com/documentation-webpages/mysqlwsrepoptions.html

2 https://www.dwhd.org/20151120_011132.html

3 http://blog.csdn.net/u011816753/article/details/52573733

4 http://www.360doc.com/content/14/0316/13/9430500_361014395.shtml

猜你喜欢

转载自blog.csdn.net/u011956172/article/details/79228708