PXC 5.6安装搭建和高可用测试

一.基本信息
集群名:pxczxw
节点一:10.16.24.107
节点二:10.16.24.108
节点三:10.16.24.109


二.软件下载
Percona‐Xtradb‐Cluster 5.6 版本下载
wget
http://www.percona.com/downloads/Percona-XtraDB-Cluster-56/Percona-XtraD-Cluster-5.6.21-25.8/binary/tarball/Percona-XtraDB-Cluster-5.6.21-rel70.1-25.8.938.Linux.x86_64.tar.gz

三.基本包安装和配置
yum install openssl openssl-devel
yum install -y perl-DBD-MySQL.x86_64 perl-IO-Socket-SSL.noarch socat.x86_64 nc
yum install -y http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
yum install -y http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/libev-4.15-1.el6.rf.x86_64.rpm
yum install -y https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.3/binary/redhat/6/x86_64/percona-xtrabackup-24-2.4.3-1.el6.x86_64.rpm
mkdir -p /opt/mysql
cd /data/software
tar -zxvf Percona-XtraDB-Cluster-5.6.21-rel70.1-25.8.938.Linux.x86_64.tar.gz -C /opt/mysql

cd /usr/local
ln -s /opt/mysql/Percona-XtraDB-Cluster-5.6.21-rel70.1-25.8.938.Linux.x86_64 mysql

建立目录如下:
mkdir -p /data/mysql/mysql_3306/{data,logs,tmp}

关闭防火墙和selinux:
/etc/selinux/config中:SELINUX=disabled,并重启OS
service iptables stop ,并chkconfig iptables off

从其它主机将已准备好的my.cnf文件copy到/etc/下,并修改3376为3306:
sed -i 's/3376/3306/g' my.cnf
sed -i 's/mysql3306/mysql_3306/g' my.cnf

并将my.cnf文件scp到另两台主机:
scp /etc/my.cnf 10.16.24.108:/etc/
scp /etc/my.cnf 10.16.24.109:/etc/

并调整my.cnf的参数:
10.16.24.108:
server-id       =1083306
10.16.24.109:
server-id       =1093306

创建mysql的用户及组
groupadd mysql
useradd -g mysql -s /bin/bash -d /usr/local/mysql mysql


创建启动文件:
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

chown -R mysql:mysql /data/mysql/mysql_3306

ln -sf /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.6

ln -sf /usr/lib64/libcrypto.so.10 /usr/lib64/libcrypto.so.6

vi /etc/profile
export PATH=/usr/local/mysql/bin:$PATH

source /etc/profile

四.pxc配置和启动
在/etc/my.cnf文件中[mysqld]增加如下:
#percona xtradb cluster
10.16.24.107:
default_storage_engine=InnoDB
innodb_locks_unsafe_for_binlog=1
innodb_autoinc_lock_mode=2
wsrep_provider_options="gcache.size=1999M"
wsrep_cluster_name='pcx_zengxw'
wsrep_cluster_address="gcomm://10.16.24.107,10.16.24.108,10.16.24.109"
wsrep_node_address="10.16.24.107"
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so
#wsrep_sst_method=rsync
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth=sst:zengxw1

10.16.24.108:
default_storage_engine=InnoDB
innodb_locks_unsafe_for_binlog=1
innodb_autoinc_lock_mode=2
wsrep_provider_options="gcache.size=1999M"
wsrep_cluster_name='pcx_zengxw'
wsrep_cluster_address="gcomm://10.16.24.107,10.16.24.108,10.16.24.109"
wsrep_node_address="10.16.24.108"
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so
#wsrep_sst_method=rsync
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth=sst:zengxw1

10.16.24.109:
default_storage_engine=InnoDB
innodb_locks_unsafe_for_binlog=1
innodb_autoinc_lock_mode=2
wsrep_provider_options="gcache.size=1999M"
wsrep_cluster_name='pcx_zengxw'
wsrep_cluster_address="gcomm://10.16.24.107,10.16.24.108,10.16.24.109"
wsrep_node_address="10.16.24.109"
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so
#wsrep_sst_method=rsync
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth=sst:zengxw1

 

初始化mysql:
cd /usr/local/mysql
./scripts/mysql_install_db

第一个节点启动(mysql用户):
/etc/init.d/mysql bootstrap-pxc

只需在第一个节点上操作:
delete from mysql.user where user!='root' or host!='localhost';
truncate mysql.db;
drop database test;
grant all privileges on *.* to 'zengxw'@'%' identified by 'zengxw1';
grant all privileges on *.* to 'sst'@'localhost' identified by 'zengxw1';
grant reload,lock tables,replication client on *.* to 'sst'@'localhost' identified by 'zengxw1';
flush privileges;

/usr/local/mysql/bin/mysqladmin -u root password 'safe2016'

其它节点启动(mysql用户):
/etc/init.d/mysql start
Stale sst_in_progress file in datadir
Starting MySQL (Percona XtraDB Cluster)State transfer in progress, setting sleep higher
...[  OK  ]

关闭:
/etc/init.d/mysql stop

五.pxc集群检查

1.通过查看4567 端口确认集群是否启动:
netstat -plantu | grep mysqld

2.检查集群是否正常

 Show global status like "wsrep_local_state";
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| wsrep_local_state | 4     |  ---表示正常监听
+-------------------+-------+
1 row in set (0.00 sec)

 Show global status like "wsrep_local_state_comment";
 +---------------------------+--------+
| Variable_name             | Value  |
+---------------------------+--------+
| wsrep_local_state_comment | Synced |
+---------------------------+--------+
1 row in set (0.00 sec)

Show global status like "wsrep_cluster_status";
+----------------------+---------+
| Variable_name        | Value   |
+----------------------+---------+
| wsrep_cluster_status | Primary |  ---表示主节点能正常写入
+----------------------+---------+
1 row in set (0.00 sec)
 Show global status like "wsrep_connected";
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| wsrep_connected | ON    |
+-----------------+-------+
1 row in set (0.00 sec)


3.监控集群
查看MySQL版本: 
SHOW GLOBAL VARIABLES LIKE 'version';
+---------------+----------------------+
| Variable_name | Value                |
+---------------+----------------------+
| version       | 5.6.21-70.1-25.8-log |
+---------------+----------------------+
1 row in set (0.00 sec)

查看wsrep版本: mysql> SHOW GLOBAL STATUS LIKE 'wsrep_provider_version';
+------------------------+---------------+
| Variable_name          | Value         |
+------------------------+---------------+
| wsrep_provider_version | 3.8(rf6147dd) |
+------------------------+---------------+
1 row in set (0.00 sec)

查看wsrep有关的所有变量: mysql> SHOW VARIABLES LIKE 'wsrep%' \G

查看集群状态: mysql> show status like 'wsrep%';
监控状态参数说明:
集群完整性检查:
            wsrep_cluster_state_uuid:在集群所有节点的值应该是相同的,有不同值的节点,说明其没有连接入集群.
            wsrep_cluster_conf_id:正常情况下所有节点上该值是一样的.如果值不同,说明该节点被临时"分区"了.当节点之间网络连接恢复的时候应该会恢复一样的值.
            wsrep_cluster_size:如果这个值跟预期的节点数一致,则所有的集群节点已经连接.
            wsrep_cluster_status:集群组成的状态.如果不为"Primary",说明出现"分区"或是"split-brain"状况.
节点状态检查:
            wsrep_ready: 该值为ON,则说明可以接受SQL负载.如果为Off,则需要检查wsrep_connected.
            wsrep_connected: 如果该值为Off,且wsrep_ready的值也为Off,则说明该节点没有连接到集群.(可能是wsrep_cluster_address或wsrep_cluster_name等配置错造成的.具体错误

需要查看错误日志)
            wsrep_local_state_comment:如果wsrep_connected为On,但wsrep_ready为OFF,则可以从该项查看原因.
复制健康检查:
            wsrep_flow_control_paused:表示复制停止了多长时间.即表明集群因为Slave延迟而慢的程度.值为0~1,越靠近0越好,值为1表示复制完全停止.可优化wsrep_slave_threads的值

来改善.
            wsrep_cert_deps_distance:有多少事务可以并行应用处理.wsrep_slave_threads设置的值不应该高出该值太多.
            wsrep_flow_control_sent:表示该节点已经停止复制了多少次.
            wsrep_local_recv_queue_avg:表示slave事务队列的平均长度.slave瓶颈的预兆.
最慢的节点的wsrep_flow_control_sent和wsrep_local_recv_queue_avg这两个值最高.这两个值较低的话,相对更好.
检测慢网络问题:
            wsrep_local_send_queue_avg:网络瓶颈的预兆.如果这个值比较高的话,可能存在网络瓶
冲突或死锁的数目:
            wsrep_last_committed:最后提交的事务数目
            wsrep_local_cert_failures和wsrep_local_bf_aborts:回滚,检测到的冲突数目 

六. 高可用测试
1)在节点1上创建demo数据库,节点2和节点3是自动创建demo
节点1:
(product)root@localhost [(none)]> create database demo;

(product)root@localhost [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| demo               |
| mysql              |
| performance_schema |
+--------------------+

节点2:
(product)root@localhost [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| demo               |
| mysql              |
| performance_schema |
+--------------------+


节点3:
(product)root@localhost [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| demo               |
| mysql              |
| performance_schema |
+--------------------+

2)在关掉节点1后,操作节点2,再启动节点1,节点2的数据自动与节点1同步
节点1:
-bash-4.1$ /etc/init.d/mysql stop
Shutting down MySQL (Percona XtraDB Cluster)......[  OK  ]

节点2:
(product)root@localhost [(none)]> use demo
(product)root@localhost [demo]> CREATE TABLE `demo1` (
  `ID` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `OID` int(11) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8

节点1:
(product)root@localhost [(none)]> use demo
Database changed
(product)root@localhost [demo]> show tables;
+----------------+
| Tables_in_demo |
+----------------+
| demo1          |
+----------------+
1 row in set (0.00 sec)

3) 节点3写入数据,检查节点一和节点二是否自动同步

节点3:
insert into demo1 select 1,1;
节点1和节点2:
select * from demo1

节点2:
insert into demo1 select 2,2;
节点1和节点2:
select * from demo1

节点1:
insert into demo1 select 3,3;
节点2和节点3:
select * from demo1


 

你可能感兴趣的:(mysql高可用)