1. 程式人生 > >基於CentOS 7 安裝Percona XtraDB Cluster(PXC) 5.7

基於CentOS 7 安裝Percona XtraDB Cluster(PXC) 5.7

轉載來源:https://blog.csdn.net/robinson_0612/article/details/78962190

 

基於CentOS 7 安裝Percona XtraDB Cluster(PXC) 5.7

 

Percona XtraDB Cluster(簡稱PXC)是很多企業基於MySQL實現叢集方案的不二選擇。PXC它支援服務高可用,資料同步複製(併發複製),幾乎無延遲;多個可同時讀寫節點,可實現寫擴充套件等等。之前整理過一篇PXC 5.6的文章,本文是基於CentOS 7 PXC 5.7版一個更為標準的安裝,可供大家參考。

 

一、當前OS環境

[[email protected] ~]# more /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)


二、配置執行環境


1、修改主機hosts檔案

[[email protected] ~]# vim /etc/hosts
127.0.0.1 localhost.localdomain localhost 
192.168.81.142 node142.example.com node142
192.168.81.146 node146.example.com node146
192.168.81.147 node147.example.com node147


2、修改selinux配置檔案

[[email protected] ~]# vim /etc/selinux/config
SELINUX=disabled



3、分發配置檔案到其餘節點

[[email protected] ~]# scp /etc/hosts 192.168.81.146:/etc/hosts 
[[email protected] ~]# scp /etc/hosts 192.168.81.147:/etc/hosts 
[[email protected] ~]# scp /etc/selinux/config 192.168.81.146:/etc/selinux/config
[
[email protected]
~]# scp /etc/selinux/config 192.168.81.147:/etc/selinux/config



4、分別3節點配置防火牆,如下示例(僅列出一個節點)

[[email protected] ~]# firewall-cmd --add-port=3306/tcp --permanent
[[email protected] ~]# firewall-cmd --add-port=4567/tcp --permanent
[[email protected] ~]# firewall-cmd --add-port=4568/tcp --permanent
[[email protected] ~]# firewall-cmd --add-port=4444/tcp --permanent
[[email protected] ~]# firewall-cmd --reload



5、配置時間同步服務

[[email protected] ~]# crontab -e
*/10 * * * * ntpdate ntp3.aliyun.com



6、分別重啟3節點

[[email protected] ~]# reboot 
[[email protected] ~]# reboot 
[[email protected] ~]# reboot 


三、安裝Percona XtraDB Cluster 5.7


1、3節點分別安裝Percona XtraDB Cluster 5.7 (如下示例)

[[email protected] ~]# rpm -Uvh https://www.percona.com/downloads/percona-release/redhat/latest/percona-release-0.1-4.noarch.rpm
[[email protected] ~]# yum install Percona-XtraDB-Cluster-57 -y

 

yum安裝時會提示UDFs功能,根據需要可以在mysql啟動後執行以下語句

Percona XtraDB Cluster is distributed with several useful UDFs from Percona Toolkit.
Run the following commands to create these functions:
mysql -e "CREATE FUNCTION fnv1a_64 RETURNS INTEGER SONAME 'libfnv1a_udf.so'"
mysql -e "CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'libfnv_udf.so'"
mysql -e "CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'libmurmur_udf.so'"


四、配置mysql及叢集配置檔案


主要包括mysqld.cnf,mysqld_safe.cnf,wsrep.cnf 
在當前的這個版本中,my.cnf為主配置檔案,其餘的配置檔案放在/etc/percona-xtradb-cluster.conf.d目錄 
在這幾個配置檔案中,大家根據自己的需要定製,本演示僅作基本修改 

1、備份配置檔案

[[email protected] ~]# cp /etc/percona-xtradb-cluster.conf.d/mysqld.cnf{,.org}
[[email protected] ~]# cp /etc/percona-xtradb-cluster.conf.d/mysqld_safe.cnf{,.org}
[[email protected] ~]# cp /etc/percona-xtradb-cluster.conf.d/wsrep.cnf{,.org}

 

2、修改配置檔案

[[email protected] ~]# vim /etc/percona-xtradb-cluster.conf.d/mysqld.cnf
[[email protected] ~]# more /etc/percona-xtradb-cluster.conf.d/mysqld.cnf
# Template my.cnf for PXC
# Edit to your requirements.

[client]
socket=/var/lib/mysql/mysql.sock

[mysqld]
server-id=142    #這個引數3個節點要使用不同的id
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin=/var/lib/mysqlbin
log_slave_updates
expire_logs_days=7
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log_bin_trust_function_creators=on
character_set_server = utf8  ##Author : Leshami
collation_server = utf8_bin  ##Blog : http://blog.csdn.net/leshami
[[email protected] ~]# vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[[email protected] ~]# grep -vE "^#|^$" /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.81.142,192.168.81.146,192.168.81.147
binlog_format=ROW
default_storage_engine=InnoDB
wsrep_slave_threads= 8
wsrep_log_conflicts
innodb_autoinc_lock_mode=2
wsrep_node_address=192.168.81.142 ##這個引數要改成相應的IP
wsrep_cluster_name=pxc-cluster
wsrep_node_name=node142               ##這個引數要改成相應的節點名稱
pxc_strict_mode=PERMISSIVE
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="sstuser:s3cretPass"


3、修改剩餘節點配置檔案

[[email protected] ~]# cp /etc/percona-xtradb-cluster.conf.d/mysqld.cnf{,.146}
[[email protected] ~]# cp /etc/percona-xtradb-cluster.conf.d/mysqld.cnf{,.147}
[[email protected] ~]# cp /etc/percona-xtradb-cluster.conf.d/wsrep.cnf{,.146}
[[email protected] ~]# cp /etc/percona-xtradb-cluster.conf.d/wsrep.cnf{,.147}
[[email protected] ~]# vim /etc/percona-xtradb-cluster.conf.d/mysqld.cnf.146  #修改對應的server_id
[[email protected] ~]# vim/etc/percona-xtradb-cluster.conf.d/mysqld.cnf.147  #修改對應的server_id

# 以下操作,分別修改wsrep_node_name,wsrep_node_address至相應的節點名稱以及IP地址
[[email protected] ~]# vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf.146 
[[email protected] ~]# vim  /etc/percona-xtradb-cluster.conf.d/wsrep.cnf.147


4、比較配置檔案,並將配置檔案分發到各個節點

[[email protected] ~]# cd /etc/percona-xtradb-cluster.conf.d/
[[email protected] percona-xtradb-cluster.conf.d]# diff mysqld.cnf mysqld.cnf.146
7c7
< server-id=142
---
> server-id=146
[[email protected] percona-xtradb-cluster.conf.d]# diff mysqld.cnf mysqld.cnf.147
7c7
< server-id=142
---
> server-id=147
[[email protected] percona-xtradb-cluster.conf.d]# diff wsrep.cnf wsrep.cnf.146
28c28
< wsrep_node_address=192.168.81.142
---
> wsrep_node_address=192.168.81.146
32c32
< wsrep_node_name=node142
---
> wsrep_node_name=node146
[[email protected] percona-xtradb-cluster.conf.d]# diff wsrep.cnf wsrep.cnf.147
28c28
< wsrep_node_address=192.168.81.142
---
> wsrep_node_address=192.168.81.147
32c32
< wsrep_node_name=node142
---
> wsrep_node_name=node147

[[email protected] percona-xtradb-cluster.conf.d]# scp mysqld.cnf.146 node146:/etc/percona-xtradb-cluster.conf.d/mysqld.cnf
[[email protected] percona-xtradb-cluster.conf.d]# scp wsrep.cnf.146 node146:/etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[[email protected] percona-xtradb-cluster.conf.d]# scp mysqld.cnf.147 node147:/etc/percona-xtradb-cluster.conf.d/mysqld.cnf
[[email protected] percona-xtradb-cluster.conf.d]# scp wsrep.cnf.147 node147:/etc/percona-xtradb-cluster.conf.d/wsrep.cnf

 

五、啟動PXC叢集


1、啟動第一個節點

[[email protected] ~]# systemctl start [email protected]
[[email protected] ~]# grep "temporary password" /var/log/mysqld.log
2017-12-28T08:57:24.231185Z 1 [Note] A temporary password is generated for [email protected]: wj!v<z/2)ctZ

[[email protected] ~]# mysql -uroot -p
Enter password:
mysql> alter user 'root'@'localhost' identified by '123456';
mysql> create user 'sstuser'@'localhost' identified by 's3cretpass';
mysql> grant reload, lock tables, replication client, process on *.* to 'sstuser'@'localhost';



2、啟動剩餘節點

[[email protected] ~]# systemctl start mysql
[[email protected] ~]# systemctl start mysql  


注,如果你使用的是CentOS7.2.1511,會發現mysql可以正常啟動,但是未加入叢集的情況
需要升級openssl,建議全部升級後再啟動叢集,這問題在CentOS 7.4.1708不存在即openssl版本較新


六、驗證叢集


在146上完成如下操作

[[email protected] ~]# mysql -uroot -p
mysql> show variables like 'version';
+---------------+--------------+
| Variable_name | Value |
+---------------+--------------+
| version | 5.7.19-17-57 |
+---------------+--------------+
1 row in set (0.00 sec)

mysql> create database pxcdb;
mysql> use pxcdb;
mysql> create table t1(id tinyint,ename varchar(20));
mysql> insert into t1 values(1,'Leshami');

 

在147上進行驗證

[[email protected] ~]# mysql -uroot -p
mysql> show databases;
+--------------------+
| Database       |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| pxcdb |
| sys |
+--------------------+
5 rows in set (0.00 sec)

mysql> show variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id    | 147 |
+---------------+-------+
1 row in set (0.01 sec)

mysql> select * from pxcdb.t1;
+------+---------+
| id | ename |
+------+---------+
| 1 | Leshami |
+------+---------+
1 row in set (0.00 sec)


--檢視叢集狀態

mysql> show status like '%wsrep_clust%';
+--------------------------+--------------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------------+
| wsrep_cluster_conf_id | 13 |  ## Author : Leshami
| wsrep_cluster_size | 3 |         ## Blog : http://blog.csdn.net/leshami
| wsrep_cluster_state_uuid | aeb87793-ebb2-11e7-b33e-eeaf4988bbe4 |
| wsrep_cluster_status | Primary |   ## Weixin/QQ : 645746311
+--------------------------+--------------------------------------+
4 rows in set (0.00 sec)

mysql> show status like 'wsrep_connected';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| wsrep_connected | ON |
+-----------------+-------+
1 row in set (0.00 sec)

 


七、openssl版本過低導致的錯誤

2017-12-28T09:23:19.605353Z 0 [ERROR] WSREP: wsrep_load(): dlopen(): /usr/lib64/galera3/libgalera_smm.so: 
symbol SSL_COMP_free_compression_methods, version libssl.so.10 not defined in file libssl.so.10 with link time reference
2017-12-28T09:23:19.605379Z 0 [ERROR] WSREP: Failed to load wsrep_provider (/usr/lib64/galera3/libgalera_smm.so).
 Error: Invalid argument (code: 22). Reverting to no provider.
2017-12-28T09:23:19.605386Z 0 [Note] WSREP: Setting wsrep_ready to false

[[email protected] ~]# rpm -qa|grep openssl
openssl-1.0.1e-42.el7.9.x86_64
openssl-libs-1.0.1e-42.el7.9.x86_64
[[email protected] ~]# yum update openssl -y



作者:Leshami   原文:https://blog.csdn.net/leshami/article/details/78962190