[MariaDB - MHA Chain replication 구성을 통한 데이터 이관]

현재 MHA구성으로 manager서버 / master(node1) / slave(node2) 구조입니다.

다운타임을 최소화하여 새로운 노드로 이관을 하며 기존 노드를 뺄 예정이기 때문에 new-node를 node2에 slave로 붙여 chain 구성 후 이관해볼 생각입니다.

 

 

전체 순서

  1. new-node를 node2의 slave로 replication 구성
  2. master 노드 제거 -> failover되며 node2가 master로 승격
  3. mha manager에 new-node정보 추가 및 failover 스크립트 수정
  4. mha 재시작
  5. node2 제거 -> failover되며 new-node가 master로 승격
  6. 결과 확인 (new-node에 vip가 붙으며 role이 master이면 성공)

 

 

테스트 환경

hostname
ip 
vip
DB version
manager
192.168.100.55
 
mariadb 10.4
node1
192.168.100.51
192.168.100.54
mariadb 10.4
node2
192.168.100.52
 
mariadb 10.4
new-node
192.168.100.53
 
mariadb 10.4

 

아키텍처

 

 

사전 작업

## 현재 Master(node1)에 데이터 insert
[root@node1 ~]# mysql -uroot -proot < sakila-mv-schema.sql
[root@node1 ~]# mysql -uroot -proot < sakila-mv-data.sql


MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| test               |
+--------------------+
5 rows in set (0.00 sec)

MariaDB [(none)]> show tables in sakila;
+----------------------------+
| Tables_in_sakila           |
+----------------------------+
| actor                      |
| actor_info                 |
| address                    |
| category                   |
| city                       |
| country                    |
| customer                   |
| customer_list              |
| film                       |
| film_actor                 |
| film_category              |
| film_list                  |
| film_text                  |
| inventory                  |
| language                   |
| nicer_but_slower_film_list |
| payment                    |
| rental                     |
| sales_by_film_category     |
| sales_by_store             |
| staff                      |
| staff_list                 |
| store                      |
+----------------------------+
23 rows in set (0.00 sec)



## replication 상탱인 Slave(node2)에서도 데이터가 동일하게 insert 된것을 볼 수 있다.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| test               |
+--------------------+
5 rows in set (0.00 sec)

MariaDB [(none)]> show tables in sakila;
+----------------------------+
| Tables_in_sakila           |
+----------------------------+
| actor                      |
| actor_info                 |
| address                    |
| category                   |
| city                       |
| country                    |
| customer                   |
| customer_list              |
| film                       |
| film_actor                 |
| film_category              |
| film_list                  |
| film_text                  |
| inventory                  |
| language                   |
| nicer_but_slower_film_list |
| payment                    |
| rental                     |
| sales_by_film_category     |
| sales_by_store             |
| staff                      |
| staff_list                 |
| store                      |
+----------------------------+
23 rows in set (0.00 sec)
 
 
 
 
 

 테스트 시작

 

   mysqldump (node2)

[root@node2 ~]# mysqldump -uroot -proot --all-databases > slave_all.sql


[root@node2 ~]# ll
total 446792
drwxr-xr-x 2 root root         6 Jan 27 17:16 Downloads
-rw-r--r-- 1 root root   3855096 Feb  4 09:10 slave_all.sql
 
 
 

 dump 파일 이동 (node2 -> new-node)

[root@node2 ~]# scp -rp slave_all.sql root@192.168.100.53:/root
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.53' (ECDSA) to the list of known hosts.
slave_all.sql                                             100% 3765KB  86.7MB/s   00:00

 

 dump import (new-node)

[root@new-node ~]# mysql -uroot -p < slave_all.sql
Enter password:


MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| test               |
+--------------------+
5 rows in set (0.00 sec)
 

 

 node2 정보

MariaDB [(none)]> show master status\G;
*************************** 1. row ***************************
            File: mysql.000005
        Position: 3375321
    Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)

ERROR: No query specified

 

 replication (new-node)

MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='192.168.100.52', MASTER_USER='repl',MASTER_PASSWORD='repl',MASTER_PORT=3306,MASTER_LOG_FILE='mysql.000005', MASTER_LOG_POS=3375321,MASTER_CONNECT_RETRY=10;
Query OK, 0 rows affected (0.01 sec)


MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)


MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.100.52
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 10
              Master_Log_File: mysql.000005
          Read_Master_Log_Pos: 3375321
               Relay_Log_File: relay-log.000002
                Relay_Log_Pos: 551
        Relay_Master_Log_File: mysql.000005
             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: 3375321
              Relay_Log_Space: 854
              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: 2
               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 for the slave I/O thread to update it
1 row in set (0.00 sec)

ERROR: No query specified
 
 
 

 동기화 확인

<master>
## dattabase 생성

MariaDB [mysql]> create database kim;
Query OK, 1 row affected (0.00 sec)


MariaDB [mysql]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| kim                |
| mysql              |
| performance_schema |
| sakila             |
| test               |
+--------------------+
6 rows in set (0.00 sec)



<node2>
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| kim                |
| mysql              |
| performance_schema |
| sakila             |
| test               |
+--------------------+
6 rows in set (0.01 sec)



<node3>
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| kim                |
| mysql              |
| performance_schema |
| sakila             |
| test               |
+--------------------+
6 rows in set (0.00 sec)
 
 
 
 
 
 

Master 제거 (failover)

 

 2초에 한번씩 vip를 통해 data insert 반복문을 돌림

[root@mha-manager ~]# while true
> do
> mysql -h 192.168.100.54 -urepl -prepl -e "insert into test.test values(1);"
> sleep 2
> done
 

 Master kill

[root@node1 ~]# ps -ef | grep mysql
root      13038      1  0 Feb03 ?        00:00:00 /bin/sh /mysql/bin/mysqld_safe --user=mysq
mysql     13146  13038  0 Feb03 ?        00:00:45 /mysql/bin/mysqld --basedir=/mysql --datadir=/data --plugin-dir=/mysql/lib/plugin --user=mysql --log-error=/log/mariadb.log --open-files-limit=5000 --pid-file=/log/mariadb.pid --socket=/tmp/mysql.sock
root      85605  73930  0 11:34 pts/1    00:00:00 grep --color=auto mysql


[root@node1 ~]# kill -9 13038 13146

 

 

 failover log

Check MHA Manager logs at mha-manager:/var/log/masterha/app1/app1.log for details.

Started automated(non-interactive) failover.
The latest slave 192.168.100.52(192.168.100.52:3306) has all relay logs for recovery.
Selected 192.168.100.52(192.168.100.52:3306) as a new master.
192.168.100.52(192.168.100.52:3306): OK: Applying all logs succeeded.
Generating relay diff files from the latest slave succeeded.
192.168.100.52(192.168.100.52:3306): Resetting slave info succeeded.
Master failover to 192.168.100.52(192.168.100.52:3306) completed successfully.

 

 node2에 vip뜨고 master로 승격

[root@node2 ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.41.181.58  netmask 255.255.254.0  broadcast 10.41.181.255
        ether f2:20:cd:f1:fb:b5  txqueuelen 1000  (Ethernet)
        RX packets 306987  bytes 498407016 (475.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 102479  bytes 31725787 (30.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.52  netmask 255.255.255.0  broadcast 192.168.100.255
        ether f2:d7:cf:d3:f4:fa  txqueuelen 1000  (Ethernet)
        RX packets 231438  bytes 15133844 (14.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 93341  bytes 13560243 (12.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.54  netmask 255.255.255.0  broadcast 192.168.100.255
        ether f2:d7:cf:d3:f4:fa  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 246  bytes 20505 (20.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 246  bytes 20505 (20.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

 

 

MHA manager 수정

 

failover를 시켜 결과적으로 new-node에 vip가 붙으며 master로 승격 되어야 하기때문에 manger에 new-node의 정보를 추가해줍니다.

 

 new-node에 vip를 생성

※ 현재 vip는 master노드인 node1에 올라와있기때문에 new-node에서는 ifup을 해서는 안됩니다. ip가 충돌나면 서비스 불가
[root@new-node network-scripts]# vi ifcfg-eth1:1
DEVICE=eth1:1
BOOTPROTO=static
IPADDR=192.168.100.54
NETMASK=255.255.255.0

 

 

구성 패키지 설치 (new-node)

[root@new-node ~]# yum -y install epel*

[root@new-node ~]# yum install -y epel perl-devel perl-CPAN perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Module-Install
 
 

SSH 설정(new-node)

[root@new-node ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):  enter
Enter passphrase (empty for no passphrase):  enter
Enter same passphrase again: enter
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:
ef:c2:74:ab:db:88:58:b5:d3:d6:a3:06:19:c1:da:fe root@jh-mha1
The key's randomart image is:
+--[ RSA 2048]----+
|       .         |
|        o        |
|       o .       |
|      . o        |
|       .So       |
|       .=+..     |
|      .oo++.o    |
|     o .o*E. .   |
|    . . +=+      |
+-----------------+


[root@new-node ~]# ls -al ~/.ssh/
total 12
drwx------  2 root root   36 Aug  3 17:04 .
dr-xr-x---. 6 root root 4096 Aug  3 17:03 ..
-rw-------  1 root root 1675 Aug  3 17:04 id_rsa
-rw-r--r--  1 root root  394 Aug  3 17:04 id_rsa.pub


[root@new-node ~]# chmod 700 ~/.ssh
[root@new-node ~]# chmod 600 ~/.ssh/id_rsa
[root@new-node ~]# chmod 644 ~/.ssh/id_rsa.pub
[root@new-node ~]# cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys
[root@new-node ~]# chmod 644 ~/.ssh/authorized_keys



[root@new-node ~]# cd ~/.ssh/
[root@new-node .ssh]# ll
total 12
-rw-r--r-- 1 root root  394 Aug  3 17:05 authorized_keys
-rw------- 1 root root 1675 Aug  3 17:04 id_rsa
-rw-r--r-- 1 root root  394 Aug  3 17:04 id_rsa.pub




## manager서버, master서버, slave서버의 pub키 공유
[root@new-node .ssh]# vi authorized_keys

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZxJmWupAjiGIuw1oI1kZHFWGgUxot1iflb9PWGOFd5C34cDuIxGieUq5oPIvw5Rv8vHHBRXfAzgmR3wnhxBhE/m8lUAf52Me+kZj8t3CgIBMSim0SZYdq2/BWBonVV3LUKe9Q3IKye0I93UHLJJzvYoNbUe1xQLq3tqavCXGY/OT5d4T6NDc6VOv539vLkGWVfPD1N9vFRGHBMTckqlJu8Fie19plbeyoyNPKcwAjUh5P1/ZU5ryrqAQNy0wDxCbqb/lTtUsmcAx6nxsvPx/NhTAWayCw2Xsr1R+GiWDd3FF1zzQZWRbEnG8sg9yycW/SnQ5yv+HXjk90zVuKoqZF root@ansible
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVW5ukgpON5mTZG3mhXuMVBuoTzv2nCytWZQeRhiGBvNvGGnpWTJyyyhxR+uLQyoDzGTvAi+XZ+LeN6zw3XAUHjC7I0IWOavh8l23csZD0kvcKoTssf1bUqCAaTTdvCivrONYMlpZhZLcs8xiOcNyIp6niWuxhzvySteWf9Ac9Nl1dAKJRdPM3F4+g/gd1EnvJS+e6vrlBdYCZJJUy2qCnfDNFSLVPJTMdojInM7LPy4HVTib/S95KqXADJxZqaxKV8xfwV/IlYDjWyDnuXKjxKyuNfzoSgLxNH/pSQhWV7IVEigRgzdKd4akf0EBXczdxnfTDtVCIbUUumsatXpsx root@node1
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnLz31lkjgrJ3hRKt7Cq3i/TtaiSStrbjLdOK3mMOPPtl2V809XrCwEjWsGgyd8KIRx30I6Hh2GokDrS3Ai+7Fzdjb66FPXsXnIXp0nDsZqeXbsc07p+AvI8u5uc7iRpqEoS8k9Z/4bytNSOcEPCY/z8pg64U3RQqio+vU0liyixm1X8E3KUnDxsbxb9UsTppUxRy4OoT9fQI7rKVdmHtMiq/SCYo76AAN+z+A0VDxgUMtmMcUBg2RYVBI56aMHIoDcpBEGxBUZ95aNSnsMY3RzezMk9puGORqieDEyIRsvbX51zW/FPm4QR63FZqz0NNr8tVVHIU7tKxJCmWfc78l root@node2
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqGccluXYCu6F7bwBZJX1hT0NP6nlnEjyHQPmsmcu+tLb/53YfDrqbtrUBvny7IEUAP9GQj772P3w88372sbopsIVqhIZZMh3yALuLC2MXV6Y45+ejp1tnshY24gEbMpqs1vW6nR4hT3qgNEKZsC5aj7f3nCgTgYmeZSdHA/mCb6Xz8g8HvnzflDZyhEqtg6v84+Vx6hRXhYSyJTgOoT16sGNqgJZbN9Di8RNsFsvBv5q1GCRJ+YKKKzl1g5faP+f4MdnYUfXQZH1P9gE4ImJsNLLo0k/wpTdfa17nf8ilUqynZpWCul5F5NbmY/oonZI0E7OXpDhiD2pxn4e86KN9 root@mha-manager



## password 없이 ssh 접속 테스트
[root@new-node ~]# ssh 192.168.100.51
[root@node1 ~]# 

[root@new-node ~]# ssh 192.168.100.52
[root@node2 ~]#
 
 

 mha4mysql-node 컴파일 & 인스톨 (new-node)

[root@new-node ~]# tar -zxvf mha4mysql-node-0.57.tar.gz


[root@new-node ~]# cd mha4mysql-node-0.57/


[root@new-node mha4mysql-node-0.57]# perl Makefile.PL
*** Module::AutoInstall version 1.06
*** Checking for Perl dependencies...
[Core Features]
- DBI        ...loaded. (1.627)
- DBD::mysql ...loaded. (4.023)
*** Module::AutoInstall configuration finished.
Checking if your kit is complete...
Looks good
Writing Makefile for mha4mysql::node
Writing MYMETA.yml and MYMETA.json


[root@new-node mha4mysql-node-0.57]# make && make install
cp lib/MHA/BinlogManager.pm blib/lib/MHA/BinlogManager.pm
cp lib/MHA/BinlogPosFindManager.pm blib/lib/MHA/BinlogPosFindManager.pm
cp lib/MHA/BinlogPosFinderXid.pm blib/lib/MHA/BinlogPosFinderXid.pm
cp lib/MHA/BinlogHeaderParser.pm blib/lib/MHA/BinlogHeaderParser.pm
cp lib/MHA/BinlogPosFinder.pm blib/lib/MHA/BinlogPosFinder.pm
cp lib/MHA/NodeUtil.pm blib/lib/MHA/NodeUtil.pm
cp lib/MHA/BinlogPosFinderElp.pm blib/lib/MHA/BinlogPosFinderElp.pm
cp lib/MHA/SlaveUtil.pm blib/lib/MHA/SlaveUtil.pm
cp lib/MHA/NodeConst.pm blib/lib/MHA/NodeConst.pm
cp bin/filter_mysqlbinlog blib/script/filter_mysqlbinlog
/usr/bin/perl "-Iinc" -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/filter_mysqlbinlog
cp bin/apply_diff_relay_logs blib/script/apply_diff_relay_logs
/usr/bin/perl "-Iinc" -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/apply_diff_relay_logs
cp bin/purge_relay_logs blib/script/purge_relay_logs
/usr/bin/perl "-Iinc" -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/purge_relay_logs
cp bin/save_binary_logs blib/script/save_binary_logs
/usr/bin/perl "-Iinc" -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/save_binary_logs
Manifying blib/man1/filter_mysqlbinlog.1
Manifying blib/man1/apply_diff_relay_logs.1
Manifying blib/man1/purge_relay_logs.1
Manifying blib/man1/save_binary_logs.1
Installing /usr/local/share/perl5/MHA/BinlogManager.pm
Installing /usr/local/share/perl5/MHA/BinlogPosFindManager.pm
Installing /usr/local/share/perl5/MHA/BinlogPosFinderXid.pm
Installing /usr/local/share/perl5/MHA/BinlogHeaderParser.pm
Installing /usr/local/share/perl5/MHA/BinlogPosFinder.pm
Installing /usr/local/share/perl5/MHA/NodeUtil.pm
Installing /usr/local/share/perl5/MHA/BinlogPosFinderElp.pm
Installing /usr/local/share/perl5/MHA/SlaveUtil.pm
Installing /usr/local/share/perl5/MHA/NodeConst.pm
Installing /usr/local/share/man/man1/filter_mysqlbinlog.1
Installing /usr/local/share/man/man1/apply_diff_relay_logs.1
Installing /usr/local/share/man/man1/purge_relay_logs.1
Installing /usr/local/share/man/man1/save_binary_logs.1
Installing /usr/local/bin/filter_mysqlbinlog
Installing /usr/local/bin/apply_diff_relay_logs
Installing /usr/local/bin/purge_relay_logs
Installing /usr/local/bin/save_binary_logs
Appending installation info to /usr/lib64/perl5/perllocal.pod


## MHA 관련 디렉토리 생성
[root@new-node ~]# mkdir -p /var/log/masterha/app5


## mysqlbinlog, mysql 심볼릭 링크 생성
[root@new-node ~]# ln -s /mysql/bin/mysqlbinlog /usr/bin/mysqlbinlog
[root@new-node ~]# ln -s /mysql/bin/mysql /usr/bin/mysql
 

 

 manager config 수정

기존 mha config 파일에 새로운 서버 정보 추가 및 기존 master였던 서버정보 삭제
[root@mha-manager ~]# vi /etc/mha.cnf
[server default]
user=repl
password=repl
ssh_user=root

# working directory on the manager
manager_workdir=/var/log/masterha/app1

# manager log file
manager_log=/var/log/masterha/app1/app1.log


# working directory on MySQL servers
remote_workdir=/var/log/masterha/app5

repl_user=repl
repl_password=repl


master_binlog_dir=/data



#ping interval, 3 times trial
ping_interval=5


#custom scripts for master ip failover
master_ip_failover_script=/var/log/masterha/app1/custom_scripts/master_ip_failover


#custom scripts for shutdown using fencing network custom script
#shutdown_script=/var/log/masterha/app1/custom_scripts/power_manager


#custom scripts for manual master switch
master_ip_online_change_script=/var/log/masterha/app1/custom_scripts/master_ip_online_change


#마스터 및 슬레이브 모든 노드들을 등록한다. (별도의 마스터/슬레이브 지정은 없다)
#[server1]
#hostname=192.168.100.51
#port=3306
#ignore_fail=1


[server1]
hostname=192.168.100.52
port=3306
ignore_fail=1

[server2]
hostname=192.168.100.53
port=3306
ignore_fail=1
 
 
 

 sshcheck (manager)

[root@mha-manager ~]# sshcheck
Fri Feb  4 10:37:40 2022 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Fri Feb  4 10:37:40 2022 - [info] Reading application default configuration from /etc/mha.cnf..
Fri Feb  4 10:37:40 2022 - [info] Reading server configuration from /etc/mha.cnf..
Fri Feb  4 10:37:40 2022 - [info] Starting SSH connection tests..
Fri Feb  4 10:37:41 2022 - [debug]
Fri Feb  4 10:37:40 2022 - [debug]  Connecting via SSH from root@192.168.100.51(192.168.100.51:22) to root@192.168.100.52(192.168.100.52:22)..
Fri Feb  4 10:37:40 2022 - [debug]   ok.
Fri Feb  4 10:37:40 2022 - [debug]  Connecting via SSH from root@192.168.100.51(192.168.100.51:22) to root@192.168.100.53(192.168.100.53:22)..
Warning: Permanently added '192.168.100.53' (ECDSA) to the list of known hosts.
Fri Feb  4 10:37:41 2022 - [debug]   ok.
Fri Feb  4 10:37:42 2022 - [debug]
Fri Feb  4 10:37:41 2022 - [debug]  Connecting via SSH from root@192.168.100.52(192.168.100.52:22) to root@192.168.100.51(192.168.100.51:22)..
Fri Feb  4 10:37:41 2022 - [debug]   ok.
Fri Feb  4 10:37:41 2022 - [debug]  Connecting via SSH from root@192.168.100.52(192.168.100.52:22) to root@192.168.100.53(192.168.100.53:22)..
Fri Feb  4 10:37:41 2022 - [debug]   ok.
Fri Feb  4 10:37:43 2022 - [debug]
Fri Feb  4 10:37:41 2022 - [debug]  Connecting via SSH from root@192.168.100.53(192.168.100.53:22) to root@192.168.100.51(192.168.100.51:22)..
Warning: Permanently added '192.168.100.53' (ECDSA) to the list of known hosts.
Fri Feb  4 10:37:41 2022 - [debug]   ok.
Fri Feb  4 10:37:41 2022 - [debug]  Connecting via SSH from root@192.168.100.53(192.168.100.53:22) to root@192.168.100.52(192.168.100.52:22)..
Fri Feb  4 10:37:42 2022 - [debug]   ok.
Fri Feb  4 10:37:43 2022 - [info] All SSH connection tests passed successfully.
Use of uninitialized value in exit at /usr/local/bin/masterha_check_ssh line 44.
 

 

 replcheck

[root@mha-manager custom_scripts]# replcheck
Fri Feb  4 13:26:59 2022 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Fri Feb  4 13:26:59 2022 - [info] Reading application default configuration from /etc/mha.cnf..
Fri Feb  4 13:26:59 2022 - [info] Reading server configuration from /etc/mha.cnf..
Fri Feb  4 13:26:59 2022 - [info] MHA::MasterMonitor version 0.57.
Fri Feb  4 13:27:00 2022 - [info] GTID failover mode = 0
Fri Feb  4 13:27:00 2022 - [info] Dead Servers:
Fri Feb  4 13:27:00 2022 - [info] Alive Servers:
Fri Feb  4 13:27:00 2022 - [info]   192.168.100.51(192.168.100.51:3306)
Fri Feb  4 13:27:00 2022 - [info]   192.168.100.52(192.168.100.52:3306)
Fri Feb  4 13:27:00 2022 - [info]   192.168.100.53(192.168.100.53:3306)
Fri Feb  4 13:27:00 2022 - [info] Alive Slaves:
Fri Feb  4 13:27:00 2022 - [info]   192.168.100.51(192.168.100.51:3306)  Version=10.2.14-MariaDB-log (oldest major version between slaves) log-bin:enabled
Fri Feb  4 13:27:00 2022 - [info]     Replicating from 192.168.100.52(192.168.100.52:3306)
Fri Feb  4 13:27:00 2022 - [info]   192.168.100.53(192.168.100.53:3306)  Version=10.2.14-MariaDB-log (oldest major version between slaves) log-bin:enabled
Fri Feb  4 13:27:00 2022 - [info]     Replicating from 192.168.100.52(192.168.100.52:3306)
Fri Feb  4 13:27:00 2022 - [info] Current Alive Master: 192.168.100.52(192.168.100.52:3306)
Fri Feb  4 13:27:00 2022 - [info] Checking slave configurations..
Fri Feb  4 13:27:00 2022 - [info]  read_only=1 is not set on slave 192.168.100.51(192.168.100.51:3306).
Fri Feb  4 13:27:00 2022 - [warning]  relay_log_purge=0 is not set on slave 192.168.100.51(192.168.100.51:3306).
Fri Feb  4 13:27:00 2022 - [warning]  relay_log_purge=0 is not set on slave 192.168.100.53(192.168.100.53:3306).
Fri Feb  4 13:27:00 2022 - [info] Checking replication filtering settings..
Fri Feb  4 13:27:00 2022 - [info]  binlog_do_db= , binlog_ignore_db=
Fri Feb  4 13:27:00 2022 - [info]  Replication filtering check ok.
Fri Feb  4 13:27:00 2022 - [info] GTID (with auto-pos) is not supported
Fri Feb  4 13:27:00 2022 - [info] Starting SSH connection tests..
Fri Feb  4 13:27:03 2022 - [info] All SSH connection tests passed successfully.
Fri Feb  4 13:27:03 2022 - [info] Checking MHA Node version..
Fri Feb  4 13:27:03 2022 - [info]  Version check ok.
Fri Feb  4 13:27:03 2022 - [info] Checking SSH publickey authentication settings on the current master..
Fri Feb  4 13:27:03 2022 - [info] HealthCheck: SSH to 192.168.100.52 is reachable.
Fri Feb  4 13:27:04 2022 - [info] Master MHA Node version is 0.57.
Fri Feb  4 13:27:04 2022 - [info] Checking recovery script configurations on 192.168.100.52(192.168.100.52:3306)..
Fri Feb  4 13:27:04 2022 - [info]   Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/data --output_file=/var/log/masterha/app5/save_binary_logs_test --manager_version=0.57 --start_file=mysql.000006
Fri Feb  4 13:27:04 2022 - [info]   Connecting to root@192.168.100.52(192.168.100.52:22)..
  Creating /var/log/masterha/app5 if not exists..    ok.
  Checking output directory is accessible or not..
   ok.
  Binlog found at /data, up to mysql.000006
Fri Feb  4 13:27:04 2022 - [info] Binlog setting check done.
Fri Feb  4 13:27:04 2022 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Fri Feb  4 13:27:04 2022 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='repl' --slave_host=192.168.100.51 --slave_ip=192.168.100.51 --slave_port=3306 --workdir=/var/log/masterha/app5 --target_version=10.2.14-MariaDB-log --manager_version=0.57 --relay_log_info=/data/relay-log.info  --relay_dir=/data/  --slave_pass=xxx
Fri Feb  4 13:27:04 2022 - [info]   Connecting to root@192.168.100.51(192.168.100.51:22)..
  Checking slave recovery environment settings..
    Opening /data/relay-log.info ... ok.
    Relay log found at /data, up to relay-log.000002
    Temporary relay log file is /data/relay-log.000002
    Testing mysql connection and privileges.. done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Fri Feb  4 13:27:04 2022 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='repl' --slave_host=192.168.100.53 --slave_ip=192.168.100.53 --slave_port=3306 --workdir=/var/log/masterha/app5 --target_version=10.2.14-MariaDB-log --manager_version=0.57 --relay_log_info=/data/relay-log.info  --relay_dir=/data/  --slave_pass=xxx
Fri Feb  4 13:27:04 2022 - [info]   Connecting to root@192.168.100.53(192.168.100.53:22)..
  Checking slave recovery environment settings..
    Opening /data/relay-log.info ... ok.
    Relay log found at /data, up to relay-log.000002
    Temporary relay log file is /data/relay-log.000002
    Testing mysql connection and privileges.. done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Fri Feb  4 13:27:04 2022 - [info] Slaves settings check done.
Fri Feb  4 13:27:04 2022 - [info]
192.168.100.52(192.168.100.52:3306) (current master)
+--192.168.100.51(192.168.100.51:3306)
+--192.168.100.53(192.168.100.53:3306)

Fri Feb  4 13:27:04 2022 - [info] Checking replication health on 192.168.100.51..
Fri Feb  4 13:27:04 2022 - [info]  ok.
Fri Feb  4 13:27:04 2022 - [info] Checking replication health on 192.168.100.53..
Fri Feb  4 13:27:04 2022 - [info]  ok.
Fri Feb  4 13:27:04 2022 - [warning] master_ip_failover_script is not defined.
Fri Feb  4 13:27:04 2022 - [warning] shutdown_script is not defined.
Fri Feb  4 13:27:04 2022 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.
 

 

 mha start

[root@mha-manager ~]# start
[1] 81615
[root@mha-manager ~]# Fri Feb  4 13:31:53 2022 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Fri Feb  4 13:31:53 2022 - [info] Reading application default configuration from /etc/mha.cnf..
Fri Feb  4 13:31:53 2022 - [info] Reading server configuration from /etc/mha.cnf..

[root@mha-manager ~]# status
mha (pid:81615) is running(0:PING_OK), master:192.168.100.52
 

 

 node2 stop(현재 master)

[root@node2 ~]# ps -ef | grep mysql
root     12098 10867  0 11:54 pts/2    00:00:00 /bin/sh /mysql/bin/mysqld_safe --user=mysql
mysql    12203 12098  0 11:54 pts/2    00:00:04 /mysql/bin/mysqld --basedir=/mysql --datadir=/data --plugin-dir=/mysql/lib/plugin --user=mysql --log-error=/log/mariadb.log --pid-file=/log/mariadb.pid --socket=/tmp/mysql.sock
root     12238 10867  0 11:55 pts/2    00:00:00 mysql -uroot -px xx
root     18337   747  0 13:35 pts/1    00:00:00 grep --color=auto mysql

[root@node2 ~]# kill -9 12203 12098

 

 

 vip & 데이터 확인

new-node에 vip가 올라왔다.

[root@new-node ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.41.227.47  netmask 255.255.254.0  broadcast 10.41.227.255
        ether f2:20:cd:b4:20:e9  txqueuelen 1000  (Ethernet)
        RX packets 311906  bytes 501860548 (478.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 107133  bytes 34401430 (32.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.53  netmask 255.255.255.0  broadcast 192.168.100.255
        ether f2:d7:cf:8b:19:1b  txqueuelen 1000  (Ethernet)
        RX packets 142261  bytes 10805722 (10.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4454  bytes 802550 (783.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.54  netmask 255.255.255.0  broadcast 192.168.100.255
        ether f2:d7:cf:8b:19:1b  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 222  bytes 17706 (17.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 222  bytes 17706 (17.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


MariaDB [(none)]> select count(*) from test.test;
+----------+
| count(*) |
+----------+
|      105 |
+----------+
1 row in set (0.00 sec)


MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| kim                |
| mysql              |
| performance_schema |
| sakila             |
| test               |
+--------------------+
6 rows in set (0.00 sec)


MariaDB [(none)]> show tables in sakila;
+----------------------------+
| Tables_in_sakila           |
+----------------------------+
| actor                      |
| actor_info                 |
| address                    |
| category                   |
| city                       |
| country                    |
| customer                   |
| customer_list              |
| film                       |
| film_actor                 |
| film_category              |
| film_list                  |
| film_text                  |
| inventory                  |
| language                   |
| nicer_but_slower_film_list |
| payment                    |
| rental                     |
| sales_by_film_category     |
| sales_by_store             |
| staff                      |
| staff_list                 |
| store                      |
+----------------------------+
23 rows in set (0.00 sec)