Salah satu point penting dalam sebuah aplikasi/website adalah database server. Banyak admin yang membuat environment server mereka hanya dengan 1 (single) database karena kesulitan untuk maintain multi database server. Membuat Master-Slave atau Master-Master replication pada database adalah hal yang cukup tricky, untuk instalasi cukup mudah namun implementasi/penyesuaian ke aplikasi terkadang lupa dilakukan.
Untuk menghilangkan hal-hal seperti itu, lebih mudah untuk implementasi high-availability databases menggunakan galera cluster, karena semua database server akan menjadi server aktif yang dapat melayani read/write ke database. di artikel ini akan dibahas secara jelas bagaimana membangun high-availability database menggunakan galera cluster.
Pada tutorial ini yang akan dibuat adalah galera cluster dengan menggunakan 3 nodes menggunakan MariaDB 10.1 pada CentOS 7 seperti gambar 1.
Gambar 1. Topology Galera Cluster
SEMUA NODE
Tambah repository MariaDB pada masing-masing node
1 |
[root@node-1 ~]# vim /etc/yum.repos.d/MariaDB.repo |
Tambahkan informasi repository MariaDB dan save filenya
1 2 3 4 5 |
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.1/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 |
Install package MariaDB
1 |
[root@node-1 ~]# yum -y install MariaDB-server MariaDB-client MariaDB-common |
Menjalankan service MariaDB
1 |
[root@node-1 ~]# systemctl start mariadb |
Enable autostart saat booting
1 |
[root@node-1 ~]# systemctl enable mariadb |
Setup MariaDB
1 2 3 4 5 6 7 |
[root@node-1 ~]# mysql_secure_installation Enter current password for root (enter for none): <ENTER> Set root password? [Y/n] Y Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y |
Stop service MariaDB di semua node
1 |
[root@node-1 ~]# systemctl stop mariadb |
Buat file log untuk MariaDB
1 |
[root@node-1 ~]# touch /var/log/mariadb.log |
Atur permission untuk file tersebut
1 |
[root@node-1 ~]# chown mysql:mysql /var/log/mariadb.log |
NODE-1
Konfigurasi Galera pada node-1
1 |
[root@node-1 ~]# vim /etc/my.cnf.d/server.cnf |
Tambahkan konfigurasi dibawah ini lalu save
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[mysqld] log_error=/var/log/mariadb.log [galera] binlog_format=ROW default-storage-engine=innodb innodb_autoinc_lock_mode=2 bind-address=0.0.0.0 wsrep_on=ON wsrep_provider=/usr/lib64/galera/libgalera_smm.so wsrep_cluster_address="gcomm://192.168.1.201,192.168.1.202,192.168.1.203" wsrep_cluster_name="rcn-cluster" wsrep_sst_method=rsync wsrep_node_address="192.168.1.201" wsrep_node_name="node-1" |
Start Galera Cluster di node-1
1 |
[root@node-1 ~]# galera_new_cluster |
Verifikasi Galera Cluster di node-1 sudah aktif dengan melihat listen port
1 2 3 4 5 6 7 |
[root@node-1 ~]# lsof -i:4567 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 1298 mysql 11u IPv4 16499 0t0 TCP *:tram (LISTEN) [root@node-1 ~]# lsof -i:3306 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 1298 mysql 26u IPv4 16516 0t0 TCP *:mysql (LISTEN) |
Cek jumlah node Galera Cluster di mysql status (harusnya hanya 1 karena ini baru 1 node yang di setup)
1 2 3 4 5 6 7 8 |
[root@node-1 ~]# mysql -uroot -p MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 1 | +--------------------+-------+ 1 row in set (0.00 sec) |
Node LAINNYA
Konfigurasi pada node yang lain
1 |
[root@node-2 ~]# vim /etc/my.cnf.d/server.cnf |
Tambahkan konfigurasi dibawah ini
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[mysqld] log_error=/var/log/mariadb.log [galera] binlog_format=ROW default-storage-engine=innodb innodb_autoinc_lock_mode=2 bind-address=0.0.0.0 wsrep_on=ON wsrep_provider=/usr/lib64/galera/libgalera_smm.so wsrep_cluster_address="gcomm://192.168.1.201,192.168.1.202,192.168.1.203" wsrep_cluster_name="rcn-cluster" wsrep_sst_method=rsync wsrep_node_address="192.168.1.202" #yang harus dirubah wsrep_node_name="node-2" #yang harus dirubah |
Start service MariaDB
1 |
[root@node-2 ~]# systemctl start mariadb |
Verifikasi jumlah node pada Galera Cluster
1 2 3 4 5 6 7 |
MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 3 | +--------------------+-------+ 1 row in set (0.00 sec) |
Cek status Galera Cluster
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
MariaDB [(none)]> SHOW STATUS LIKE 'wsrep%'; +------------------------------+-------------------------------------------------------------+ | Variable_name | Value | +------------------------------+-------------------------------------------------------------+ | wsrep_apply_oooe | 0.000000 | | wsrep_apply_oool | 0.000000 | | wsrep_apply_window | 0.000000 | | wsrep_causal_reads | 0 | | wsrep_cert_deps_distance | 0.000000 | | wsrep_cert_index_size | 0 | | wsrep_cert_interval | 0.000000 | | wsrep_cluster_conf_id | 3 | | wsrep_cluster_size | 3 | | wsrep_cluster_state_uuid | a5a504c0-3013-11e8-95e1-ee37252c7bb8 | | wsrep_cluster_status | Primary | | wsrep_commit_oooe | 0.000000 | | wsrep_commit_oool | 0.000000 | | wsrep_commit_window | 0.000000 | | wsrep_connected | ON | | wsrep_desync_count | 0 | | wsrep_evs_delayed | | | wsrep_evs_evict_list | | | wsrep_evs_repl_latency | 0/0/0/0/0 | | wsrep_evs_state | OPERATIONAL | | wsrep_flow_control_paused | 0.000000 | | wsrep_flow_control_paused_ns | 0 | | wsrep_flow_control_recv | 0 | | wsrep_flow_control_sent | 0 | | wsrep_gcomm_uuid | a5a49b35-3013-11e8-8ad5-0be86fe5f5a3 | | wsrep_incoming_addresses | 192.168.1.202:3306,192.168.1.203:3306,192.168.1.201:3306 | | wsrep_last_committed | 0 | | wsrep_local_bf_aborts | 0 | | wsrep_local_cached_downto | 18446744073709551615 | | wsrep_local_cert_failures | 0 | | wsrep_local_commits | 0 | | wsrep_local_index | 2 | | wsrep_local_recv_queue | 0 | | wsrep_local_recv_queue_avg | 0.142857 | | wsrep_local_recv_queue_max | 2 | | wsrep_local_recv_queue_min | 0 | | wsrep_local_replays | 0 | | wsrep_local_send_queue | 0 | | wsrep_local_send_queue_avg | 0.000000 | | wsrep_local_send_queue_max | 1 | | wsrep_local_send_queue_min | 0 | | wsrep_local_state | 4 | | wsrep_local_state_comment | Synced | | wsrep_local_state_uuid | a5a504c0-3013-11e8-95e1-ee37252c7bb8 | | wsrep_protocol_version | 7 | | wsrep_provider_name | Galera | | wsrep_provider_vendor | Codership Oy <info@codership.com> | | wsrep_provider_version | 25.3.22(r3764) | | wsrep_ready | ON | | wsrep_received | 7 | | wsrep_received_bytes | 698 | | wsrep_repl_data_bytes | 0 | | wsrep_repl_keys | 0 | | wsrep_repl_keys_bytes | 0 | | wsrep_repl_other_bytes | 0 | | wsrep_replicated | 0 | | wsrep_replicated_bytes | 0 | | wsrep_thread_count | 2 | +------------------------------+-------------------------------------------------------------+ 58 rows in set (0.00 sec) |
Testing Galera Cluster dengan cara membuat database
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
MariaDB [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec) MariaDB [(none)]> CREATE DATABASE rcn; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | rcn | +--------------------+ 4 rows in set (0.00 sec) |
Cek pada node yang lain
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[root@node-2 ~]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 10.1.31-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | rcn | +--------------------+ 4 rows in set (0.00 sec) |
Sekian dulu untuk tutorialnya nanti akan dilanjut untuk performance Galera Cluster dibandingkan dengan Single Database Server.
Komentar