-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 4444 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 4567 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 4568 -j ACCEPT service iptables reload
3.3 关闭selinux
临时关闭
1
setenforce 0
永久关闭:
1 2
vi /etc/sysconfig/selinux SELINUX=disabled
确认已经关闭
1 2
[root@mydbt001 local]# getenforce Disabled
3.4 创建MySQL 用户
1 2
groupadd mysql useradd -r -g mysql -s /bin/false mysql
[root@mydbt001 pxc]# xtrabackup --defaults-file=/etc/my.cnf -uroot -pPassword123 --backup --target-dir=/pxc/ xtrabackup: recognized server arguments: --datadir=/data/mysql --open_files_limit=65535 --server-id=1003306 --log_bin=/data/mysql/mysql-bin --innodb_buffer_pool_size=100M --innodb_data_file_path=ibdata1:1024M:autoextend --innodb_flush_log_at_trx_commit=2 --innodb_log_buffer_size=64M --innodb_log_file_size=256M --innodb_log_files_in_group=3 --innodb_max_dirty_pages_pct=90 --innodb_file_per_table=1 --innodb_io_capacity=2000 --innodb_flush_method=O_DIRECT xtrabackup: recognized client arguments: --datadir=/data/mysql --open_files_limit=65535 --server-id=1003306 --log_bin=/data/mysql/mysql-bin --innodb_buffer_pool_size=100M --innodb_data_file_path=ibdata1:1024M:autoextend --innodb_flush_log_at_trx_commit=2 --innodb_log_buffer_size=64M --innodb_log_file_size=256M --innodb_log_files_in_group=3 --innodb_max_dirty_pages_pct=90 --innodb_file_per_table=1 --innodb_io_capacity=2000 --innodb_flush_method=O_DIRECT --port=3306 --socket=/tmp/mysql.sock --user=root --password=* --backup=1 --target-dir=/pxc/ 190702 09:42:52 version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup;port=3306;mysql_socket=/tmp/mysql.sock' as 'root' (using password: YES). 190702 09:42:52 version_check Connected to MySQL server 190702 09:42:52 version_check Executing a version check against the server... 190702 09:42:52 version_check Done. 190702 09:42:52 Connecting to MySQL server host: localhost, user: root, password: set, port: 3306, socket: /tmp/mysql.sock Using server version 5.7.22-22-29.26-log xtrabackup version 2.4.14 based on MySQL server 5.7.19 Linux (x86_64) (revision id: ef675d4) xtrabackup: uses posix_fadvise(). xtrabackup: cd to /data/mysql xtrabackup: open files limit requested 65535, set to 65535 xtrabackup: using the following InnoDB configuration: xtrabackup: innodb_data_home_dir = . xtrabackup: innodb_data_file_path = ibdata1:1024M:autoextend xtrabackup: innodb_log_group_home_dir = ./ xtrabackup: innodb_log_files_in_group = 3 xtrabackup: innodb_log_file_size = 268435456 xtrabackup: using O_DIRECT InnoDB: Number of pools: 1 190702 09:42:52 >> log scanned up to (2638564) xtrabackup: Generating a list of tablespaces InnoDB: Allocated tablespace ID 2 for mysql/plugin, old maximum was 0 190702 09:42:52 [01] Copying ./ibdata1 to /pxc/ibdata1 190702 09:42:53 >> log scanned up to (2638564)
……
备份完成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
xtrabackup: The latest check point (for incremental): '2647383' xtrabackup: Stopping log copying thread. .190702 09:43:11 >> log scanned up to (2647392)
190702 09:43:11 Executing UNLOCK TABLES 190702 09:43:11 All tables unlocked 190702 09:43:11 [00] Copying ib_buffer_pool to /pxc/ib_buffer_pool 190702 09:43:11 [00] ...done 190702 09:43:11 Backup created in directory '/pxc/' 190702 09:43:11 [00] Writing /pxc/backup-my.cnf 190702 09:43:11 [00] ...done 190702 09:43:11 [00] Writing /pxc/xtrabackup_info 190702 09:43:11 [00] ...done xtrabackup: Transaction log of lsn (2638555) to (2647392) was copied. 190702 09:43:11 completed OK! [root@mydbt001 pxc]#
备份完成时间是 190702 09:43:43
6.3.2 传输备份到目标主机
1
scp -r pxc 10.31.91.204:/
6.3.3 目标节点 prepare 数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[root@fengshuo local]# xtrabackup --defaults-file=/etc/my.cnf --prepare target-dir=/pxc/ xtrabackup: recognized server arguments: --datadir=/data/mysql --open_files_limit=65535 --server-id=1003306 --log_bin=/data/mysql/mysql-bin --innodb_buffer_pool_size=100M --innodb_data_file_path=ibdata1:1024M:autoextend --innodb_flush_log_at_trx_commit=2 --innodb_log_buffer_size=64M --innodb_log_file_size=256M --innodb_log_files_in_group=3 --innodb_max_dirty_pages_pct=90 --innodb_file_per_table=1 --innodb_io_capacity=2000 --innodb_flush_method=O_DIRECT xtrabackup: recognized client arguments: --datadir=/data/mysql --open_files_limit=65535 --server-id=1003306 --log_bin=/data/mysql/mysql-bin --innodb_buffer_pool_size=100M --innodb_data_file_path=ibdata1:1024M:autoextend --innodb_flush_log_at_trx_commit=2 --innodb_log_buffer_size=64M --innodb_log_file_size=256M --innodb_log_files_in_group=3 --innodb_max_dirty_pages_pct=90 --innodb_file_per_table=1 --innodb_io_capacity=2000 --innodb_flush_method=O_DIRECT --port=3306 --socket=/tmp/mysql.sock --prepare=1 xtrabackup: Error: unknown argument: 'target-dir=/pxc/' [root@fengshuo local]# xtrabackup --defaults-file=/etc/my.cnf --prepare --target-dir=/pxc/ xtrabackup: recognized server arguments: --innodb_checksum_algorithm=crc32 --innodb_log_checksum_algorithm=strict_crc32 --innodb_data_file_path=ibdata1:1024M:autoextend --innodb_log_files_in_group=3 --innodb_log_file_size=268435456 --innodb_fast_checksum=0 --innodb_page_size=16384 --innodb_log_block_size=512 --innodb_undo_directory=./ --innodb_undo_tablespaces=0 --server-id=1003306 --redo-log-version=1 xtrabackup: recognized client arguments: --innodb_checksum_algorithm=crc32 --innodb_log_checksum_algorithm=strict_crc32 --innodb_data_file_path=ibdata1:1024M:autoextend --innodb_log_files_in_group=3 --innodb_log_file_size=268435456 --innodb_fast_checksum=0 --innodb_page_size=16384 --innodb_log_block_size=512 --innodb_undo_directory=./ --innodb_undo_tablespaces=0 --server-id=1003306 --redo-log-version=1 --prepare=1 --target-dir=/pxc/ xtrabackup version 2.4.12 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 170eb8c) xtrabackup: cd to /pxc/ xtrabackup: This target seems to be not prepared yet. InnoDB: Number of pools: 1 xtrabackup: xtrabackup_logfile detected: size=8388608, start_lsn=(2638555) xtrabackup: using the following InnoDB configuration for recovery: xtrabackup: innodb_data_home_dir = . xtrabackup: innodb_data_file_path = ibdata1:1024M:autoextend xtrabackup: innodb_log_group_home_dir = .
……
1 2 3 4 5 6 7 8 9 10 11
InnoDB: File './ibtmp1' size is now 12 MB. InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active. InnoDB: 32 non-redo rollback segment(s) are active. InnoDB: Waiting for purge to start InnoDB: page_cleaner: 1000ms intended loop took 7793ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.) InnoDB: 5.7.19 started; log sequence number 2648597 xtrabackup: starting shutdown with innodb_fast_shutdown = 1 InnoDB: FTS optimize thread exiting. InnoDB: Starting shutdown... InnoDB: Shutdown completed; log sequence number 2648616 190702 10:06:08 completed OK!
6.4 安装 pxc 软件
采用二进制软件包的方式按照,直接复制软件包到 basedir,并创建软连。
1 2 3
cp /usr/local/src/Percona-XtraDB-Cluster-5.7.25-rel28-31.35.1.Linux.x86_64.ssl101.tar.gz / /usr/local/ ln -s Percona-XtraDB-Cluster-5.7.25-rel28-31.35.1.Linux.x86_64.ssl101 mysql
mysql> create user repl@'%' identified by 'Repl1234'; Query OK, 0 rows affected (0.04 sec) grant replication slave, replication client on *.* to repl@'%';
2019-07-03T12:27:34.666497Z 0 [Warning] WSREP: Fail to access the file (/data/mysql//gvwstate.dat) error (No such file or directory). It is possible if node is booting for first time or re-booting after a graceful shutdown 2019-07-03T12:27:34.669345Z 0 [Warning] WSREP: (ef903445, 'tcp://0.0.0.0:4567') address 'tcp://10.31.91.204:4567' points to own listening address, blacklisting 2019-07-03T12:27:35.669742Z 1 [Warning] WSREP: Gap in state sequence. Need state transfer. 2019-07-03T12:27:36.832833Z WSREP_SST: [INFO] xtrabackup_ist received from donor: Running IST 2019-07-03T12:27:36.834756Z WSREP_SST: [INFO] Galera co-ords from recovery: b25b348e-9c06-11e9-84f5-ce5173cbcbb4:50 2019-07-03T12:27:37.405886Z 0 [Warning] CA certificate ca.pem is self signed. 2019-07-03T12:27:37.458437Z 0 [Warning] Neither --relay-log nor --relay-log-index were used; so replication may break when this MySQL server acts as a slave and has his hostname changed!! Please use '--relay-log=fengshuo-relay-bin' to avoid this problem. 2019-07-03T12:27:37.470574Z 0 [Warning] Recovery from master pos 12798 and file mysql-bin.000002 for channel ''. Previous relay log pos and relay log file had been set to 320, ./fengshuo-relay-bin.000005 respectively.
加入集群成功
6.6.5 检查pxc集群状态
1 2 3 4 5 6 7 8 9 10 11 12 13
mysql> show status like '%wsrep_cluster%' -> ; +--------------------------+--------------------------------------+ | Variable_name | Value | +--------------------------+--------------------------------------+ | wsrep_cluster_conf_id | 21 | | wsrep_cluster_size | 3 | | wsrep_cluster_state_uuid | b25b348e-9c06-11e9-84f5-ce5173cbcbb4 | | wsrep_cluster_status | Primary | +--------------------------+--------------------------------------+ 4 rows in set (0.00 sec) mysql>