您的位置:首页 > 数据库 > MySQL

Percona galera cluster配置(mysql集群cluster同步)

2016-12-08 21:09 417 查看
1.准备

node #1
hostname: percona1
IP: 192.168.0.18

node #2
hostname: percona2
IP: 192.168.0.19

Firewall has been disabled for convenience
Selinux is disabled
需要关闭firewalld和selinux
2.安装percona 5.6

yum -y install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
yum -y install Percona-XtraDB-Cluster-56 Percona-XtraDB-Cluster-client-56


3.配置第一台mysql node /etc/my.cnf

[mysqld]
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci

log_bin

binlog_format                  = ROW
innodb_buffer_pool_size        = 100M
innodb_flush_log_at_trx_commit = 0
innodb_flush_method            = O_DIRECT
innodb_log_files_in_group      = 2
innodb_log_file_size           = 20M
innodb_file_per_table          = 1
datadir                        = /var/lib/mysql

wsrep_cluster_address          = gcomm://192.168.0.18,192.168.0.19
wsrep_provider                 = /usr/lib64/galera3/libgalera_smm.so

wsrep_slave_threads            = 8
wsrep_cluster_name             = Cluster
wsrep_node_name                = mysql02
wsrep_node_address             = 192.168.0.18

wsrep_sst_method               = xtrabackup-v2
wsrep_sst_auth                 = sst:PASSWORD

innodb_locks_unsafe_for_binlog = 1
innodb_autoinc_lock_mode       = 2

[mysqld_safe]
pid-file = /run/mysqld/mysql.pid
syslog


systemctl start mysql@bootstrap.service


验证配置成功:
mysql> show status like 'wsrep%';
+------------------------------+------------------------------------------------+
| Variable_name                | Value                                          |
+------------------------------+------------------------------------------------+
| wsrep_local_state_uuid       | 76a53f80-1d8a-11e6-9bc3-2a7a67e390ad           |
...
| wsrep_local_state            | 4                                              |
| wsrep_local_state_comment    | Synced                                         |
...
| wsrep_cluster_size           | 1                                              |
| wsrep_cluster_state_uuid     | 76a53f80-1d8a-11e6-9bc3-2a7a67e390ad           |
| wsrep_cluster_status         | Primary                                        |
| wsrep_connected              | ON                                             |
...
| wsrep_ready                  | ON                                             |
+------------------------------+------------------------------------------------+


配置root用户以及cluster用户(需与配置文件对应)

mysql -uroot <<EOF
DELETE FROM mysql.user WHERE user='';
GRANT ALL privileges ON *.* TO 'root'@'%' IDENTIFIED BY 'PASS_CLUSTER';
GRANT ALL privileges ON *.* TO 'root'@'localhost' IDENTIFIED BY 'PASS_CLUSTER';
FLUSH PRIVILEGES;



4.配置第二台Mysql node /etc/my.cnf

[mysqld]
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci

log_bin

binlog_format                  = ROW
innodb_buffer_pool_size        = 100M
innodb_flush_log_at_trx_commit = 0
innodb_flush_method            = O_DIRECT
innodb_log_files_in_group      = 2
innodb_log_file_size           = 20M
innodb_file_per_table          = 1
datadir                        = /var/lib/mysql

wsrep_cluster_address          = gcomm://192.168.0.18,192.168.0.19
wsrep_provider                 = /usr/lib64/galera3/libgalera_smm.so

wsrep_slave_threads            = 8
wsrep_cluster_
4000
name             = Cluster
wsrep_node_name                = mysql02
wsrep_node_address             = 192.168.0.19

wsrep_sst_method               = xtrabackup-v2
wsrep_sst_auth                 = sst:PASSWORD

innodb_locks_unsafe_for_binlog = 1
innodb_autoinc_lock_mode       = 2

[mysqld_safe]
pid-file = /run/mysqld/mysql.pid
syslog

EOF

mysql -uroot -pPASS_CLUSTER <<EOF
CREATE USER 'sst'@'localhost' IDENTIFIED BY 'PASSWORD';
CREATE USER 'sst'@'%' IDENTIFIED BY 'PASSWORD;
GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'sst'@'localhost';
FLUSH PRIVILEGES;
EOF


systemctl start mysql.service


mysql> show status like 'wsrep%';
+------------------------------+---------------------------------------------------+
| Variable_name                | Value                                             |
+------------------------------+---------------------------------------------------+
| wsrep_local_state_uuid       | 76a53f80-1d8a-11e6-9bc3-2a7a67e390ad              |
...
| wsrep_local_state            | 4                                                 |
| wsrep_local_state_comment    | Synced                                            |
...
| wsrep_cluster_size           | 2                                                 |
| wsrep_cluster_state_uuid     | 76a53f80-1d8a-11e6-9bc3-2a7a67e390ad              |
| wsrep_cluster_status         | Primary                                           |
| wsrep_connected              | ON                                                |
...
| wsrep_ready                  | ON                                                |
+------------------------------+---------------------------------------------------+


5.测试是否配置成功

mysql -uroot -pPASS_CLUSTER <<EOF
CREATE DATABASE PASS_CLUSTER;
EOF

mysql>show  databases;





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  percona mysql galera cluster