mysql5.7 Percona XtraDB Cluster 多主集群配置

来源:互联网 发布:怎么样优化关键词 编辑:程序博客网 时间:2024/06/07 00:04
1.添加用户和组
groupadd -g 1001 mysql
useradd  -u 1002 -g mysql mysql


2.关闭防火墙及selinux  /etc/selinux/config
service iptables stop
chkconfig iptables off
setenforce 0


3.创建目录
mkdir -p /u01/mysqldata /u01/mysqlredo /u01/mysqlundo /u01/mysqllog
chown -R mysql:mysql /u01


4.修改主机名
cat >> /etc/hosts << EOF
192.168.194.139 mgc1
192.168.194.141 mgc2
192.168.194.137 mgc3
EOF


5.安装xtraDB
处理依赖包
yum install -y libev-4.03-3.el6.x86_64.rpm
yum install -y socat-1.7.2.3-1.el6.x86_64.rpm


安装YUM源 
yum install -y http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm


检查包是否可用 
yum list | grep Percona-XtraDB-Cluster-57 


安装Percona XtraDB集群包 
yum install -y Percona-XtraDB-Cluster-57 


6.查看mysql启动参数文件默认顺序
mysql --help|grep 'my.cnf'


7.修改启动配置文件
[mysqld]
#server_id=1
datadir=/u01/mysqldata
pid-file=/u01/mysqldata/mysql.pid
log-error=/u01/mysqllog/mysql.log
socket=/var/lib/mysql/mysql.sock
user=mysql
port=5919
slow_query_log=1
slow_query_log_file=/u01/mysqllog/slow.log
#[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_address="gcomm://mgc1,mgc2,mgc3"
wsrep_cluster_name="Mysql5.7_Cluster"
binlog_format=row
#wsrep_sst_method=rsync
wsrep_sst_method=xtrabackup-v2
wsrep_node_address=192.168.194.141
default_storage_engine=InnoDB
wsrep_slave_threads= 8
# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2
pxc_strict_mode=ENFORCING
wsrep_sst_auth="sstuser:sstuser"




8.在第一个节点启动
service mysql bootstrap-pxc


9.在第一个节点登录并重置密码,mysql5.7在安装日志找初始密码
cat /u01/mysqllog/mysql.log  |grep root@localhost
mysql -uroot -p
SET PASSWORD=PASSWORD('root');
GRANT ALL PRIVILEGES ON *.* TO ' root '@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
GRANT PROCESS,RELOAD,LOCK TABLES,REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost' IDENTIFIED BY 'sstuser';


10.启动剩下的所有节点
service mysql start


可能出现的问题
集群所有节点宕机,启动集群的命令如果不是在最后一个脱离环境节点执行,会报出如下错误
2017-11-28T06:28:52.573503Z 0 [ERROR] WSREP: It may not be safe to bootstrap the cluster from this node. It was not the last one to leave the cluster and may not contain all the updates. To force cluster bootstrap with this node, edit the grastate.dat file manually and set safe_to_bootstrap to 1 .
解决方法:所有节点cat grastate.dat |grep safe_to_bootstrap 找到 safe_to_bootstrap 为1的节点来启动集群 或者grastate.dat文件里seqno,找到最大的那个
非特殊场景下,不要使用报错信息里修改 safe_to_bootstrap 为1 来强制启动。虽然最终能成功启动集群,但是各个节点的数据已经不在一致了。
到了上一步并还没有到无法挽救的地步,此时,只有一个方法,你要知道你哪一台的数据是最全的,然后停掉所有少数据的节点,再最后一个节点做一次任意dml操作(或者修改上面提到的seqno(只是个人猜测))。接下来最后一个节点重启动集群,在启动所有少数据的节点,下面所有少数据的节点会自动重新同步数据




安装过程出现如下信息
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'"


参阅了https://www.percona.com/doc/percona-server/5.6/management/udf_percona_toolkit.html 
不是很了解什么是udf


mysql -uroot -p -e "CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'libmurmur_udf.so'"


原创粉丝点击