MySQL PXC 高可用集群搭建
一些名词介绍:
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
MySQL PXC 高可用集群搭建的更多相关文章
- MySQL数据库高可用集群搭建-PXC集群部署
Percona XtraDB Cluster(下文简称PXC集群)提供了MySQL高可用的一种实现方法.集群是有节点组成的,推荐配置至少3个节点,但是也可以运行在2个节点上. PXC原理描述: 分布式 ...
- MySQL mha 高可用集群搭建
[mha] MHA作为MySQL故障切换和主从提升的高可用软件,在故障切换过程中,MHA能做到在0~30秒之内自动完成数据库的故障切换操作,并且在进行故障切换的过程中,MHA能在最大程度上保证数据的一 ...
- (转)基于keepalived搭建MySQL的高可用集群
基于keepalived搭建MySQL的高可用集群 原文:http://www.cnblogs.com/ivictor/p/5522383.html MySQL的高可用方案一般有如下几种: keep ...
- Hadoop 3.1.2(HA)+Zookeeper3.4.13+Hbase1.4.9(HA)+Hive2.3.4+Spark2.4.0(HA)高可用集群搭建
目录 目录 1.前言 1.1.什么是 Hadoop? 1.1.1.什么是 YARN? 1.2.什么是 Zookeeper? 1.3.什么是 Hbase? 1.4.什么是 Hive 1.5.什么是 Sp ...
- MHA 高可用集群搭建(二)
MHA 高可用集群搭建安装scp远程控制http://www.cnblogs.com/kevingrace/p/5662839.html yum install openssh-clients mys ...
- rancher1.6高可用集群搭建
rancher高可用集群搭建 一.搭建环境 1.安装系统 下载centos最新版, http://mirrors.sohu.com/centos/7/isos/x86_64/CentOS-7-x86_ ...
- MySQL MHA 高可用集群部署及故障切换
MySQL MHA 高可用集群部署及故障切换 1.概念 2.搭建MySQL + MHA 1.概念: a)MHA概念 : MHA(MasterHigh Availability)是一套优秀的MySQL高 ...
- hadoop高可用集群搭建小结
hadoop高可用集群搭建小结1.Zookeeper集群搭建2.格式化Zookeeper集群 (注:在Zookeeper集群建立hadoop-ha,amenode的元数据)3.开启Journalmno ...
- Spark高可用集群搭建
Spark高可用集群搭建 node1 node2 node3 1.node1修改spark-env.sh,注释掉hadoop(就不用开启Hadoop集群了),添加如下语句 export ...
随机推荐
- 解决 504 Gateway Time-out和502 Bad Gateway(nginx)
504 Gateway Time-out 问题所在: 所请求的网关没有请求到,简单来说就是没有请求到可以执行的PHP-CGI. 一般看来, 这种情况可能是由于nginx默认的fastcgi进程响应的缓 ...
- Paypal支付接口
先吐槽一下,国外的创业环境真的远远好于国内的创业环境. vps便宜,网络质量好,没有各种政策监管,各种便捷的金融工具.这其中就包括paypal. Paypal 支持两种付款方式,信用卡+paypal注 ...
- iPhone的Push(推送通知)功能原理浅析
第一部分:Push原理(以下绝大多数内容参考自.图片来自iPhone OS Reference Library)机制简介Push 的工作机制可以简单的概括为下图图中,Provider是指某个iPhon ...
- halcon车牌的识别
read_image (Audi2, 'audi2') fill_interlace (Audi2, ImageFilled, 'odd') dev_set_color('green') thresh ...
- 【转】Eclipse打JAR包,插件FatJar安装与使用
原文地址:http://blog.csdn.net/jikeyzhang/article/details/4731968 下载RUL: 下载fatJar插件,解压缩后是一个.../plugins/(n ...
- InnoSetup 如何获取安装程序的路径?
两个常量可以使用: {srcexe} 安装程序执行文件的路径. {src} 安装程序所在路径. path := ExpandConstant('{srcexe}');
- 假期实践作业:从IT角度看地铁
实习时间:2016/02/23——2016/02/26 实习地点:京港地铁14号线 实习报告: 大学四年过得真快,转眼就大三了,大学前两年半的生活可谓多姿多彩,从不懂计算机到对编程感兴趣,期待得最多的 ...
- Angular ngClick 阻止冒泡和默认行为
这其实是一个很简单的问题,如果你认真查看过Angular官方的API文档,本来不想记录的.但是这个问题不止一次的被人问起,所以今天在记录在这里. 在Angular中已经对一些ng事件如ngClick, ...
- memcache(三)内存管理
memcached(三)内存管理 memcached使用预申请的方式来管理内存的分配,从而避免内存碎片化的问题.如果采用mallo和free来动态的申请和销毁内存,必然会产生大量的内存碎片. 基本知识 ...
- Gradle中的buildScript代码块
在编写Gradle脚本的时候,在build.gradle文件中经常看到这样的代码: build.gradle 1 2 3 4 5 6 7 8 9 buildScript { repositories ...