PXC高可用集群配置

作者: admin 分类: Linux 发布时间: 2018-07-05 15:52 浏览:1,130 次    

环境:centos7.4      pxc5.7

            pxc1:172.20.10.7        pxc2:172.20.10.8         pxc3:172.20.10.9

pxc项目地址:

             https://www.percona.com/downloads/XtraBackup/LATEST/
             https://github.com/percona/percona-xtradb-cluster

 

1、修改主机名

# hostnamectl set-hostname pxc1
# hostnamectl set-hostname pxc2
# hostnamectl set-hostname pxc3

2、配置yum源

# yum -y install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
# yum -y install epel-release

3、安装PXC

#  yum -y install Percona-XtraDB-Cluster-server-57 Percona-Server-shared-compat-57 Percona-XtraDB-Cluster-client-57 percona-xtrabackup-24

4、启动服务

# systemctl start mysql.service

5、查找密码(mysql5.7以后会随机生成密码在日志中)

# grep 'temporary password' /var/log/mysqld.log

6、修改root密码

mysql -u root -p

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'rootPass';

7、关闭服务

# systemctl stop mysql.service

8、配置

  • pxc1
[root@pxc1 ~]# vim /etc/my.cnf
!includedir /etc/my.cnf.d/
!includedir /etc/percona-xtradb-cluster.conf.d/
[mysqld]
user=mysql
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_name=pxc-cluster
wsrep_cluster_address=gcomm://172.20.10.7,172.20.10.8,172.20.10.9
wsrep_node_name=pxc1
wsrep_node_address=172.20.10.7
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
  • pxc2
wsrep_node_name=pxc2
wsrep_node_address=172.20.10.8
  • pxc3
wsrep_node_name=pxc3
wsrep_node_address=172.20.10.9

注:所有节点配置基本相同,修改以上节点名和地址即可!

9、启动集群

  • 启动第一个节点
[root@pxc1 ~]# systemctl start mysql@bootstrap.service          #centos7.x
[root@pxc1 ~]# /etc/init.d/mysql bootstrap-pxc          #centos6.x 
  • 启动其它节点
# systemctl start mysql.service

10、查看集群信息

mysql> 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_incoming_addresses | 172.20.10.9:3306,172.20.10.7:3306,172.20.10.8:3306 |
| ... | ... |
| wsrep_ready | ON |
+----------------------------+--------------------------------------+
40 rows in set (0.01 sec)

11、授权

mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'passw0rd';
mysql> GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON * . *  TO 'sstuser'@'localhost';
mysql> FLUSH PRIVILEGES;

12、测试

  • pxc2上创建 percona库
mysql> CREATE DATABASE percona;
  • pxc3在percona库中创建表
mysql> USE percona;
Database changed
mysql> CREATE TABLE example (node_id INT PRIMARY KEY, node_name VARCHAR(30));
Query OK, 0 rows affected (0.23 sec)
  • pcx1查看
 mysql> INSERT INTO percona.example VALUES (1, 'percona1');
Query OK, 1 row affected (0.02 sec)
 mysql> SELECT FROM percona.example;
+---------+-----------+
| node_id | node_name |
+---------+-----------+
| 1 | percona1 |
+---------+-----------+
1 row in set (0.00 sec)

以上已看到完全同步,说明集群成功搭建!

 


温馨提示:如无特殊说明,本站文章均为作者原创,转载时请注明出处及相应链接!

发表评论