1.准备阶段
1.1 在三个节点上分别创建:用户组 用户组 目录
--用户组 用户组
#/usr/sbin/groupadd mysql
#/usr/sbin/useradd -g mysql mysql
--目录
#mkdir –p /usr/local/mysql
#chown -R mysql:mysql /usr/local/mysql
#chmod -R 755 /usr/local/mysql
#mkdir -p /mysql/3306/{data,redo,binlog,tmp,logs}
#chown -R mysql:mysql /mysql
#chmod -R 755 /mysql
1.2 修改内核参数
切换到root用户
[root@DBMysql2 ~]# vi /etc/security/limits.conf
mysql soft nproc 65535
mysql hard nproc 65535
mysql soft nofile 65535
mysql hard nofile 65535
[root@node1 ~]#
2.开始部署
2.1 三个节点分别安装依赖包:
yum -y install percona-xtrabackup-24-2.4.12-1.el7.x86_64.rpm
yum -y install
2.2 解压Percona-XtraDB-Cluster
在mysql用户下,将压缩包(Percona-XtraDB-Cluster-5.7.23-rel23-31.31.2.Linux.x86_64.ssl101.tar)解压到 /usr/local/mysql下
[mysql@node1 mysql]$ pwd
/usr/local/mysql
[mysql@node1 mysql]$ ls -l
总用量 88
drwxrwxr-x. 2 mysql mysql 4096 12月 19 14:28 bin
-rw-rw-r--. 1 mysql mysql 17987 12月 19 14:31 COPYING
-rw-rw-r--. 1 mysql mysql 1703 12月 19 14:31 COPYING-jemalloc
-rw-rw-r--. 1 mysql mysql 17987 12月 19 14:31 COPYING-test
drwxrwxr-x. 2 mysql mysql 55 12月 19 14:28 docs
drwxrwxr-x. 3 mysql mysql 4096 12月 19 14:28 include
drwxrwxr-x. 4 mysql mysql 228 12月 19 14:28 lib
drwxrwxr-x. 4 mysql mysql 30 12月 19 14:28 man
drwxrwxr-x. 10 mysql mysql 4096 12月 19 14:31 mysql-test
drwxrwxr-x. 5 mysql mysql 50 12月 19 14:31 percona-xtradb-cluster-tests
-rw-rw-r--. 1 mysql mysql 2478 12月 19 14:31 README.MySQL
-rw-rw-r--. 1 mysql mysql 444 12月 19 14:31 README-test
-rw-rw-r--. 1 mysql mysql 19626 12月 19 14:31 README-wsrep
drwxrwxr-x. 28 mysql mysql 4096 12月 19 14:31 share
drwxrwxr-x. 2 mysql mysql 110 12月 19 14:31 support-files
drwxrwxr-x. 2 mysql mysql 22 12月 19 14:31 xinetd.d
[mysql@node1 mysql]$
2.3 创建my.cnf配置文件(只截取pxc部分)
#pxc
server_id = 1
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so
wsrep_cluster_name=pxc-mysql
wsrep_cluster_address=gcomm://192.168.2.55,192.168.2.56,192.168.2.57
wsrep_node_name=node1
wsrep_node_address=192.168.2.55
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth=pxc:123456
pxc_strict_mode=ENFORCING
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
注意:
其他两个个节点,只需要修改:
server-id=1 --id不能一样
wsrep_node_name=node1 --改成自己节点的主机名
wsrep_node_address=192.168.2.55 --改成自己节点的主机IP
2.4 各个节点分别初始化数据库:
./mysqld --defaults-file=/mysql/3306/my.cnf --initialize
./mysqld --defaults-file=/mysql/3306/my.cnf --initialize
./mysqld --defaults-file=/mysql/3306/my.cnf --initialize
2.5 启动节点node1
./mysqld_safe --defaults-file=/mysql/3306/my.cnf --wsrep-new-cluster &
2.6 在node1节点修改密码,创建复制用户
--修改密码
(root@localhost:mysql.sock) [(none)]>set password='123456';
Query OK, 0 rows affected (0.32 sec)
---创建一个SST用户
(root@localhost:mysql.sock) [(none)]>GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO 'pxc'@'%' IDENTIFIED BY '123456'; ---创建一个SST用户
2.7 启动节点node2、node3
./mysqld_safe --defaults-file=/mysql/3306/my.cnf --user=mysql &
./mysqld_safe --defaults-file=/mysql/3306/my.cnf --user=mysql &
3、验证集群
--节点node1
(root@localhost:mysql.sock) [(none)]>show status like 'wsrep_cluster_%';
+--------------------------+--------------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------------+
| wsrep_cluster_weight | 3 |
| wsrep_cluster_conf_id | 3 | --表示3个节点
| wsrep_cluster_size | 3 |
| wsrep_cluster_state_uuid | 1814041e-0365-11e9-9a41-53781b688bfb |
| wsrep_cluster_status | Primary |
+--------------------------+--------------------------------------+
5 rows in set (0.00 sec)
(root@localhost:mysql.sock) [(none)]>
--任意一个节点执行创建数据库操作,看其他节点是否同步
PXC-01:
(root@localhost:mysql.sock) [(none)]>> create database pxc01; #注意查看其他节点是否同步
PXC-02:
(root@localhost:mysql.sock) [(none)]>> create database pxc02; #注意查看其他节点是否同步
PXC-03:
(root@localhost:mysql.sock) [(none)]>> create database pxc03; #注意查看其他节点是否同步
停止数据库:
--最后停主节点
./mysqladmin --defaults-file=/mysql/3306/my.cnf -uroot -p123456 -hlocalhost shutdown
4.部署期间遇到的问题:
--关闭防火墙:systemctl stop firewalld
2018-12-19T08:44:46.598184Z 0 [Warning] WSREP: last inactive check more than PT1.5S (3*evs.inactive_check_period) ago (PT3.5271S), skipping check
2018-12-19T08:45:16.264325Z 0 [Note] WSREP: Current view of cluster as seen by this node
view ((empty))
2018-12-19T08:45:16.266833Z 0 [ERROR] WSREP: failed to open gcomm backend connection: 110: failed to reach primary view (pc.wait_prim_timeout): 110 (Connection timed out)
at gcomm/src/pc.cpp:connect():159
2018-12-19T08:45:16.267665Z 0 [ERROR] WSREP: gcs/src/gcs_core.cpp:gcs_core_open():209: Failed to open backend connection: -110 (Connection timed out)
2018-12-19T08:45:16.272534Z 0 [ERROR] WSREP: gcs/src/gcs.cpp:gcs_open():1514: Failed to open channel 'pxc-mysql' at 'gcomm://192.168.2.55,192.168.2.56,192.168.2.57': -110 (Connection timed out)
2018-12-19T08:45:16.272618Z 0 [ERROR] WSREP: gcs connect failed: Connection timed out
2018-12-19T08:45:16.272647Z 0 [ERROR] WSREP: Provider/Node (gcomm://192.168.2.55,192.168.2.56,192.168.2.57) failed to establish connection with cluster (reason: 7)
2018-12-19T08:45:16.272676Z 0 [ERROR] Aborting
2018-12-19T08:45:16.272695Z 0 [Note] Giving 0 client threads a chance to die gracefully
2018-12-19T08:45:16.272723Z 0 [Note] WSREP: Waiting for active wsrep applier to exit
2018-12-19T08:45:16.272741Z 0 [Note] WSREP: Service disconnected.
2018-12-19T08:45:16.272756Z 0 [Note] WSREP: Waiting to close threads......
2018-12-19T08:45:21.274280Z 0 [Note] WSREP: Some threads may fail to exit.
2018-12-19T08:45:21.275314Z 0 [Note] Binlog end
2018-12-19T08:45:21.277021Z 0 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
--安装 percona-xtrabackup-24-2.4.12-1.el7.x86_64.rpm
2018-12-20T05:53:59.541638Z 0 [Note] WSREP: Initiating SST/IST transfer on JOINER side (wsrep_sst_xtrabackup-v2 --role 'joiner' --address '192.168.2.56' --datadir '/my
sql/3306/data/' --defaults-file '/mysql/3306/my.cnf' --defaults-group-suffix '' --parent '14448' --mysqld-version '5.7.23-23-31.31' '' )
which: no xtrabackup in (/usr/sbin:/sbin:/usr/local/mysql/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/mysql/.local/bin:/home/mysql/bin)
2018-12-20T05:53:59.695991Z WSREP_SST: [ERROR] ******************* FATAL ERROR **********************
2018-12-20T05:53:59.700710Z WSREP_SST: [ERROR] xtrabackup not in path: /usr/sbin:/sbin:/usr/local/mysql/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/s
bin:/home/mysql/.local/bin:/home/mysql/bin
2018-12-20T05:53:59.705288Z WSREP_SST: [ERROR] ******************************************************
2018-12-20T05:53:59.708133Z 0 [ERROR] WSREP: Failed to read 'ready <addr>' from: wsrep_sst_xtrabackup-v2 --role 'joiner' --address '192.168.2.56' --datadir '/mysql/330
6/data/' --defaults-file '/mysql/3306/my.cnf' --defaults-group-suffix '' --parent '14448' --mysqld-version '5.7.23-23-31.31' ''
Read: '(null)'
2018-12-20T05:53:59.708181Z 0 [ERROR] WSREP: Process completed with error: wsrep_sst_xtrabackup-v2 --role 'joiner' --address '192.168.2.56' --datadir '/mysql/3306/data
/' --defaults-file '/mysql/3306/my.cnf' --defaults-group-suffix '' --parent '14448' --mysqld-version '5.7.23-23-31.31' '' : 2 (No such file or directory)
2018-12-20T05:53:59.708302Z 2 [ERROR] WSREP: Failed to prepare for 'xtrabackup-v2' SST. Unrecoverable.
2018-12-20T05:53:59.708333Z 2 [ERROR] Aborting
---主节点忘记安装:percona-xtrabackup-24-2.4.12-1.el7.x86_64.rpm
2018-12-20T07:27:52.624492Z 2 [Note] WSREP: Requesting state transfer: success, donor: 0
2018-12-20T07:27:52.624544Z 2 [Note] WSREP: GCache history reset: 00000000-0000-0000-0000-000000000000:0 -> 1814041e-0365-11e9-9a41-53781b688bfb:3
2018-12-20T07:27:52.769911Z 0 [Warning] WSREP: 0.0 (node1): State transfer to 1.0 (node2) failed: -2 (No such file or directory)
2018-12-20T07:27:52.769950Z 0 [ERROR] WSREP: gcs/src/gcs_group.cpp:gcs_group_handle_join_msg():766: Will never receive state. Need to abort.
2018-12-20T07:27:52.770158Z 0 [Note] WSREP: gcomm: terminating thread
2018-12-20T07:27:52.770181Z 0 [Note] WSREP: gcomm: joining thread