Triển khai Mạng lưới Phân tán OceanBase với 3 Nút

Điều kiện tiên quyết

Một cụm cơ sở dữ liệu OceanBase yêu cầu ít nhất ba nút, vì vậy hãy chuẩn bị sẵn 3 máy chủ:

IP Cấu hình Hệ điều hành
x.x.x.150 Intel x86 12C 64G RAM 1T SSD CentOS 7.9
x.x.x.155 Intel x86 12C 64G RAM 1T SSD CentOS 7.9
x.x.x.222 Intel x86 12C 64G RAM 1T SSD CentOS 7.9

Để biết thêm về yêu cầu phần cứng và phần mềm hệ thống cho việc chạy cụm OceanBase, bạn có thể tham khảo gợi ý chính thức:

https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000000508277

Các cài đặt đặc biệt trên máy chủ (cần áp dụng cho tất cả các máy):

$ vi /etc/sysctl.conf
vm.swappiness = 0
vm.max_map_count = 655360
vm.min_free_kbytes = 2097152
vm.overcommit_memory = 0
fs.file-max = 6573688

$ sysctl -p    

$ echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled
$ echo never > /sys/kernel/mm/transparent_hugepage/enabled

$ systemctl disable firewalld 
$ systemctl stop firewalld

Nếu sử dụng máy vật lý, hãy đảm bảo rằng BIOS được thiết lập ở chế độ hiệu suất tối đa, và chip X86 được kích hoạt tính năng siêu luồng. Ba nút cần phải đồng bộ thời gian.

OceanBase cung cấp nhiều cách triển khai, chúng ta sẽ sử dụng cách triển khai qua dòng lệnh, công cụ quản lý cụm OBD (được gọi là triển khai màn hình đen).

Tải xuống gói cài đặt, sử dụng phiên bản All in One: https://www.oceanbase.com/softwarecenter

Khởi tạo Máy chủ Trung tâm

Chọn một trong ba máy để làm máy chủ trung tâm, thông qua OBD để quản lý toàn bộ cụm. Máy chủ trung tâm chỉ dùng để quản lý, có thể đặt trên máy riêng biệt.

Tải gói cài đặt lên máy chủ trung tâm, sau đó cài đặt OBD:

[ob@localhost ~]$ tar -xzf oceanbase-all-in-one-*.tar.gz
[ob@localhost ~]$ cd oceanbase-all-in-one/bin/
[ob@localhost ~]$ ./install.sh
[ob@localhost ~]$ source ~/.oceanbase-all-in-one/bin/env.sh

Ở đây, công cụ quản lý cụm obd và công cụ kết nối obclient đã được cài đặt.

[ob@localhost ~]$ which obd
~/.oceanbase-all-in-one/obd/usr/bin/obd
[ob@localhost ~]$ which obclient
~/.oceanbase-all-in-one/obclient/u01/obclient/bin/obclient

Viết cấu hình triển khai cụm

Trong thư mục oceanbase-all-in-one/conf có nhiều tệp cấu hình mẫu, tùy chỉnh theo nhu cầu triển khai thực tế. Tôi sẽ triển khai một cụm phân tán tiêu chuẩn của OceanBase, bao gồm các thành phần sau:

  • observer - dịch vụ lõi cơ sở dữ liệu
  • obproxy - proxy cơ sở dữ liệu, cân bằng tải cho nhiều nút
  • obagent - dịch vụ thu thập giám sát
  • grafana - dịch vụ hiển thị giám sát
  • prometheus - lưu trữ dữ liệu giám sát

Nội dung tệp cấu hình như sau:

## Chỉ cần cấu hình khi đăng nhập từ xa là bắt buộc
user:
  username: ob
  password: oceanbase
#   key_file: đường dẫn đến tệp ssh-key nếu cần
#   port: cổng ssh, mặc định là 22
#   timeout: thời gian chờ kết nối ssh (giây), mặc định là 30
oceanbase-ce:
  servers:
    - name: server1
      # Chỉ hỗ trợ IP, không dùng hostname
      ip: x.x.x.222
    - name: server2
      ip: x.x.x.150
    - name: server3
      ip: x.x.x.155
  global:
    devname: eno1
    memory_limit: 32G # Giới hạn bộ nhớ chạy tối đa cho observer
    system_memory: 8G # Bộ nhớ hệ thống được giữ lại
    datafile_size: 50G # Kích thước tệp dữ liệu
    log_disk_size: 20G # Kích thước đĩa sử dụng bởi tệp clog
    syslog_level: INFO # Mức độ nhật ký hệ thống
    enable_syslog_wf: false # In nhật ký hệ thống mức độ cao hơn WARNING vào tệp nhật ký riêng
    enable_syslog_recycle: true # Bật tái chế tự động nhật ký hệ thống
    max_syslog_file_count: 4 # Số lượng tệp nhật ký được giữ lại trước khi bật tái chế tự động
    appname: obcluster # Tên cụm observer, giống với cluster_name của obproxy
    production_mode: false
  server1:
    mysql_port: 2881 # Cổng ngoại bộ cho OceanBase Database
    rpc_port: 2882 # Cổng nội bộ cho OceanBase Database
    home_path: /home/ob/deploy/observer
    zone: zone1
  server2:
    mysql_port: 2881
    rpc_port: 2882
    home_path: /home/ob/deploy/observer
    zone: zone2
  server3:
    mysql_port: 2881
    rpc_port: 2882
    home_path: /home/ob/deploy/observer
    zone: zone3
obproxy-ce:
  depends:
    - oceanbase-ce
  servers:
    - x.x.x.222
  global:
    listen_port: 2883 # Cổng ngoại bộ
    prometheus_listen_port: 2884 # Cổng Prometheus
    home_path: /home/ob/deploy/obproxy
    enable_cluster_checkout: false
    skip_proxy_sys_private_check: true
    enable_strict_kernel_release: false
obagent:
  depends:
    - oceanbase-ce
  servers:
    - name: server1
      ip: x.x.x.222
    - name: server2
      ip: x.x.x.150
    - name: server3
      ip: x.x.x.155
  global:
    home_path: /home/ob/deploy/obagent
    ob_monitor_status: active
prometheus:
  depends:
    - obagent
  servers:
    - x.x.x.222
  global:
    home_path: /home/ob/deploy/prometheus
grafana:
  depends:
    - prometheus
  servers:
    - x.x.x.222
  global:
    home_path: /home/ob/deploy/grafana
    login_password: oceanbase

Cấu trúc tệp cấu hình theo từng thành phần, ba nút được định nghĩa thành ba server, phân bố trên ba zone, lưu trữ ba bản sao dữ liệu, tham khảo chú thích cho các tham số.

Lưu ý các cổng: observer sử dụng cổng 2881 cho dịch vụ ngoại bộ, 2882 cho giao tiếp giữa các nút, obproxy sử dụng cổng 2883.

Triển khai cụm

Sau khi chuẩn bị tệp cấu hình, triển khai cụm chỉ cần hai lệnh:

[ob@localhost ~]$ obd cluster deploy obtest -c topology.yaml

Bước này sẽ truyền các tệp cần thiết qua ssh đến các nút, tạo thư mục, dịch vụ, cấp quyền, v.v.

Khi thấy thông báo cuối cùng, tức là đã triển khai thành công. Tiếp theo, khởi động cụm theo hướng dẫn:

[ob@localhost ~]$ obd cluster start obtest
Get local repositories ok
Search plugins ok
Load cluster param plugin ok
Open ssh connection ok
Check before start observer ok
Check before start obproxy ok
Check before start obagent ok
Check before start prometheus ok
Check before start grafana ok
Start observer ok
observer program health check ok
Connect to observer x.x.x.222:2881 ok
Initialize oceanbase-ce ok
Start obproxy ok
obproxy program health check ok
Connect to obproxy ok
Initialize obproxy-ce ok
Start obagent ok
obagent program health check ok
Connect to Obagent ok
Start promethues ok
prometheus program health check ok
Connect to Prometheus ok
Initialize prometheus ok
Start grafana ok
grafana program health check ok
Connect to grafana ok
Initialize grafana ok
Wait for observer init ok
+-----------------------------------------------+
|                    observer                   |
+-------------+---------+------+-------+--------+
| ip          | version | port | zone  | status |
+-------------+---------+------+-------+--------+
| x.x.x.150 | 4.2.2.0 | 2881 | zone2 | ACTIVE |
| x.x.x.155 | 4.2.2.0 | 2881 | zone3 | ACTIVE |
| x.x.x.222 | 4.2.2.0 | 2881 | zone1 | ACTIVE |
+-------------+---------+------+-------+--------+
obclient -hx.x.x.150 -P2881 -uroot -p'KHaaKw9dcLwXNvKrT3lc' -Doceanbase -A

+-----------------------------------------------+
|                    obproxy                    |
+-------------+------+-----------------+--------+
| ip          | port | prometheus_port | status |
+-------------+------+-----------------+--------+
| x.x.x.222 | 2883 | 2884            | active |
+-------------+------+-----------------+--------+
obclient -hx.x.x.222 -P2883 -uroot -p'KHaaKw9dcLwXNvKrT3lc' -Doceanbase -A

+----------------------------------------------------------------+
|                            obagent                             |
+-------------+--------------------+--------------------+--------+
| ip          | mgragent_http_port | monagent_http_port | status |
+-------------+--------------------+--------------------+--------+
| x.x.x.222 | 8089               | 8088               | active |
| x.x.x.150 | 8089               | 8088               | active |
| x.x.x.155 | 8089               | 8088               | active |
+-------------+--------------------+--------------------+--------+
+-------------------------------------------------------+
|                       prometheus                      |
+-------------------------+-------+------------+--------+
| url                     | user  | password   | status |
+-------------------------+-------+------------+--------+
| http://x.x.x.222:9090 | admin | qISoDdWHRX | active |
+-------------------------+-------+------------+--------+
+------------------------------------------------------------------+
|                             grafana                              |
+-------------------------------------+-------+-----------+--------+
| url                                 | user  | password  | status |
+-------------------------------------+-------+-----------+--------+
| http://x.x.x.222:3000/d/oceanbase | admin | oceanbase | active |
+-------------------------------------+-------+-----------+--------+
obtest running
Trace ID: 98204f6e-e1d5-11ee-b268-1c697a639d50
If you want to view detailed obd logs, please run: obd display-trace 98204f6e-e1d5-11ee-b268-1c697a639d50

Có thể sử dụng lệnh list và display để xem trạng thái cụm:

[ob@localhost ~]$ obd cluster list
[ob@localhost ~]$ obd cluster display obtest

Thao tác với cụm

Trước đó, khi khởi động cụm, đã in ra cách kết nối cụm. Có hai cách kết nối: trực tiếp đến bất kỳ nút observer nào hoặc thông qua proxy cân bằng tải obproxy. Lưu ý địa chỉ IP và cổng kết nối. Công cụ kết nối có thể là obclient hoặc mysql.

[ob@localhost ~]$ obclient -hx.x.x.222 -P2883 -uroot -p'KHaaKw9dcLwXNvKrT3lc' -Doceanbase -A
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 5
Server version: OceanBase_CE 4.2.2.0 (r100010012024022719-c984fe7cb7a4cef85a40323a0d073f0c9b7b8235) (Built Feb 27 2024 19:20:54)

Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

obclient [oceanbase]>

Kiểm tra tình trạng của ba nút:

obclient [oceanbase]> SELECT TENANT_ID,TENANT_NAME,TENANT_TYPE,PRIMARY_ZONE,LOCALITY FROM oceanbase.DBA_OB_TENANTS;
+-----------+-------------+-------------+--------------+---------------------------------------------+
| TENANT_ID | TENANT_NAME | TENANT_TYPE | PRIMARY_ZONE | LOCALITY                                    |
+-----------+-------------+-------------+--------------+---------------------------------------------+
|         1 | sys         | SYS         | RANDOM       | FULL{1}@zone1, FULL{1}@zone2, FULL{1}@zone3 |
+-----------+-------------+-------------+--------------+---------------------------------------------+
1 row in set (0.012 sec)

Trường LOCALITY ghi lại sự phân phối của các bản sao, FULL đại diện cho bản sao đầy đủ, có thể hỗ trợ đọc và ghi, cũng như tham gia bầu chọn leader, sau đó là zone chứa bản sao.

Thử tạo pool tài nguyên và tenant chéo zone, lưu ý UNIT_NUM không được vượt quá số lượng observer trong mỗi zone:

obclient [oceanbase]> CREATE RESOURCE UNIT uc1 MAX_CPU 1, MEMORY_SIZE '2G', LOG_DISK_SIZE '2G';
Query OK, 0 rows affected (0.009 sec)

obclient [oceanbase]> CREATE RESOURCE POOL rp1 UNIT 'uc1', UNIT_NUM 1, ZONE_LIST ('zone1', 'zone2', 'zone3');
Query OK, 0 rows affected (0.029 sec)

obclient [oceanbase]> CREATE TENANT tt resource_pool_list=('rp1')  set ob_tcp_invited_nodes = '%';
Query OK, 0 rows affected (51.995 sec)

Đăng nhập vào tenant mới và thực hiện một số thao tác dữ liệu (mặc định mật khẩu root trong tenant mới là rỗng):

[ob@localhost ~]$ obclient -h10.3.72.222 -P2883 -uroot@tt  -Doceanbase -A
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 59
Server version: OceanBase_CE 4.2.2.0 (r100010012024022719-c984fe7cb7a4cef85a40323a0d073f0c9b7b8235) (Built Feb 27 2024 19:20:54)

Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

obclient [oceanbase]>
obclient [oceanbase]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| oceanbase          |
| test               |
+--------------------+
4 rows in set (0.002 sec)

obclient [oceanbase]> create database tt_db1;
Query OK, 1 row affected (0.069 sec)

obclient [oceanbase]> use tt_db1;
Database changed
obclient [tt_db1]> create table t1(id int primary key,name varchar(50),dt datetime);
Query OK, 0 rows affected (0.234 sec)

obclient [tt_db1]> select * from t1;
Empty set (0.022 sec)

obclient [tt_db1]> insert into t1 values(1,'aaa',now());
Query OK, 1 row affected (0.004 sec)

obclient [tt_db1]> select * from t1;
+----+------+---------------------+
| id | name | dt                  |
+----+------+---------------------+
|  1 | aaa  | 2024-03-14 16:24:00 |
+----+------+---------------------+
1 row in set (0.001 sec)

Thẻ: oceanbase obd obproxy obagent Grafana

Đăng vào ngày 23 tháng 7 lúc 09:54