一、部署说明
部署环境:
k8s版本:V1.21
OBProxy版本:bproxy-ce:4.2.1.0-11
OceanBase Dashboard 版本:0.3.1
组件说明:
(1)ODP(OceanBase Database Proxy)
OceanBase 数据库代理,ODP是 OceanBase 数据库专用的代理服务器,简称为 ODP(又称为 OBProxy),OceanBase 是分布式数据库,不同表和分区可能存储在不同机器上,读写时需定位到主副本位置。OBProxy 是专用的反向代理软件,核心功能是路由,将客户端的请求转发至正确的 OBServer 节点,并将响应结果返回客户端。

客户端通过 OBProxy 访问 OceanBase 数据库的数据链路如上图(来自官网),用户通过任意 Client 驱动发出请求,请求通过负载均衡组件(LVS/SLB/F5等)访问到任意一台无状态的 OBProxy 上,然后 OBProxy 再将用户请求转发到后端 OceanBase 集群中最佳的 OBServer 节点上去执行。
(2)OceanBase Dashboard(k8s中的OCP)
OceanBase Dashboard 是配合 ob-operator 的白屏运维工具,支持集群管理、租户管理、备份管理、性能监控和终端连接等功能,是在 K8s 环境中监控 OceanBase 集群性能指标的首选工具。

二、部署OBProxy
OBProxy 可以有2种部署方式,分别是yaml-apply和shell脚本部署。
1、首先我们使用yaml+kubectl apply来部署OBProxy
(1)通过 yaml 配置文件进行定义,创建 OBProxy 的配置文件oceanbase-obproxy.yaml如下
apiVersion: v1kind: Servicemetadata:name: svc-obproxynamespace: oceanbase-test1spec:type: ClusterIPclusterIP: Noneselector:app: obproxyports:- name: "sql"port: 2883targetPort: 2883- name: "prometheus"port: 2884targetPort: 2884---apiVersion: apps/v1kind: Deploymentmetadata:name: obproxynamespace: oceanbase-test1spec:selector:matchLabels:app: obproxyreplicas: 2template:metadata:labels:app: obproxyspec:containers:- name: obproxyimage: oceanbase/obproxy-ce:4.2.1.0-11ports:- containerPort: 2883name: "sql"- containerPort: 2884name: "prometheus"env:- name: APP_NAMEvalue: ob_test1_obproxy- name: OB_CLUSTERvalue: obcluster- name: RS_LISTvalue: {ob-pod-ip1}:2881;{ob-pod-ip2}:2881;{ob-pod-ip3}:2881- name: PROXYRO_PASSWORDvalueFrom:secretKeyRef:name: ob-proxyro-passwordkey: passwordresources:limits:memory: 8Gicpu: "8"requests:memory: 8Gicpu: "8"
(2)应用并执行
kubectl apply -f oceanbase-obproxy.yaml -n oceanbase-test1
2、基于setup-obproxy.sh脚本部署
基于脚本,首先需要下载脚本,地址如下:
https://github.com/oceanbase/ob-operator/blob/master/scripts/setup-obproxy.sh
脚本说明:-n oceanbase-test1指定namespace,指定自己的镜像地址:--proxy-image,-d是指定要安装的obporxy的deployment的名称,最后的obcluster是kubectl get obcluster -n oceanbase-test1的结果。
脚本执行如下:
bash setup-obproxy.sh -n oceanbase-test1 --proxy-image oceanbase/obproxy-ce:4.2.1.0-11 -d obproxy-test obclusterPS:用/bin/bash执行以上shell脚本,用/bin/sh执行报错
3、查看obproxy安装情况
/opt/ob-operator# kubectl get pods -n oceanbase-test1 -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESobcluster-test-1-zone1-6a036c0d84bf 2/2 Running 0 3h37m 10.xxx.xxx.143 db02 <none> <none>obcluster-test-1-zone2-384f9bf55992 2/2 Running 0 3h37m 10.xxx.xxx.142 db08 <none> <none>obcluster-test-1-zone3-6f375db39867 2/2 Running 0 3h37m 10.xxx.xxx.241 db07 <none> <none>obproxy-776875754f-2747l 1/1 Running 0 81m 10.xxx.xxx.203 kube607 <none> <none>obproxy-776875754f-lgd55 1/1 Running 0 81m 10.xxx.xxx.90 kube610 <none> <none>
4、尝试使用obproxy链接ob数据库
~# mysql -h10.xxx.xxx.182 -P2883 -uroot@sys -p oceanbase -A -cEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.6.25 OceanBase_CE 4.3.3.0 (r100000142024101215-0723f9774e5f77a1253149261ba75a94414625d0) (Built Oct 12 2024 16:04:08)Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || LBACSYS || mysql || oceanbase || ORAAUDITOR || SYS || sys_external_tbs || test |+--------------------+8 rows in set (0.02 sec)mysql> exitBye
三、部署 OceanBase Dashboard
OceanBase Dashboard 部署建议使用helm安装当前最新的0.3.1版本,默认官方安装在default这个namespace,可以通过-n参数调整namespace,命令如下。
~# helm install ob-ocp ob-operator/oceanbase-dashboard --version=0.3.1 -n oceanbase-dashboard --create-namespaceNAME: ob-ocpLAST DEPLOYED: Thu Oct 31 14:22:33 2024NAMESPACE: oceanbase-dashboardSTATUS: deployedREVISION: 1TEST SUITE: NoneNOTES:Welcome to OceanBase dashboard!___ _____ \ ___ ___ __ _ _ __ | __ ) __ _ ___ ___| | | |/ __/ _ \/ _` | '_ \| _ \ _` __|/ _ \| |_| | (_| __/ (_| | | | | |_) | (_| \__ \ __/\___/ \___\___|\__,_|_| |_|____/ \__,_|___/\___|____ _ _ _| _ \ __ _ ___| |__ | |__ ___ __ _ _ __ __| || | | |/ _` __| '_ \| '_ \ _ \ _` | '__/ _` || |_| | (_| \__ \ | | | |_) | (_) | (_| | | | (_| ||____/ \__,_|___/_| |_|_.__/ \___/ \__,_|_| \__,_|1. [Temporary accessing] After installing the dashboard chart, you can use `port-forward` to expose the dashboard outside as following command:> kubectl port-forward -n oceanbase-dashboard services/oceanbase-dashboard-ob-ocp 18081:80 --address 0.0.0.0then you can visit the dashboard on http://$YOUR_SERVER_IP:18081 (Take 18081 as an example here)2. For security reason, it is recommended to use a service to access the dashboard. By default the oceanbase-dashboard helm chart creates a service of type NodePort.You can use the following command to get the nodePort of the dashboard service:> export SERVICE_NODE_PORT=$(kubectl get -n oceanbase-dashboard service/oceanbase-dashboard-ob-ocp -o jsonpath="{.spec.ports[?(@.name=='dashboard-backend')].nodePort}")then you can visit the dashboard on http://$YOUR_SERVER_IP:$SERVICE_NODE_PORT3. Login the dashboard with the following default account.For users that log in for the first time, it is required to reset the password.Username: adminPassword: <The password you set in values or "admin" by default>
查看dashboard的部署情况
/opt/ob-operator# kubectl get pods -n oceanbase-dashboard -o wideoceanbase-dashboard-ob-dashboard-569db8d45b-4r9z6 3/3 Running 0 41m 10.xxx.xxx.136 kube610 <none> <none>/opt/ob-operator# kubectl get svc -n oceanbase-dashboard -o wideoceanbase-dashboard-ob-dashboard NodePort 172.16.148.32 <none> 80:30502/TCP 41m app=oceanbase-dashboard-ob-dashboard
因为需要页面访问,首先通过上面的部署情况发现dashboard被部署在kube610(物理ip:10.xxx.xxx.13)上,并且查看svc的转发端口是30502,页面输入10.xxx.xxx.13:30502登录即可,默认登录用户名admin,初始密码admin(登录成功后强制改密码)

四、总结
本文首先使用2种方式安装了OBproxy,这OceanBase的无状态代理,更好 的完成了业务client的SQL分发,建议生产环境都通过OBproxy访问OceanBase。另外就是安装了OceanBase Dashboard(k8s中ocp),通过上文看出,OceanBase Dashboard已经可以管理OceanBase集群了,但是相对于OCP还是有很多功能需要实现,OceanBase继续加油。
参考文档:
官方文档:https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000001499737
obproxy部署脚本:https://github.com/oceanbase/ob-operator/blob/master/scripts/setup-obproxy.sh





