【注:本来所有节点的wsrep_sst_method均配置为xtrabackup-v2,但是添加第二个节点时报错:WSREP_SST: [ERROR] Error while getting data from donor node: exit codes: 137 0,换成了rsync后,就没有问题了,待验证是否是xtrabackup的版本问题,我之前用的是2.4.7】
4、启动节点1【132上执行】:
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3306/my_3306.cnf --wsrep-new-cluster
【注:当node1启动的时候,它会先尝试加入一个已存在的集群,但是现在集群并不存在,pxc必须从0开始,所以node1的启动必须加上命令--wsrep-new-cluster,用于新建一个新的集群。node1正常启动之后,其他的node就可以使用平时的启动方式,它们都会自动连接上primary node】
在error.log里看到
[Note] WSREP: Shifting JOINED -> SYNCED (TO: 7)
[Note] WSREP: Waiting for SST/IST to complete.
[Note] WSREP: New cluster view: global state: f71affa6-2b55-11e7-b8db-6afbe908670d:7, view# 1: Primary, number of nodes: 1, my index: 0, protocol version 3
则启动成功,登录mysql -S /tmp/mysql_3306.sock -p
节点一密码在error.log中:
[root@dpstcmsweb00 ~]# cat /data/mysql/mysql_3306/logs/error.log |grep password
2017-05-09T02:46:25.724852Z 1 [Note] A temporary password is generated for root@localhost: worQi;aYF9eQ
登录进去后修改root密码:mysql>set password=password('mysql');
主节点添加账号:
grant usage on *.* to 'pxc-monitor'@'%' identified by 'pxc-monitor';
grant all privileges on *.* to 'sst'@'%' identified by 'sampson';
5、启动剩下的两个节点【133/134上执行】 :
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3306/my_3306.cnf &
查看对应的error.log,能看到
[Note] WSREP: Shifting JOINER -> JOINED (TO: 7)
[Note] WSREP: Member 1.0 (node3307) synced with group.
[Note] WSREP: Shifting JOINED -> SYNCED (TO: 7)
[Note] WSREP: Synchronized with group, ready for connections
则表示node启动并加入cluster集群成功。
启动成功后,直接使用节点1上的账号密码登录即可,这里是mysql -uroot -pmysql
6、查看节点个数:
"root@localhost:mysql_3306.sock [(none)]>show global status like 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 3 |
+--------------------+-------+
1 row in set (0.00 sec)
7、查看集群状态
"root@localhost:mysql_3306.sock [(none)]>show global status like 'wsrep%';
+------------------------------+----------------------------------------------------------+
| Variable_name | Value |
+------------------------------+----------------------------------------------------------+
| wsrep_local_state_uuid | bed19806-3465-11e7-85af-731d83552ec6 |
| wsrep_protocol_version | 7 |
| wsrep_last_committed | 4 |
| wsrep_replicated | 3 |
| wsrep_replicated_bytes | 732 |
| wsrep_repl_keys | 3 |
| wsrep_repl_keys_bytes | 93 |