Pagi ini awan sangat cerah membuatku lebih bersemangat lagi untuk menulis agar membuat setiap orang menjadi lebih bercerah untuk bersemangat belajar.
Hari ini saya akan sharing mengenai Load Balancing Percona XtraDB Cluster, Load Balancing akan memudahkan kita dalam memanggil database clustering,dimana di dalam konfigurasinya kita tinggal menambahkan daftar IP Cluster servernya . gambaran singkatnya seperti itu deh . . Oke Langsung saja.
1. Login ke Server Cluster anda , lalu masuk ke /usr/bin/clustercheck dengan perintah : nano /usr/bin/clustercheck
Nanti akan terlihat baris seperti dibawah ini , silahkan anda masukkan user mysql dan password mysql anda
19
20
| MYSQL_USERNAME="${1-clustercheckuser}" MYSQL_PASSWORD="${2-clustercheckpassword!}" |
2. Masuk ke mysql command dengan perintah : mysql -u root -p
Setelah itu masukkan 2 Command dibawah ini secara berurutan
mysql>
grant
process
on
*.*
to
'clustercheckuser'
@
'localhost'
identified
by
'clustercheckpassword!'
;
mysql> flush
privileges
;
3. Sekarang coba anda jalankan clustercheck dengan perintah : clustercheck
Jika terdapat respon 200 OK seperti dibawah ini,berarti sudah berhasil
$ clustercheck
HTTP/1.1 200 OK
Content-Type: text/plain
Connection: close
Content-Length: 40
Percona XtraDB Cluster Node is synced.
4.Setelah itu kita masuk ke config mysqlchk dengan perintah : nano /etc/xinetd.d/mysqlchk dan pastikan sudah seperti dibawah ini , pastikan port di isi dengan 9200
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| service mysqlchk { # this is a config for xinetd, place it in /etc/xinetd.d/ disable = no flags = REUSE socket_type = stream port = 9200 wait = no user = nobody server = /usr/bin/clustercheck log_on_failure += USERID only_from = 0.0.0.0 /0 # recommended to put the IPs that need # to connect exclusively (security purposes) per_source = UNLIMITED }
|
5. Lalu edit /etc/services dengan perintah nano /etc/services untuk mengijinkan xinetd berjalan . Tambahkan baris ini dibagian paling bawah :
Local services mysqlchk 9200 /tcp # mysqlchk
|
6.Install xinetd jika belum terinstall ,masukkan perintah : sudo apt-get install xinetd
$ sudo apt-get install xinetd |
7. Restart xinetd dengan perintah : sudo service xinetd restart
$ sudo service xinetd restart |
jika sudah seperti dibawah ini berarti sudah berjalan
$ netstat -ntlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address ... State PID/Program name tcp 0 0 0.0.0.0:3306 ... LISTEN 2877/mysqld tcp 0 0 0.0.0.0:9200 ... LISTEN 3545/xinetd tcp 0 0 0.0.0.0:22 ... LISTEN 786/sshd tcp 0 0 0.0.0.0:4567 ... LISTEN 2877/mysqld tcp6 0 0 :::22 ... LISTEN 786/sshd |
9. Coba lakukan telnet dengan perintah seperti dibawah ini
$ telnet 127.0.0.1 9200 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. HTTP/1.1 200 OK Content-Type: text/plain Connection: close Content-Length: 40 Percona XtraDB Cluster Node is synced. Connection closed by foreign host. |
10. Lakukan perintah - perintah diatas semua dari nomor 1 - 9 di server cluster lainnya
11. Sekarang kita lakukan konfigurasi Load Balancer, Terlebih dahulu Buat Fresh Server (Server Baru) yang khusus untuk dijadikan Load Balancer nantinya , Setelah itu baru lakukan langkah dibawah ini :
12. Install Haproxy dengan perintah : sudo apt-get install haproxy
$ sudo apt-get install haproxy
|
14. Lalu tambahkan baris yang dicetak tebal dibawah ini dibagian paling bawah konfigurasi haproxy.cfg
31
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
uid 99
gid 99
#daemon
debug
#quiet
defaults
log global
mode http
option tcplog
option dontlognull
retries 3
redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen mysql-cluster 0.0.0.0:3306
mode tcp
balance roundrobin
option tcpka
option httpchk
server db01 192.168.10.11:3306 check port 9200 inter 12000 rise 3 fall 3
server db02 192.168.10.12:3306 check port 9200 inter 12000 rise 3 fall 3
server db03 192.168.10.13:3306 check port 9200 inter 12000 rise 3 fall 3
1
2
3
4
| # Set ENABLED to 1 if you want the init script to start haproxy. ENABLED=1 # Add extra flags here. #EXTRAOPTS="-de -m 16" |
16.Jalankan haproxy dengan perintah : sudo service haproxy start
sudo service haproxy start
|
18. Sekarang kita cek haproxy sudah berjalan dengan perintah ps aux seperti dibawah ini :
$ ps aux | grep -i haproxy
... /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -D -p /var/run/haproxy.pid
19. Dan cek port apakah sudah berjalan dengan perintah seperti dibawah ini :
$ sudo netstat -ntlp | grep 3306 tcp 0 0 0.0.0.0:3306 ... LISTEN 2783/haproxy |
Semoga Bermanfaat . ..
Load Balancing Percona XtraDB Clustering dengan "haproxy"
4/
5
Oleh
Jordan Andrean