MariaDB
 sql >> Teknologi Basis Data >  >> RDS >> MariaDB

Manajemen Dasar MaxScale Menggunakan MaxCtrl untuk MariaDB Cluster

Dalam posting blog sebelumnya, kami telah membahas beberapa pengenalan instalasi, peningkatan, dan penerapan MaxScale menggunakan klien baris perintah MaxCtrl. Dalam posting blog ini, kita akan membahas aspek manajemen MaxScale untuk Cluster MariaDB kita.

Ada beberapa komponen MaxScale yang bisa kita kelola dengan MaxCtrl, yaitu:

  1. Manajemen server
  2. Manajemen layanan
  3. Manajemen pemantauan
  4. Manajemen pendengar
  5. Pengelolaan filter
  6. Manajemen MaxScale
  7. Manajemen pencatatan

Dalam posting blog ini, kita akan membahas 4 komponen pertama yang umum digunakan di MariaDB Cluster. Semua perintah dalam posting blog ini didasarkan pada MaxScale 2.4.11.

Manajemen Server

Daftar/Tampilkan Server

Buat daftar ringkasan semua server di MaxScale:

  maxctrl: list servers
┌────────────────┬────────────────┬──────┬─────────────┬─────────────────────────┬─────────────┐
│ Server         │ Address        │ Port │ Connections │ State                   │ GTID        │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
│ mariadbgalera1 │ 192.168.10.201 │ 3306 │ 0           │ Slave, Synced, Running  │ 100-100-203 │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
│ mariadbgalera2 │ 192.168.10.202 │ 3306 │ 0           │ Slave, Synced, Running  │ 100-100-203 │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
│ mariadbgalera3 │ 192.168.10.203 │ 3306 │ 0           │ Master, Synced, Running │ 100-100-203 │
└────────────────┴────────────────┴──────┴─────────────┴─────────────────────────┴─────────────┘

Untuk MariaDB Cluster, daftar server merangkum node dan status cluster, dengan MariaDB GTID-nya, hanya jika cluster diatur untuk mereplikasi dari cluster lain melalui Replikasi MariaDB standar. Status digunakan oleh MaxScale untuk mengontrol perilaku algoritme perutean:

  • Master - Untuk Cluster, ini dianggap sebagai Write-Master.
  • Slave - Jika semua slave down, tetapi master masih tersedia, maka router akan menggunakan master.
  • Synced - Sebuah node Cluster yang berada dalam status tersinkronisasi dengan cluster.
  • Berjalan - Server yang aktif dan berjalan. Semua server yang dapat terhubung dengan MariaDB MaxScale diberi label sebagai berjalan.

Meskipun MariaDB Cluster mampu menangani replikasi multi-master, MaxScale akan selalu memilih satu node untuk memegang peran Master yang akan menerima semua penulisan untuk perutean readwritesplit. Secara default, Galera Monitor akan memilih node dengan nilai wsrep_local_index terendah sebagai master. Ini berarti bahwa dua MaxScales yang berjalan di server yang berbeda akan memilih server yang sama sebagai master.

Tampilkan semua server lebih detail:

maxctrl: show servers

Buat Server

Ini biasanya hal pertama yang perlu Anda lakukan saat menyiapkan MaxScale sebagai penyeimbang beban. Adalah umum untuk menambahkan semua node MariaDB Cluster ke MaxScale dan memberi label dengan nama objek. Dalam contoh ini, kami memberi label node Galera seperti dalam format "mariadbgalera#":

maxctrl: create server mariadbgalera1 192.168.0.221 3306
maxctrl: create server mariadbgalera2 192.168.0.222 3306
maxctrl: create server mariadbgalera3 192.168.0.222 3306

Status server hanya akan dilaporkan dengan benar setelah kami mengaktifkan modul pemantauan, seperti yang ditunjukkan di bagian Manajemen Monitor di bagian bawah.

Menghapus Server

Untuk menghapus server, seseorang harus memutuskan tautan server dari layanan atau monitor apa pun sebelumnya. Sebagai contoh, dalam daftar server berikut, kami ingin menghapus mariadbgalera3 dari MaxScale:

  maxctrl: list servers
┌────────────────┬────────────────┬──────┬─────────────┬─────────────────────────┬─────────────┐
│ Server         │ Address        │ Port │ Connections │ State                   │ GTID        │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
│ mariadbgalera1 │ 192.168.10.201 │ 3306 │ 0           │ Slave, Synced, Running  │ 100-100-203 │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
│ mariadbgalera2 │ 192.168.10.202 │ 3306 │ 0           │ Slave, Synced, Running  │ 100-100-203 │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼─────────────┤
│ mariadbgalera3 │ 192.168.10.203 │ 3306 │ 0           │ Master, Synced, Running │ 100-100-203 │
└────────────────┴────────────────┴──────┴─────────────┴─────────────────────────┴─────────────┘

Buat daftar semua monitor dan lihat apakah server merupakan bagian dari modul monitor:

 maxctrl: list monitors
 ┌─────────────────┬─────────┬────────────────────────────────────────────────┐
 │ Monitor         │ State   │ Servers                                        │
 ├─────────────────┼─────────┼────────────────────────────────────────────────┤
 │ MariaDB-Monitor │ Running │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
 └─────────────────┴─────────┴────────────────────────────────────────────────┘

Sepertinya mariadbgalera3 adalah bagian dari MariaDB-Monitor, jadi kita harus menghapusnya terlebih dahulu dengan menggunakan perintah "unlink monitor":

 maxctrl: unlink monitor MariaDB-Monitor mariadbgalera3
 OK

Selanjutnya, buat daftar semua layanan untuk memeriksa apakah server yang sesuai adalah bagian dari layanan MaxScale:

  maxctrl: list services
┌─────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
│ Service             │ Router         │ Connections │ Total Connections │ Servers                                        │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Read-Write-Service  │ readwritesplit │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Round-Robin-Service │ readconnroute  │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Replication-Service │ binlogrouter   │ 1           │ 1                 │                                                │
└─────────────────────┴────────────────┴─────────────┴───────────────────┴────────────────────────────────────────────────┘

Seperti yang Anda lihat, mariadbgalera3 adalah bagian dari Layanan Baca-Tulis dan Layanan Round-Robin. Hapus server dari layanan tersebut dengan menggunakan perintah "batalkan tautan layanan":

 maxctrl: unlink service Read-Write-Service mariadbgalera3
OK
 maxctrl: unlink service Round-Robin-Service mariadbgalera3
OK

Akhirnya, kita dapat menghapus server dari MaxScale dengan menggunakan perintah "destroy server":

 maxctrl: destroy server mariadbgalera3
OK

Verifikasi menggunakan "server daftar" bahwa kami telah menghapus mariadbgalera3 dari MaxScale.:

  maxctrl: list servers
┌────────────────┬────────────────┬──────┬─────────────┬─────────────────────────┬──────┐
│ Server         │ Address        │ Port │ Connections │ State                   │ GTID │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼──────┤
│ mariadbgalera1 │ 192.168.10.201 │ 3306 │ 0           │ Master, Synced, Running │      │
├────────────────┼────────────────┼──────┼─────────────┼─────────────────────────┼──────┤
│ mariadbgalera2 │ 192.168.10.202 │ 3306 │ 0           │ Slave, Synced, Running  │      │
└────────────────┴────────────────┴──────┴─────────────┴─────────────────────────┴──────┘

Ubah Parameter Server

Untuk mengubah parameter server, seseorang dapat menggunakan perintah "ubah server" yang hanya membutuhkan satu parameter kunci/nilai dalam satu waktu. Misalnya:

  maxctrl: alter server mariadbgalera3 priority 10
 OK

Gunakan perintah "show server" dan lihat ke bagian Parameter, untuk daftar parameter yang dapat diubah untuk objek "server":

maxctrl: show server mariadbgalera3
...

│ Parameters       │ {                                         │
│                  │     "address": "192.168.10.203",          │
│                  │     "protocol": "mariadbbackend",         │
│                  │     "port": 3306,                         │
│                  │     "extra_port": 0,                      │
│                  │     "authenticator": null,                │
│                  │     "monitoruser": null,                  │
│                  │     "monitorpw": null,                    │
│                  │     "persistpoolmax": 0,                  │
│                  │     "persistmaxtime": 0,                  │
│                  │     "proxy_protocol": false,              │
│                  │     "ssl": "false",                       │
│                  │     "ssl_cert": null,                     │
│                  │     "ssl_key": null,                      │
│                  │     "ssl_ca_cert": null,                  │
│                  │     "ssl_version": "MAX",                 │
│                  │     "ssl_cert_verify_depth": 9,           │
│                  │     "ssl_verify_peer_certificate": false, │
│                  │     "disk_space_threshold": null,         │
│                  │     "priority": "10"                      │
│                  │ }

Perhatikan bahwa efek perintah ubah bersifat langsung dan nilai parameter dalam waktu proses akan dimodifikasi serta nilai dalam file konfigurasi MaxScale individualnya di dalam /var/lib/maxscale/maxscale.cnf.d/ untuk kegigihan saat memulai ulang.

Setel Status Server

MaxScale memungkinkan server Galera backend untuk sementara dikecualikan dari set penyeimbangan beban dengan mengaktifkan mode pemeliharaan. Kita dapat mencapai ini dengan menggunakan perintah "set server":

 maxctrl: set server mariadbgalera3 maintenance
OK

Saat melihat status server, kita akan melihat ini:

 maxctrl: show server mariadbgalera3
...
│ State            │ Maintenance, Running
...

Saat server dalam mode pemeliharaan, tidak ada koneksi yang dibuat ke server dan koneksi yang ada akan ditutup. Untuk menghapus status pemeliharaan dari host, gunakan perintah "hapus server":

 maxctrl: clear server mariadbgalera3 maintenance
OK

Verifikasi dengan "tampilkan server":

 maxctrl: show server mariadbgalera3
...
│ State            │ Slave, Synced, Running                    │
...

Memantau Manajemen

Buat Monitor

Modul monitor MaxScale untuk MariaDB Cluster disebut galeramon. Mendefinisikan modul pemantauan yang benar diperlukan agar MaxScale dapat menentukan perutean terbaik untuk kueri tergantung pada status node. Misalnya, jika node Galera berfungsi sebagai donor untuk node joiner, haruskah itu menjadi bagian dari node yang sehat? Dalam beberapa kasus seperti ketika ukuran database sangat kecil, menandai node donor sebagai sehat (dengan menyetel parameter available_when_donor=true di MaxScale) bukanlah rencana yang buruk dan terkadang meningkatkan kinerja perutean kueri.

Untuk membuat layanan (router), seseorang harus membuat pengguna pemantauan di backend server MariaDB. Biasanya, seseorang akan menggunakan pengguna pemantauan yang sama yang telah kita definisikan untuk modul monitor. Untuk Galera Cluster, jika pengguna pemantauan tidak ada, buat saja di salah satu node dengan hak istimewa berikut:

MariaDB> CREATE USER [email protected]'192.168.0.220' IDENTIFIED BY 'MaXSc4LeP4ss';
MariaDB> GRANT SELECT ON mysql.* TO 'maxscale_monitor'@'192.168.0.220';
MariaDB> GRANT SHOW DATABASES ON *.* TO 'maxscale_monitor'@'192.168.0.220';

Gunakan perintah "buat monitor" dan tentukan nama dengan galeramon sebagai modul monitor:

  maxctrl: create monitor MariaDB-Monitor galeramon servers=mariadbgalera1,mariadbgalera2,mariadbgalera3 user=maxscale_monitor password=MaXSc4LeP4ss
OK

Perhatikan bahwa kami tidak mengonfigurasi rahasia MaxScale yang berarti kami menyimpan kata sandi pengguna dalam format teks biasa. Untuk mengaktifkan enkripsi, lihat contoh di posting blog ini, Pengantar Administrasi MaxScale Menggunakan maxctrl untuk MariaDB Cluster di bagian Menambahkan Pemantauan ke MaxScale.

Daftar/Tampilkan Monitor

Untuk membuat daftar semua monitor:

 maxctrl: list monitors
┌─────────────────┬─────────┬────────────────────────────────────────────────┐
│ Monitor         │ State   │ Servers                                        │
├─────────────────┼─────────┼────────────────────────────────────────────────┤
│ MariaDB-Monitor │ Running │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
└─────────────────┴─────────┴────────────────────────────────────────────────┘

Untuk mendapatkan tampilan monitor yang lebih detail, gunakan perintah "tampilkan monitor":

 maxctrl: show monitor MariaDB-Monitor

┌─────────────────────┬───────────────────────────────────────────┐
│ Monitor             │ MariaDB-Monitor                           │
├─────────────────────┼───────────────────────────────────────────┤
│ State               │ Running                                   │
├─────────────────────┼───────────────────────────────────────────┤
│ Servers             │ mariadbgalera1                            │
│                     │ mariadbgalera2                            │
│                     │ mariadbgalera3                            │
├─────────────────────┼───────────────────────────────────────────┤
│ Parameters          │ {                                         │
│                     │     "user": "maxscale_monitor",           │
│                     │     "password": "*****",                  │
│                     │     "passwd": null,                       │
│                     │     "monitor_interval": 2000,             │
│                     │     "backend_connect_timeout": 3,         │
│                     │     "backend_read_timeout": 1,            │
│                     │     "backend_write_timeout": 2,           │
│                     │     "backend_connect_attempts": 1,        │
│                     │     "journal_max_age": 28800,             │
│                     │     "disk_space_threshold": null,         │
│                     │     "disk_space_check_interval": 0,       │
│                     │     "script": null,                       │
│                     │     "script_timeout": 90,                 │
│                     │     "events": "all",                      │
│                     │     "disable_master_failback": false,     │
│                     │     "available_when_donor": true,         │
│                     │     "disable_master_role_setting": false, │
│                     │     "root_node_as_master": false,         │
│                     │     "use_priority": false,                │
│                     │     "set_donor_nodes": false              │
│                     │ }                                         │
├─────────────────────┼───────────────────────────────────────────┤
│ Monitor Diagnostics │ {                                         │
│                     │     "disable_master_failback": false,     │
│                     │     "disable_master_role_setting": false, │
│                     │     "root_node_as_master": false,         │
│                     │     "use_priority": false,                │
│                     │     "set_donor_nodes": false              │
│                     │ }                                         │
└─────────────────────┴───────────────────────────────────────────┘

Hentikan/Mulai Monitor

Menghentikan monitor akan menghentikan sementara pemantauan server. Ini biasanya digunakan bersama dengan perintah "set server" untuk mengontrol status server secara manual. Untuk menghentikan layanan pemantauan, gunakan perintah "stop monitor":

 maxctrl: stop monitor MariaDB-Monitor
OK

Verifikasi status dengan "tampilkan monitor":

 maxctrl: show monitors MariaDB-Monitor
┌─────────────────────┬───────────────────────────────────────────┐
│ Monitor             │ MariaDB-Monitor                           │
├─────────────────────┼───────────────────────────────────────────┤
│ State               │ Stopped                                   │
...

Untuk memulai lagi, gunakan "start monitor":

 maxctrl: start monitor MariaDB-Monitor
OK

Ubah Parameter Monitor

Untuk mengubah parameter monitor ini, gunakan perintah "alter monitor" dan tentukan kunci/nilai parameter seperti di bawah ini:

 maxctrl: alter monitor MariaDB-Monitor available_when_donor true
OK

Gunakan perintah "tampilkan monitor" dan lihat ke bagian Parameter, untuk daftar parameter yang dapat diubah untuk modul galeramon:

maxctrl: show server mariadbgalera3
...
│ Parameters          │ {                                         │
│                     │     "user": "maxscale_monitor",           │
│                     │     "password": "*****",                  │
│                     │     "monitor_interval": 2000,             │
│                     │     "backend_connect_timeout": 3,         │
│                     │     "backend_read_timeout": 1,            │
│                     │     "backend_write_timeout": 2,           │
│                     │     "backend_connect_attempts": 1,        │
│                     │     "journal_max_age": 28800,             │
│                     │     "disk_space_threshold": null,         │
│                     │     "disk_space_check_interval": 0,       │
│                     │     "script": null,                       │
│                     │     "script_timeout": 90,                 │
│                     │     "events": "all",                      │
│                     │     "disable_master_failback": false,     │
│                     │     "available_when_donor": true,         │
│                     │     "disable_master_role_setting": false, │
│                     │     "root_node_as_master": false,         │
│                     │     "use_priority": false,                │
│                     │     "set_donor_nodes": false              │
│                     │ }                                         │

Menghapus Monitor

Untuk menghapus monitor, seseorang harus menghapus semua server yang terhubung dengan monitor terlebih dahulu. Misalnya, perhatikan monitor berikut di MaxScale:

 maxctrl: list monitors
┌─────────────────┬─────────┬────────────────────────────────────────────────┐
│ Monitor         │ State   │ Servers                                        │
├─────────────────┼─────────┼────────────────────────────────────────────────┤
│ MariaDB-Monitor │ Running │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
└─────────────────┴─────────┴────────────────────────────────────────────────┘

Hapus semua server dari layanan tertentu:

 maxctrl: unlink monitor MariaDB-Monitor mariadbgalera1 mariadbgalera2 mariadbgalera3

OK

Monitor kami sekarang terlihat seperti ini:

 maxctrl: list monitors
┌─────────────────┬─────────┬─────────┐
│ Monitor         │ State   │ Servers │
├─────────────────┼─────────┼─────────┤
│ MariaDB-Monitor │ Running │         │
└─────────────────┴─────────┴─────────┘

Hanya setelah itu kita dapat menghapus monitor:

 maxctrl: destroy monitor MariaDB-Monitor
OK

Tambah/Hapus Server ke Monitor

Setelah membuat monitor, kita dapat menggunakan perintah "link monitor" untuk menambahkan server Galera ke dalam monitor. Gunakan nama server seperti yang dibuat di bagian Buat Server:

 maxctrl: link monitor MariaDB-Monitor mariadbgalera1 mariadbgalera2 mariadbgalera3
OK

Demikian pula, untuk menghapus server dari layanan, cukup gunakan perintah "unlink monitor":

 maxctrl: unlink monitor MariaDB-Monitor mariadbgalera3
OK

Verifikasi dengan perintah "daftar monitor" atau "tampilkan monitor".

Manajemen Layanan

Buat Layanan

Untuk membuat layanan (router), seseorang harus membuat pengguna pemantauan di backend server MariaDB. Biasanya, seseorang akan menggunakan pengguna pemantauan yang sama yang telah kita definisikan untuk modul monitor. Untuk Galera Cluster, jika pengguna pemantauan tidak ada, buat saja di salah satu node dengan hak istimewa berikut:

MariaDB> CREATE USER [email protected]'192.168.0.220' IDENTIFIED BY 'MaXSc4LeP4ss';
MariaDB> GRANT SELECT ON mysql.* TO 'maxscale_monitor'@'192.168.0.220';
MariaDB> GRANT SHOW DATABASES ON *.* TO 'maxscale_monitor'@'192.168.0.220';

Dimana 192.168.0.220 adalah alamat IP dari host MaxScale.

Kemudian, tentukan nama layanan, jenis perutean bersama dengan pengguna pemantauan untuk MaxScale untuk terhubung ke server backend:

 maxctrl: create service Round-Robin-Service readconnroute user=maxscale_monitor password=******
OK

Anda juga dapat menentukan parameter tambahan saat membuat layanan. Dalam contoh ini, kami ingin node "master" disertakan dalam set keseimbangan round-robin untuk Klaster Galera MariaDB kami:

 maxctrl: create service Round-Robin-Service readconnroute user=maxscale_monitor password=****** router_options=master,slave
OK

Gunakan perintah "show service" untuk melihat parameter yang didukung. Untuk router round-robin, daftarnya sebagai berikut:

  maxctrl: show service Round-Robin-Service
...
│ Parameters          │ {                                          │
│                     │     "router_options": null,                │
│                     │     "user": "maxscale_monitor",            │
│                     │     "password": "*****",                   │
│                     │     "passwd": null,                        │
│                     │     "enable_root_user": false,             │
│                     │     "max_retry_interval": 3600,            │
│                     │     "max_connections": 0,                  │
│                     │     "connection_timeout": 0,               │
│                     │     "auth_all_servers": false,             │
│                     │     "strip_db_esc": true,                  │
│                     │     "localhost_match_wildcard_host": true, │
│                     │     "version_string": null,                │
│                     │     "weightby": null,                      │
│                     │     "log_auth_warnings": true,             │
│                     │     "retry_on_failure": true,              │
│                     │     "session_track_trx_state": false,      │
│                     │     "retain_last_statements": -1,          │
│                     │     "session_trace": 0

Untuk router split baca-tulis, parameter yang didukung adalah:

  maxctrl: show service Read-Write-Service
...
│ Parameters          │ {                                                           │
│                     │     "router_options": null,                                 │
│                     │     "user": "maxscale_monitor",                             │
│                     │     "password": "*****",                                    │
│                     │     "passwd": null,                                         │
│                     │     "enable_root_user": false,                              │
│                     │     "max_retry_interval": 3600,                             │
│                     │     "max_connections": 0,                                   │
│                     │     "connection_timeout": 0,                                │
│                     │     "auth_all_servers": false,                              │
│                     │     "strip_db_esc": true,                                   │
│                     │     "localhost_match_wildcard_host": true,                  │
│                     │     "version_string": null,                                 │
│                     │     "weightby": null,                                       │
│                     │     "log_auth_warnings": true,                              │
│                     │     "retry_on_failure": true,                               │
│                     │     "session_track_trx_state": false,                       │
│                     │     "retain_last_statements": -1,                           │
│                     │     "session_trace": 0,                                     │
│                     │     "use_sql_variables_in": "all",                          │
│                     │     "slave_selection_criteria": "LEAST_CURRENT_OPERATIONS", │
│                     │     "master_failure_mode": "fail_instantly",                │
│                     │     "max_slave_replication_lag": -1,                        │
│                     │     "max_slave_connections": "255",                         │
│                     │     "retry_failed_reads": true,                             │
│                     │     "prune_sescmd_history": false,                          │
│                     │     "disable_sescmd_history": false,                        │
│                     │     "max_sescmd_history": 50,                               │
│                     │     "strict_multi_stmt": false,                             │
│                     │     "strict_sp_calls": false,                               │
│                     │     "master_accept_reads": false,                           │
│                     │     "connection_keepalive": 300,                            │
│                     │     "causal_reads": false,                                  │
│                     │     "causal_reads_timeout": "10",                           │
│                     │     "master_reconnection": false,                           │
│                     │     "delayed_retry": false,                                 │
│                     │     "delayed_retry_timeout": 10,                            │
│                     │     "transaction_replay": false,                            │
│                     │     "transaction_replay_max_size": "1Mi",                   │
│                     │     "optimistic_trx": false                                 │
│                     │ }

List/Show Services
 

To list out all created services (routers), use the "list services" command:

 maxctrl: list services
┌─────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
│ Service             │ Router         │ Connections │ Total Connections │ Servers                                        │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Read-Write-Service  │ readwritesplit │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Round-Robin-Service │ readconnroute  │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Binlog-Repl-Service │ binlogrouter   │ 1           │ 1                 │                                                │
└─────────────────────┴────────────────┴─────────────┴───────────────────┴────────────────────────────────────────────────┘

In the above examples, we have created 3 services, with 3 different routers. However, the Binlog-Repl-Service for our binlog server is not linked with any servers yet.

To show all services in details:

 maxctrl: show services

Or if you want to show a particular service:

 maxctrl: show service Round-Robin-Service

Stop/Start Services

Stopping a service will prevent all the listeners for that service from accepting new connections. Existing connections will still be handled normally until they are closed. To stop and start all services, use the "stop services":

 maxctrl: stop services
 maxctrl: show services
 maxctrl: start services
 maxctrl: show services

Or we can use the "stop service" to stop only one particular service:

 maxctrl: stop services Round-Robin-Service

Delete a Service

In order to delete a service, one has to remove all servers and destroy the listeners associated with the service first. For example, consider the following services in MaxScale:

 maxctrl: list services
┌─────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
│ Service             │ Router         │ Connections │ Total Connections │ Servers                                        │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Read-Write-Service  │ readwritesplit │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Round-Robin-Service │ readconnroute  │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Replication-Service │ binlogrouter   │ 1           │ 1                 │                                                │
└─────────────────────┴────────────────┴─────────────┴───────────────────┴────────────────────────────────────────────────┘

Let's remove Round-Robin-Service from the setup. Remove all servers from this particular service:

 maxctrl: unlink service Round-Robin-Service mariadbgalera1 mariadbgalera2 mariadbgalera3
OK

Our services are now looking like this:

 maxctrl: list services
┌─────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
│ Service             │ Router         │ Connections │ Total Connections │ Servers                                        │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Read-Write-Service  │ readwritesplit │ 1           │ 1                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Round-Robin-Service │ readconnroute  │ 1           │ 1                 │                                                │
├─────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Replication-Service │ binlogrouter   │ 1           │ 1                 │                                                │
└─────────────────────┴────────────────┴─────────────┴───────────────────┴────────────────────────────────────────────────┘

If the service is tied with a listener, we have to remove it as well. Use "list listeners" and specify the service name to look for it:

 maxctrl: list listeners Round-Robin-Service
┌──────────────────────┬──────┬─────────┬─────────┐
│ Name                 │ Port │ Host    │ State   │
├──────────────────────┼──────┼─────────┼─────────┤
│ Round-Robin-Listener │ 3307 │ 0.0.0.0 │ Running │
└──────────────────────┴──────┴─────────┴─────────┘

And then remove the listener:

 maxctrl: destroy listener Round-Robin-Service Round-Robin-Listener
OK

Finally, we can remove the service:

 maxctrl: destroy service Round-Robin-Service
OK

Modify Service's Parameter

Similar to the other object, one can modify a service parameter by using the "alter service" command:

 maxctrl: alter service Read-Write-Service master_accept_reads true
OK

Some routers support runtime configuration changes to all parameters. Currently all readconnroute, readwritesplit and schemarouter parameters can be changed at runtime. In addition to module specific parameters, the following list of common service parameters can be altered at runtime:

  • user
  • passwd
  • enable_root_user
  • max_connections
  • connection_timeout
  • auth_all_servers
  • optimize_wildcard
  • strip_db_esc
  • localhost_match_wildcard_host
  • max_slave_connections
  • max_slave_replication_lag
  • retain_last_statements

Note that alter command effect is immediate and the parameter's value in the runtime will be modified as well as the value in its individual MaxScale configuration file inside /var/lib/maxscale/maxscale.cnf.d/ for persistence across restart.

Add/Remove Servers into Service

After creating a service, we can use the link command to add our servers into the service. Use the server's name as created under Create Servers section:

 maxctrl: link service Round-Robin-Service mariadbgalera1 mariadbgalera2 mariadbgalera3
OK

Similarly, to remove a server from the service, just use "unlink service" command:

 maxctrl: unlink service Round-Robin-Service mariadbgalera3
OK

We can only remove one server from a service at a time, so repeat it for other nodes to delete them. Verify with "list services" or "show services" command.

Listener Management

List Listeners

To list all listeners, we need to know the service name in advanced:

maxctrl: list services
┌──────────────────────┬────────────────┬─────────────┬───────────────────┬────────────────────────────────────────────────┐
│ Service              │ Router         │ Connections │ Total Connections │ Servers                                        │
├──────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Read-Write-Service   │ readwritesplit │ 0           │ 0                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├──────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤
│ Round-Robin-Service  │ readconnroute  │ 0           │ 0                 │ mariadbgalera1, mariadbgalera2, mariadbgalera3 │
├──────────────────────┼────────────────┼─────────────┼───────────────────┼────────────────────────────────────────────────┤

In the above example, we have two services, Read-Write-Service and Round-Robin-Service. Then, we can list out the listener for that particular service. For Read-Write-Service:

 maxctrl: list listeners Read-Write-Service
┌─────────────────────┬──────┬─────────┬─────────┐
│ Name                │ Port │ Host    │ State   │
├─────────────────────┼──────┼─────────┼─────────┤
│ Read-Write-Listener │ 3306 │ 0.0.0.0 │ Running │
└─────────────────────┴──────┴─────────┴─────────┘

And for Round-Robin-Service:

 maxctrl: list listeners Round-Robin-Service
┌──────────────────────┬──────┬─────────┬─────────┐
│ Name                 │ Port │ Host    │ State   │
├──────────────────────┼──────┼─────────┼─────────┤
│ Round-Robin-Listener │ 3307 │ 0.0.0.0 │ Running │
└──────────────────────┴──────┴─────────┴─────────┘

Unlike other objects in MaxScale, the listener does not have a "show" and "alter" commands since it is a fairly simple object.

Create a Listener

Make sure a service has been created. In this example, taken from the Create Service section above, we will create a listener so MaxScale will listen on port 3307 to process the MariaDB connections in a round-robin fashion:

 maxctrl: create listener Round-Robin-Service Round-Robin-Listener 3307
OK

Delete a Listener

To delete a listener, use the "destroy listener" command with the respective service name and listener name:

 maxctrl: destroy listener Round-Robin-Service Round-Robin-Listener
OK

This concludes this episode of basic MaxScale management tasks for MariaDB Cluster. In the next series, we are going to cover the MaxScale advanced management tasks like service filters, MaxScale user management and so on.


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. MariaDB JSON_DETAILED() Dijelaskan

  2. MariaDB LCASE() Dijelaskan

  3. Apa yang Baru di MariaDB MaxScale 2.4

  4. Menggunakan Sysbench untuk Menghasilkan Data Uji untuk Tabel Sharded di MySQL

  5. Bagaimana SIGN() Bekerja di MariaDB