暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

OceanBase Dashboard/obproxy on K8S 部署篇

晓磊聊DB 2024-11-08
244

一、部署说明

部署环境:

  •     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: v1
    kind: Service
    metadata:
    name: svc-obproxy
    namespace: oceanbase-test1
    spec:
    type: ClusterIP
    clusterIP: None
    selector:
    app: obproxy
    ports:
    - name: "sql"
    port: 2883
    targetPort: 2883
    - name: "prometheus"
    port: 2884
    targetPort: 2884


    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: obproxy
    namespace: oceanbase-test1
    spec:
    selector:
    matchLabels:
    app: obproxy
    replicas: 2
    template:
    metadata:
    labels:
    app: obproxy
    spec:
    containers:
    - name: obproxy
    image: oceanbase/obproxy-ce:4.2.1.0-11
    ports:
    - containerPort: 2883
    name: "sql"
    - containerPort: 2884
    name: "prometheus"
    env:
    - name: APP_NAME
    value: ob_test1_obproxy
    - name: OB_CLUSTER
    value: obcluster
    - name: RS_LIST
                  value: {ob-pod-ip1}:2881;{ob-pod-ip2}:2881;{ob-pod-ip3}:2881
    - name: PROXYRO_PASSWORD
    valueFrom:
    secretKeyRef:
    name: ob-proxyro-password
    key: password
    resources:
    limits:
    memory: 8Gi
    cpu: "8"
    requests:
    memory: 8Gi
    cpu: "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 obcluster
          PS:用/bin/bash执行以上shell脚本,用/bin/sh执行报错


          3、查看obproxy安装情况


            /opt/ob-operator# kubectl get pods -n oceanbase-test1 -o wide
            NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
            obcluster-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 -c
              Enter password:
              Welcome to the MySQL monitor. Commands end with ; or \g.
              Your MySQL connection id is 4
              Server 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> exit
              Bye



              三、部署 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-namespace
                NAME: ob-ocp
                LAST DEPLOYED: Thu Oct 31 14:22:33 2024
                NAMESPACE: oceanbase-dashboard
                STATUS: deployed
                REVISION: 1
                TEST SUITE: None
                NOTES:
                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.0


                then 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_PORT


                3. 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: admin
                Password: <The password you set in values or "admin" by default>


                查看dashboard的部署情况

                  /opt/ob-operator# kubectl get pods -n oceanbase-dashboard -o wide
                  oceanbase-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 wide
                  oceanbase-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


                  文章转载自晓磊聊DB,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                  评论