Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

We are using MySQL Master-Master replication strategy to set up replication across two kubernetes clusters (aka sites). The setup is done through below manual steps.

 1. Verify mysql MySQL server-id is different in both sites.

Code Block
#Login to master thedb pod on site 1 and site 2
ubuntu@k8s-s1-master:~$ kubectl exec -it sdnc-dbhost-0 -n onap bash
Defaulting container name to sdnc-db-container.
Use 'kubectl describe pod/sdnc-dbhost-0' to see all of the containers in this pod.
root@sdnc-dbhost-0:/#
 
#site#Verify server-id on site 1
root@sdnc-dbhost-0:/# cd /etc/mysql/conf.d
root@sdnc-dbhost-0:/etc/mysql/conf.d# cat server-id.cnf
[mysqld]
server-id=100

#site#Verify server-id on site 2
root@sdnc-dbhost-0:/# cd /etc/mysql/conf.d
root@sdnc-dbhost-0:/etc/mysql/conf.d# cat server-id.cnf
[mysqld]
server-id=200


  2. Make mysql server Ids unique in sites (optional, need basis)If MySQL site-id for site 1 and site 2, resulting form step 1, are not different, proceed with the below step to make them unique.

Info

You can skip this step if the server Ids -ids are verified to be unique in step #1. This step is only to be followed on site 2 (i.e. secondary site).

Code Block
#replace#Set server id as 200-id to a different number (e.g. 200) in the secondary site
root@sdnc-dbhost-0:/# sed 's/100/200/g' /etc/mysql/conf.d/server-id.cnf > /etc/file.conf.
#Assuming the current value for server-id on site 2 is 100, we aim to change it to 200.
root@sdnc-dbhost-0:/# cp /etc/file.confsed -i 's/100/200/g' /etc/mysql/conf.d/server-id.cnf
#restart mysql service 
root@sdnc-dbhost-0:/etc/mysql/conf.d# service mysql restart
[info] Stopping MySQL Community Server 5.7.21.
...........command terminated with exit code 137
ubuntu@k8s-s1-master:~$
 
#verify
root@sdnc-dbhost-0:/# cd /etc/mysql/conf.d
root@sdnc-dbhost-0:/etc/mysql/conf.d# cat server-id.cnf
[mysqld]
server-id=200


3. Setup Master-Master Replication

site2 On site 2 (secondary Secondary site):

Code Block
#Login to the master db pod
ubuntu@k8s-s1-master:~$ kubectl exec -it sdnc-dbhost-0 -n onap bash
Defaulting container name to sdnc-db-container.
Use 'kubectl describe pod/sdnc-dbhost-0' to see all of the containers in this pod.

#Login to mysql
root@sdnc-dbhost-0:/etc/mysql/conf.d# mysql -u root -popenECOMP1.0 
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 id is 46083 Server version: 5.7.21-log MySQL Community Server (GPL) 
 
Copyright (c) 2000, 2018, 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' for help. Type '\c' to clear the current input statement. 
 
mysql>
 
#find out log bin position
mysql> show master status;
+--------------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+--------------------------+----------+--------------+------------------+-------------------+
| sdnc-dbhost-0-bin.000004 | 154 | | | |
+--------------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql> stop slave;
#use master host as
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>


#Set: 
# - "master_host" to site 1's IP, master port as nodePortmaster node IP address
# - "master_port" to NodePort service port number, master log file as
# - "master_user" to user name (here 'root')
# - "master_password" to user's password (here 'root' user'd default password)
# - "master_log_file" to log file ofname from "show master status" commands on the peer site 1, master log pos as log pos of site 1(Primary)
# - "master_log_pos" to log pos from "show master status" commands on the peer site (Primary)
mysql> CHANGE MASTER TO master_host='10.147.99112.145136', MASTERmaster_PORTport=30031, master_user='root', master_password='openECOMP1.0', master_log_file='sdnc-dbhost-0-bin.000004', master_log_pos=3297054337433012;
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql>


On site 1 (Primary site1 (primary site):

Code Block
#Login to the master db pod
ubuntu@k8s-s1-master:~$ kubectl exec -it sdnc-dbhost-0 -n onap bash
Defaulting container name to sdnc-db-container.
Use 'kubectl describe pod/sdnc-dbhost-0' to see all of the containers in this pod.

#Login to mysql
root@sdnc-dbhost-0:/etc/mysql/conf.d# mysql -u root -popenECOMP1.0 
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 id is 46083 Server version: 5.7.21-log MySQL Community Server (GPL) 
 
Copyright (c) 2000, 2018, 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' for help. Type '\c' to clear the current input statement. 
mysql>
 
#find out log bin position
mysql> show master status;
+--------------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+--------------------------+----------+--------------+------------------+-------------------+
| sdnc-dbhost-0-bin.000004 | 3297054337433012 | | | |
+--------------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
#use master host as site 2 IP, master port as nodePort
mysql>


#Set: 
# - "master_host" to site 1's master node IP address
# - "master_port" to NodePort service port number, master log file as log file of site 2, master log pos as log pos of site 2
# - "master_user" to user name (here 'root')
# - "master_password" to user's password (here 'root' user'd default password)
# - "master_log_file" to log file name from "show master status" commands on peer site (Seconday)
# - "master_log_pos" to log pos from "show master status" commands on the peer site (Seconday)
mysql> CHANGE MASTER TO master_host='10.147.99113.14536', MASTERmaster_PORTport=30031, master_user='root', master_password='openECOMP1.0', master_log_file='sdnc-dbhost-0-bin.000004',master_log_pos=32970543154;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql>


Verify replication status on both sites.

...