Percona Xtradb Cluster 安裝
Percona Xtradb Cluster 介紹 Percona XtraDB Cluster 簡稱:PXC,是針對MySQL 用戶的高可用性和擴展性解決方案,基於Percona Server。其包括了Write Set REPlication 補丁,使用Galera庫,這是一個針對事務性應用程序的同步多主機複製插件。
Percona XtraDB Cluster特色:
(1)同步複製,事務在全部集羣節點要麼同時提交,要麼不提交。
(2)多主複製,能夠在任意一個節點寫入。
(3)從服務器上的並行應用事件,真正的「並行複製」。
(4)自動配置節點。
(5)數據一致性,沒有不一樣步的從服務器。
PXC 安裝環境需求
環境:
CentOS 6.5 64bits
IP:
192.168.1.88
192.168.1.89
192.168.1.90
PXC 安裝基本步驟
Percona-Xtradb-Cluster
5.6 版本下載
wget http://www.percona.com/downloads/Percona-XtraDB-Cluster-56/Percona-XtraDB-Cluster-5.6.21-25.8/binary/tarball/Percona-XtraDB-Cluster-5.6.21-rel70.1-25.8.938.Linux.x86_64.tar.gz
1.安裝依賴包:(使用系統光盤配置本地yum源便可)
yum -y install perl perl-devel libaio libaio-devel perl-Time-HiRes perl-DBD-MySQL
2.安裝軟件包percona-xtrabackup:
rpm -ivh percona-xtrabackup-2.3.5-1.el6.x86_64.rpm
可能須要依賴軟件包libev.
rpm -ivh libev-4.04-2.el6.x86_64.rpm
3.安裝
建立安裝目錄
mkdir /usr/local/mysql
tar -xvf Percona-XtraDB-Cluster-5.6.21-rel70.1-25.8.938.Linux.x86_64.tar.gz
mv Percona-XtraDB-Cluster-5.6.21-rel70.1-25.8.938.Linux.x86_64 /usr/local/mysql
建立mysql 的用戶及組
groupadd mysql
useradd -g msyql mysql
建立啓動文件:
#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
建立mysql 須要的基本目錄
mkdir -p /data/mysql/mysql_3306
mkdir -p /data/mysql/mysql_3306/data
mkdir -p /data/mysql/mysql_3306/logs
mkdir -p /data/mysql/mysql_3306/tmp
chown mysql:mysql /data -R
chmod 755 /data -R
./mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/
確認結果正確
4.PXC 配置
cat /etc/my.cnf
[client]
socket=/data/mysql/mysql_3306/tmp/mysql.sock
port = 3306
[mysqld]
server_id=88
basedir = /usr/local/mysql
port = 3306
datadir = /data/mysql/mysql_3306/data
tmpdir = /data/mysql/mysql_3306/tmp
socket = /data/mysql/mysql_3306/tmp/mysql.sock
user=mysql
pid-file=/data/mysql/mysql_3306/data/mysqld.pid
log-error=/data/mysql/mysql_3306/logs/mysql.err
general-log-file=/data/mysql/mysql_3306/logs/mysql.log
slow-query-log-file=/data/mysql/mysql_3306/logs/mysql.log
default_storage_engine=InnoDB
innodb_locks_unsafe_for_binlog=1
innodb_autoinc_lock_mode=2
wsrep_cluster_name="mycluster"
#cluster 的名字
wsrep_cluster_address=gcomm://192.168.1.88,192.168.1.89,192.168.1.90
#cluster 中的節點ip
wsrep_node_address=192.168.1.88
#cluster 當前節點的ip
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so
wsrep_sst_method=rsync
wsrep_sst_auth="sstuser:sstuser"
wsrep_node_name=pxc1
有兩個地方須要注意:
一、wsrep_node_address=192.168.1.88 安裝每一個mysql服務時,須要修改成自身的ip
二、wsrep_sst_method:在剛安裝時,須要將slave節點設置爲rsync,才能同步成功
每臺集羣中的mysql服務都按以上的步驟安裝便可
注意下面幾個值根據實際狀況設置,3臺主機須要設置成不一樣的值:
server_id=88
wsrep_node_address
wsrep_node_name
5.啓動
# 首先啓動第一節點
修改/etc/init.d/mysql配置文件中basedir和datadir的路徑
basedir=/usr/local/mysql
datadir=/data/mysql/mysql_3306/data
/etc/init.d/mysql bootstrap-pxc --wsrep-cluster-address="gcomm://"
tail -f /data/mysql/mysql_3306/logs/mysql.log ----- 觀察錯誤日誌
# 以上述方式啓動完第一個節點後,用命令service mysql start依次啓動第二和第三個節點。當所有節點啓動完畢後,# 再回過來把第一個節點service mysql restart從新啓動。這是由於在集羣節點所有關閉狀態下,第一個啓動的節點# 必須以gcomm://方式啓動。
/etc/init.d/mysql start
/etc/init.d/mysql start
/etc/init.d/mysql restart
6.驗證是否配置成功:
mysql> show global status like 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 3 |
+--------------------+-------+
1 row in set (0.00 sec)
mysql> show global status like 'wsrep_incoming_addresses';
+--------------------------+-------------------------------------------------------+
| Variable_name | Value |
+--------------------------+-------------------------------------------------------+
| wsrep_incoming_addresses | 192.168.1.90:3306,192.168.1.89:3306,192.168.1.88:3306 |
+--------------------------+-------------------------------------------------------+
1 row in set (0.25 sec)
# 比較重要的參數狀態
mysql> show status like 'wsrep%';
+------------------------------+-------------------------------------------------------------+
| Variable_name | Value |
+------------------------------+-------------------------------------------------------------+
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
| wsrep_ready | ON |
+------------------------------+-------------------------------------------------------------+
測試數據
第一個節點:
mysql> create database db1;
Query OK, 1 row affected (0.05 sec)
mysql> use db1;
Database changed
mysql> create table t1(x int);
Query OK, 0 rows affected (0.21 sec)
mysql> insert into t1 values(1);
第二個節點:
mysql> use db1;
Database changed
mysql> show tables;
+---------------+
| Tables_in_db1 |
+---------------+
| t1 |
+---------------+
1 row in set (0.00 sec)
mysql> insert into t1 values(2);
Query OK, 1 row affected (0.01 sec)
第三個節點:
mysql> use db1;
Database changed
mysql> show tables;
+---------------+
| Tables_in_db1 |
+---------------+
| t1 |
+---------------+
1 row in set (0.00 sec)
mysql> select * from t1;
+------+
| x |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)
遇到的問題及解決辦法:
可能提示缺乏libssl.so.6和libcrypto.so.6
/usr/local/mysql//bin/my_print_defaults: error while loading shared libraries:
libssl.so.6: cannot open shared object file: No such file or directory
/usr/local/mysql//bin/my_print_defaults: error while loading shared libraries:
libcrypto.so.6: cannot open shared object file: No such file or directory
安裝
openssl
# rpm -qa | grep openssl
krb5-pkinit-openssl-1.10.3-65.el6.x86_64
openssl-1.0.1e-57.el6.x86_64
openssl098e-0.9.8e-20.el6.centos.1.i686
cd /usr/lib64
# ln -s libssl.so.1.0.1e libssl.so.6
# ln -s libcrypto.so.1.0.1e libcrypto.so.6