ITPub博客

首页 > 数据库 > 国内数据库 > OceanBase 全链路 SSL 加密访问配置指南

OceanBase 全链路 SSL 加密访问配置指南

原创 国内数据库 作者:瑞蓝创_RLC_888 时间:2026-05-15 10:41:02 0 删除 编辑

OceanBase SSL 加密访问配置指南

一、功能介绍

SSL(Secure Socket Layer)是基于 TCP/IP 传输通信协议实现的安全协议,采用公开密钥技术,广泛支持各类网络,提供三种基础安全服务。

为全面提升数据安全,OceanBase 全数据链路(Observer、Obproxy、JDBC 驱动层)均已全面支持 SSL 加密访问。

二、相关参数

参数名称 默认值 描述
disableSslHostnameVerification false 使用 SSL 时,驱动会校验服务器证书中的主机名(备用名称/证书 CN),防范中间人攻击;该参数可关闭校验,需配合 trustServerCertificate=true 使用
useSSL false 强制启用 SSL 连接
trustStore null 信任库文件路径,等价于 Java 属性 javax.net.ssl.trustStore
trustStorePassword 无 信任库密码,等价于 Java 属性 javax.net.ssl.trustStorePassword

三、配置开启 SSL

使用 SSL 功能需完成 全链路 SSL 开启 + 证书生成 两步核心操作。

(一)证书生成

1. CA 证书生成



# 1. 生成 RSA 私钥

openssl genrsa 2048 > cakey.pem

# 2. 创建 CA 证书
openssl req -new -x509 -nodes -days 3600 -key cakey.pem -out ca.pem

2. 服务端证书生成



# 1. 生成私钥与证书请求文件

openssl req -newkey rsa:2048 -days 3600 -nodes -keyout server-key.pem -out server-req.pem

# 2. 写入 RSA
openssl rsa - in server-key.pem -out server-key.pem

# 3. CA 签名(必须填写 common name:observer)
openssl x509 -req - in server-req.pem -days 3600 -CA ca.pem -CAkey cakey.pem -set_serial 01 -out server-cert.pem

3. 客户端证书生成



# 1. 生成私钥与证书请求文件

openssl req -newkey rsa:2048 -days 3600 -nodes -keyout client-key.pem -out client-req.pem

# 2. 写入 RSA
openssl rsa - in client-key.pem -out client-key.pem

# 3. CA 签名(必须填写 common name:obclient)
openssl x509 -req - in client-req.pem -days 3600 -CA ca.pem -CAkey cakey.pem -set_serial 01 -out client-cert.pem

4. Proxy 证书生成



# 1. 生成私钥与证书请求文件

openssl req -newkey rsa:2048 -days 3600 -nodes -keyout proxy-key.pem -out proxy-req.pem

# 2. 写入 RSA
openssl rsa - in proxy-key.pem -out proxy-key.pem

# 3. CA 签名
openssl x509 -req - in proxy-req.pem -days 3600 -CA ca.pem -CAkey cakey.pem -set_serial 01 -out proxy-cert.pem

(二)Observer 开启 SSL 并验证

1. Observer 配置



# 1. 创建证书存放目录

mkdir /home/admin/oceanbase/wallet

# 2. 拷贝证书文件至目录
cp ca.pem server-cert.pem server-key.pem /home/admin/oceanbase/wallet/


-- 3. 关闭 SSL(初始状态)

alter  system  set ssl_client_authentication= FALSE;

-- 4. 设置 kms_info 为 file
alter  system  set ssl_external_kms_info =  '{"ssl_mode":"file"}';

-- 5. 开启客户端 SSL 认证
alter  system  set ssl_client_authentication= TRUE;

-- 6. 设置 SSL 白名单(允许 obclient、obproxy 连接)
alter  system  set ob_ssl_invited_common_names= 'obclient,obproxy' tenant= all;

2. 验证

  1. 使用 obclient 连接 Observer
  2. 执行 SQL 查看 SSL 连接:


select * 
from oceanbase.__all_virtual_processlist 
where ssl_cipher 
is 
not 
null;

(三)Obproxy 开启 SSL 并验证

1. Obproxy 配置



# 1. 放置证书至 wallet 目录

cp ca.pem proxy-cert.pem proxy-key.pem /home/xuping.lz/ob9.proxy0/wallet/


-- 2. 连接 Obproxy(使用 proxysys 账户)

mysql -h 192.168.0.XX -P 1XX3 -u root@proxysys -paaAA11__

-- 3. 配置证书路径
update proxyconfig.security_config  set CONFIG_VAL=  '{"sourceType" : "FILE", "CA" : "/home/xuping.lz/ob9.proxy0/wallet/ca.pem", "publicKey" : "/home/xuping.lz/ob9.proxy0/wallet/proxy-cert.pem", "privateKey" : "/home/xuping.lz/ob9.proxy0/wallet/proxy-key.pem"}'  where APP_NAME =  'obprox '  and  VERSION =  '1';

-- 4. 开启客户端/服务端 SSL
alter proxyconfig  set enable_client_ssl= true;
alter proxyconfig  set enable_server_ssl= true;

2. 验证



-- 查看证书配置

select CONFIG_VAL  from proxyconfig.security_config  where APP_NAME =  'obproxy';

-- 查看 SSL 相关配置
show proxyconfig  like  '%ssl%';

(四)创建 SSL 专用用户



-- 创建必须使用 SSL 连接的用户

create  user testssl  identified  by  '123456' require ssl;

-- 授权
grant  all  on *.*  to testssl@ '%';

四、JDBC SSL 配置

(一)证书库转换

1. 导入服务器 CA 证书到信任库


sudo /opt/taobao/java/jre/bin/keytool -import -
alias mysqlServerCACert -file /home/xuping.lz/wallet/ca.pem -keystore test.jks

# 输入密码:123456

2. 客户端证书捆绑为 PKCS12 文件


openssl pkcs12 -
export -
in client-cert.pem -inkey client-key.pem -out client.p12 -name clientalias -CAfile ca-cert.pem

# 输入密码:123456

3. PKCS12 导入密钥库


keytool -importkeystore -deststorepass 123456 -destkeystore test.jks -srckeystore client.p12 -srcstoretype PKCS12 -srcstorepass 123456 -
alias clientalias

(二)JDBC 连接使用 SSL

1. HTTP 服务器远程加载 JKS 文件


String url = 
"jdbc:oceanbase://192.168.0.XX:1xxx1/sys?user=testssl&password=123456&pool=false&useSSL=true&disableSslHostnameVerification=true&trustStore=http://100.81.152.xx:7xx7/wallet/truststore.jks&trustStorePassword=123456";

2. 本地使用 JKS 文件



// 方式1:连接串配置

String url =  "jdbc:oceanbase://192.168.0.XX:1xxx1/sys?user=testssl&password=123456&pool=false&useSSL=true&disableSslHostnameVerification=true";

// 方式2:系统属性配置
System.setProperty( "javax.net.ssl.trustStore",  "/Users/lize/Downloads/test.jks");
System.setProperty( "javax.net.ssl.trustStorePassword",  "123456");
Class.forName( "com.oceanbase.jdbc.Driver");
Connection connection = DriverManager.getConnection(url);

总结

  1. 全链路 SSL 需先生成 CA、服务端、客户端、Proxy 四类证书,且证书签名时需严格指定对应 common name;
  2. Observer 和 Obproxy 需分别配置证书路径并开启 SSL 开关,配置白名单限制连接来源;
  3. JDBC 需完成证书格式转换,支持 远程 HTTP 和 本地文件两种方式加载信任库,实现 SSL 加密连接。

如果你在实际操作中遇到问题,可以在评论区留言交流。后续我们会持续分享更多运维干货,记得     关注不迷路   ,下次见~ 暂无图片

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70047467/viewspace-3117917/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
专注于企业信息科技战略咨询、数据中心规划及运维、智能化软件产品研发,致力于为金融、能源、电信、制造等行业提供智能的业务永续及流程自动化解决方案。

注册时间:2025-09-08

  • 博文量
    89
  • 访问量
    86723