Versions Compared

Key

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

Setup Steps

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 server id is different in both sites.

Code Block
#Login to the 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.
root@sdnc-dbhost-0:/#
 
#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 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)

Info

You can skip this step if the server 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 server id as 200 in secondary site
root@sdnc-dbhost-0:/# sed 's/100/200/g' /etc/mysql/conf.d/server-id.cnf > /etc/file.conf
root@sdnc-dbhost-0:/# cp /etc/file.conf /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 Replication

site2 (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 site 1 IP, master port as nodePort service port number, master log file as log file of site 1, master log pos as log pos of site 1
mysql> CHANGE MASTER TO master_host='10.147.99.145', MASTER_PORT=30031, master_user='root', master_password='openECOMP1.0', master_log_file='sdnc-dbhost-0-bin.000004', master_log_pos=32970543;
mysql> start slave;


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 | 32970543 | | | |
+--------------------------+----------+--------------+------------------+-------------------+
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 service port number, master log file as log file of site 2, master log pos as log pos of site 2
mysql> CHANGE MASTER TO master_host='10.147.99.145', MASTER_PORT=30031, master_user='root', master_password='openECOMP1.0', master_log_file='sdnc-dbhost-0-bin.000004',master_log_pos=32970543;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)


Verify replication status on both sites.

Code Block
mysql> show slave status\G;

It should look like below:

Image Added