操作系统
[root@cts07 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
内存
[root@cts07 ~]# free -h
total used free shared buff/cache available
Mem: 14G 541M 13G 8.5M 123M 13G
Swap: 3.9G 0B 3.9G
CPU
[root@cts07 ~]# cat /proc/cpuinfo | grep processor
processor : 0
processor : 1
processor : 2
processor : 3
processor : 4
processor : 5
processor : 6
processor : 7
配置yum环境
[root@cts07 ~]# yum install -y yum-utils
Installed:
yum-utils.noarch 0:1.1.31-54.el7_8
Dependency Installed:
libxml2-python.x86_64 0:2.9.1-6.el7_9.6 python-chardet.noarch 0:2.2.1-3.el7 python-kitchen.noarch 0:1.1.1-5.el7
Dependency Updated:
libxml2.x86_64 0:2.9.1-6.el7_9.6
Complete!
[root@cts07 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
安装docker
yum install docker-ce docker-ce-cli containerd.io -y
Installed:
containerd.io.x86_64 0:1.6.16-3.1.el7 docker-ce.x86_64 3:20.10.23-3.el7 docker-ce-cli.x86_64 1:20.10.23-3.el7
Dependency Installed:
audit-libs-python.x86_64 0:2.8.5-4.el7 checkpolicy.x86_64 0:2.5-8.el7 container-selinux.noarch 2:2.119.2-1.911c772.el7_8 docker-ce-rootless-extras.x86_64 0:20.10.23-3.el7
docker-scan-plugin.x86_64 0:0.23.0-3.el7 fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 fuse3-libs.x86_64 0:3.6.1-4.el7 libcgroup.x86_64 0:0.41-21.el7
libsemanage-python.x86_64 0:2.5-14.el7 policycoreutils-python.x86_64 0:2.5-34.el7 python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-4.el7
slirp4netns.x86_64 0:0.4.3-4.el7_8
Complete!
systemctl start docker
查找OceanBase镜像
[root@cts07 ~]# docker search oceanbase
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
oceanbase/oceanbase-ce OceanBase is an open-source, distributed HTA… 11
obpilot/oceanbase-ce 3 steps to run an OceanBase-CE docker in you… 4
oceanbase/oceanbase-xe OceanBase Database 2.2 Express Edition 4
oceanbase/obce-mini obce-mini is a mini standalone test image fo… 3
oceanbase/miniob miniob database competition 2
zibuyu886/oceanbase-ce-cluster OceanBase ce cluster 1
oceanbase/obce-operator obce-operator 1
oceanbase/centos7 0
oceanbase/ob-operator 0
oceanbase/obagent 0
oceanbase/obproxy-ce 0
oceanbasedev/oceanbase-cn 0
oceanbasedev/ob-operator 0
oceanbase/oceanbase-cloud-native 0
datatomdev/oceanbase 0
oceanbasedev/obagent 0
huweijie/oceanbase-ce-deploy 0
superbigfu/oceanbase 0
oceanbasedev/obproxy-ce 0
hongxinsun/oceanbase-cn 0
hnwyllmm/oceanbase-ce 0
oceanbasedev/obproxy 0
hnwyllmm/oceanbase-ce-x86 0
oceanbasedev/create_tenant 0
20220121/oceanbase 0
安装oceanbase-ce
[root@cts07 ~]# docker pull obpilot/oceanbase-ce:latest
latest: Pulling from obpilot/oceanbase-ce
a1d0c7532777: Pull complete
42e2faadf654: Pull complete
b888a9404e21: Pull complete
426c12926548: Pull complete
a66beb305b92: Pull complete
2d1899456ae1: Pull complete
Digest: sha256:4c2d16106cdc4bd610baf155e43e048d896de4d6bfc777534e75bfa0497bff49
Status: Downloaded newer image for obpilot/oceanbase-ce:latest
docker.io/obpilot/oceanbase-ce:latest
# 运行
[root@cts07 ~]# docker run -itd -m 10G --name oceanbase-ce obpilot/oceanbase-ce:latest
56144849726f7d9ecdce6f20f56ebea8c693ca93efb2eac2a7990313de5a89dc
[root@cts07 ~]# docker exec -it oceanbase-ce bash
[admin@56144849726f ~]$
[admin@56144849726f ~]$ obd cluster list
+------------------------------------------------------------+
| Cluster List |
+--------+---------------------------------+-----------------+
| Name | Configuration Path | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | deployed |
+--------+---------------------------------+-----------------+
[admin@56144849726f ~]$ obd cluster start obdemo
Get local repositories ok
Search plugins ok
Open ssh connection ok
Load cluster param plugin ok
Check before start observer ok
[WARN] (127.0.0.1) The recommended value of fs.aio-max-nr is 1048576 (Current value: 65536)
[WARN] (127.0.0.1) clog and data use the same disk (/)
Check before start obproxy ok
Start observer ok
observer program health check ok
Connect to observer ok
Initialize cluster ok
Start obproxy ok
obproxy program health check ok
Connect to obproxy ok
Initialize cluster ok
Wait for observer init ok
+---------------------------------------------+
| observer |
+-----------+---------+------+-------+--------+
| ip | version | port | zone | status |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 4.0.0.0 | 2881 | zone1 | ACTIVE |
+-----------+---------+------+-------+--------+
obclient -h127.0.0.1 -P2881 -uroot -pXXXXXXXX -Doceanbase
+---------------------------------------------+
| obproxy |
+-----------+------+-----------------+--------+
| ip | port | prometheus_port | status |
+-----------+------+-----------------+--------+
| 127.0.0.1 | 2883 | 2884 | active |
+-----------+------+-----------------+--------+
obclient -h127.0.0.1 -P2883 -uroot -pXXXXXXXX -Doceanbase
obdemo running
[admin@56144849726f ~]$ obd cluster display obdemo
Get local repositories and plugins ok
Open ssh connection ok
Cluster status check ok
Connect to observer ok
Wait for observer init ok
+---------------------------------------------+
| observer |
+-----------+---------+------+-------+--------+
| ip | version | port | zone | status |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 4.0.0.0 | 2881 | zone1 | ACTIVE |
+-----------+---------+------+-------+--------+
obclient -h127.0.0.1 -P2881 -uroot -pXXXXXXXX -Doceanbase
Connect to obproxy ok
+---------------------------------------------+
| obproxy |
+-----------+------+-----------------+--------+
| ip | port | prometheus_port | status |
+-----------+------+-----------------+--------+
| 127.0.0.1 | 2883 | 2884 | active |
+-----------+------+-----------------+--------+
obclient -h127.0.0.1 -P2883 -uroot -pXXXXXXXX -Doceanbase
# 创建MySQL租户
[admin@56144849726f ~]$ obclient -h127.1 -uroot@sys -P2881 -pXXXXXXX -c -A oceanbase
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 3221487618
Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov 1 2022 14:56:31)
Copyright (c) 2000, 2018, OB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
obclient [oceanbase]> show parameters like 'cluster';
+-------+----------+-----------+----------+---------+-----------+--------+---------------------+----------+---------+---------+-------------------+
| zone | svr_type | svr_ip | svr_port | name | data_type | value | info | section | scope | source | edit_level |
+-------+----------+-----------+----------+---------+-----------+--------+---------------------+----------+---------+---------+-------------------+
| zone1 | observer | 127.0.0.1 | 2882 | cluster | NULL | obdemo | Name of the cluster | OBSERVER | CLUSTER | DEFAULT | DYNAMIC_EFFECTIVE |
+-------+----------+-----------+----------+---------+-----------+--------+---------------------+----------+---------+---------+-------------------+
1 row in set (0.018 sec)
# 使用obproxy 2883端口登录
[admin@56144849726f ~]$ obclient -h127.1 -uroot@sys#obdemo -P2883 -pXXXXXXX -c -A oceanbase
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 3
Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov 1 2022 14:56:31)
Copyright (c) 2000, 2018, OB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
obclient [oceanbase]>
创建租户#命令汇总
obclient [oceanbase]> alter resource unit sys_unit_config min_cpu=1;
Query OK, 0 rows affected (0.018 sec)
obclient [oceanbase]> create resource unit S1C1G max_cpu 1,memory_size '1G',max_iops 1024;
Query OK, 0 rows affected (0.012 sec)
obclient [oceanbase]> alter system __min_full_resource_pool_memory=1073741824;
Query OK, 0 rows affected (0.075 sec)
obclient [oceanbase]> CREATE resource pool my_pool unit = 'S1C1G', unit_num = 1;
Query OK, 0 rows affected (0.034 sec)
obclient [oceanbase]> create tenant obmysql resource_pool_list=('my_pool'), primary_zone='RANDOM',comment 'mysql tenant/instance', charset='utf8' set ob_tcp_invited_nodes='%', ob_compatibility_mode='mysql';
Query OK, 0 rows affected (33.818 sec)
登录租户并创建业务数据库
[admin@56144849726f ~]$ obclient -h 127.1 -uroot@obmysql#obdemo -P2883 -p -c -A test
Enter password:
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 7
Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov 1 2022 14:56:31)
Copyright (c) 2000, 2018, OB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
obclient [test]> create database db1 ;
Query OK, 1 row affected (0.099 sec)
obclient [test]> create user user1@'%' identified by 'user1' ;
Query OK, 0 rows affected (0.092 sec)
obclient [test]> grant all privileges on *.* to user1@'%';
Query OK, 0 rows affected (0.078 sec)
建业务表
# 使用业务用户 user1 登录 obmysql 租户,登录租户并创建业务数据库,创建业务用户,表
[admin@56144849726f ~]$ obclient -h 127.1 -uuser1@obmysql#obdemo -P2883 -puser1 -c -A db1
Welcome to the OceanBase. Commands end with ; or \g.
Your OceanBase connection id is 8
Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov 1 2022 14:56:31)
Copyright (c) 2000, 2018, OB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
obclient [db1]> create table t1(id int) ;
Query OK, 0 rows affected (0.307 sec)
obclient [db1]> insert into t1 values(1) ;
Query OK, 1 row affected (0.079 sec)
obclient [db1]> select * from t1 ;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.007 sec)