1、如果主节点已经运行了一段时间,且有大量数据时,如何配置并启动slave节点
#在主服务器上做完全备份,复制到从服务器上
[root@master ~]#mysqldump -A -F --single-transaction --master-data=1> /data/fullbackup.sql
[root@master ~]#scp/data/fullbackup.sql10.0.0.18:/data
The authenticity of host '10.0.0.18 (10.0.0.18)'can't be established.ECDSA key fingerprint is SHA256:E8oPeOCwQOdj6sRDLmQ9KsGivUoLOysv2Xj2/oUP0G4.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.0.0.18' (ECDSA) to the list of known hosts.
[email protected]'s password: fullbackup.sql100% 476KB78.9MB/s00:00
#将完全备份还原到新节点
[root@slave ~]#yum-yinstallmariadb-server
[root@slave ~]#vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
server-id=2read-only
[root@slave ~]#systemctl start mariadb.service
[root@slave ~]#grep'^CHANGE MASTER'/data/fullbackup.sql
CHANGE MASTER TO MASTER_LOG_FILE='mariadb-bin.000002', MASTER_LOG_POS=389;
[root@slave ~]#mysql < /data/fullbackup.sql
[root@slave ~]#mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection idis9Server version: 10.3.17-MariaDB MariaDB Server
Copyright (c) 2000,2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;'or'\h'forhelp. Type'\c'toclear the current input statement.
MariaDB [(none)]> CHANGE MASTER TO
-> MASTER_HOST='10.0.0.8',
-> MASTER_USER='repluser',
-> MASTER_PASSWORD='magedu',
-> MASTER_LOG_FILE='mariadb-bin.000002',
-> MASTER_LOG_POS=389;
Query OK, 0rows affected (0.003 sec)
MariaDB [(none)]> start slave;
Query OK, 0rows affected (0.001 sec)
MariaDB [(none)]> show slave status\G***************************1. row *************************** Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.0.8 Master_User: repluser
Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mariadb-bin.000002 Read_Master_Log_Pos: 586 Relay_Log_File: mariadb-relay-bin.000002 Relay_Log_Pos: 754 Relay_Master_Log_File: mariadb-bin.000002 Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0 Last_Error:
Skip_Counter: 0 Exec_Master_Log_Pos: 586 Relay_Log_Space: 1065 Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0 Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0 Last_IO_Error:
Last_SQL_Errno: 0 Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1 Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Replicate_Do_Domain_Ids:
Replicate_Ignore_Domain_Ids:
Parallel_Mode: conservative
SQL_Delay: 0 SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting forthe slave I/O thread to update it
Slave_DDL_Groups: 1Slave_Non_Transactional_Groups: 0 Slave_Transactional_Groups: 01rowinset (0.001sec)
2、当master服务器宕机,提升一个slave成为新的master
[root@slave ~]#vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
server-id=2read-only=OFF
log-bin=/data/mysql/mariadb-bin
[root@slave ~]#mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection idis13Server version: 10.3.17-MariaDB MariaDB Server
Copyright (c) 2000,2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;'or'\h'forhelp. Type'\c'toclear the current input statement.
MariaDB [(none)]> set global read_only=off;
Query OK, 0rows affected (0.000 sec)
MariaDB [(none)]> stop slave;
Query OK, 0rows affected (0.002 sec)
MariaDB [(none)]> reset slave all;
Query OK, 0rows affected (0.000 sec)
MariaDB [(none)]> show slave status;
Empty set (0.000 sec)
#后面将其他从节点指向新主
3、通过 MHA 0.58 搭建一个数据库集群结构
#给管理端安装mha-manager和mha-node包
[root@mha-manager ~]#yum-yinstallmha4mysql-node-0.58-0.el7.centos.noarch.rpm
[root@mha-manager ~]#yum-yinstallmha4mysql-manager-0.58-0.el7.centos.noarch.rpm
#给mysql服务器节点安装mha-node包
[root@master ~]#yum-yinstallmha4mysql-node-0.58-0.el7.centos.noarch.rpm
[root@slave1 ~]#yum-yinstallmha4mysql-node-0.58-0.el7.centos.noarch.rpm
[root@slave2 ~]#yum-yinstallmha4mysql-node-0.58-0.el7.centos.noarch.rpm
#在所有节点之间实现基于key验证
[root@mha-manager ~]#ssh-keygenGenerating public/private rsa key pair.
Enter fileinwhichto save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in/root/.ssh/id_rsa.
Your public key has been saved in/root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:fTNTrKIR3DWJFNW7fUJsCGz/JuKE7QIgfiSjhWrB/Rc root@mha-manager
The key's randomart image is:+---[RSA2048]----+| oo++o || . .=..o. ||... o..o oo. ||.o=.o E o oo= ||.+.=.. Soo *+ o ||o.. .....o+o.+= o||. . ...+ . o ..|| . o || . |+----[SHA256]-----+[root@mha-manager ~]#rsync -av .ssh10.0.0.8:
[email protected]'s password: sending incrementalfile list
.ssh/.ssh/authorized_keys
.ssh/id_rsa
.ssh/id_rsa.pub
.ssh/known_hosts
sent 4,007bytes received96bytes1,641.20bytes/sec
total size is 3,670speedup is0.89[root@mha-manager ~]#rsync -av .ssh10.0.0.18:
[email protected]'s password: sending incrementalfile list
.ssh/.ssh/authorized_keys
.ssh/id_rsa
.ssh/id_rsa.pub
.ssh/known_hosts
sent 4,007bytes received96bytes1,641.20bytes/sec
total size is 3,670speedup is0.89[root@mha-manager ~]#rsync -av .ssh10.0.0.28:
[email protected]'s password: sending incrementalfile list
.ssh/.ssh/authorized_keys
.ssh/id_rsa
.ssh/id_rsa.pub
.ssh/known_hosts
sent 4,007bytes received96bytes1,641.20bytes/sec
total size is 3,670speedup is0.89#在管理节点建立配置文件
[root@mha-manager ~]#mkdir/etc/mastermha/[root@mha-manager ~]#vim /etc/mastermha/app1.cnf
[server default]
user=mhauser
password=magedu
manager_workdir=/data/mastermha/app1/manager_log=/data/mastermha/app1/manager.log
remote_workdir=/data/mastermha/app1/ssh_user=root
repl_user=repluser
repl_password=magedu
ping_interval=1master_ip_failover_script=/usr/local/bin/master_ip_failover
report_script=/usr/local/bin/sendmail.shcheck_repl_delay=0master_binlog_dir=/data/mysql/[server1]hostname=10.0.0.8candidate_master=1
[server2]hostname=10.0.0.18master
[server3]hostname=10.0.0.28candidate_master=1#相关脚本
[root@mha-manager ~]#vim /usr/local/bin/sendmail.shecho"MySQL is down"| mail -s"MHA Warning"[email protected]
[root@mha-manager ~]#chmod+x /usr/local/bin/sendmail.sh[root@mha-manager ~]#vim /usr/local/bin/master_ip_failover
#!/usr/bin/envperluse strict;
use warnings FATAL =>'all';
use Getopt::Long;
my (
$command, $ssh_user, $orig_master_host, $orig_master_ip,
$orig_master_port, $new_master_host, $new_master_ip, $new_master_port
);
my $vip ='10.0.0.100/24';
my $gateway ='10.0.0.2';
my $interface ='eth0';
my $key ="1";
my $ssh_start_vip ="/sbin/ifconfig $interface:$key $vip;/sbin/arping -I $interface -c3-s $vip $gateway >/dev/null2>&1";my $ssh_stop_vip ="/sbin/ifconfig $interface:$key down";
GetOptions('command=s'=> \$command,'ssh_user=s'=> \$ssh_user,'orig_master_host=s'=> \$orig_master_host,'orig_master_ip=s'=> \$orig_master_ip,'orig_master_port=i'=> \$orig_master_port,'new_master_host=s'=> \$new_master_host,'new_master_ip=s'=> \$new_master_ip,'new_master_port=i'=> \$new_master_port,
);
exit &main();
sub main {
print "\n\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\n\n";if( $command eq"stop"|| $command eq"stopssh" ) {
# $orig_master_host, $orig_master_ip, $orig_master_port are passed.
# If you manage master ip address at global catalog database,
# invalidate orig_master_ip here.
my $exit_code =1;
eval {
print "Disabling the VIP on old master: $orig_master_host \n";&stop_vip();
$exit_code =0;
};if ($@) {
warn "Got Error: $@\n";
exit $exit_code;
}
exit $exit_code;
}
elsif ( $command eq "start" ) {
# all arguments are passed.
# If you manage master ip address at global catalog database,
# activate new_master_ip here.
# You can also grant writeaccess (create user, set read_only=0, etc) here.
my $exit_code =10;
eval {
print "Enabling the VIP - $vip on the new master - $new_master_host \n";&start_vip();
$exit_code =0;
};if ($@) {
warn $@;
exit $exit_code;
}
exit $exit_code;
}
elsif ( $command eq "status" ) {
print "Checking the Status of the script.. OK \n";
`ssh$ssh_user\@$orig_master_host \" $ssh_start_vip \"`;exit0;
}else {&usage();
exit 1;
}
}
# A simple system call that enable the VIP on the new master
sub start_vip() {
`ssh$ssh_user\@$new_master_host \" $ssh_start_vip \"`;}
# A simple system call that disable the VIP on the old_master
sub stop_vip() {
`ssh$ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;}
sub usage {
print"Usage: master_ip_failover --command=start|stop|stopssh|status --orig_master_host=host --orig_master_ip=ip --orig_master_port=port --new_master_host=host --new_master_ip=ip --new_master_port=port\n";}
[root@mha-manager ~]#chmod+x /usr/local/bin/master_ip_failover
#配置master
[root@master ~]#mkdir/data/mysql
[root@master ~]#chownmysql.mysql /data/mysql/[root@master ~]#vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=8log-bin=/data/mysql/mysql-bin
skip_name_resolve=1general_log
[root@master ~]#systemctl start mysqld.service
[root@master ~]#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection idis8Server version: 8.0.21 Source distribution
Copyright (c) 2000,2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'or'\h'forhelp. Type'\c'toclear the current input statement.
mysql> show master logs;+------------------+-----------+-----------+| Log_name | File_size | Encrypted |+------------------+-----------+-----------+| mysql-bin.000001|179| No || mysql-bin.000002|156| No |+------------------+-----------+-----------+2rowsinset (0.00 sec)
mysql> create user repluser@'10.0.0.%'identified by'magedu';
Query OK, 0rows affected (0.00 sec)
mysql> grant replication slave on *.* to repluser@'10.0.0.%';
Query OK, 0rows affected (0.00 sec)
mysql> create user mhauser@'10.0.0.%'identified by'magedu';
Query OK, 0rows affected (0.00 sec)
mysql> grant all on *.* to mhauser@'10.0.0.%';
Query OK, 0rows affected (0.00 sec)
[root@master ~]#ifconfigeth0:110.0.0.100/24#配置slave1
[root@slave1 ~]#mkdir/data/mysql
[root@slave1 ~]#chownmysql.mysql /data/mysql/[root@slave1 ~]#vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=18log-bin=/data/mysql/mysql-bin
read-only
relay_log_purge=0skip_name_resolve=1[root@slave1 ~]#systemctl start mysqld.service
[root@slave1 ~]#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection idis8Server version: 8.0.21 Source distribution
Copyright (c) 2000,2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'or'\h'forhelp. Type'\c'toclear the current input statement.
mysql> CHANGE MASTER TO
-> MASTER_HOST='10.0.0.8',
-> MASTER_USER='repluser',
-> MASTER_PASSWORD='magedu',
-> MASTER_LOG_FILE='mysql-bin.000002',
-> MASTER_LOG_POS=156;
Query OK, 0rows affected,2warnings (0.01 sec)
mysql> start slave;
Query OK, 0rows affected (0.00 sec)
mysql> show slave status\G***************************1. row *************************** Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.0.8 Master_User: repluser
Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000002 Read_Master_Log_Pos: 1201 Relay_Log_File: slave1-relay-bin.000002 Relay_Log_Pos: 1369 Relay_Master_Log_File: mysql-bin.000002 Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0 Last_Error:
Skip_Counter: 0 Exec_Master_Log_Pos: 1201 Relay_Log_Space: 1579 Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0 Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0 Last_IO_Error:
Last_SQL_Errno: 0 Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 8 Master_UUID: 00db05a9-1074-11eb-abdd-000c2980df3c
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0 SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting formore updates
Master_Retry_Count: 86400 Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0 Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0 Network_Namespace: 1rowinset (0.00 sec)
#配置slave2
[root@slave2 ~]#mkdir/data/mysql
[root@slave2 ~]#chownmysql.mysql /data/mysql
[root@slave2 ~]#vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=28log-bin=/data/mysql/mysql-bin
read-only
relay_log_purge=0skip_name_resolve=1[root@slave2 ~]#systemctl start mysqld.service
[root@slave2 ~]#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection idis8Server version: 8.0.21 Source distribution
Copyright (c) 2000,2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'or'\h'forhelp. Type'\c'toclear the current input statement.
mysql>
mysql> CHANGE MASTER TO
-> MASTER_HOST='10.0.0.8',
-> MASTER_USER='repluser',
-> MASTER_PASSWORD='magedu',
-> MASTER_LOG_FILE='mysql-bin.000002',
-> MASTER_LOG_POS=156;
Query OK, 0rows affected,2warnings (0.01 sec)
mysql> start slave;
Query OK, 0rows affected (0.00 sec)
mysql> show slave status\G***************************1. row *************************** Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.0.8 Master_User: repluser
Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000002 Read_Master_Log_Pos: 1201 Relay_Log_File: slave2-relay-bin.000002 Relay_Log_Pos: 1369 Relay_Master_Log_File: mysql-bin.000002 Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0 Last_Error:
Skip_Counter: 0 Exec_Master_Log_Pos: 1201 Relay_Log_Space: 1579 Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0 Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0 Last_IO_Error:
Last_SQL_Errno: 0 Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 8 Master_UUID: 00db05a9-1074-11eb-abdd-000c2980df3c
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0 SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting formore updates
Master_Retry_Count: 86400 Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0 Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0 Network_Namespace: 1rowinset (0.00 sec)
#检查管理端环境
[root@mha-manager ~]#masterha_check_ssh --conf=/etc/mastermha/app1.cnf
Sat Oct 1712:37:112020- [warning] Global configurationfile/etc/masterha_default.cnf not found. Skipping.
Sat Oct 1712:37:112020- [info] Reading application default configuration from /etc/mastermha/app1.cnf..
Sat Oct 1712:37:112020- [info] Reading server configuration from /etc/mastermha/app1.cnf..
Sat Oct 1712:37:112020- [info] Starting SSH connection tests..
Sat Oct 1712:37:122020- [debug]
Sat Oct 1712:37:112020- [debug] Connecting via SSH from [email protected](10.0.0.8:22) to [email protected](10.0.0.18:22)..
Sat Oct 1712:37:112020- [debug] ok.
Sat Oct 1712:37:112020- [debug] Connecting via SSH from [email protected](10.0.0.8:22) to [email protected](10.0.0.28:22)..
Sat Oct 1712:37:112020- [debug] ok.
Sat Oct 1712:37:122020- [debug]
Sat Oct 1712:37:112020- [debug] Connecting via SSH from [email protected](10.0.0.18:22) to [email protected](10.0.0.8:22)..
Sat Oct 1712:37:112020- [debug] ok.
Sat Oct 1712:37:112020- [debug] Connecting via SSH from [email protected](10.0.0.18:22) to [email protected](10.0.0.28:22)..
Sat Oct 1712:37:122020- [debug] ok.
Sat Oct 1712:37:132020- [debug]
Sat Oct 1712:37:122020- [debug] Connecting via SSH from [email protected](10.0.0.28:22) to [email protected](10.0.0.8:22)..
Sat Oct 1712:37:122020- [debug] ok.
Sat Oct 1712:37:122020- [debug] Connecting via SSH from [email protected](10.0.0.28:22) to [email protected](10.0.0.18:22)..
Sat Oct 1712:37:122020- [debug] ok.
Sat Oct 1712:37:132020- [info] All SSH connection tests passed successfully.
[root@mha-manager ~]#masterha_check_repl --conf=/etc/mastermha/app1.cnf
Sat Oct 1712:37:432020- [warning] Global configurationfile/etc/masterha_default.cnf not found. Skipping.
Sat Oct 1712:37:432020- [info] Reading application default configuration from /etc/mastermha/app1.cnf..
Sat Oct 1712:37:432020- [info] Reading server configuration from /etc/mastermha/app1.cnf..
Sat Oct 1712:37:432020- [info] MHA::MasterMonitor version0.58.
Sat Oct 1712:37:442020- [info] GTID failover mode =0Sat Oct 1712:37:442020- [info] Dead Servers:
Sat Oct 1712:37:442020- [info] Alive Servers:
Sat Oct 1712:37:442020- [info]10.0.0.8(10.0.0.8:3306)
Sat Oct 1712:37:442020- [info]10.0.0.18(10.0.0.18:3306)
Sat Oct 1712:37:442020- [info]10.0.0.28(10.0.0.28:3306)
Sat Oct 1712:37:442020- [info] Alive Slaves:
Sat Oct 1712:37:442020- [info]10.0.0.18(10.0.0.18:3306) Version=8.0.21(oldest major version between slaves) log-bin:enabled
Sat Oct 1712:37:442020- [info] Replicating from10.0.0.8(10.0.0.8:3306)
Sat Oct 1712:37:442020- [info]10.0.0.28(10.0.0.28:3306) Version=8.0.21(oldest major version between slaves) log-bin:enabled
Sat Oct 1712:37:442020- [info] Replicating from10.0.0.8(10.0.0.8:3306)
Sat Oct 1712:37:442020- [info] Primary candidatefor the new Master (candidate_master is set)
Sat Oct 1712:37:442020- [info] Current Alive Master:10.0.0.8(10.0.0.8:3306)
Sat Oct 1712:37:442020- [info] Checking slave configurations..
Sat Oct 1712:37:442020- [info] Checking replication filtering settings..
Sat Oct 1712:37:442020- [info] binlog_do_db= , binlog_ignore_db=
Sat Oct 1712:37:442020- [info] Replication filtering check ok.
Sat Oct 1712:37:442020- [info] GTID (with auto-pos) is not supported
Sat Oct 1712:37:442020- [info] Starting SSH connection tests..
Sat Oct 1712:37:472020- [info] All SSH connection tests passed successfully.
Sat Oct 1712:37:472020- [info] Checking MHA Node version..
Sat Oct 1712:37:472020- [info] Version check ok.
Sat Oct 1712:37:472020- [info] Checking SSH publickey authentication settings on the current master..
Sat Oct 1712:37:472020- [info] HealthCheck: SSH to10.0.0.8 is reachable.
Sat Oct 1712:37:472020- [info] Master MHA Node version is0.58.
Sat Oct 1712:37:472020- [info] Checking recovery script configurations on10.0.0.8(10.0.0.8:3306)..
Sat Oct 1712:37:472020- [info] Executing command: save_binary_logs --command=test --start_pos=4--binlog_dir=/data/mysql/ --output_file=/data/mastermha/app1//save_binary_logs_test --manager_version=0.58 --start_file=mysql-bin.000002 Sat Oct1712:37:472020- [info] Connecting to [email protected](10.0.0.8:22)..
Creating /data/mastermha/app1ifnot exists.. Creating directory /data/mastermha/app1..done.
ok.
Checking output directory is accessible or not..
ok.
Binlog found at /data/mysql/, up to mysql-bin.000002Sat Oct 1712:37:482020- [info] Binlog setting checkdone.
Sat Oct 1712:37:482020- [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Sat Oct 1712:37:482020- [info] Executing command : apply_diff_relay_logs --command=test --slave_user='mhauser'--slave_host=10.0.0.18--slave_ip=10.0.0.18--slave_port=3306--workdir=/data/mastermha/app1/ --target_version=8.0.21--manager_version=0.58--relay_dir=/var/lib/mysql --current_relay_log=slave1-relay-bin.000002--slave_pass=xxx
Sat Oct 1712:37:482020- [info] Connecting to [email protected](10.0.0.18:22)..
Creating directory /data/mastermha/app1/..done.
Checking slave recovery environment settings..
Relay log found at /var/lib/mysql, up to slave1-relay-bin.000002 Temporary relay log fileis /var/lib/mysql/slave1-relay-bin.000002 Checking if super_read_only is defined and turned on.. not present or turned off, ignoring.
Testing mysql connection and privileges..
mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s)..done.
Sat Oct 1712:37:482020- [info] Executing command : apply_diff_relay_logs --command=test --slave_user='mhauser'--slave_host=10.0.0.28--slave_ip=10.0.0.28--slave_port=3306--workdir=/data/mastermha/app1/ --target_version=8.0.21--manager_version=0.58--relay_dir=/var/lib/mysql --current_relay_log=slave2-relay-bin.000002--slave_pass=xxx
Sat Oct 1712:37:482020- [info] Connecting to [email protected](10.0.0.28:22)..
Creating directory /data/mastermha/app1/..done.
Checking slave recovery environment settings..
Relay log found at /var/lib/mysql, up to slave2-relay-bin.000002 Temporary relay log fileis /var/lib/mysql/slave2-relay-bin.000002 Checking if super_read_only is defined and turned on.. not present or turned off, ignoring.
Testing mysql connection and privileges..
mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s)..done.
Sat Oct 1712:37:482020- [info] Slaves settings checkdone.
Sat Oct 1712:37:482020- [info] 10.0.0.8(10.0.0.8:3306) (current master)
+--10.0.0.18(10.0.0.18:3306)
+--10.0.0.28(10.0.0.28:3306)
Sat Oct 1712:37:482020- [info] Checking replication health on10.0.0.18..
Sat Oct 1712:37:482020- [info] ok.
Sat Oct 1712:37:482020- [info] Checking replication health on10.0.0.28..
Sat Oct 1712:37:482020- [info] ok.
Sat Oct 1712:37:482020- [info] Checking master_ip_failover_script status:
Sat Oct 1712:37:482020- [info] /usr/local/bin/master_ip_failover --command=status --ssh_user=root --orig_master_host=10.0.0.8--orig_master_ip=10.0.0.8--orig_master_port=3306
IN SCRIPT TEST====/sbin/ifconfigeth0:1down==/sbin/ifconfigeth0:110.0.0.100/24;/sbin/arping -I
eth0 -c3-s10.0.0.100/2410.0.0.2>/dev/null2>&1===Checking the Status of the script.. OK /sbin/arping: option requires an argument --'I'Usage: arping [-fqbDUAV] [-c count] [-wtimeout] [-I device] [-s source] destination
-f : quit on first reply
-q : be quiet
-b : keep broadcasting, don't go unicast-D : duplicate address detection mode
-U : Unsolicited ARP mode, update your neighbours
-A : ARP answer mode, update your neighbours
-V : print version and exit
-c count : how many packets to send
-wtimeout : howlongtowaitfor a reply
-I device :which ethernet device to use
-s source : source ip address
destination : ask for what ip address
Sat Oct 1712:37:482020- [info] OK.
Sat Oct 1712:37:482020- [warning] shutdown_script is not defined.
Sat Oct 1712:37:482020- [info] Got exit code0 (Not master dead).
MySQL Replication Health is OK.
[root@mha-manager ~]#masterha_check_status --conf=/etc/mastermha/app1.cnf
app1 is stopped(2:NOT_RUNNING).
#启动mha
[root@mha-manager ~]#masterha_manager --conf=/etc/mastermha/app1.cnf
Sat Oct 1712:39:092020- [warning] Global configurationfile/etc/masterha_default.cnf not found. Skipping.
Sat Oct 1712:39:092020- [info] Reading application default configuration from /etc/mastermha/app1.cnf..
Sat Oct 1712:39:092020- [info] Reading server configuration from /etc/mastermha/app1.cnf..
[root@master ~]#tail-f /var/lib/mysql/master.log 2020-10-17T12:41:33.799439Z15Query SELECT1 As Value2020-10-17T12:41:34.800094Z15Query SELECT1 As Value2020-10-17T12:41:35.800754Z15Query SELECT1 As Value2020-10-17T12:41:36.802357Z15Query SELECT1 As Value2020-10-17T12:41:37.802221Z15Query SELECT1 As Value2020-10-17T12:41:38.802487Z15Query SELECT1 As Value2020-10-17T12:41:39.803444Z15Query SELECT1 As Value2020-10-17T12:41:40.804324Z15Query SELECT1 As Value
[root@mha-manager ~]#masterha_check_status --conf=/etc/mastermha/app1.cnf
app1 (pid:12292) is running(0:PING_OK), master:10.0.0.8#模拟故障
[root@mha-manager ~]#masterha_manager --conf=/etc/mastermha/app1.cnf
Sat Oct 1712:39:092020- [warning] Global configurationfile/etc/masterha_default.cnf not found. Skipping.
Sat Oct 1712:39:092020- [info] Reading application default configuration from /etc/mastermha/app1.cnf..
Sat Oct 1712:39:092020- [info] Reading server configuration from /etc/mastermha/app1.cnf..
Sat Oct 1712:44:192020- [warning] Global configurationfile/etc/masterha_default.cnf not found. Skipping.
Sat Oct 1712:44:192020- [info] Reading application default configuration from /etc/mastermha/app1.cnf..
Sat Oct 1712:44:192020- [info] Reading server configuration from /etc/mastermha/app1.cnf..
[root@mha-manager ~]#
[root@mha-manager ~]#masterha_check_status --conf=/etc/mastermha/app1.cnf
app1 is stopped(2:NOT_RUNNING).
[root@slave2 ~]# ip a1: lo: mtu65536qdisc noqueue state UNKNOWN group default qlen1000 link/loopback00:00:00:00:00:00brd00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever2: eth0: mtu1500qdisc mq state UP group default qlen1000 link/ether00:0c:29:5c:a0:c5 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.28/24brd10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet 10.0.0.100/24brd10.0.0.255scope global secondary eth0:1 valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe5c:a0c5/64 scope link
valid_lft forever preferred_lft forever
4、实战案例:Percona XtraDB Cluster(PXC 5.7)
#配置pxc清华yum源并安装
[root@pxc1 ~]#vim /etc/yum.repos.d/pxc.repo
[percona]
name=percona_repo
baseurl =https://mirrors.tuna.tsinghua.edu.cn/percona/release/$releasever/RPMS/$basearchenabled =1gpgcheck =0[root@pxc1 ~]#scp/etc/yum.repos.d/pxc.repo10.0.0.17:/etc/yum.repos.d/[root@pxc1 ~]#scp/etc/yum.repos.d/pxc.repo10.0.0.27:/etc/yum.repos.d/[root@pxc1 ~]#scp/etc/yum.repos.d/pxc.repo10.0.0.37:/etc/yum.repos.d/[root@pxc1 ~]#yuminstallPercona-XtraDB-Cluster-57-y
[root@pxc2 ~]#yuminstallPercona-XtraDB-Cluster-57-y
[root@pxc3 ~]#yuminstallPercona-XtraDB-Cluster-57-y
[root@pxc4 ~]#yuminstallPercona-XtraDB-Cluster-57-y
#配置各个节点mysql和集群配置文件
[root@pxc1 ~]#vim /etc/percona-xtradb-cluster.conf.d/mysqld.cnf
[mysqld]
server-id=7datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin
log_slave_updates
expire_logs_days=7[root@pxc2 ~]#vim /etc/percona-xtradb-cluster.conf.d/mysqld.cnf
[mysqld]
server-id=17datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin
log_slave_updates
expire_logs_days=7[root@pxc3 ~]#vim /etc/percona-xtradb-cluster.conf.d/mysqld.cnf
[mysqld]
server-id=27datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin
log_slave_updates
expire_logs_days=7[root@pxc4 ~]#vim /etc/percona-xtradb-cluster.conf.d/mysqld.cnf
[mysqld]
server-id=37datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin
log_slave_updates
expire_logs_days=7[root@pxc1 ~]#vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[root@pxc1 ~]#grep-Ev"^#|^$"/etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_address=gcomm://10.0.0.7,10.0.0.17,10.0.0.27binlog_format=ROW
default_storage_engine=InnoDB
wsrep_slave_threads=8wsrep_log_conflicts
innodb_autoinc_lock_mode=2wsrep_node_address=10.0.0.7wsrep_cluster_name=pxc-cluster
wsrep_node_name=pxc-cluster-node-1pxc_strict_mode=ENFORCING
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="sstuser:s3cretPass"[root@pxc2 ~]#vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[root@pxc2 ~]#
[root@pxc2 ~]#grep-Ev"^#|^$"/etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_address=gcomm://10.0.0.7,10.0.0.17,10.0.0.27binlog_format=ROW
default_storage_engine=InnoDB
wsrep_slave_threads=8wsrep_log_conflicts
innodb_autoinc_lock_mode=2wsrep_node_address=10.0.0.17wsrep_cluster_name=pxc-cluster
wsrep_node_name=pxc-cluster-node-2pxc_strict_mode=ENFORCING
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="sstuser:s3cretPass"[root@pxc3 ~]#vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[root@pxc3 ~]#grep-Ev"^#|^$"/etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_address=gcomm://10.0.0.7,10.0.0.17,10.0.0.27binlog_format=ROW
default_storage_engine=InnoDB
wsrep_slave_threads=8wsrep_log_conflicts
innodb_autoinc_lock_mode=2wsrep_node_address=10.0.0.27wsrep_cluster_name=pxc-cluster
wsrep_node_name=pxc-cluster-node-3pxc_strict_mode=ENFORCING
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="sstuser:s3cretPass"#启动PXC集群中第一个节点
[root@pxc1 ~]#systemctl start [email protected]
[root@pxc1 ~]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0128*:22*:*
LISTEN 0128*:4567*:*
LISTEN 0100127.0.0.1:25*:*
LISTEN 0128[::]:22[::]:*
LISTEN 0100[::1]:25[::]:*
LISTEN 080[::]:3306[::]:*
[root@pxc1 ~]#grep"temporary password"/var/log/mysqld.log2020-10-17T06:59:53.765387Z1[Note] A temporary password is generatedforroot@localhost: Vkyf+nVci9wW
[root@pxc1 ~]#mysql -uroot -pVkyf+nVci9wW
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection idis11Server version: 5.7.31-34-57-log
Copyright (c) 2009-2020Percona LLC and/or its affiliates
Copyright (c) 2000,2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'or'\h'forhelp. Type'\c'toclear the current input statement.
mysql> alter user root@'localhost'identified by'magedu';
Query OK, 0rows affected (0.00 sec)
mysql> grant reload,lock tables,process,replication client on *.* to sstuser@'localhost'identified by's3cretPass';
Query OK, 0rows affected,1warning (0.01 sec)
mysql> show variables like'wsrep%'\G***************************1. row ***************************Variable_name: wsrep_OSU_method
Value: TOI***************************2. row ***************************Variable_name: wsrep_RSU_commit_timeout
Value: 5000***************************3. row ***************************Variable_name: wsrep_auto_increment_control
Value: ON***************************4. row ***************************Variable_name: wsrep_causal_reads
Value: OFF***************************5. row ***************************Variable_name: wsrep_certification_rules
Value: strict***************************6. row ***************************Variable_name: wsrep_certify_nonPK
Value: ON***************************7. row ***************************Variable_name: wsrep_cluster_address
Value: gcomm://10.0.0.7,10.0.0.17,10.0.0.27***************************8. row ***************************Variable_name: wsrep_cluster_name
Value: pxc-cluster***************************9. row ***************************Variable_name: wsrep_convert_LOCK_to_trx
Value: OFF***************************10. row ***************************Variable_name: wsrep_data_home_dir
Value: /var/lib/mysql/***************************11. row ***************************Variable_name: wsrep_dbug_option
Value: ***************************12. row ***************************Variable_name: wsrep_debug
Value: OFF***************************13. row ***************************Variable_name: wsrep_desync
Value: OFF***************************14. row ***************************Variable_name: wsrep_dirty_reads
Value: OFF***************************15. row ***************************Variable_name: wsrep_drupal_282555_workaround
Value: OFF***************************16. row ***************************Variable_name: wsrep_forced_binlog_format
Value: NONE***************************17. row ***************************Variable_name: wsrep_load_data_splitting
Value: ON***************************18. row ***************************Variable_name: wsrep_log_conflicts
Value: ON***************************19. row ***************************Variable_name: wsrep_max_ws_rows
Value: 0***************************20. row ***************************Variable_name: wsrep_max_ws_size
Value: 2147483647***************************21. row ***************************Variable_name: wsrep_node_address
Value: 10.0.0.7***************************22. row ***************************Variable_name: wsrep_node_incoming_address
Value: AUTO***************************23. row ***************************Variable_name: wsrep_node_name
Value: pxc-cluster-node-1***************************24. row ***************************Variable_name: wsrep_notify_cmd
Value: ***************************25. row ***************************Variable_name: wsrep_on
Value: ON***************************26. row ***************************Variable_name: wsrep_preordered
Value: OFF***************************27. row ***************************Variable_name: wsrep_provider
Value: /usr/lib64/galera3/libgalera_smm.so***************************28. row ***************************Variable_name: wsrep_provider_options
Value: base_dir = /var/lib/mysql/; base_host =10.0.0.7; base_port =4567; cert.log_conflicts = no; cert.optimistic_pa = yes; debug = no; evs.auto_evict =0; evs.causal_keepalive_period = PT1S; evs.debug_log_mask =0x1; evs.delay_margin = PT1S; evs.delayed_keep_period = PT30S; evs.inactive_check_period = PT0.5S; evs.inactive_timeout = PT15S; evs.info_log_mask =0; evs.install_timeout = PT7.5S; evs.join_retrans_period = PT1S; evs.keepalive_period = PT1S; evs.max_install_timeouts =3; evs.send_window =10; evs.stats_report_period = PT1M; evs.suspect_timeout = PT5S; evs.use_aggregate =true; evs.user_send_window =4; evs.version =0; evs.view_forget_timeout = P1D; gcache.dir= /var/lib/mysql/; gcache.freeze_purge_at_seqno = -1; gcache.keep_pages_count =0; gcache.keep_pages_size =0; gcache.mem_size =0; gcache.name = /var/lib/mysql//galera.cache; gcache.page_size = 128M; gcache.recover = no; gcache.size = 128M; gcomm.thread_prio = ; gcs.fc_debug = 0; gcs.fc_factor = 1; gcs.fc_limit = 100; gcs.fc_master_slave = no; gcs***************************29. row ***************************Variable_name: wsrep_recover
Value: OFF***************************30. row ***************************Variable_name: wsrep_reject_queries
Value: NONE***************************31. row ***************************Variable_name: wsrep_replicate_myisam
Value: OFF***************************32. row ***************************Variable_name: wsrep_restart_slave
Value: OFF***************************33. row ***************************Variable_name: wsrep_retry_autocommit
Value: 1***************************34. row ***************************Variable_name: wsrep_slave_FK_checks
Value: ON***************************35. row ***************************Variable_name: wsrep_slave_UK_checks
Value: OFF***************************36. row ***************************Variable_name: wsrep_slave_threads
Value: 8***************************37. row ***************************Variable_name: wsrep_sst_auth
Value: ***********************************38. row ***************************Variable_name: wsrep_sst_donor
Value: ***************************39. row ***************************Variable_name: wsrep_sst_donor_rejects_queries
Value: OFF***************************40. row ***************************Variable_name: wsrep_sst_method
Value: xtrabackup-v2***************************41. row ***************************Variable_name: wsrep_sst_receive_address
Value: AUTO***************************42. row ***************************Variable_name: wsrep_start_position
Value: 00000000-0000-0000-0000-000000000000:-1***************************43. row ***************************Variable_name: wsrep_sync_wait
Value: 043rowsinset (0.00 sec)
mysql> show status like'wsrep%';+----------------------------------+--------------------------------------+| Variable_name | Value |+----------------------------------+--------------------------------------+| wsrep_local_state_uuid | 6085b686-1046-11eb-ac84-631f2cc73305 || wsrep_protocol_version |9|| wsrep_last_applied |3|| wsrep_last_committed |3|| wsrep_replicated |3|| wsrep_replicated_bytes |816|| wsrep_repl_keys |3|| wsrep_repl_keys_bytes |96|| wsrep_repl_data_bytes |521|| wsrep_repl_other_bytes |0|| wsrep_received |2|| wsrep_received_bytes |150|| wsrep_local_commits |0|| wsrep_local_cert_failures |0|| wsrep_local_replays |0|| wsrep_local_send_queue |0|| wsrep_local_send_queue_max |1|| wsrep_local_send_queue_min |0|| wsrep_local_send_queue_avg |0.000000|| wsrep_local_recv_queue |0|| wsrep_local_recv_queue_max |2|| wsrep_local_recv_queue_min |0|| wsrep_local_recv_queue_avg |0.500000|| wsrep_local_cached_downto |1|| wsrep_flow_control_paused_ns |0|| wsrep_flow_control_paused |0.000000|| wsrep_flow_control_sent |0|| wsrep_flow_control_recv |0|| wsrep_flow_control_interval | [100,100] || wsrep_flow_control_interval_low |100|| wsrep_flow_control_interval_high |100|| wsrep_flow_control_status | OFF || wsrep_cert_deps_distance |1.000000|| wsrep_apply_oooe |0.000000|| wsrep_apply_oool |0.000000|| wsrep_apply_window |1.000000|| wsrep_commit_oooe |0.000000|| wsrep_commit_oool |0.000000|| wsrep_commit_window |1.000000|| wsrep_local_state |4|| wsrep_local_state_comment | Synced || wsrep_cert_index_size |1|| wsrep_cert_bucket_count |22|| wsrep_gcache_pool_size |2256|| wsrep_causal_reads |0|| wsrep_cert_interval |0.000000|| wsrep_open_transactions |0|| wsrep_open_connections |0|| wsrep_ist_receive_status | || wsrep_ist_receive_seqno_start |0|| wsrep_ist_receive_seqno_current |0|| wsrep_ist_receive_seqno_end |0|| wsrep_incoming_addresses |10.0.0.7:3306|| wsrep_cluster_weight |1|| wsrep_desync_count |0|| wsrep_evs_delayed | || wsrep_evs_evict_list | || wsrep_evs_repl_latency |0/0/0/0/0|| wsrep_evs_state | OPERATIONAL || wsrep_gcomm_uuid |60853201-1046-11eb-b428-d757c0543d63 || wsrep_cluster_conf_id |1|| wsrep_cluster_size |1|| wsrep_cluster_state_uuid | 6085b686-1046-11eb-ac84-631f2cc73305 || wsrep_cluster_status | Primary || wsrep_connected | ON || wsrep_local_bf_aborts |0|| wsrep_local_index |0|| wsrep_provider_name | Galera || wsrep_provider_vendor | Codership Oy || wsrep_provider_version |3.45(ra60e019) || wsrep_ready | ON |+----------------------------------+--------------------------------------+71rowsinset (0.00 sec)
#启动PXC集群中其它所有节点
[root@pxc2 ~]#systemctl start mysql
[root@pxc2 ~]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0128*:22*:*
LISTEN 0128*:4567*:*
LISTEN 0100127.0.0.1:25*:*
LISTEN 080[::]:3306[::]:*
LISTEN 0128[::]:22[::]:*
LISTEN 0100[::1]:25[::]:*[root@pxc3 ~]#systemctl start mysql
[root@pxc3 ~]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0128*:22*:*
LISTEN 0128*:4567*:*
LISTEN 0100127.0.0.1:25*:*
LISTEN 080[::]:3306[::]:*
LISTEN 0128[::]:22[::]:*
LISTEN 0100[::1]:25[::]:*#查看集群状态,验证集群是否成功
[root@pxc1 ~]#mysql -uroot -pmagedu
mysql> show variables like'wsrep_node_name';+-----------------+--------------------+| Variable_name | Value |+-----------------+--------------------+| wsrep_node_name | pxc-cluster-node-1|+-----------------+--------------------+1rowinset (0.00 sec)
mysql> show variables like'wsrep_node_address';+--------------------+----------+| Variable_name | Value |+--------------------+----------+| wsrep_node_address |10.0.0.7|+--------------------+----------+1rowinset (0.00 sec)
mysql> show variables like'wsrep_on';+---------------+-------+| Variable_name | Value |+---------------+-------+| wsrep_on | ON |+---------------+-------+1rowinset (0.01 sec)
mysql> show status like'wsrep_cluster_size';+--------------------+-------+| Variable_name | Value |+--------------------+-------+| wsrep_cluster_size |3|+--------------------+-------+1rowinset (0.00 sec)
[root@pxc2 ~]#mysql -uroot -pmagedu
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection idis14Server version: 5.7.31-34-57-log Percona XtraDB Cluster (GPL), Release rel34, Revision7359e4f, WSREP version31.45, wsrep_31.45Copyright (c) 2009-2020Percona LLC and/or its affiliates
Copyright (c) 2000,2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'or'\h'forhelp. Type'\c'toclear the current input statement.
mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys |+--------------------+4rowsinset (0.00 sec)
[root@pxc3 ~]#mysql -uroot -pmagedu
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection idis11Server version: 5.7.31-34-57-log Percona XtraDB Cluster (GPL), Release rel34, Revision7359e4f, WSREP version31.45, wsrep_31.45Copyright (c) 2009-2020Percona LLC and/or its affiliates
Copyright (c) 2000,2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'or'\h'forhelp. Type'\c'toclear the current input statement.
mysql> create database db1;
Query OK, 1row affected (0.00 sec)
[root@pxc1 ~]#mysql -uroot -pmagedu
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection idis16Server version: 5.7.31-34-57-log Percona XtraDB Cluster (GPL), Release rel34, Revision7359e4f, WSREP version31.45, wsrep_31.45Copyright (c) 2009-2020Percona LLC and/or its affiliates
Copyright (c) 2000,2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'or'\h'forhelp. Type'\c'toclear the current input statement.
mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || db1 || mysql || performance_schema || sys |+--------------------+5rowsinset (0.00 sec)
##在PXC集群中再加一台新的主机PXC4:10.0.0.37[root@pxc4 ~]#vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[root@pxc4 ~]#grep-Ev"^#|^$"/etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_address=gcomm://10.0.0.7,10.0.0.17,10.0.0.27,10.0.0.37binlog_format=ROW
default_storage_engine=InnoDB
wsrep_slave_threads=8wsrep_log_conflicts
innodb_autoinc_lock_mode=2wsrep_node_address=10.0.0.37wsrep_cluster_name=pxc-cluster
wsrep_node_name=pxc-cluster-node-4pxc_strict_mode=ENFORCING
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="sstuser:s3cretPass"[root@pxc4 ~]#systemctl start mysql
[root@pxc4 ~]#mysql -uroot -pmagedu
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection idis11Server version: 5.7.31-34-57-log Percona XtraDB Cluster (GPL), Release rel34, Revision7359e4f, WSREP version31.45, wsrep_31.45Copyright (c) 2009-2020Percona LLC and/or its affiliates
Copyright (c) 2000,2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'or'\h'forhelp. Type'\c'toclear the current input statement.
mysql> show status like'wsrep_cluster_size';+--------------------+-------+| Variable_name | Value |+--------------------+-------+| wsrep_cluster_size |4|+--------------------+-------+1rowinset (0.00 sec)
mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || db1 || mysql || performance_schema || sys |+--------------------+5rowsinset (0.00 sec)
#修改其他节点的配置文件
[root@pxc1 ~]#vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[root@pxc1 ~]#grep-E"^wsrep_cluster_address=gcomm:"/etc/percona-xtradb-cluster.conf.d/wsrep.cnf
wsrep_cluster_address=gcomm://10.0.0.7,10.0.0.17,10.0.0.27,10.0.0.37[root@pxc2 ~]#grep-E"^wsrep_cluster_address=gcomm:"/etc/percona-xtradb-cluster.conf.d/wsrep.cnf
wsrep_cluster_address=gcomm://10.0.0.7,10.0.0.17,10.0.0.27,10.0.0.37[root@pxc3 ~]#grep-E"^wsrep_cluster_address=gcomm:"/etc/percona-xtradb-cluster.conf.d/wsrep.cnf
wsrep_cluster_address=gcomm://10.0.0.7,10.0.0.17,10.0.0.27,10.0.0.37