Albatron Xenon management mysql master-slave replication test

Environment: 2 VM virtual machine CentOS7 X86_64 bit systems

Configuration Environmental requirements:

One, two virtual machines to be shut down iptables close firewalld, close selinux, on-time synchronization parameters to ensure 2 virtual machine time is consistent with
two, two virtual machines sshd service to open 22 ports (Xenon code only supported by ssh port 22 access between each other)
three, Xenon service users to start and start the mysql user services must be the same user for the job, the system user mysql this example demonstrates the simulation are used.
Fourth, the system user 2 virtual machines mysql, to allow login shell, and mysql between two virtual machines that users can avoid each other access keys
V. mysql version 2 is installed on the virtual machine system must be mysql5.7 or later (including mysql5.7), and 2 mysql to turn semi-synchronous replication parameters (Xenon is based on the semi-synchronous replication)
six were required to install the software on 2 sshpass virtual machine system
seven, Xenon.json configuration files on 2 virtual machine system to call the shell command Related commands to execute. Because xenon is a system service mysql start a normal user, it executes a command line command, by xenon.json document
requires authorization system mysql user sudo privileges related commands, to be able to execute system commands
eight, xenon.json configuration file to configure a few accounts permission to allow xenon service can automatically create a master copy mysql from the relationship, as well as automatic switching mysql replication relationship and automatic fault recovery operation, etc.
Tip: when you configure mysql replication account and password in the configuration file xenon.json, xenon service It is the ability to automatically create a copy of an account, and permission was given permission%. And automatically create a copy relationship. But it found an error in the test will be prompted to copy the account permissions are incorrect.

So in this presentation, it copied the same to create their own accounts directly on the instance of two mysql.
Command is as follows :

grant replication slave on *.* to repuser@'172.16.0.%' identified by 'repuser9slave'; flush privileges; ##复制账户和密码 
 grant all on *.* to root@'127.0.0.1' identified by 'rrtestjianwei';flush privileges;  

## built in xenon HA + mysql cluster, it is recommended to read and write in the master database, so the xenon maintenance mysql cluster, slave library is not allowed to write .master after the failure of the main library, the library node slave switch to take place become the main library, so the original read-only access to the account by logging into the database becomes read-write permission to modify

 grant all on *.* to codeuser@'172.16.0.%' identified by 'rrtestjianwei';flush privileges;   

## allows code to link library accounts and passwords, and IP addresses, we recommend here to go directly to the service ip 172.16.0.100 binding NIC address as the unique code link library

Nine, 2 virtual machine IP address and binding / etc / hosts

系统IP地址
10.0.0.130  172.16.0.130
10.0.0.131  172.16.0.131

Tip: When in the two physical machine test, beginning since the two physical machine interpolation cable network port are not the same (one network port 2, one network port 3), so that the card within the configuration network ip address also not the same, binding service ip 2 machines xenon.json configuration file onto the card em1.
Although later tests, the xenon Services 2 machines can be started successfully, and can also pull up their mysql service, on 2 machines / data / xenon / bin / xenoncli cluster add ip: 8801 add each other's node mysql.
Ip and services can be successfully bound to the em1 set in advance. Then behind the question arises: In the binding machine has a service ip ip through this service and his own network ip can log in the database, but the service is not bound by this machine ip ip log on to the service end of mysql service
was surprised to be denied login mysql service (mysql log on to the service authority to determine no problem)
so let this room again within two cables plugged into the same network card, and then configure each network ip address on the same card , while binding service specified in the configuration file xenon.json ip on the card to the interpolation network cable. More than at this time the problem is resolved

Binding / etc / hosts:

[root@mgr01 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.0.130 mgr01
172.16.0.131 mgr03
[root@mgr03 ~]# cat /etc/hosts
172.16.0.130 mgr01
172.16.0.131 mgr03

Here are the specific configuration steps

Tip: The following configuration steps to be performed on the two virtual machines

First, install the binary version mysql5.7.24

tar xf  mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -sv mysql-5.7.24-linux-glibc2.12-x86_64 mysql
echo "export PATH=$PATH:/usr/local/mysql/bin" >/etc/profile.d/mysql.sh 
source  /etc/profile
初始化mysql:
mysqld  --defaults-file=/data/mysql/mysql3306/my3306.cnf  --initialize
启动mysql:
mysqld  --defaults-file=/data/mysql/mysql3306/my3306.cnf  &

[root@mgr01 ~]# cat .my.cnf 
[client]
socket = /tmp/mysql.sock
user=root
password=123456
prompt="(\\u@\\'mgr01':\\p)[\\d]>"

Mysql login account were authorized:

grant replication slave on *.* to repuser@'172.16.0.%' identified by 'repuser9slave'; flush privileges;
grant all on *.* to root@'127.0.0.1' identified by 'rrtestjianwei';flush privileges;
grant all on *.* to codeuser@'172.16.0.%' identified by 'rrtestjianwei';flush privileges;

Note: The above steps are executed on two machines installed mysql requirements /data/mysql/mysql3306/my3306.cnf configuration file must be open half MySQL parameters of synchronous replication.

The following parameters are to be written to /data/mysql/mysql3306/my3306.cnf profile:

plugin-load="semisync_master.so;semisync_slave.so"
rpl_semi_sync_master_enabled=OFF
rpl_semi_sync_slave_enabled=ON
rpl_semi_sync_master_wait_no_slave=ON
rpl_semi_sync_master_timeout=1000000000000000000  ##参数目的就是不让半同步复制转化为异步复制

Second, install xenon service

Description:
Xenon is a binary file a self-contained, no other system libraries in the operating system level. It is based on Linux build. No tips on MS Windows and OS / X, and this version is not compatible with Windows and OS / X.
It is a standalone application. Configured to run with MySQL backend when, requiring mysqld.

Xenon parallel using semi-synchronous replication GTID, MySQL version 5.7 or preferably version later . For more information, see my.cnf
Address: https://github.com/radondb/xenon/blob/master/docs/config/MySQL.md
semi-synchronous replication mysql following parameters to be written to / data / mysql /mysql3306/my3306.cnf profile

plugin-load="semisync_master.so;semisync_slave.so"
rpl_semi_sync_master_enabled=OFF
rpl_semi_sync_slave_enabled=ON
rpl_semi_sync_master_wait_no_slave=ON
rpl_semi_sync_master_timeout=1000000000000000000

Since the service is go xenon language development, it is necessary to go to run the environment, and the need to Go requires version 1.8 or later

2.1 Installation environment go

需要Go版本1.8或更高版本(对于ubuntu是“ sudo apt install golang”,对于centOS / redhat是“ yum install golang”)。
采用二进制安装golang ,版本是go1.9.3.linux-amd64.tar.gz
go 二进制包下载地址:
wget  https://storage.googleapis.com/golang/go1.9.3.linux-amd64.tar.gz
tar xf go1.11.linux-amd64.tar.gz  -C /usr/local/

[root@mgr01 ~]# tail -2 /etc/profile
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
[root@mgr01 ~]# go version
go version go1.11 linux/amd64

2.2 Installation Services xenon

1下载:
git clone https://github.com/radondb/xenon.git
cd xenon
2.编译构建
make build
 ls bin/
xenon  xenoncli
3.配置config
 cp xenon/conf/xenon-sample.conf.json /etc/xenon/xenon.json

[mysql@mgr01 ~]$ cat /data/xenon/bin/config.path
/etc/xenon/xenon.json

It should be noted that the operation of xenon account must match the mysql account, such as xenon start using ubuntu account, it needs permissions to start and ubuntu mysql directory mysql.
This is not the same as with traditional local mysql, mysql colleagues do not need an account, the account is running xenon mysql account.

Note: The following is a summary of the command line examples. For simplicity, we assume that xenon in the specified path for you. If not, replace xenon with / path / to / xenon.
In the xenon command path, you need to have a file named config.path, which is the absolute path xenon.json file. Ensure that the location specified using -c or --config of xenon_config_file.

2.3,2 machine to create a system user mysql

2 machines to create and implement a system user mysql mysql users free access to the secret key between two machines, but only 22 mysql system account to access the port

mysql useradd
passwd mysql
authorized mysql user sudo privileges can execute the following command:

 [root@mgr01 ~]# tail -1 /etc/sudoers
mysql ALL=(ALL)     NOPASSWD: /usr/sbin/ip

2 between the virtual machine system each user mysql keys Free Operation:

 ssh-keygen -t rsa 
 .ssh/authorized_keys
 chmod 600 .ssh/authorized_keys 

2.4, start the xenon services:

172.16.0.130 machine xenon.json as follows: (172.16.0.131 configuration file should be replaced with IP address 172.16.0.131 own internal network card)


[mysql@mgr01 ~]$ cat /etc/xenon/xenon.json 
{
    "server":
    {
        "endpoint":"172.16.0.130:8801"
    },

    "raft":
    {
        "meta-datadir":"raft.meta",
        "heartbeat-timeout":1000,
        "election-timeout":3000,
        "leader-start-command":"sudo /usr/sbin/ip a a 172.16.0.100/16 dev eth0 && arping -c 3 -A  172.16.0.100  -I eth0",
        "leader-stop-command":"sudo /usr/sbin/ip a d 172.16.0.100/16 dev eth0"
    },

    "mysql":
    {
        "admin":"root",
        "passwd":"rrtestjianwei",
        "host":"127.0.0.1",
        "port":3306,
        "basedir":"/usr/local/mysql",
        "defaults-file":"/data/mysql/mysql3306/my3306.cnf",
        "ping-timeout":1000,
        "master-sysvars":"super_read_only=0;read_only=0;sync_binlog=default;innodb_flush_log_at_trx_commit=default",
        "slave-sysvars": "super_read_only=1;read_only=1;sync_binlog=1000;innodb_flush_log_at_trx_commit=2"
    },

    "replication":
    {
        "user":"repuser",
        "passwd":"repuser9slave"
    },

    "backup":
    {
        "ssh-host":"172.16.0.130",
        "ssh-user":"mysql",
        "ssh-passwd":"rrtestjianwei669",
        "ssh-port":22,
        "backupdir":"/data/mysql/mysql3306/data",
        "xtrabackup-bindir":"/usr/bin",
        "backup-iops-limits":100000,
        "backup-use-memory": "1GB",
        "backup-parallel": 2
    },

    "rpc":
    {
        "request-timeout":500
    },

    "log":
    {
        "level":"INFO"
    }
}

Start command:
172.16.0.130 machine operation:

[mysql@mgr01 ~]$ /data/xenon/bin/xenon -c /etc/xenon/xenon.json > /data/xenon/xenon.log 2>&1 &

Adding xenon node :

[mysql@mgr01 xenon]$  /data/xenon/bin/xenoncli  cluster add 172.16.0.131:8801
 2019/12/08 23:13:29.937943       [WARNING]     cluster.prepare.to.add.nodes[172.16.0.131:8801].to.leader[]
 2019/12/08 23:13:29.938024       [WARNING]     cluster.canot.found.leader.forward.to[172.16.0.130:8801]
 2019/12/08 23:13:29.950792       [WARNING]     cluster.add.nodes.to.leader[].done

View xenon node:

[mysql@mgr01 ~]$ /data/xenon/bin/xenoncli  cluster status
+-------------------+--------------------------------+---------+---------+--------------------------+---------------------+----------------+-------------------+
|        ID         |              Raft              | Mysqld  | Monitor |          Backup          |        Mysql        | IO/SQL_RUNNING |     MyLeader      |
+-------------------+--------------------------------+---------+---------+--------------------------+---------------------+----------------+-------------------+
| 172.16.0.130:8801 | [ViewID:16 EpochID:1]@LEADER   | RUNNING | ON      | state:[NONE]␤            | [ALIVE] [READWRITE] | [true/true]    | 172.16.0.130:8801 |
|                   |                                |         |         | LastError:               |                     |                |                   |
+-------------------+--------------------------------+---------+---------+--------------------------+---------------------+----------------+-------------------+
| 172.16.0.131:8801 | [ViewID:16 EpochID:1]@FOLLOWER | RUNNING | ON      | state:[NONE]␤            | [ALIVE] [READONLY]  | [true/true]    | 172.16.0.130:8801 |
|                   |                                |         |         | LastError:               |                     |                |                   |
+-------------------+--------------------------------+---------+---------+--------------------------+---------------------+----------------+-------------------+
(2 rows)
操作完成过6s后,有最初的都是read_only变成了一个[READONLY和一个READWRITE

172.16.0.131 machine operation:

[mysql@mgr03 ~]$ /data/xenon/bin/xenon -c /etc/xenon/xenon.json > /data/xenon/xenon.log 2>&1 &
[mysql@mgr03 ~]$ /data/xenon/bin/xenoncli  cluster add 172.16.0.130:8801

[mysql@mgr03 ~]$ /data/xenon/bin/xenoncli  cluster status
+-------------------+--------------------------------+---------+---------+--------------------------+---------------------+----------------+-------------------+
|        ID         |              Raft              | Mysqld  | Monitor |          Backup          |        Mysql        | IO/SQL_RUNNING |     MyLeader      |
+-------------------+--------------------------------+---------+---------+--------------------------+---------------------+----------------+-------------------+
| 172.16.0.131:8801 | [ViewID:16 EpochID:1]@FOLLOWER | RUNNING | ON      | state:[NONE]␤            | [ALIVE] [READONLY]  | [true/true]    | 172.16.0.130:8801 |
|                   |                                |         |         | LastError:               |                     |                |                   |
+-------------------+--------------------------------+---------+---------+--------------------------+---------------------+----------------+-------------------+
| 172.16.0.130:8801 | [ViewID:16 EpochID:1]@LEADER   | RUNNING | ON      | state:[NONE]␤            | [ALIVE] [READWRITE] | [true/true]    | 172.16.0.130:8801 |
|                   |                                |         |         | LastError:               |                     |                |                   |
+-------------------+--------------------------------+---------+---------+--------------------------+---------------------+----------------+-------------------+
操作完成过6s后,有最初的都是read_only变成了一个[READONLY和一个READWRITE

At the same time service IP172.16.0.100 address bound to the 10.0.0.130 machine on

[mysql@mgr01 xenon]$ ip a|grep 172.16.0.100
    inet 172.16.0.100/16 scope global eth0

Log in mysql through service ip, and then create a test database:

[mysql@mgr01 xenon]$ mysql -ucodeuser -h172.16.0.100 -p'rrtestjianwei' -e "create database test03;show databases;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test01             |
| test02             |
| test03             |
+--------------------+
[mysql@mgr01 xenon]$ 

Third, xenon mysql management failures demonstrate a master-slave

Fault presentations, kill off the main library, try ip link library service, approximately 25s to link the success of the main library, and then delete the data in the new primary database after connecting
the main library switch can be completed in the 25s

Fault presentations,
1. Log master database, execute the shutdown turn off the main library, try ip link library service, about 17s to 20s to re-bind ip service to the master library card on the machine, and then connect the main success through this service ip library, and then you can view the operation of the database, write, update the data
(physical server several tests derived)

2. Log server master library, kill -9 mysql off process, and xenon on the master machine will 4s into the 11s in the master machine automatically pull up the mysql service, then the card ip to the master of the binding service, through this service ip then successfully connected the main library, you can view the operation of the database, write, update the data
(physical server several tests derived)

3 .. login server master database, remove the data directory data, close the master database mysql service, although this time around 1m minutes after the service has been blown another one ip mysql, but this time, the library can only be read, not write. Will ramming (physical server several tests derived) writing

4. If the shutdown only slave database then closed by ip address of the service record is then written to a close this instance mysql;
command is as follows:

[root@slavedb 3306]# mysql -ucodeuser -h192.168.1.100 -p'rrtestjianwei' -e "INSERT INTO test01.test1(username,password,create_time) values('tomcat', 'xiaohuahua',now());"; mysql -e "shutdown;

After the shutdown command, then execute the command immediately following the insertion of the recording:

mysql -ucodeuser -h192.168.1.100 -p'rrtestjianwei' -e "INSERT INTO test01.test1(username,password,create_time) values('tomcat', 'xiaohuahua',now());"

At this time ramming will continuously executed multiple times, then will not work, the duration of the 10-15s, it can be written to normal, but this time the same record will be written twice to the master library. (Test results of several physical servers)
as follows:

| 31 | tomcat   | xiaohuahua | 2019-12-12 17:20:11 |
| 32 | tomcat   | xiaohuahua | 2019-12-12 17:23:28 |
| 33 | tomcat   | xiaohuahua | 2019-12-12 17:23:28 |
| 34 | tomcat   | xiaohuahua | 2019-12-12 17:23:38 |
| 35 | tomcat   | xiaohuahua | 2019-12-12 17:23:40 |
| 36 | tomcat   | xiaohuahua | 2019-12-12 17:25:32 |
| 37 | tomcat   | xiaohuahua | 2019-12-12 17:25:32 |
| 38 | tomcat   | xiaohuahua | 2019-12-12 17:25:45 |
+----+----------+------------+---------------------+

5. If the removed slave data directory database, a record is written by the remote service ip address mysql then close this instance;
command is as follows:

[root@slavedb ~]#  mv data data_bak
[root@slavedb 3306]# ls
binlog  data_bak  logs  my.cnf  tmp
[root@slavedb ~]# mysql -ucodeuser -h192.168.1.100 -p'rrtestjianwei' -e "INSERT INTO test01.test1(username,password,create_time)values('tomcat', 'xiaohuahua',now());";mysql -e "shutdown;"
[mysql@localhost xenon]$ mysql -ucodeuser -h192.168.1.100 -p'rrtestjianwei' -e "INSERT INTO test01.test1(username,password,create_time) values('tomcat', 'xiaohuahua',now());"

Duration of time between 10-15s ramming, it can be written correctly, but at this time the same record are written twice to the master database. (Results of several tests of physical servers)

 39 | tomcat   | xiaohuahua | 2019-12-12 17:37:31 |
| 40 | tomcat   | xiaohuahua | 2019-12-12 17:37:31 |
| 41 | tomcat   | xiaohuahua | 2019-12-12 17:37:42 |
| 42 | tomcat   | xiaohuahua | 2019-12-12 17:37:43 |
+----+----------+------------+---------------------+
42 rows in set (0.00 sec)

Create a test table, insert the test statement:

CREATE TABLE `test1` (
`id` int(8) NOT NULL AUTO_INCREMENT, 
`username` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(20) COLLATE utf8_unicode_ci NOT NULL, 
`create_time` varchar(20) COLLATE utf8_unicode_ci NOT NULL, 
PRIMARY KEY (`id`) #主键ID
) ENGINE=innodb AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

INSERT INTO test1(username,password,create_time) values('tomcat', 'xiaohuahua',now());
INSERT INTO test1(username,password,create_time) values('tomcat', 'xiaohuahua',now());

The following is a physical machine dellR620 configuration commands:


 /data/xenon/bin/xenon -c /etc/xenon/xenon.json > /data/xenon/xenon.log 2>&1 &
 /data/xenon/bin/xenoncli cluster status
 /data/xenon/bin/xenoncli cluster add 192.168.1.39:8801,192.168.1.182:8801
  /data/xenon/bin/xenoncli cluster remove 192.168.1.105:8801
 sudo /usr/sbin/ip a a 192.168.1.100/32 dev em3 && arping -c 3 -A  192.168.1.100  -I em3

 sudo /usr/sbin/ip a d 192.168.1.100/32 dev em3

The following is an account create a database on the physical machine dellR620 command:

grant replication slave on *.* to repl@'192.168.1.%' identified by 'repl4slave'; flush privileges;
grant all on *.* to root@'127.0.0.1' identified by 'rrtestjianwei';flush privileges;
grant all on *.* to codeuser@'192.168.1.%' identified by 'rrtestjianwei';flush privileges;

The following are the contents dellR620 xenon.json profile wherein one of the physical machines:


[root@slavedb ~]# cat /etc/xenon/xenon.json 
{
    "server":
    {
        "endpoint":"192.168.1.39:8801"
    },

    "raft":
    {
        "meta-datadir":"raft.meta",
        "heartbeat-timeout":1000,
        "election-timeout":3000,
        "leader-start-command":"sudo /usr/sbin/ip a a 192.168.1.100/32 dev em3 && arping -c 3 -A  192.168.1.100  -I em3",
        "leader-stop-command":"sudo /usr/sbin/ip a d 192.168.1.100/32 dev em3"
    },

    "mysql":
    {
        "admin":"root",
        "passwd":"rrtestjianwei",
        "host":"127.0.0.1",
        "port":3306,
        "basedir":"/usr/local/mysql",
        "defaults-file":"/data/mysql/3306/my.cnf",
        "ping-timeout":1000,
        "master-sysvars":"super_read_only=0;read_only=0;sync_binlog=default;innodb_flush_log_at_trx_commit=default",
        "slave-sysvars": "super_read_only=1;read_only=1;sync_binlog=1000;innodb_flush_log_at_trx_commit=2"
    },

    "replication":
    {
        "user":"repl",
        "passwd":"repl4slave"
    },

    "backup":
    {
        "ssh-host":"192.168.1.39",
        "ssh-user":"mysql",
        "ssh-passwd":"rrtestjianwei669",
        "ssh-port":22,
        "backupdir":"/data/mysql/3306/data",
        "xtrabackup-bindir":"/usr/bin",
        "backup-iops-limits":100000,
        "backup-use-memory": "1GB",
        "backup-parallel": 2
    },

    "rpc":
    {
        "request-timeout":500
    },

    "log":
    {
        "level":"INFO"
    }
}

The above is a brief presentation on this record, to facilitate their access to, and hope you can help those in need of netizens

Guess you like

Origin blog.51cto.com/wujianwei/2458340