Para configurar um cluster MySQL de alta disponibilidade em dois servidores usando Docker, siga os passos abaixo.
cd /home
mkdir zbx7-mysql-ha-01
cd /home/zbx7-mysql-ha-01
escrever gitclone
escrever gitclone
chmod +x setup.sh
./setup.sh
docker-compose up -d
docker exec -it <NOME-DO-CONTAINER> bash
echo -e "[mysqld]\nreport_host=<IP-DO-SERVIDOR-PRINCIPAL>" | tee -a /etc/my.cnf
mysqlsh --sql -e "SHUTDOWN;"
docker-compose ps
docker-compose stop
docker-compose start
docker exec -it <NOME-DO-CONTAINER> mysqlsh root@localhost --password=<SENHA-ROOT>
dba.configureInstance('root@localhost:3306', {password: '<SENHA-ROOT>'});
dba.checkInstanceConfiguration('root@localhost:3306', {password: '<SENHA-ROOT>'});
var cluster = dba.createCluster('ZabbixCluster');
\sql
SHOW VARIABLES LIKE 'group_replication%';
SET GLOBAL group_replication_group_seeds = '<IP-DO-SERVIDOR-PRINCIPAL>:3306,<IP-DO-SERVIDOR-SECUNDARIO>:3306';
START GROUP_REPLICATION;
##############################################################################################
sudo ufw allow from <IP-DO-SERVIDOR-PRINCIPAL> to any port 3306 proto tcp
cd /home
mkdir zbx7-mysql-ha-02
cd /home/zbx7-mysql-ha-02
chmod +x setup.sh
./setup.sh
cd /home/zbx7-mysql-ha-02
docker-compose up -d
docker exec -it <NOME-DO-CONTAINER> bash
echo -e "[mysqld]\nreport_host=177.137.208.38" | tee -a /etc/my.cnf
mysqlsh --sql -e "SHUTDOWN;"
docker-compose ps
docker-compose stop
docker-compose start
docker exec -it <NOME-DO-CONTAINER> mysqlsh root@localhost --password=7xJQFBSceexH
dba.configureInstance('root@localhost:3306', {password: '7xJQFBSceexH'});
dba.checkInstanceConfiguration('root@localhost:3306', {password: '7xJQFBSceexH'});
##############################################################################################
cluster.addInstance('[email protected]:3306', {password: '7xJQFBSceexH', recoveryMethod: 'clone'});
Passo 4: Para criar o banco de dados 'zabbix-ha' após configurar o cluster MySQL, siga os passos abaixo:
docker exec -it mysql-zabbix-01 mysql -u root -p
SET GLOBAL super_read_only = OFF;
CREATE DATABASE `zabbix-ha`;
CREATE USER 'zabbix'@'%' IDENTIFIED BY '7xJQFBSceexH';
GRANT ALL PRIVILEGES ON `zabbix-ha`.* TO 'zabbix'@'%';
FLUSH PRIVILEGES;
SHOW DATABASES;
SHOW GRANTS FOR 'zabbix'@'%';
SET GLOBAL super_read_only = ON;
mysql -u <USUARIO> -p<SENHA-ROOT> -h <IP do servidor MySQL>
jdbc:mysql://<IP do servidor MySQL>:3306/<NOME-DATABASE>?allowPublicKeyRetrieval=true&useSSL=false
##############################################################################################
dba.dropMetadataSchema();
dba.rebootClusterFromCompleteOutage();
var cluster = dba.createCluster('ZabbixCluster');
cluster.addInstance('root@<IP-DO-HOST-SECUNDARIO>', {password: '<SENHA-ROOT>'});
START GROUP_REPLICATION;
cluster.status(); pct enter vmid
SHOW VARIABLES LIKE 'group_replication%'; SET GLOBAL group_replication_group_seeds = '45.224.129.55:3306,177.137.208.34:3306'; START GROUP_REPLICATION;
var cluster = dba.getCluster(); typeof cluster; cluster.addInstance("[email protected]:3306");