Percona XtraDB Cluster(简称PXC集群)提供了MySQL高可用的一种实现方法。
一、安装软件
1、下载Percona-XtraDB-Cluster-5.7.19-rel17-29.22.3.Linux.x86_64.ssl101.tar.gz
- 注意一点:centos要下载带ssl101的安装包
- ssl100: for all supported Debian and Ubuntu versions
- ssl101: for supported Red Hat Enterprise Linux derivatives
默认端口
- 3306
- 4444
- 4567
- 4568
[root@my01 ~]# getenforce
Disabled
[root@my01 ~]# /etc/init.d/iptables status
iptables:未运行防火墙。
官方文档已经没有卸载mysql-lib,还是按照以前方法卸载
rpm -qa|grep mysql-libs|xargs rpm -e --nodeps
需要依赖包
perl-Time-HiRes perl-DBD-MySQL.x86_64 perl-IO-Socket-SSL.noarch nc libev
socat 提供
两个独立数据的双向传输之间起到中继作用的软件
Percona-XtraDB-Cluster-galera 提供
/
usr
/
lib64
/
libgalera_smm
.
so tarball的lib目录已经包含了这个库文件,所以路径要记得修改
2、第一个节点修改 /etc/my.cnf
mkdir /data/mysql/pxc3306/{data,logs,tmp} -p
chown mysql.mysql /data/mysql/pxc3306/ -R
#其他参数
#pxc from percona
binlog_format=row
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so
wsrep_cluster_address=gcomm://10.20.30.101,10.20.30.102,10.20.30.103
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_node_address=10.20.30.101
wsrep_sst_method=xtrabackup-v2
wsrep_cluster_name=my_pxc_cluster
wsrep_sst_auth="sstuser:sstpwd"
|
3、启动第一个节点
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
mysqld --defaults-file=/etc/my.cnf --initialize
cat error.log 查看是否有错误和临时root密码
[root@my01 data]# /etc/init.d/mysql bootstrap-pxc
Bootstrapping PXC (Percona XtraDB Cluster)Starting MySQL (Percona XtraDB Cluster).2018-01-02T09:21:15.749596Z mysqld_safe The file /mnt/workspace/percona-xtradb-cluster-5.7-binary-tarball/label_exp/centos6-64/Percona-XtraDB-Cluster-5.7.19-29.22/374/usr/local/Percona-XtraDB-Cluster-5.7.19-rel17-29.22.3.Linux.x86_64.ssl101/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
The server quit without updating PID file (/data/mysql/pxc3[失败]ta/mysql.pid).
MySQL (Percona XtraDB Cluster) server startup failed! [失败]
|
代码写死了,需要执行替换
cp mysqld_safe mysqld_safe.bak
sed -i 's#/mnt/workspace/percona-xtradb-cluster-5.7-binary-tarball/label_exp/centos6-64/Percona-XtraDB-Cluster-5.7.19-29.22/374/usr/local/Percona-XtraDB-Cluster-5.7.19-rel17-29.22.3.Linux.x86_64.ssl101#/usr/local/mysql#g' /usr/local/mysql/bin/mysqld_safe
/etc/init.d/mysql bootstrap-pxc
mysql -S /tmp/pxc3306.sock -uroot -p
>alter user user() identified by 'gouliping';
>flush privileges;
> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'sstpwd';
> GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT, PROCESS ON *.* TO 'sstuser'@'localhost'; # 比官方文档中多了PROCESS权限
> FLUSH PRIVILEGES;
mysql -usstuser -psstpwd -e 'show databases'
4、第二个节点配置
- 修改my.cnf (改server_uuid和wsrep_node_address)
- 初始化(不需要修改密码,启动起来后,会同步)
- 启动
-
- cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
- /etc/init.d/mysql start
5、第三个节点配置
同第二个节点一样
6、建表测试同步
root@
localhost@pxc3306.sock [(none)]>create database pxc;
Query OK, 1 row affected (0.04 sec)
root@
localhost@pxc3306.sock [(none)]>use pxc;
Database changed
root@
localhost@pxc3306.sock [pxc]>create table exp (node_id int primary key,node_name varchar(30));
Query OK, 0 rows affected (0.02 sec)
root@
localhost@pxc3306.sock [pxc]>insert into exp values(1,'my03');
Query OK, 1 row affected (0.01 sec)
root@
localhost@pxc3306.sock [(none)]>select * from pxc.exp;
+---------+-----------+
| node_id | node_name |
+---------+-----------+
| 1 | my03 |
+---------+-----------+
1 row in set (0.00 sec)