最近有需求要在开发环境弄一套Oceanbase,说是客户有要求,找了下文档,这里简单记录下部署过程,免得以后要用又要重新找文档。
环境
| 名称 |
版本 |
| linux系统 |
centos7.9 |
| kubernetes |
1.18.8 |
准备
容器镜像:由于我们内网环境问题,只能提前下好然后导入进节点。
存储:local-path-provisioner
代码:ob-operator
部署 CRD
1
|
kubectl apply -f ./deploy/crd.yaml
|
部署 ob-operator
您需要根据您的配置修改 operator.yaml 。
您需要添加启动参数 --cluster-name,该参数需要与 obcluster 中的 cluster 配置一致。
该配置的含义:ob-operator 只会处理 cluster 的值与自身启动参数 --cluster-name 的值相同的 CRD。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
control-plane: controller-manager
name: ob-operator-controller-manager
namespace: oceanbase-system
spec:
replicas: 1
selector:
matchLabels:
control-plane: controller-manager
template:
metadata:
labels:
control-plane: controller-manager
spec:
containers:
- args:
- --health-probe-bind-address=:8081
- --metrics-bind-address=127.0.0.1:8080
- --leader-elect
- --cluster-name=cn
command:
- /manager
image: ob-operator:latest
imagePullPolicy: Always
name: manager
|
配置节点 label
需要将 Kubernetes 节点打 label,label 需要与 obcluster.yaml 中 nodeSelector 配置相匹配。ob-operator 会将 Pod 调度到具有相应 label 的节点上。
推荐配置 label 的 key 为 topology.kubernetes.io/zone。不同 Zone 推荐配置不同的 label 以做容灾。
1
|
kubectl label node nodename topology.kubernetes.io/zone=zonename
|
部署 OceanBase 集群
obcluster.yaml 中需要用户根据自己的配置做一些修改。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
apiVersion: cloud.oceanbase.com/v1
kind: OBCluster
metadata:
namespace: oceanbase
name: ob-test
spec:
version: 3.1.1-4
clusterID: 1
topology:
- cluster: cn
zone:
- name: zone1
region: regio1
nodeSelector:
topology.kubernetes.io/zone: zone1
replicas: 1
- name: zone2
region: regio1
nodeSelector:
topology.kubernetes.io/zone: zone2
replicas: 1
- name: zone3
region: regio1
nodeSelector:
topology.kubernetes.io/zone: zone3
replicas: 1
resources:
cpu: 2
memory: 10Gi
storage:
- name: data-file
storageClassName: "local-path"
size: 50Gi
- name: data-log
storageClassName: "local-path"
size: 50Gi
- name: log
storageClassName: "local-path"
size: 30Gi
|
version OceanBase 集群的版本。
cluster 需要按需配置,如果需要在该 Kubernetes 集群中部署 OceanBase 集群,请将 cluster 配置为与 ob-operator 启动参数 --cluster-name 相同的配置。
cpu 配置建议为大于 2 的整数,小于 2 会引发系统异常。
memory 配置建议为大于 10Gi 的整数,小于 10Gi 会引发系统异常。
storage 的 data-file 部分为 OBServer 系统配置项 datafile_size 的大小,建议为 memory 的 3 倍以上。storageClassName 用户可以自行按需配置。
storage 的 data-log 部分为 OBServer 系统配置项 data_dir 的大小,建议为 memory 的 5 倍以上。storageClassName 用户可以自行按需配置。
storage 的 log 部分为 OBServer 系统日志的大小,建议为 30Gi 以上。storageClassName 用户可以自行按需配置。
nodeSelector 的数据结构:
1
2
3
4
5
6
|
// NodeSelector is a selector which must be true for the pod to fit on a node.
// Selector which must match a node's labels for the pod to be scheduled on that node.
// More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
// +optional
// +mapType=atomic
NodeSelector map[string]string `json:"nodeSelector,omitempty" protobuf:"bytes,7,rep,name=nodeSelector"`
|
部署ob-proxy
1
2
3
4
|
kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/ma
ster/deploy/obproxy/deployment.yaml
kubectl apply -f https://raw.githubusercontent.com/oceanbase/ob-operator/ma
ster/deploy/obproxy/service.yaml
|
部署OCP
新建租户
连接集群使⽤ sql 来新建租户
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# 获取 obproxy 的 service 地址, obproxy 的 service 名为 obproxy-service
kubectl get svc -A
# 使⽤ sys 租户连接集群
mysql -h${OBPROXY_IP} -P2881 -uroot oceanbase -A -c
# 查询可⽤的资源
select (CPU_CAPACITY - CPU_ASSIGNED) as cpu_free,( MEM_CAPACITY - MEM_ASSI
GNED) as mem_free from GV$OB_SERVERS;
# 创建资源单元
create resource unit meta_tenant_unit max_cpu ${cpu_count}, MEMORY_SIZE ${
memory_size};
# 创建资源池
create resource pool meta_tenant_pool unit=meta_tenant_unit, UNIT_NUM=1,
ZONE_LIST=("zone1","zone2","zone3");
#创建租户, 设置可以任意ip访问
create tenant meta zone_list=("zone1","zone2","zone3"), resource_pool_list
=("meta_tenant_pool"), PRIMARY_ZONE='zone1;zone2,zone3' SET ob_tcp_invited
_nodes='%' ;
# 创建⽤户(可选)
使⽤新建的租户连接
mysql -h${OBPROXY_IP} -P2881 -uroot@meta oceanbase -A -c
修改root密码
alter user root identified by 'xxx';
# 创建ocp⽤户
create user ocp identified by 'xxx';
grant all on *.* to ocp;
|
⼀般需要创建两个租户,⼀个⽤来存meta信息,⼀个⽤来存监控信息,建租户的⽅法是⼀样的,需要根,上面的步骤全部在来一遍,创建出一个monitordb租户,并且创建下属账号root@monitor
据查询到的可⽤资源来分配
在 k8s 集群中,可以通过执⾏⼀个 job 来初始化 metadb, 实际上是调⽤了 ocp-all-in-one 这个镜像中
的⼀个脚本来做的初始化操作,初始化的过程会持续⼀段时间,具体的⽤户名和密码需要按照新建租户
步骤的值来修改, 如果job失败了,需要⽤mysql命令⾏连接到metadb,删除调对应的database,清理之
后才能重新跑job
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
apiVersion: batch/v1
kind: Job
metadata:
name: ocp-init
namespace: obcluster
spec:
template:
metadata:
name: ocp-init
namespace: obcluster
spec:
containers:
- name: metadb-init
image: reg.docker.alibaba-inc.com/oceanbase/ocp-all-in-one:v4.0.0-ce
workingDir: /home/admin/ocp-init/src/ocp-init
command: ["python"]
args: [ "create_metadb.py", $(OCP_METADB_HOST), $(OCP_METADB_PORT), $(OCP_METADB_USER), $(OCP_METADB_PASSWORD), $(OCP_METADB_DBNAME), $(OCP_MONITORDB_USER), $(OCP_MONITORDB_PASSWORD), $(OCP_MONITORDB_DBNAME) ]
env:
- name: OCP_METADB_HOST
# 这⾥可以使⽤ob的service地址,或者obproxy的都可以,当前⽤的是ob的service地址
value: $(SVC_OB_TEST_SERVICE_HOST)
- name: OCP_METADB_PORT
value: $(SVC_OB_TEST_SERVICE_PORT)
- name: OCP_METADB_USER
value: root@meta
- name: OCP_METADB_PASSWORD
value: root
- name: OCP_METADB_DBNAME
value: metadb
- name: OCP_MONITORDB_USER
value: root@monitor
- name: OCP_MONITORDB_PASSWORD
value: root
- name: OCP_MONITORDB_DBNAME
value: monitordb
restartPolicy: Never
|
运行成功后部署ocp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: obcluster
name: ocp
spec:
selector:
matchLabels:
app: ocp
replicas: 1
template:
metadata:
labels:
app: ocp
spec:
containers:
- name: ocp
image: reg.docker.alibaba-inc.com/oceanbase/ocp-all-in-one:v4.0.0-ce
ports:
- containerPort: 8080
name: "service"
env:
- name: OCP_METADB_HOST
value: $(OBPROXY_SERVICE_SERVICE_HOST)
- name: OCP_METADB_PORT
value: $(OBPROXY_SERVICE_SERVICE_PORT)
- name: OCP_METADB_USER
value: ocp@meta
- name: OCP_METADB_PASSWORD
value: meta_password
- name: OCP_METADB_DBNAME
value: metadb
- name: OB_PORT
value: "8080"
resources:
limits:
memory: 8Gi
cpu: "4"
---
apiVersion: v1
kind: Service
metadata:
namespace: obcluster
name: ocp-service
spec:
type: NodePort
selector:
app: ocp
ports:
- name: "tcp"
port: 8080
targetPort: 8080
nodePort: 32080
|
部署之后可以看到各个节点的状态
打开ocp⻚⾯,在 ocp 的系统参数配置中修改 ocp.site.url 的值为服务地址的真实值