Centos7.9 单机安装OceanBase 社区版
目录
1.环境准备
2.安装依赖和系统配置
2.1关闭防火墙
2.2关闭 SELinux
2.3 安装基础依赖
2.4 解压并安装 OceanBase All-in-One 包
2.5 一键启动单机 OceanBase 集群
2.6 连接并验证数据库
3.java程序连接OceanBase
工作有用到OceanBase,为方便学习研究,本地虚拟机安装OceanBase 社区版,更能直接感受OceanBase的功能,同时方便平时工作中自测。
1.环境准备
项目 | 要求 |
---|---|
操作系统 | CentOS 7.9 x86_64 |
CPU | 4 核及以上 |
内存 | 8 GB 以上(建议 12GB+) |
磁盘 | 50 GB 以上(建议 SSD) |
网络 | 可访问外网(用于下载依赖) |
首先到官网下载:https://www.oceanbase.com/softwarecenter
查询系统是什么CPU类型,下载对应的安装包
我的系统信息:
[root@node01 oceanbase-ce]# hostnamectlStatic hostname: node01Icon name: computer-vmChassis: vmMachine ID: cd4406118bce4895b15ce6dea6173badBoot ID: 3fe9a6841eee451095add67c4c5c7331Virtualization: vmwareOperating System: CentOS Linux 7 (Core)CPE OS Name: cpe:/o:centos:centos:7Kernel: Linux 3.10.0-1160.el7.x86_64Architecture: x86-64
[root@node01 oceanbase-ce]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@node01 oceanbase-ce]#
所以下载x86,如果是 ARM 服务器选 ARM版-el7
oceanbase-all-in-one-4.3.5_bp4_20250910.el7.x86_64.tar.gz
然后上传到服务器
2.安装依赖和系统配置
2.1关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
2.2关闭 SELinux
# 临时关闭
setenforce 0# 永久关闭
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
2.3 安装基础依赖
yum install -y wget tar net-tools
2.4 解压并安装 OceanBase All-in-One 包
tar -xzf oceanbase-all-in-one-4.3.5_bp4_20250910.el7.x86_64.tar.gz# 进入目录
cd oceanbase-all-in-one/bin# 安装 OBD(OceanBase Deployer)和依赖
./install.sh
[root@node01 bin]# ./install.sh
install obd as root
No previous obd installed, try install..., wait a moment
name: alertmanager
version: 0.28.1
release:32025073111.el7
arch: x86_64
md5: c5fe05fcc8263b83f6d0602a871d7e1a7a79bdb8
size: 69543154
add /root/soft/oceanbase-all-in-one/rpms/alertmanager-0.28.1-32025073111.el7.x86_64.rpm to local mirror
name: grafana
version: 7.5.17
release:1
arch: x86_64
md5: 1bf1f338d3a3445d8599dc6902e7aeed4de4e0d6
size: 177766248
add /root/soft/oceanbase-all-in-one/rpms/grafana-7.5.17-1.el7.x86_64.rpm to local mirror
name: obagent
version: 4.2.2
release:100000042024011120.el7
arch: x86_64
md5: 19739a07a12eab736aff86ecf357b1ae660b554e
size: 72919140
add /root/soft/oceanbase-all-in-one/rpms/obagent-4.2.2-100000042024011120.el7.x86_64.rpm to local mirror
name: ob-configserver
version: 1.0.0
release:2.el7
arch: x86_64
md5: feca6b9c76e26ac49464f34bfa0780b5a8d3f4a0
size: 24259515
add /root/soft/oceanbase-all-in-one/rpms/ob-configserver-1.0.0-2.el7.x86_64.rpm to local mirror
name: ob-deploy
version: 3.6.0
release:3.el7
arch: x86_64
md5: c48f82f988f8da512a8dc0bf0948b9584c3e7a34
size: 186044735
add /root/soft/oceanbase-all-in-one/rpms/ob-deploy-3.6.0-3.el7.x86_64.rpm to local mirror
name: obproxy-ce
version: 4.3.5.0
release:3.el7
arch: x86_64
md5: f17b277b681adb1c86bfc3cfda369ad88896da9d
size: 123559862
add /root/soft/oceanbase-all-in-one/rpms/obproxy-ce-4.3.5.0-3.el7.x86_64.rpm to local mirror
name: ob-sysbench
version: 1.0.20
release:21.el7
arch: x86_64
md5: 34eb6ecba0ebc4c31c4cfa01162045cbbbec55f7
size: 1566511
add /root/soft/oceanbase-all-in-one/rpms/ob-sysbench-1.0.20-21.el7.x86_64.rpm to local mirror
name: obtpcc
version: 5.0.0
release:1.el7
arch: x86_64
md5: 8624590be4bfe16f28bdd9fc5e4849cda19577d6
size: 1890344
add /root/soft/oceanbase-all-in-one/rpms/obtpcc-5.0.0-1.el7.x86_64.rpm to local mirror
name: obtpch
version: 3.0.0
release:1.el7
arch: x86_64
md5: 3e3e88f87527677998fedf25087f5c87779dee62
size: 1856985
add /root/soft/oceanbase-all-in-one/rpms/obtpch-3.0.0-1.el7.x86_64.rpm to local mirror
name: oceanbase-ce
version: 4.2.1.8
release:108000022024072217.el7
arch: x86_64
md5: 499b676f2ede5a16e0c07b2b15991d1160d972e8
size: 457041540
add /root/soft/oceanbase-all-in-one/rpms/oceanbase-ce-4.2.1.8-108000022024072217.el7.x86_64.rpm to local mirror
name: oceanbase-ce
version: 4.3.5.4
release:104000042025090916.el7
arch: x86_64
md5: a30a15dd7a80f6acd0f113993bb70b2e56d40f80
size: 947769455
add /root/soft/oceanbase-all-in-one/rpms/oceanbase-ce-4.3.5.4-104000042025090916.el7.x86_64.rpm to local mirror
name: oceanbase-ce-libs
version: 4.2.1.8
release:108000022024072217.el7
arch: x86_64
md5: d02f4bfd321370a02550424293beb1be31204038
size: 468528
add /root/soft/oceanbase-all-in-one/rpms/oceanbase-ce-libs-4.2.1.8-108000022024072217.el7.x86_64.rpm to local mirror
name: oceanbase-ce-libs
version: 4.3.5.4
release:104000042025090916.el7
arch: x86_64
md5: 86d1bfdde0e48da54f81a5e9eb09e6d3ad67f0d9
size: 7848
add /root/soft/oceanbase-all-in-one/rpms/oceanbase-ce-libs-4.3.5.4-104000042025090916.el7.x86_64.rpm to local mirror
name: oceanbase-ce-utils
version: 4.2.1.8
release:108000022024072217.el7
arch: x86_64
md5: 6f87392f95b399a21382323f256cfda5969375c4
size: 403350984
add /root/soft/oceanbase-all-in-one/rpms/oceanbase-ce-utils-4.2.1.8-108000022024072217.el7.x86_64.rpm to local mirror
name: oceanbase-ce-utils
version: 4.3.5.4
release:104000042025090916.el7
arch: x86_64
md5: eac57ef76301a631519ce0b0794b373dee3fd595
size: 1694464200
add /root/soft/oceanbase-all-in-one/rpms/oceanbase-ce-utils-4.3.5.4-104000042025090916.el7.x86_64.rpm to local mirror
name: oceanbase-diagnostic-tool
version: 3.6.0
release:22025080417.el7
arch: x86_64
md5: ce431826e5571a6e00d81b9849e32eb53991169f
size: 71847711
add /root/soft/oceanbase-all-in-one/rpms/oceanbase-diagnostic-tool-3.6.0-22025080417.el7.x86_64.rpm to local mirror
name: ocp-agent-ce
version: 4.3.6
release:20250815135607.el7
arch: aarch64
md5: 0cd43c9c59ff3f0b5133c21fc394611d95fa9974
size: 123008375
add /root/soft/oceanbase-all-in-one/rpms/ocp-agent-ce-4.3.6-20250815135607.el7.aarch64.rpm to local mirror
name: ocp-agent-ce
version: 4.3.6
release:20250815135607.el7
arch: x86_64
md5: d7a743e37308bdb88678edcc5370ab770c2c72b2
size: 179048741
add /root/soft/oceanbase-all-in-one/rpms/ocp-agent-ce-4.3.6-20250815135607.el7.x86_64.rpm to local mirror
name: ocp-express
version: 4.2.2
release:100000022024011120.el7
arch: x86_64
md5: 09ffcf156d1df9318a78af52656f499d2315e3f7
size: 78426196
add /root/soft/oceanbase-all-in-one/rpms/ocp-express-4.2.2-100000022024011120.el7.x86_64.rpm to local mirror
name: ocp-server-ce
version: 4.3.6
release:20250815135607.el7
arch: noarch
md5: a8ec6271c5b8fa11c068dd396dcba763510e2adc
size: 446852421
add /root/soft/oceanbase-all-in-one/rpms/ocp-server-ce-4.3.6-20250815135607.el7.noarch.rpm to local mirror
name: openjdk-jre
version: 1.8.0_322
release:b09.el7
arch: x86_64
md5: 051aa69c5abb8697d15c2f0dcb1392b3f815f7ed
size: 69766947
add /root/soft/oceanbase-all-in-one/rpms/openjdk-jre-1.8.0_322-b09.el7.x86_64.rpm to local mirror
name: prometheus
version: 2.37.1
release:10000102022110211.el7
arch: x86_64
md5: 58913c7606f05feb01bc1c6410346e5fc31cf263
size: 211224073
add /root/soft/oceanbase-all-in-one/rpms/prometheus-2.37.1-10000102022110211.el7.x86_64.rpm to local mirror
Trace ID: 5f722170-99e3-11f0-b76c-000c29a85316
If you want to view detailed obd logs, please run: obd display-trace 5f722170-99e3-11f0-b76c-000c29a85316
Disable remote ok
Trace ID: 69a7d842-99e3-11f0-81a1-000c29a85316
If you want to view detailed obd logs, please run: obd display-trace 69a7d842-99e3-11f0-81a1-000c29a85316add auto set env logic to profile: /root/.bash_profile#########################################################################################Install Finished
=========================================================================================
Setup Environment: source ~/.oceanbase-all-in-one/bin/env.sh
Quick Start: obd demo
Use Web Service to install: obd web
Use Web Service to upgrade: obd web upgrade
More Details: obd -h
=========================================================================================
2.5 一键启动单机 OceanBase 集群
# 使用 OBD 快速部署单机集群
obd demo
[root@node01 bin]# obd demo
Package prometheus-2.37.1-10000102022110211.el7 is available.
Package obagent-4.2.2-100000042024011120.el7 is available.
Package obproxy-ce-4.3.5.0-3.el7 is available.
Package oceanbase-ce-4.3.5.4-104000042025090916.el7 is available.
Package grafana-7.5.17-1 is available.
install prometheus-2.37.1 for local ok
install obagent-4.2.2 for local ok
install obproxy-ce-4.3.5.0 for local ok
install oceanbase-ce-4.3.5.4 for local ok
install grafana-7.5.17 for local ok
Cluster param config check ok
Open ssh connection ok
Generate prometheus configuration ok
Generate obagent configuration ok
Generate obproxy configuration ok
Generate grafana configuration ok
+--------------------------------------------------------------------------------------------+
| Packages |
+--------------+---------+------------------------+------------------------------------------+
| Repository | Version | Release | Md5 |
+--------------+---------+------------------------+------------------------------------------+
| prometheus | 2.37.1 | 10000102022110211.el7 | 58913c7606f05feb01bc1c6410346e5fc31cf263 |
| obagent | 4.2.2 | 100000042024011120.el7 | 19739a07a12eab736aff86ecf357b1ae660b554e |
| obproxy-ce | 4.3.5.0 | 3.el7 | f17b277b681adb1c86bfc3cfda369ad88896da9d |
| oceanbase-ce | 4.3.5.4 | 104000042025090916.el7 | a30a15dd7a80f6acd0f113993bb70b2e56d40f80 |
| grafana | 7.5.17 | 1 | 1bf1f338d3a3445d8599dc6902e7aeed4de4e0d6 |
+--------------+---------+------------------------+------------------------------------------+
Repository integrity check ok
Load param plugin ok
Open ssh connection ok
Initializes obagent work home ok
Initializes observer work home ok
Initializes obproxy work home ok
Initializes prometheus work home ok
Initializes grafana work home ok
Parameter check ok
Remote prometheus-2.37.1-10000102022110211.el7-58913c7606f05feb01bc1c6410346e5fc31cf263 repository install ok
Remote prometheus-2.37.1-10000102022110211.el7-58913c7606f05feb01bc1c6410346e5fc31cf263 repository lib check ok
Remote obagent-4.2.2-100000042024011120.el7-19739a07a12eab736aff86ecf357b1ae660b554e repository install ok
Remote obagent-4.2.2-100000042024011120.el7-19739a07a12eab736aff86ecf357b1ae660b554e repository lib check ok
Remote obproxy-ce-4.3.5.0-3.el7-f17b277b681adb1c86bfc3cfda369ad88896da9d repository install ok
Remote obproxy-ce-4.3.5.0-3.el7-f17b277b681adb1c86bfc3cfda369ad88896da9d repository lib check ok
Remote oceanbase-ce-4.3.5.4-104000042025090916.el7-a30a15dd7a80f6acd0f113993bb70b2e56d40f80 repository install ok
Remote oceanbase-ce-4.3.5.4-104000042025090916.el7-a30a15dd7a80f6acd0f113993bb70b2e56d40f80 repository lib check ok
Remote grafana-7.5.17-1-1bf1f338d3a3445d8599dc6902e7aeed4de4e0d6 repository install ok
Remote grafana-7.5.17-1-1bf1f338d3a3445d8599dc6902e7aeed4de4e0d6 repository lib check ok
demo deployed
Get local repositories ok
Load cluster param plugin ok
Open ssh connection ok
[WARN] OBD-1011: (127.0.0.1) The recommended value of fs.aio-max-nr is 1048576 (Current value: 65536)
[WARN] OBD-1007: (127.0.0.1) The recommended number of open files is 655350 (Current value: 65535)
[WARN] OBD-1007: (127.0.0.1) The recommended number of core file size is unlimited (Current value: 0)
[WARN] OBD-1007: (127.0.0.1) The recommended number of stack size is unlimited (Current value: 8192)
[WARN] OBD-1017: (127.0.0.1) The value of the "fs.file-max" must be greater than 6573688 (Current value: 761208, Recommended value: 6573688)
[WARN] OBD-2000: (127.0.0.1) not enough memory. (Free: 132M, Need: 6G)
[WARN] OBD-1012: (127.0.0.1) clog and data use the same disk (/)
Check before start obagent ok
Check before start prometheus ok
Check before start grafana ok
cluster scenario: express_oltp
Start observer ok
observer program health check ok
Connect to observer 127.0.0.1:2881 ok
oceanbase bootstrap ok
obshell start ok
obshell program health check ok
obshell bootstrap ok
Start obagent ok
obagent program health check ok
start obproxy ok
obproxy program health check ok
Connect to obproxy ok
Start promethues ok
prometheus program health check ok
Start grafana ok
grafana program health check ok
Connect to grafana ok
Grafana modify password ok
Connect to observer 127.0.0.1:2881 ok
Wait for observer init ok
+---------------------------------------------+
| oceanbase-ce |
+-----------+---------+------+-------+--------+
| ip | version | port | zone | status |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 4.3.5.4 | 2881 | zone1 | ACTIVE |
+-----------+---------+------+-------+--------+
obclient -h127.0.0.1 -P2881 -uroot@sys -p'ShhnyW0vcL6VycJgM4lB' -Doceanbase -Acluster unique id: d575453f-c03d-53cc-b572-ae821686dcf2-1997fdfd1f1-04050304Connect to Obagent ok
+-----------------------------------------------------------------+
| obagent |
+--------------+--------------------+--------------------+--------+
| ip | mgragent_http_port | monagent_http_port | status |
+--------------+--------------------+--------------------+--------+
| 10.100.51.30 | 8089 | 8088 | active |
+--------------+--------------------+--------------------+--------+
Connect to obproxy ok
+---------------------------------------------------------------+
| obproxy-ce |
+-----------+------+-----------------+-----------------+--------+
| ip | port | prometheus_port | rpc_listen_port | status |
+-----------+------+-----------------+-----------------+--------+
| 127.0.0.1 | 2883 | 2884 | 2885 | active |
+-----------+------+-----------------+-----------------+--------+
obclient -h127.0.0.1 -P2883 -uroot -p'ShhnyW0vcL6VycJgM4lB' -Doceanbase -A Connect to Prometheus ok
+-----------------------------------------------------+
| prometheus |
+--------------------------+------+----------+--------+
| url | user | password | status |
+--------------------------+------+----------+--------+
| http://10.100.51.30:9090 | | | active |
+--------------------------+------+----------+--------+
Connect to grafana ok
+----------------------------------------------------------------------+
| grafana |
+--------------------------------------+-------+--------------+--------+
| url | user | password | status |
+--------------------------------------+-------+--------------+--------+
| http://10.100.51.30:3000/d/oceanbase | admin | 'FAZP9GzEcb' | active |
+--------------------------------------+-------+--------------+--------+
obshell program health check ok
display ob-dashboard ok
+-------------------------------------------------------------------+
| ob-dashboard |
+--------------------------+------+------------------------+--------+
| url | user | password | status |
+--------------------------+------+------------------------+--------+
| http://10.100.51.30:2886 | root | 'ShhnyW0vcL6VycJgM4lB' | active |
+--------------------------+------+------------------------+--------+demo running
This is a basic setup with minimal resources, good for testing and learning. For full OceanBase performance, please destroy this cluster and redeploy by using `obd pref`
Trace ID: c4e55e4a-99e4-11f0-b6c0-000c29a85316
If you want to view detailed obd logs, please run: obd display-trace c4e55e4a-99e4-11f0-b6c0-000c29a85316
[root@node01 bin]# ls
env.sh install.sh uninstall.sh
[root@node01 bin]#
重点,日志输入会打印密码,一定要记下来
obclient -h127.0.0.1 -P2883 -uroot -p'ShhnyW0vcL6VycJgM4lB' -Doceanbase -A
同时有监控地址,日志输出:
Connect to Prometheus ok
+-----------------------------------------------------+
| prometheus |
+--------------------------+------+----------+--------+
| url | user | password | status |
+--------------------------+------+----------+--------+
| http://10.100.51.30:9090 | | | active |
+--------------------------+------+----------+--------+
Connect to grafana ok
+----------------------------------------------------------------------+
| grafana |
+--------------------------------------+-------+--------------+--------+
| url | user | password | status |
+--------------------------------------+-------+--------------+--------+
| http://10.100.51.30:3000/d/oceanbase | admin | 'FAZP9GzEcb' | active |
+--------------------------------------+-------+--------------+--------+
实际上我的虚拟机IP地址是:192.168.180.25,但日志输入并不是这个IP,可能是缓存原因,这个10.100。51.30是我以前设置过的IP,所以用:
http://192.168.180.25:9090/alerts?search=
可以打开界面看监控
http://192.168.180.25:3000/login
输入账号密码,配置
-
左侧菜单 → Configuration(齿轮图标)→ Data Sources
-
找到名为 "OceanBase" 或 "Prometheus" 的数据源
-
点击进入,检查 URL 应该是:http://192.168.180.25:9090/
可以查看OceanBase运行状态了
2.6 连接并验证数据库
-h
:主机(本机)-P
:端口(2883 是 OBProxy 端口)-u
:用户(root@sys
,格式:用户名@租户名)-A
:跳过权限检查
首次登录密码为空,直接回车即可。
obclient -h127.0.0.1 -P2883 -uroot -p'ShhnyW0vcL6VycJgM4lB' -Doceanbase -A
安装成功了,并成功连接:
查看数据库状态
-- 查看租户
SHOW TENANT;-- 查看数据库
SHOW DATABASES;-- 切换到 test 数据库
USE test;-- 创建测试表
CREATE TABLE t1(id INT, name VARCHAR(20));
INSERT INTO t1 VALUES (1, 'hello');
SELECT * FROM t1;
使用SQLyog客户端连接:
3.java程序连接OceanBase
引入maven坐标
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency>
程序代码
package com.example.ob;import java.sql.*;public class TestOB {public static void main(String[] args) throws Exception {String url = "jdbc:mysql://192.168.180.25:2883/test?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";String user = "root";String password = "ShhnyW0vcL6VycJgM4lB";try (Connection conn = DriverManager.getConnection(url, user, password)) {Statement stmt = conn.createStatement();ResultSet rs = stmt.executeQuery("SELECT * FROM t1");while (rs.next()) {System.out.println(rs.getInt("id") + ", " + rs.getString("name"));}}}
}
至此,安装成功。