当前位置:   article > 正文

OceanBase初体验之部署生产标准的三节点分布式集群

oceanbase数据库三副本

前置条件

OceanBase 数据库集群至少由三个节点组成,所以先准备好3台服务器:

IP配置操作系统
x.x.x.150Intel x86 12C 64G内存 1T SSDCentOS 7.9
x.x.x.155Intel x86 12C 64G内存 1T SSDCentOS 7.9
x.x.x.222Intel x86 12C 64G内存 1T SSDCentOS 7.9

关于运行 OceanBase 集群对于硬件资源和系统软件的要求,大家可以参考官方建议:

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

服务器特殊的配置项(每台都要设置):

  1. $ vi /etc/sysctl.conf
  2. vm.swappiness = 0
  3. vm.max_map_count = 655360
  4. vm.min_free_kbytes = 2097152
  5. vm.overcommit_memory = 0
  6. fs.file-max = 6573688
  7. $ sysctl -p
  8. $ echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled
  9. $ echo never > /sys/kernel/mm/transparent_hugepage/enabled
  10. $ systemctl disable firewalld
  11. $ systemctl stop firewalld

如果是使用的物理机部署,建议在BIOS中开启最大性能模式,X86芯片开启超线程。三台节点保证时间一致。

OceanBase 提供了多种部署方式,我们这里采用命令行部署,官方提供了集群管理工具OBD(俗称黑屏部署)。

下载安装包,直接上全家桶 All in One 的版本:https://www.oceanbase.com/softwarecenter

初始化中控机

在三台机器中任意挑选一台当做集群的中控机,通过OBD来操作整个集群,中控机只是用于管理集群,用单独的机器部署也可以。

把安装包上传到中控机,先把OBD装好:

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

到这里集群管理工具 obd 和客户端连接工具 obclient 就都装好了。

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

编写集群部署配置

oceanbase-all-in-one/conf目录下放了很多配置文件示例,可根据实际部署需要来修改。我这里要部署一套标准的 OceanBase 分布式集群,包含的组件有:

  • observer - 数据库核心服务
  • obproxy - 数据库代理,对多节点做负载均衡
  • obagent - 监控采集服务
  • grafana - 监控显示服务
  • prometheus - 监控数据存储

配置文件内容如下:

  1. ## Only need to configure when remote login is required
  2. user:
  3. username: ob
  4. password: oceanbase
  5. # key_file: your ssh-key file path if need
  6. # port: your ssh port, default 22
  7. # timeout: ssh connection timeout (second), default 30
  8. oceanbase-ce:
  9. servers:
  10. - name: server1
  11. # Please don't use hostname, only IP can be supported
  12. ip: x.x.x.222
  13. - name: server2
  14. ip: x.x.x.150
  15. - name: server3
  16. ip: x.x.x.155
  17. global:
  18. # Please set devname as the network adaptor's name whose ip is in the setting of severs.
  19. # if set severs as "127.0.0.1", please set devname as "lo"
  20. # if current ip is 192.168.1.10, and the ip's network adaptor's name is "eth0", please use "eth0"
  21. devname: eno1
  22. # if current hardware's memory capacity is smaller than 50G, please use the setting of "mini-single-example.yaml" and do a small adjustment.
  23. memory_limit: 32G # The maximum running memory for an observer
  24. # The reserved system memory. system_memory is reserved for general tenants. The default value is 30G.
  25. system_memory: 8G
  26. datafile_size: 50G # Size of the data file.
  27. log_disk_size: 20G # The size of disk space used by the clog files.
  28. syslog_level: INFO # System log level. The default value is INFO.
  29. enable_syslog_wf: false # Print system logs whose levels are higher than WARNING to a separate log file. The default value is true.
  30. enable_syslog_recycle: true # Enable auto system log recycling or not. The default value is false.
  31. max_syslog_file_count: 4 # The maximum number of reserved log files before enabling auto recycling. The default value is 0.
  32. # observer cluster name, consistent with obproxy's cluster_name
  33. appname: obcluster
  34. production_mode: false
  35. # root_password: # root user password, can be empty
  36. # proxyro_password: # proxyro user pasword, consistent with obproxy's observer_sys_password, can be empty
  37. # In this example , support multiple ob process in single node, so different process use different ports.
  38. # If deploy ob cluster in multiple nodes, the port and path setting can be same.
  39. server1:
  40. mysql_port: 2881 # External port for OceanBase Database. The default value is 2881. DO NOT change this value after the cluster is started.
  41. rpc_port: 2882 # Internal port for OceanBase Database. The default value is 2882. DO NOT change this value after the cluster is started.
  42. # The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field.
  43. home_path: /home/ob/deploy/observer
  44. # The directory for data storage. The default value is $home_path/store.
  45. # data_dir: /data
  46. # The directory for clog, ilog, and slog. The default value is the same as the data_dir value.
  47. # redo_dir: /redo
  48. zone: zone1
  49. server2:
  50. mysql_port: 2881 # External port for OceanBase Database. The default value is 2881. DO NOT change this value after the cluster is started.
  51. rpc_port: 2882 # Internal port for OceanBase Database. The default value is 2882. DO NOT change this value after the cluster is started.
  52. # The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field.
  53. home_path: /home/ob/deploy/observer
  54. # The directory for data storage. The default value is $home_path/store.
  55. # data_dir: /data
  56. # The directory for clog, ilog, and slog. The default value is the same as the data_dir value.
  57. # redo_dir: /redo
  58. zone: zone2
  59. server3:
  60. mysql_port: 2881 # External port for OceanBase Database. The default value is 2881. DO NOT change this value after the cluster is started.
  61. rpc_port: 2882 # Internal port for OceanBase Database. The default value is 2882. DO NOT change this value after the cluster is started.
  62. # The working directory for OceanBase Database. OceanBase Database is started under this directory. This is a required field.
  63. home_path: /home/ob/deploy/observer
  64. # The directory for data storage. The default value is $home_path/store.
  65. # data_dir: /data
  66. # The directory for clog, ilog, and slog. The default value is the same as the data_dir value.
  67. # redo_dir: /redo
  68. zone: zone3
  69. obproxy-ce:
  70. # Set dependent components for the component.
  71. # When the associated configurations are not done, OBD will automatically get the these configurations from the dependent components.
  72. depends:
  73. - oceanbase-ce
  74. servers:
  75. - x.x.x.222
  76. global:
  77. listen_port: 2883 # External port. The default value is 2883.
  78. prometheus_listen_port: 2884 # The Prometheus port. The default value is 2884.
  79. home_path: /home/ob/deploy/obproxy
  80. # oceanbase root server list
  81. # format: ip:mysql_port;ip:mysql_port. When a depends exists, OBD gets this value from the oceanbase-ce of the depends.
  82. # rs_list: 192.168.1.2:2881;192.168.1.3:2881;192.168.1.4:2881
  83. enable_cluster_checkout: false
  84. # observer cluster name, consistent with oceanbase-ce's appname. When a depends exists, OBD gets this value from the oceanbase-ce of the depends.
  85. # cluster_name: obcluster
  86. skip_proxy_sys_private_check: true
  87. enable_strict_kernel_release: false
  88. # obproxy_sys_password: # obproxy sys user password, can be empty. When a depends exists, OBD gets this value from the oceanbase-ce of the depends.
  89. # observer_sys_password: # proxyro user pasword, consistent with oceanbase-ce's proxyro_password, can be empty. When a depends exists, OBD gets this value from the oceanbase-ce of the depends.
  90. obagent:
  91. depends:
  92. - oceanbase-ce
  93. servers:
  94. - name: server1
  95. # Please don't use hostname, only IP can be supported
  96. ip: x.x.x.222
  97. - name: server2
  98. ip: x.x.x.150
  99. - name: server3
  100. ip: x.x.x.155
  101. global:
  102. home_path: /home/ob/deploy/obagent
  103. ob_monitor_status: active
  104. prometheus:
  105. depends:
  106. - obagent
  107. servers:
  108. - x.x.x.222
  109. global:
  110. home_path: /home/ob/deploy/prometheus
  111. grafana:
  112. depends:
  113. - prometheus
  114. servers:
  115. - x.x.x.222
  116. global:
  117. home_path: /home/ob/deploy/grafana
  118. login_password: oceanbase

配置文件的整体格式是按组件来配置,三个节点定义成三个server,分布在三个zone,保存了三副本数据,参数定义参考注释即可。

这里要注意几个端口,observer 对外服务是用2881,对内节点间通信是用2882,obproxy是用2883。

部署集群

准备好配置文件后部署集群就两行命令的事,先执行:

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

这一步会把各组件需要的文件通过shh传到各个节点上,同时创建目录、服务、给权限等等。

等最后输出下面这个信息就表示部署成功了。

接下来按提示启动集群即可:

  1. [ob@localhost ~]$ obd cluster start obtest
  2. Get local repositories ok
  3. Search plugins ok
  4. Load cluster param plugin ok
  5. Open ssh connection ok
  6. Check before start observer ok
  7. Check before start obproxy ok
  8. Check before start obagent ok
  9. Check before start prometheus ok
  10. Check before start grafana ok
  11. Start observer ok
  12. observer program health check ok
  13. Connect to observer x.x.x.222:2881 ok
  14. Initialize oceanbase-ce ok
  15. Start obproxy ok
  16. obproxy program health check ok
  17. Connect to obproxy ok
  18. Initialize obproxy-ce ok
  19. Start obagent ok
  20. obagent program health check ok
  21. Connect to Obagent ok
  22. Start promethues ok
  23. prometheus program health check ok
  24. Connect to Prometheus ok
  25. Initialize prometheus ok
  26. Start grafana ok
  27. grafana program health check ok
  28. Connect to grafana ok
  29. Initialize grafana ok
  30. Wait for observer init ok
  31. +-----------------------------------------------+
  32. | observer |
  33. +-------------+---------+------+-------+--------+
  34. | ip | version | port | zone | status |
  35. +-------------+---------+------+-------+--------+
  36. | x.x.x.150 | 4.2.2.0 | 2881 | zone2 | ACTIVE |
  37. | x.x.x.155 | 4.2.2.0 | 2881 | zone3 | ACTIVE |
  38. | x.x.x.222 | 4.2.2.0 | 2881 | zone1 | ACTIVE |
  39. +-------------+---------+------+-------+--------+
  40. obclient -hx.x.x.150 -P2881 -uroot -p'KHaaKw9dcLwXNvKrT3lc' -Doceanbase -A
  41. +-----------------------------------------------+
  42. | obproxy |
  43. +-------------+------+-----------------+--------+
  44. | ip | port | prometheus_port | status |
  45. +-------------+------+-----------------+--------+
  46. | x.x.x.222 | 2883 | 2884 | active |
  47. +-------------+------+-----------------+--------+
  48. obclient -hx.x.x.222 -P2883 -uroot -p'KHaaKw9dcLwXNvKrT3lc' -Doceanbase -A
  49. +----------------------------------------------------------------+
  50. | obagent |
  51. +-------------+--------------------+--------------------+--------+
  52. | ip | mgragent_http_port | monagent_http_port | status |
  53. +-------------+--------------------+--------------------+--------+
  54. | x.x.x.222 | 8089 | 8088 | active |
  55. | x.x.x.150 | 8089 | 8088 | active |
  56. | x.x.x.155 | 8089 | 8088 | active |
  57. +-------------+--------------------+--------------------+--------+
  58. +-------------------------------------------------------+
  59. | prometheus |
  60. +-------------------------+-------+------------+--------+
  61. | url | user | password | status |
  62. +-------------------------+-------+------------+--------+
  63. | http://x.x.x.222:9090 | admin | qISoDdWHRX | active |
  64. +-------------------------+-------+------------+--------+
  65. +------------------------------------------------------------------+
  66. | grafana |
  67. +-------------------------------------+-------+-----------+--------+
  68. | url | user | password | status |
  69. +-------------------------------------+-------+-----------+--------+
  70. | http://x.x.x.222:3000/d/oceanbase | admin | oceanbase | active |
  71. +-------------------------------------+-------+-----------+--------+
  72. obtest running
  73. Trace ID: 98204f6e-e1d5-11ee-b268-1c697a639d50
  74. If you want to view detailed obd logs, please run: obd display-trace 98204f6e-e1d5-11ee-b268-1c697a639d50

还可以通过 list 和 display 命名查看集群状态:

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

操作集群

前面启动集群的时候已经打印出了连接集群的方式,这里连接入口有两种。

一种是直连任意一台 observer,另一种是走负载均衡代理连接 obproxy,两种方式注意区别 ip 和端口号。另外连接工具用 obclient 或者 mysql 都可以。

  1. [ob@localhost ~]$ obclient -hx.x.x.222 -P2883 -uroot -p'KHaaKw9dcLwXNvKrT3lc' -Doceanbase -A
  2. Welcome to the OceanBase. Commands end with ; or \g.
  3. Your OceanBase connection id is 5
  4. Server version: OceanBase_CE 4.2.2.0 (r100010012024022719-c984fe7cb7a4cef85a40323a0d073f0c9b7b8235) (Built Feb 27 2024 19:20:54)
  5. Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
  6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  7. obclient [oceanbase]>

先看一下3个节点的情况:

再看三副本的分布情况:

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

LOCALITY字段记录了副本的分布,这里面FULL代表全量副本,可以支持读写和参与投票选举leader,后面是该副本分布在哪个zone。

尝试创建跨zone的资源池和租户,注意 UNIT_NUM 不能超过每个zone里的 observer 数量

  1. obclient [oceanbase]> CREATE RESOURCE UNIT uc1 MAX_CPU 1, MEMORY_SIZE '2G', LOG_DISK_SIZE '2G';
  2. Query OK, 0 rows affected (0.009 sec)
  3. obclient [oceanbase]> CREATE RESOURCE POOL rp1 UNIT 'uc1', UNIT_NUM 1, ZONE_LIST ('zone1', 'zone2', 'zone3');
  4. Query OK, 0 rows affected (0.029 sec)
  5. obclient [oceanbase]> CREATE TENANT tt resource_pool_list=('rp1') set ob_tcp_invited_nodes = '%';
  6. Query OK, 0 rows affected (51.995 sec)

登录到新租户里面做一些数据操作(新租户里的root用户默认是空密码):

  1. [ob@localhost ~]$ obclient -h10.3.72.222 -P2883 -uroot@tt -Doceanbase -A
  2. Welcome to the OceanBase. Commands end with ; or \g.
  3. Your OceanBase connection id is 59
  4. Server version: OceanBase_CE 4.2.2.0 (r100010012024022719-c984fe7cb7a4cef85a40323a0d073f0c9b7b8235) (Built Feb 27 2024 19:20:54)
  5. Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
  6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  7. obclient [oceanbase]>
  8. obclient [oceanbase]> show databases;
  9. +--------------------+
  10. | Database |
  11. +--------------------+
  12. | information_schema |
  13. | mysql |
  14. | oceanbase |
  15. | test |
  16. +--------------------+
  17. 4 rows in set (0.002 sec)
  18. obclient [oceanbase]> create database tt_db1;
  19. Query OK, 1 row affected (0.069 sec)
  20. obclient [oceanbase]> use tt_db1;
  21. Database changed
  22. obclient [tt_db1]> create table t1(id int primary key,name varchar(50),dt datetime);
  23. Query OK, 0 rows affected (0.234 sec)
  24. obclient [tt_db1]> select * from t1;
  25. Empty set (0.022 sec)
  26. obclient [tt_db1]> insert into t1 values(1,'aaa',now());
  27. Query OK, 1 row affected (0.004 sec)
  28. obclient [tt_db1]> select * from t1;
  29. +----+------+---------------------+
  30. | id | name | dt |
  31. +----+------+---------------------+
  32. | 1 | aaa | 2024-03-14 16:24:00 |
  33. +----+------+---------------------+
  34. 1 row in set (0.001 sec)

下一篇尝试从 mysql 迁移数据到 OceanBase。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/553812
推荐阅读
相关标签
  

闽ICP备14008679号