Announcement

Collapse
No announcement yet.

How to configured MySQL Master to Master Replication on CentOS/RHEL 5.x/6.x?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to configured MySQL Master to Master Replication on CentOS/RHEL 5.x/6.x?

    How to configured MySQL Master to Master Replication on CentOSRHEL 5.x/6.x?
    What are the most required steps to do it?

    Thanks in advance.

  • #2
    Iptables service should be off on both Master1 & Master2 server
    Code:
    [[email protected] ~]# iptables -F
    [[email protected] ~]# iptables -t nat -F
    [[email protected] ~]# /etc/init.d/iptables save
    [[email protected] ~]# /etc/init.d/iptables restart
    Selinux should be disabled on both server
    Code:
    [[email protected] ~]# getenforce
    Disabled
    Step:1 MySQL installation on both Master1 & Master2 server

    Install package on both Master1 & Master2 server for Replication
    Code:
      [[email protected] ~]# yum install mysql mysql-server -y
    Start Mysql service on both server
    Code:
    [[email protected] ~]# service mysqld start
    [[email protected] ~]# chkconfig mysqld on
    Generate mysql root password on both server
    Code:
    [[email protected] ~]# /usr/bin/mysql_secure_installation
    Step: 2 Configure MySQL Master1 Server (192.168.0.62)

    Edit MySQL configuration file /etc/my.cnf and add below mentioned following entries in [mysqld] section. Make sure parameter which are in bold this should be changed with yours.
    Code:
    [[email protected] ~]# cp -p /etc/my.cnf /etc/my.cnf.org
    [[email protected] ~]# vi /etc/my.cnf
    [mysqld]
    server-id=1
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    log-bin
    binlog-do-db=[B]db1[/B]
    master-host = [B]192.168.0.63[/B]
    master-user = [B]shahzad[/B] ## this user is created on master2 server
    master-password = [B]redhat[/B] ## this password is created on master2 server
    master-port = 3306
    [[email protected] ~]# service mysqld restart
    Create a user with replication slave privileges on master 1 server for master2 through MySQL master2 server will connect/synchronize with master1 server.
    Code:
    [[email protected] ~]# mysql -u root –p
    Syntax,
    mysql>grant replication slave on *.* to ‘[B]rep_user[/B]‘@192.168.0.63 identified by ‘[B]rep_password[/B]‘;
    Example,
    mysql>grant replication slave on *.* to ‘shahzad’@192.168.0.63 identified by ‘redhat’;
    mysql>select user from mysql.user;
    mysql>start slave;
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    Step: 3 Configure MySQL Master2 Server (192.168.0.63)

    Configure MySQL Master2 Server
    Code:
    [[email protected] ~]# cp -p /etc/my.cnf /etc/my.cnf.org
    [[email protected] ~]# vi /etc/my.cnf
    [mysqld]
    server-id=2
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    #old_passwords=1
    master-host = [B]192.168.0.62[/B]
    master-user = [B]shahzad[/B] ####this user is created on master1 server
    master-password = [B]redhat[/B] ####this password is created on master1 server
    master-port = 3306
    log-bin #information for becoming master added
    binlog-do-db=[B]db1[/B]
    
    [[email protected] ~]# service mysqld restart
    Create a user with replication privileges on Maste2 Server for master1 connectivity
    Code:
    [[email protected] ~]# mysql -u root –p
    Syntax,
    mysql>grant replication slave on *.* to ‘rep_user’@192.168.0.62 identified by ‘rep_password’;
    Example,
    mysql>grant replication slave on *.* to ‘shahzad’@192.168.0.62 identified by ‘redhat’;
    mysql>start slave;
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    Check the status of Binary File and Position on Master2 Server
    Code:
      mysql> show master status;
    +——————-+—————-+——————-+————————–+
    | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +————————+—————-+——————-+———————-+
    | mysqld-bin.000001 | 448 | db1 | |
    +——————-+—————-+——————-+—————————+
    1 row in set (0.00 sec)
    Check status on Master1 server

    mysql> show slave status \G;


    Step: 4 Replication Testing

    On Master1 Server
    Code:
      mysql>create database db1;
    mysql>show databases;
    mysql>use db1;
    mysql>create table emp(name varchar(20), salary int);
    mysql> show databases;
    +————————+
    | Database |
    +————————+
    | information_schema |
    | db1 |
    | mysql |
    +————————+
    3 rows in set (0.00 sec)
    Now, Go on Master2 Server and check the replicated data
    Code:
     mysql> show databases;
    +————————+
    | Database |
    +————————-+
    | information_schema |
    | db1 |
    | mysql |
    +————————–+
    3 rows in set (0.00 sec)
    Successfully database is replicated from Master1 to Master2 server.
    Now, create a table inside MySQL database “db1” and check whether data is replicating from master2 server to master1 server or not.
     mysql>use db1;
    mysql>show tables
    mysql>create table course(book varchar(20) semester int);
    Go on Master1 Server and check the replicated data
    Code:
      mysql> show tables;
    +—————+
    | Tables_in_db1 |
    +—————–+
    | course |
    | emp |
    +——————+
    2 rows in set (0.00 sec)
    Cheers!! you now configured MySQL Master to Master Replication.

    Last edited by Nimbus; 22-08-16, 09:13 AM.

    Comment


    • #3
      Hello guys! Peachy essay writing service was the first I’ve ever used and will be the only one. I was skeptical about ordering an essay from any site. On top of that my paper was based on a field that was more complex and I didn’t really know if any essay writing service was equipped with a writer who is also knowledgeable in IT. But https://master-paper.com service finished paper a day before the actual due date and that was pretty good.

      Comment


      • #4
        Originally posted by louisford View Post
        Hello guys! Peachy essay writing service was the first I’ve ever used and will be the only one. I was skeptical about ordering an essay from any site. On top of that my paper was based on a field that was more complex and I didn’t really know if any essay writing service was equipped with a writer who is also knowledgeable in IT. But master-paper.com service finished paper a day before the actual due date and that was pretty good.
        EssayHelp is an essay aid internet site. As a writer looking for essay help, you can discover all type of aid to keep you writing in order. EssayHelp is cost free and is easy to use. You only require to fill in a simple form as well as you are given with assistance that relates to your essay subject. essay assistance on the solution likewise provides you tips to help you prosper with essay writing and additionally advice on exactly how to become a better author.

        Comment

        Working...
        X