setting replicate mysql

huff.. setelah sukses install vmware dan setting network dengan bridge connection dari komputer guest (yang diinstall di vmware) — atau diasumsikan sebagai server baru (dalam artikel ini server database)– sekarang aku akan coba replicate mysql. kita asumsikan ada 2 server yaitu master (computer host:192.168.22.15) dan slave (computer guest–vmware–:192.168.22.115).

master slave

master slave

syarat2 yang dibutuhkan untuk replicate mysql ini adalah :

  1. terdapat lebih dari satu server database
  2. adanya mysql di kedua server
  3. adanya koneksi antara server2 tersebut

step2nya adalah sbb :

  1. untuk memudahkan remote ke slave, kita grant dulu akses mysql dari server luar
    mysql> GRANT ALL PRIVILEGES ON *.* TO cuplis@localhost IDENTIFIED BY ‘pass’ WITH GRANT OPTION;
    mysql> GRANT ALL PRIVILEGES ON *.* TO cuplis@192.168.22.15 IDENTIFIED BY ‘pass’ WITH GRANT OPTION;
    mysql> flush privileges;
  2. setting my.cnf di slave
    sebelum setting dimulai, lebih baik kita backup dulu file my.cnf supaya jika terjadi kesalahan lebih mudah restorenya.

    user@computer:$ sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf-ori
    user@computer:$ sudo vim /etc/mysql/my.cnf

    temukan baris seperti di bawah ini, kemudian remark dengan memberi tanda # (jika belum ada) di awal baris dan lakukan hal ini pada master dan slave.

    #bind-address           = 127.0.0.1

    konfigurasi bind-address ini hanya semula (ketika belum diremark) mengijinkan ip 127.0.0.1 untuk terhubung dengan mysql (dalam hal ini di server mysql yang akan dijadikan slave). supaya mysql di server slave bisa di akses selain dari ip yang didefinisikan di bind-address, maka kita remark bind-address.

  3. lakukan remote dari master (jika dirasa perlu) dengan menjalankan perintah berikut :
    user@computer:$ mysql -u cuplis -h 192.168.22.115 -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 9
    Server version: 5.0.51a-3ubuntu5.4 (Ubuntu)

    Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

    mysql>
  4. siapkan database yang akan di replicate, dalam kasusku ini adalah dbuks
    mysql> use dbuks;
    Database changed
    mysql> show tables;
    +—————–+
    | Tables_in_dbuks |
    +—————–+
    | medical         |
    | obat            |
    | siswa           |
    +—————–+
    3 rows in set (0.00 sec)

    mysql>

  5. konfigurasi my.cnf di master. tambahkan 3 baris berikut ini di my.cnf :server-id               = 1
    log_bin                 = /var/log/mysql/mysql-bin.log
    binlog_do_db     = dbuks
  6. restart mysql service di master
    user@computer:$ sudo /etc/init.d/mysql restart
  7. kemudian kita buat user untuk mysql dengan level replication di master
    user@computer:$ mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 35
    Server version: 5.0.75-0ubuntu10 (Ubuntu)

    Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

    mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'password_slave';
    Query OK, 0 rows affected (0.02 sec)

    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.03 sec)

    mysql>
  8. masih setting mysql di master
    user@computer:$ mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 31
    Server version: 5.0.75-0ubuntu10-log (Ubuntu)

    Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

    mysql> use dbuks;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    Database changed
    mysql> FLUSH TABLES WITH READ LOCK;
    Query OK, 0 rows affected (0.00 sec)

    mysql> show master status;
    +------------------+----------+--------------+------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+----------+--------------+------------------+
    | mysql-bin.000001 |       98 | dbuks        |                  |
    +------------------+----------+--------------+------------------+
    1 row in set (0.00 sec)

    mysql>

    informasi2 hasil dari show master status di atas akan diperlukan untuk konfigurasi di slave. kemudian kita keluar dari shell mysql dengan mengetikkan perintah quit.

  9. kopikan database yang ada di master ke slave. ada 2 cara yang dapat dilakukan untuk pengopian database ini. yang pertama dengan menggunakan dump database dan yang lainnya adalah dengan menggunakan “LOAD DATA FROM MASTER” di command slave. kali ini kita akan gunakan cara yang pertama. lakukan command berikut :
    user@computer:$ mysql -u cuplis -h 192.168.22.115 -p
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 9
    Server version: 5.0.51a-3ubuntu5.4 (Ubuntu)

    Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

    mysql>mysqldump -u root -p<password root di master> --opt dbuks > dbuks.sql
    (tidak ada spasi di antara -p dan password)

    perintah di atas akan menghasilkan SQL dump untuk database dbuks di file dbuks.sql. kemudian kita unlock tabel yang ada di database dbuks :

    user@computer:$ mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 33
    Server version: 5.0.75-0ubuntu10-log (Ubuntu)

    Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

    mysql> use dbuks;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A

    Database changed
    mysql> UNLOCK TABLES;
    Query OK, 0 rows affected (0.00 sec)
    mysql> quit;
  10. kopikan file dbuks.sql yang ada di master ke slave
    user@computer:$ scp /home/arditto/dbuks.sql arditto@192.168.22.115:~
    arditto@192.168.22.115's password:
    dbuks.sql                         100% 3363     3.3KB/s   00:00
  11. buat database dbuks di slave
    user@computer:$ mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 13
    Server version: 5.0.51a-3ubuntu5.4 (Ubuntu)

    Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

    mysql> create database dbuks;
    Query OK, 1 row affected (0.02 sec)

    mysql> quit;
  12. kemudian import SQL dump yang sudah kita dapatkan dari master tadi
    user@computer:$ mysql -u root -p dbuks < ~/dbuks.sql
  13. konfigurasi my.cnf di slave. tambahkan 5 baris berikut ini di my.cnf slave :
    user@computer:$ sudo vim /etc/mysql/my.cnf

    server-id=2
    master-host=192.168.22.15
    master-user=slave_user
    master-password=password_slave
    master-connect-retry=60
    replicate-do-db=dbuks

  14. restart mysql service di slave
    user@computer:$ sudo /etc/init.d/mysql restart
  15. langkah terakhir adalah setting change master di slave :
    user@computer:$ mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 10
    Server version: 5.0.51a-3ubuntu5.4 (Ubuntu)

    Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

    mysql> SLAVE START;
    Query OK, 0 rows affected (0.00 sec)

    mysql> CHANGE MASTER TO MASTER_HOST='192.168.22.15', MASTER_USER='slave_user', MASTER_PASSWORD='password_slave', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=98;
    Query OK, 0 rows affected (0.10 sec)

    mysql>

    MASTER_HOST : ip address master (dalam kasus ini 192.168.22.15)
    MASTER_USER : user yang sudah kita grant dengan privileges replication di master
    MASTER_PASSWORD : password MASTER_USER di master
    MASTER_LOG_FILE : file MySql yang diterima ketika kita menjalankan SHOW MASTER STATUS; di master
    MASTER_LOG_POS : posisi MySql yang diterima ketika kita menjalankan SHOW MASTER STATUS; di master

source :
http://groups.google.com/group/mysql-indonesia?hl=id
http://www.howtoforge.com/mysql_database_replication
http://forums.mysql.com/read.php?11,6916,184947#msg-184947
http://forums.mysql.com/read.php?26,36723,253532#msg-253532

Bookmarks:
  • Facebook
  • Google Bookmarks
  • Digg
  • LinkedIn
  • Twitter

Related posts:

  1. ubuntu ssh-copy-id : setting ssh tanpa password sebenernya proses ssh ke mirror dapat dipercepat dengan tanpa password....
  2. how to setting dns server pertama install bind9 : user@computer:$ sudo apt-get install bind9 kemudian...
  3. how to install and configure dhcp server salah satu cara untuk configure dhcp server adalah sbb :...
  4. how to install wordpress mu on nginx setting dns server tambahkan zone sarunkgenk.com di file /etc/bind/named.conf user@computer:$...

Related posts brought to you by Yet Another Related Posts Plugin.

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

1 Comment »

 
 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre user="" computer="" escaped="">