一些名词介绍:
WS:write set 写数据集
IST: Incremental State Transfer 增量同步
SST:State Snapshot Transfer 全量同步
pxc环境所涉及的端口:
#mysql实例端口
1. Regular MySQL port, default 3306.
#pxc cluster相互通讯的端口
2. Port for group communication, default 4567. It can be changed by the option:
wsrep_provider_options ="gmcast.listen_addr=tcp://0.0.0.0:4010; "
#用于SST传送的端口
3. Port for State Transfer, default 4444. It can be changed by the option:
wsrep_sst_receive_address=10.11.12.205:5555
#用于IST传送的端口
4. Port for Incremental State Transfer, default port for group communication + 1 (4568). It can be changed by the option:
wsrep_provider_options = "ist.recv_addr=10.11.12.206:7777; "
搭建步骤:
一、环境情况:
node1:192.168.1.81:6000
node2:192.168.1.240:6000
-A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT #本实验需要改为6000
-A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT #本实验需要改为6020
-A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT #本实验需要改为6030
-A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT #本实验需要改为6031
setenforce
yum install -y http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
yum install -y perl-DBD-MySQL.x86_64 perl-IO-Socket-SSL.noarch socat.x86_64 nc
yum install -y openssl openssl-devel #step prepare :5.6. needs libssl.so. libcrypto.so. ()
cd /usr/lib64
ln -s libssl.so.1.0.1e libssl.so.
ln -s libcrypto.so.1.0.1e libcrypto.so. #step2:download pxc
cd /usr/local/src
wget https://www.percona.com/downloads/Percona-XtraDB-Cluster-56/Percona-XtraDB-Cluster-5.6.26-25.12/binary/tarball/Percona-XtraDB-Cluster-5.6.26-rel74.0-25.12.1.Linux.x86_64.tar.gz
cd /usr/local
mv Percona-XtraDB-Cluster-5.6.-rel74.-25.12..Linux.x86_64.tar.gz pxc_56 #step3:install pxc
cd /usr/local/pxc_56
./scripts/mysql_install_db --defaults-file=/home/mysql/my6000.cnf --basedir=/usr/local/pxc_56
[client]
port = 6000
socket = /home/mysql/I6000/mysql.sock
default-character-set=utf8 [mysqld]
basedir = /usr/local/pxc_56
datadir = /home/mysql/I6000 pid-file = /home/mysql/I6000/mysql.pid
character-set-server=utf8
init_connect = 'SET NAMES utf8'
log-bin=/home/mysql/I6000/log_bin
server-id = 9816000 innodb_buffer_pool_size = 100M
innodb_data_file_path = ibdata1:10M:autoextend
innodb_data_home_dir = /home/mysql/I6000
innodb_file_per_table=1 skip-name-resolve port = 6000
socket = /home/mysql/I6000/mysql.sock
user=mysql
log_error=/home/mysql/I6000/mysql_error.log #pxc
user=mysql
log_error=error.log
binlog_format=ROW #6000 for mysqld port, 6020 for sst port, 6031 for ist port, 6030 for cluster communication port 端口作用及说明见上面
wsrep_cluster_address='gcomm://192.168.1.81:6030,192.168.1.238:6030,192.168.1.240:6030' #三个节点都保持一样
wsrep_provider=/usr/local/pxc_56/lib/libgalera_smm.so
wsrep_sst_receive_address=192.168.1.238:6020 #根据不同的node ip进行修改
wsrep_node_incoming_address=192.168.1.238:6000 #根据不同的node ip进行修改
wsrep_node_address=192.168.1.238:6000 #根据不同的node ip进行修改
wsrep_provider_options = "gmcast.listen_addr=tcp://192.168.1.238:6030;ist.recv_addr=192.168.1.238:6031;" #根据不同的node ip进行修改 wsrep_slave_threads=2
wsrep_cluster_name=pxc_zejin #同一个cluster此值需要一致
wsrep_sst_method=xtrabackup-v2
wsrep_node_name=node6000_238 #不同节点修改为不同的名字
innodb_autoinc_lock_mode=2
wsrep_sst_auth="sstuser:123"
log-slave-updates [mysql]
no-auto-rehash
default-character-set=utf8
#安装实例
/usr/local/pxc_56/scripts/mysql_install_db --defaults-file=/home/mysql/my6000.cnf --basedir=/usr/local/pxc_56
#启动第一个实例
/usr/local/pxc_56/bin/mysqld_safe --defaults-file=/home/mysql/my6000.cnf --ledir=/usr/local/pxc_56/bin/ --wsrep-new-cluster &
#修改密码
/usr/local/pxc_56/bin/mysqladmin -u root -P6000 password '' -S /home/mysql/I6000/mysql.sock
#登陆并增加用户
/usr/local/pxc_56/bin/mysql -uroot -p -P6000 -S /home/mysql/I6000/mysql.sock
grant all on *.* to 'sstuser'@'localhost' identified by '';
flush privielges;
mysql> show global status like 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | |
+--------------------+-------+
row in set (0.00 sec)
#不需要加--wsrep-new-cluster
/usr/local/pxc_56/bin/mysqld_safe --defaults-file=/home/mysql/I6000/my6000.cnf --ledir=/usr/local/pxc_56/bin/ & 整个过程大约如下:
• Stage I on joiner checks if it is SST or IST based on presence of xtrabackup_ist file.
• In Stage II it starts the data transfer, if it’s SST, it empties the data directory sans few files (galera.cache, sst_in_progress, grastate.dat) and then proceed with the SST or if it’s IST, proceeds as before.
加入成功:
:: root@127.0.0.1:[test] >show global status like 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | |
+--------------------+-------+
row in set (0.00 sec)
五、操作过程中经常用到的命令:
安装:/usr/local/pxc_56/scripts/mysql_install_db --defaults-file=/home/mysql/my6000.cnf --basedir=/usr/local/pxc_56
启动:/usr/local/pxc_56/bin/mysqld_safe --defaults-file=/home/mysql/my6000.cnf --ledir=/usr/local/pxc_56/bin/ & ( 第一个节点要加上--wsrep-new-cluster )
登陆:/usr/local/pxc_56/bin/mysql -uroot -p -P6000 -S /home/mysql/I6000/mysql.sock
关闭:/usr/local/pxc_56/bin/mysqladmin -uroot -p -P6000 -S /home/mysql/I6000/mysql.sock shutdown
节点启动时:
/usr/local/pxc_56/bin/mysqld_safe --defaults-file=/home/mysql/my3307.cnf --ledir=/usr/local/pxc_56/bin/ &
有可能启动会提示:
WSREP_SST: [ERROR] socat not found in path: /usr/sbin:/sbin:/usr/local/pxc_56//bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/lamp/mysql/bin:/root/bi
n ( ::04.404)
-- :: [ERROR] WSREP: Failed to read 'ready <addr>' from: wsrep_sst_xtrabackup-v2 --role 'joiner' --address '192.168.1.238' --datadir '/home/mysql/I3307/
' --defaults-file '/home/mysql/I3307/my3307.cnf' --defaults-group-suffix '' --parent '' ''
Read: '(null)'
-- :: [ERROR] WSREP: Process completed with error: wsrep_sst_xtrabackup-v2 --role 'joiner' --address '192.168.1.238' --datadir '/home/mysql/I3307/' --de
faults-file '/home/mysql/I3307/my3307.cnf' --defaults-group-suffix '' --parent '' '' : (No such file or directory)
-- :: [ERROR] WSREP: Failed to prepare for 'xtrabackup-v2' SST. Unrecoverable.
-- :: [ERROR] Aborting
原因及解决方法:socat 没有安装到,之前源包没有,可以进行如下安装:
第一个节点如果直接这样启动:
/usr/local/pxc_56/bin/mysqld_safe --defaults-file=/home/mysql/my6000.cnf & 在errorlog里面会出现:
-- :: [ERROR] WSREP: failed to open gcomm backend connection: : failed to reach primary view: (Connection timed out)
at gcomm/src/pc.cpp:connect():
-- :: [ERROR] WSREP: gcs/src/gcs_core.cpp:gcs_core_open():: Failed to open backend connection: - (Connection timed out)
-- :: [ERROR] WSREP: gcs/src/gcs.cpp:gcs_open():: Failed to open channel 'pxc_zejin' at 'gcomm://192.168.1.240,192.168.1.238,192.168.1.81': - (Con
nection timed out)
-- :: [ERROR] WSREP: gcs connect failed: Connection timed out
-- :: [ERROR] WSREP: wsrep::connect(gcomm://192.168.1.240,192.168.1.238,192.168.1.81) failed: 7
-- :: [ERROR] Aborting -- :: [Note] WSREP: Service disconnected.
-- :: [Note] WSREP: Some threads may fail to exit.
-- :: [Note] Binlog end
-- :: [Note] /usr/local/pxc_56/bin/mysqld: Shutdown complete
解决方法:第一个节点启动要加上:--wsrep-new-cluster
/usr/local/pxc_56/bin/mysqld_safe --defaults-file=/home/mysql/my6000.cnf --ledir=/usr/local/pxc_56/bin --wsrep-new-cluster &
#第二个节点或第三个节点启动报错:
WSREP_SST: [ERROR] Cleanup after exit with status: ( ::50.483)
-- :: [ERROR] WSREP: Process completed with error: wsrep_sst_xtrabackup-v2 --role 'joiner' --address '192.168.1.240:6020' --datadir '/home/mysql/I6000/'
--defaults-file '/home/mysql/I6000/my6000.cnf' --defaults-group-suffix '' --parent '' '' : (Operation not permitted)
-- :: [ERROR] WSREP: Failed to read uuid:seqno from joiner script.
-- :: [ERROR] WSREP: SST script aborted with error (Operation not permitted)
-- :: [ERROR] WSREP: SST failed: (Operation not permitted)
-- :: [ERROR] Aborting
原因及解决方法:配置文件my6000.cnf放在与datadir目录下,在Cleaning the existing datadir阶段被删除,在重启服务时就会找不到配置文件,在重新启动服务就会出错,把配置文件放在非datadir目录下即可。如/etc/my6000.cnf