环境:
centOS 6
IP:
192.168.56.131
192.168.56.132
192.168.56.133
------------------------------
Installing Percona XtraDB Cluster on Red Hat Enterprise Linux and CentOS
环境准备:
setenforce 0
vi /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted
/etc/init.d/iptables stop
chkconfig iptables off
配置yum源:
yum install ca-certificates
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
cd /etc/yum.repos.d
vi epel.repo
修改enabled=1
将baseurl的注释取消, mirrorlist注释掉
配置fadora的epel源
yum install socat libev
yum install Percona-XtraDB-Cluster-57 -y
[root@pxc1 pxcdata]# cat /etc/my.cnf
[mysqld]
server-id=56131
pid-file=/var/run/mysqld/mysqld.pid
#log-error=/var/log/mysqld.log
log-error=/pxcdata/mysql/log/mysqld.log
#datadir=/var/lib/mysql
datadir=/pxcdata/mysql/data/
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/pxcdata/mysql/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
mkdir -p /pxcdata/mysql/data/
mkdir -p /pxcdata/mysql/log/
chown -R mysql.mysql /pxcdata/
安装:
service mysql start
grep 'temporary password' /pxcdata/mysql/log/mysqld.log
2018-09-16T12:54:45.475375Z 1 [Note] A temporary password is generated for root@localhost: ;qO>8nzS4StD
吐槽:给我生成的随机密码开头是个特么分号,刚开始我以为不是密码的一部分呢,这块折腾了十几分钟。。。
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';
exit
service mysql stop
------------------------------
Configuring Nodes for Write-Set Replication
vi /etc/my.cnf
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_name=pxc-cluster
wsrep_cluster_address=gcomm://192.168.56.131,192.168.56.132,192.168.56.133
wsrep_node_name=pxc1
wsrep_node_address=192.168.56.131
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth=sstuser:passw0rd
pxc_strict_mode=ENFORCING
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
节点2,节点3也用上面相同的配置,但需要修改wsrep_node_name,wsrep_node_address,server-id
节点2:
wsrep_node_name=pxc2
wsrep_node_address=192.168.56.132
节点3:
wsrep_node_name=pxc3
wsrep_node_address=192.168.56.133
------------------------------
Bootstrapping the First Node
节点1:
/etc/init.d/mysql bootstrap-pxc
mysql@pxc1> show status like 'wsrep%';
+----------------------------+--------------------------------------+
| Variable_name | Value |
+----------------------------+--------------------------------------+
| wsrep_local_state_uuid | c2883338-834d-11e2-0800-03c9c68e41ec |
| ... | ... |
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
| ... | ... |
| wsrep_cluster_size | 1 |
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
| ... | ... |
| wsrep_ready | ON |
+----------------------------+--------------------------------------+
创建sst用户,
CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'passw0rd';
GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost';
FLUSH PRIVILEGES;
------------------------------
Adding Nodes to Cluster
我这里用的虚拟机,现在可以把node1的cluster停了,通过node1把node2,node3克隆出来
启动节点1,等待其他两个节点的加入。
/etc/init.d/mysql bootstrap-pxc
确认日志是否正常
节点2,节点3,修改IP,修改hostname
还原/etc/my.cnf文件
清空/pxcdata目录,初始化mysql:
/etc/init.d/mysql start
观察日志信息
------------------------------
验证:
可以在其中一个节点建库,建表,之后到其他节点确认是否同步。
Next Steps
Consider installing ProxySQL on client nodes for efficient workload management across the cluster
without any changes to the applications that generate queries. This is the recommended high-availability solution for Percona XtraDB Cluster.
可以考虑部署个proxysql,实现PXC的高可用解决方案。