OpenTenBase/OpenTenBase
GitHub: OpenTenBase/OpenTenBase
OpenTenBase 是一款基于 PostgreSQL 架构演进的企业级开源分布式 HTAP 数据库,旨在解决大规模数据场景下的水平扩展与混合负载问题。
Stars: 511 | Forks: 352
### 准备工作
#### 1. 安装 opentenbase 并将 opentenbase 安装包的路径导入环境变量。
```
PG_HOME=${INSTALL_PATH}/opentenbase_bin_v5.0
export PATH="$PATH:$PG_HOME/bin"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PG_HOME/lib"
export LC_ALL=C
```
#### 2. 禁用 SELinux 和防火墙(可选)
```
vi /etc/selinux/config
set SELINUX=disabled
# 禁用 firewalld
sudo systemctl disable firewalld
sudo systemctl stop firewalld
```
#### 3. 创建用于初始化实例的 *.tar.gz 包。
1)如果您是从源代码编译,编译完成后,您可以使用 'cd ${INSTALL_PATH}' 进入编译结果目录,然后对其进行打包。
例如:opentenbase-5.21.8-i.x86_64.tar.gz。打包过程和包结构信息如下:
```
[opentenbase@VM-32-23-tencentos opentenbase]$ cd ${INSTALL_PATH}
[opentenbase@VM-32-23-tencentos opentenbase]$ ls
bin include lib share
[opentenbase@VM-32-23-tencentos opentenbase]$ tar zcf opentenbase-5.21.8-i.x86_64.tar.gz *
[opentenbase@VM-32-23-tencentos opentenbase]$ ls
bin include lib share opentenbase-5.21.8-i.x86_64.tar.gz
```
2)如果您获取的是 RPM 包,您可以使用命令 'rpm2cpio opentenbase-5.21.8-i.x86_64.rpm | cpio -idmv' 在当前目录解压 RPM 包。然后,进入相应的目录并将其打包为 *.tar.gz 格式。
```
[opentenbase@VM-32-21-tencentos ~/install/opentenbase_bin_v5.0/bin]$ rpm2cpio opentenbase-5.21.8-i.x86_64.rpm | cpio -idmv
[opentenbase@VM-32-21-tencentos ~/install/opentenbase_bin_v5.0/bin]$ cd ./usr/local/install/opentenbase/
[opentenbase@VM-32-21-tencentos ~/install/opentenbase_bin_v5.0/bin/usr/local/install/opentenbase]$ ls
bin include lib share
[opentenbase@VM-32-21-tencentos ~/install/opentenbase_bin_v5.0/bin/usr/local/install/opentenbase]$ tar -zcf opentenbase-5.21.8-i.x86_64.tar.gz *
[opentenbase@VM-32-21-tencentos ~/install/opentenbase_bin_v5.0/bin/usr/local/install/opentenbase]$ ls
bin include lib opentenbase-5.21.8-i.x86_64.tar.gz share
```
### 集群启动步骤
#### 生成并填写配置文件 opentenbase\_config.ini 。
opentenbase\_ctl 工具可以生成配置文件的模板。您需要在模板中填写集群节点信息。opentenbase\_ctl 工具启动后,会在当前用户的主目录下生成 opentenbase\_ctl 目录。输入“ prepare config”命令后,将在 opentenbase\_ctl 目录中生成可以直接修改的配置文件模板。
* opentenbase\_config.ini 中各字段的说明
```
| Configuration Category | Configuration Item | Description |
|------------------------|-------------------|----------------------------------------------------------------------------|
| instance | name | Instance name, available characters: letters, numbers, underscores, e.g.: opentenbase_instance01 |
| | type | distributed represents distributed mode, requires gtm, coordinator and data nodes; centralized represents centralized mode |
| | package | Software package. Full path (recommended) or relative path to opentenbase_ctl |
| gtm | master | Master node, only one IP |
| | slave | Slave nodes. If n slave nodes are needed, configure n IPs here, separated by commas |
| coordinators | master | Master node IPs, automatically generate node names, deploy nodes-per-server nodes on each IP |
| | slave | Slave node IPs, the number is an integer multiple of master |
| | | Example: If 1 master 1 slave, the number of IPs is the same as master; if 1 master 2 slaves, the number of IPs is twice that of master |
| | nodes-per-server | Optional, default 1. Number of nodes deployed on each IP. Example: master has 3 IPs, configured as 2, then there will be 6 nodes |
| | | cn001-cn006 total 6 nodes, 2 nodes distributed on each server |
| datanodes | master | Master node IPs, automatically generate node names, deploy nodes-per-server nodes on each IP |
| | slave | Slave node IPs, the number is an integer multiple of master |
| | | Example: If 1 master 1 slave, the number of IPs is the same as master; if 1 master 2 slaves, the number of IPs is twice that of master |
| | nodes-per-server | Optional, default 1. Number of nodes deployed on each IP. Example: master has 3 IPs, configured as 2, then there will be 6 nodes |
| | | dn001-dn006 total 6 nodes, 2 nodes distributed on each server |
| server | ssh-user | Username for remote command execution, needs to be created in advance, all servers should have the same account for simpler configuration management |
| | ssh-password | Password for remote command execution, needs to be created in advance, all servers should have the same password for simpler configuration management |
| | ssh-port | SSH port, all servers should be consistent for simpler configuration management |
| log | level | Log level for opentenbase_ctl tool execution (not the log level of opentenbase nodes) |
```
#### 1. 为实例创建配置文件 opentenbase\_config.ini
```
touch opentenbase_config.ini
vim opentenbase_config.ini
```
* 例如,如果我有两台服务器 172.16.16.49 和 172.16.16.131,跨这两台服务器的典型分布式实例配置如下。您可以复制此配置信息,并根据您的部署需求进行修改。不要忘记填写 ssh 密码配置。
```
# 实例配置
[instance]
name=opentenbase01
type=distributed
package=/data/opentenbase/install/opentenbase-5.21.8-i.x86_64.tar.gz
# GTM 节点
[gtm]
master=172.16.16.49
slave=172.16.16.50,172.16.16.131
# Coordinator 节点
[coordinators]
master=172.16.16.49
slave= 172.16.16.131
nodes-per-server=1
# Data 节点
[datanodes]
master=172.16.16.49,172.16.16.131
slave=172.16.16.131,172.16.16.49
nodes-per-server=1
# 登录和部署账户
[server]
ssh-user=opentenbase
ssh-password=
ssh-port=36000
# 日志配置
[log]
level=DEBUG
```
* 同样,典型的集中式实例配置如下。不要忘记填写 ssh 密码配置。
```
# 实例配置
[instance]
name=opentenbase02
type=centralized
package=/data/opentenbase/install/opentenbase-5.21.8-i.x86_64.tar.gz
# Data 节点
[datanodes]
master=172.16.16.49
slave=172.16.16.131
nodes-per-server=1
# 登录和部署账户
[server]
ssh-user=opentenbase
ssh-password=
ssh-port=36000
# 日志配置
[log]
level=DEBUG
```
#### 2. 执行实例安装命令。
```
opentenbase_ctl install -c opentenbase_config.ini
====== Start to Install Opentenbase test_cluster01 ======
step 1: Make *.tar.gz pkg ...
Make opentenbase-5.21.8-i.x86_64.tar.gz successfully.
step 2: Transfer and extract pkg to servers ...
Package_path: /data/opentenbase/opentenbase_ctl/opentenbase-5.21.8-i.x86_64.tar.gz
Transfer and extract pkg to servers successfully.
step 3: Install gtm master node ...
Install gtm0001(172.16.16.49) ...
Install gtm0001(172.16.16.49) successfully
Success to install gtm master node.
step 4: Install cn/dn master node ...
Install cn0001(172.16.16.49) ...
Install dn0001(172.16.16.49) ...
Install dn0002(172.16.16.131) ...
Install cn0001(172.16.16.49) successfully
Install dn0001(172.16.16.49) successfully
Install dn0002(172.16.16.131) successfully
Success to install all cn/dn master nodes.
step 5: Install slave nodes ...
Install gtm0002(172.16.16.131) ...
Install cn0001(172.16.16.131) ...
Install dn0001(172.16.16.131) ...
Install dn0002(172.16.16.49) ...
Install gtm0002(172.16.16.131) successfully
Install dn0002(172.16.16.49) successfully
Install dn0001(172.16.16.131) successfully
Install cn0001(172.16.16.131) successfully
Success to install all slave nodes.
step 6:Create node group ...
Create node group successfully.
====== Installation completed successfully ======
```
* 当您看到“Installation completed successfully”字样时,表示安装已完成。尽情享受您的 opentenbase 之旅吧。
* 您可以检查实例的状态
```
[opentenbase@VM-16-49-tencentos opentenbase_ctl]$ ./opentenbase_bin_v5.0/bin/opentenbase_ctl status -c opentenbase_config.ini
------------- Instance status -----------
Instance name: test_cluster01
Version: 5.21.8
-------------- Node status --------------
Node gtm0001(172.16.16.49) is Running
Node dn0001(172.16.16.49) is Running
Node dn0002(172.16.16.49) is Running
Node cn0001(172.16.16.49) is Running
Node dn0002(172.16.16.131) is Running
Node cn0001(172.16.16.131) is Running
Node gtm0002(172.16.16.131) is Running
Node dn0001(172.16.16.131) is Running
[Result] Total: 8, Running: 8, Stopped: 0, Unknown: 0
------- Master CN Connection Info -------
[1] cn0001(172.16.16.49)
Environment variable: export LD_LIBRARY_PATH=/data/opentenbase/install/opentenbase/5.21.8/lib && export PATH=/data/opentenbase/install/opentenbase/5.21.8/bin:${PATH}
PSQL connection: psql -h 172.16.16.49 -p 11000 -U opentenbase postgres
```
## 使用方法
* 连接到 CN 主节点执行 SQL
```
export LD_LIBRARY_PATH=/home/opentenbase/install/opentenbase/5.21.8/lib && export PATH=/home/opentenbase/install/opentenbase/5.21.8/bin:${PATH}
$ psql -h ${CoordinateNode_IP} -p ${CoordinateNode_PORT} -U opentenbase -d postgres
postgres=#
```
## 参考资料
```
https://docs.opentenbase.org/
```
## 谁在使用 OpenTenBase
Tencent
## 许可证
OpenTenBase 采用 BSD 3-Clause 许可证授权。版权和许可信息可以在文件 [LICENSE.txt](LICENSE.txt) 中找到
## 新闻与活动
|最新动态|
|------|
|[云原生开源项目应用实践专题回顾](https://www.opentenbase.org/en/event/event-post-1/)|
## 博客与文章
|博客与文章|
|------------------|
|[快速入门](https://www.opentenbase.org/en/blog/01-quickstart/)|
## 历史
[历史事件](history_events.md)标签:HTAP数据库, PostgreSQL, 企业级组件, 关系型数据库, 分布式数据库, 分布式架构, 安全测试工具, 客户端加密, 测试用例