节点分配
IP
|
hostname
|
用途
|
192.168.137.201
|
c1
|
node1
|
192.168.137.202
|
c2
|
node2
|
192.168.137.203
|
c3
|
node3
|
需要的包
percona-xtrabackup-24-2.4.7-2.el6.x86_64.rpm
Percona-XtraDB-Cluster-5.7.18-rel15-29.20.1.Linux.x86_64.ssl101.tar.gz
安装epel源(所有节点)
centos6
rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
centos7
rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
安装依赖包
yum install perl-IO-Socket-SSL perl-DBD-MySQL perl-Time-HiRes socat nc -y
安装xtrabackup
wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.7/binary/redhat/6/x86_64/percona-xtrabackup-24-2.4.7-2.el6.x86_64.rpm
rpm -ivh percona-xtrabackup-24-2.4.7-2.el6.x86_64.rpm
数据库初始化
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3306/data --user=mysql --initialize
修改mysqld_safe启动文件
#####具体需要替换的路径根据安装的包名称去mysqld_safe文件中查询#############
sed -i 's#/mnt/workspace/percona-xtradb-cluster-5.7-binary-tarball/label_exp/centos6-64/Percona-XtraDB-Cluster-5.7.18-29.20/346/usr/local/Percona-XtraDB-Cluster-5.7.18-rel15-29.20.1.Linux.x86_64.ssl101#/usr/local/mysql#g' /usr/local/mysql/bin/mysqld_safe
vi /usr/local/mysql/support-files/mysql.server
basedir=/usr/local/mysql
datadir=/data/mysql/mysql3306/data
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
添加PXC相关的参数
vi /etc/my.cnf
[mysqld]
...
#PXC
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.137.201,192.168.137.202,192.168.137.203
wsrep_node_address=192.168.137.201
wsrep_slave_threads=2
innodb_autoinc_lock_mode=2
binlog_format = ROW
default_storage_engine=InnoDB
wsrep_cluster_name=pxc-jiangzq
wsrep_sst_auth=sst:jiangzq
wsrep_sst_method=xtrabackup-v2
检查环境
[root@c1 xtrabackup]# /etc/init.d/mysql --help
Usage: mysql {start|stop|restart|restart-bootstrap|reload|force-reload|status|bootstrap-pxc} [ MySQL (Percona XtraDB Cluster) options ]
启动第一个节点
shell>/etc/init.d/mysql bootstrap-pxc
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf bootstrap-pxc &
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf bootstrap-pxc
修改root密码和添加sst账户
alter user user() identified by 'root';
create user 'sst'@'localhost' identified by 'jiangz';
grant all on *.* to 'sst'@'localhost';
将整个虚拟机再克隆两个
#####修改主机名
shell>hostname c2
shell>vi /etc/sysconfig/network
hostname=c2
#####修改ip地址
shell>vi /etc/sysconfig/network-script/ifcfg-eth0
shell>service network restart
#####修改mysql配置文件
shell>vi /etc/my.cnf
server-id=203306
pid-file = c2.pid
wsrep_node_address=192.168.137.202
第2、3个节点启动
遇到的错误
##############启动第二个节点报的错误###############
2017-07-18T06:40:24.829678Z 0 [ERROR] WSREP: Failed to read 'ready ' from: wsrep_sst_xtrabackup-v2 --role 'joiner' --address '192.168.137.202' --datadir '/data/mysql/mysql3306/data/' --defaults-file '/etc/my.cnf' --defaults-group-suffix '' --parent '10520' --binlog '/data/mysql/mysql3306/logs/mysql-bin'
Read: '(null)'
2017-07-18T06:40:24.829714Z 0 [ERROR] WSREP: Process completed with error: wsrep_sst_xtrabackup-v2 --role 'joiner' --address '192.168.137.202'
--datadir '/data/mysql/mysql3306/data/' --defaults-file '/etc/my.cnf' --defaults-group-suffix '' --parent '10520' --binlog '/data/mysql/mysql3306/logs/mysql-bin' :
2 (No such file or directory)
selinux 没关和xtrabackup版本太低
日常启动关闭
#/etc/init.d/mysql stop
全部节点关闭后重启
第一个节点启动的节点( 如果集群全部关闭,第一个起动也需要用这样的形式)
#/etc/init.d/mysql bootstrap-pxc
其它节点
#/etc/init.d/mysql start
备注:
如集群是不是所有的节点都关闭不用使#/etc/init.d/mysql bootstrap-pxc 启动。都可以用
#/etc/init.d/mysql start
启动。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30236014/viewspace-2142358/,如需转载,请注明出处,否则将追究法律责任。