做評測好的視頻網(wǎng)站有哪些北京seo關(guān)鍵詞優(yōu)化收費(fèi)
OceanBase社區(qū)版單節(jié)點(diǎn)安裝搭建(Docker)
文章目錄
- OceanBase社區(qū)版單節(jié)點(diǎn)安裝搭建(Docker)
- 一、環(huán)境檢查及Docker配置
- 1.1 安裝docker
- 1.2 配置docker鏡像源
- 二、OB鏡像下載
- 三、obd部署單節(jié)點(diǎn)數(shù)據(jù)庫
- 四、創(chuàng)建業(yè)務(wù)租戶、數(shù)據(jù)庫、表
- 4.1 創(chuàng)建租戶
- 4.2 創(chuàng)建數(shù)據(jù)庫、表
- 五、參考鏈接
一、環(huán)境檢查及Docker配置
本文采用redhat7.9作為測試環(huán)境,虛擬機(jī)安裝操作系統(tǒng)的步驟不再列出。
官方的docker鏡像要求主機(jī)資源至少為2C10G。本機(jī)主機(jī)資源配置(4c16G,磁盤100G)
[root@rac04 ~]# lscpu
CPU(s): 4
[root@rac04 ~]# free -mtotal used free shared buff/cache available
Mem: 15866 981 14534 12 350 14606
Swap: 8063 0 8063
[root@rac04 ~]# df -h
文件系統(tǒng) 容量 已用 可用 已用% 掛載點(diǎn)
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 13M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/rhel-root 92G 4.2G 87G 5% /
/dev/sda1 1014M 183M 832M 19% /boot
tmpfs 1.6G 8.0K 1.6G 1% /run/user/42
tmpfs 1.6G 0 1.6G 0% /run/user/0
1.1 安裝docker
#內(nèi)核版本不低于3.10。
uname -a#設(shè)置docker源倉庫
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo#安裝docker
yum install -y docker-ce docker-ce-cli containerd.io#啟動docker服務(wù)
systemctl start docker
#激活docker服務(wù)開機(jī)自啟動
systemctl enable docker.service#校驗(yàn)
[root@rac04 ~]# docker version
Client: Docker Engine - CommunityVersion: 25.0.3API version: 1.44Go version: go1.21.6Git commit: 4debf41Built: Tue Feb 6 21:17:10 2024OS/Arch: linux/amd64Context: defaultServer: Docker Engine - CommunityEngine:Version: 25.0.3API version: 1.44 (minimum version 1.24)Go version: go1.21.6Git commit: f417435Built: Tue Feb 6 21:16:08 2024OS/Arch: linux/amd64Experimental: falsecontainerd:Version: 1.6.28GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bbrunc:Version: 1.1.12GitCommit: v1.1.12-0-g51d5e94docker-init:Version: 0.19.0GitCommit: de40ad0
1.2 配置docker鏡像源
國內(nèi)從 DockerHub 拉取鏡像有時會遇到困難,此時可以配置鏡像加速器。Docker 官方和國內(nèi)很多云服務(wù)商都提供了國內(nèi)加速器服務(wù),參考Docker Hub 鏡像源 - 掘金 (juejin.cn)
vi /etc/docker/daemon.json{"registry-mirrors": ["https://dockerproxy.com","https://hub-mirror.c.163.com","https://mirror.baidubce.com","https://ccr.ccs.tencentyun.com"]
}#重啟docker服務(wù)
systemctl restart docker.service #校驗(yàn)鏡像源
[root@rac04 ~]# docker info |grep Mirrors -A 5Registry Mirrors:https://dockerproxy.com/https://hub-mirror.c.163.com/https://mirror.baidubce.com/https://ccr.ccs.tencentyun.com/Live Restore Enabled: false
二、OB鏡像下載
下載地址:https://hub.docker.com/r/oceanbase/oceanbase-ce/tags,該地址可能需要使用代理訪問。這里直接貼出來docker pull oceanbase/oceanbase-ce:3.1.3
找到3.1.3版本,復(fù)制拉取命令
[root@rac04 ~]# docker pull oceanbase/oceanbase-ce:3.1.3
3.1.3: Pulling from oceanbase/oceanbase-ce
13add961a70d: Pull complete
1cf396138e36: Pull complete
de207e7387d3: Pull complete
Digest: sha256:22c2d82e5e7223ee510b1c53400edd05e622d9a09bc33987bd85ce560bb0781a
Status: Downloaded newer image for oceanbase/oceanbase-ce:3.1.3
docker.io/oceanbase/oceanbase-ce:3.1.3
[root@rac04 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
oceanbase/oceanbase-ce 3.1.3 66c986c2d478 23 months ago 783MB
三、obd部署單節(jié)點(diǎn)數(shù)據(jù)庫
運(yùn)行docker容器
[root@rac04 ~]# docker run -d -m 12G --cpus 4 --name oceanbase-ce oceanbase/oceanbase-ce:3.1.3
61d0ccd3ea95e36938527701c07d85f89fe950921004c4b133302dd32051dc5c[root@rac04 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
61d0ccd3ea95 oceanbase/oceanbase-ce:3.1.3 "/bin/sh -c _boot" 8 seconds ago Up 8 seconds oceanbase-ce
檢查docker日志
[root@rac04 ~]# docker logs oceanbase-ce
generate boot.yaml ...
create boot dirs and deploy ob cluster ...
Package oceanbase-ce-3.1.3 is available.
install oceanbase-ce-3.1.3 for local ok
Cluster param config check ok
Open ssh connection ok
Generate observer configuration ok
oceanbase-ce-3.1.3 already installed.
+-------------------------------------------------------------------------------------------+
| Packages |
+--------------+---------+-----------------------+------------------------------------------+
| Repository | Version | Release | Md5 |
+--------------+---------+-----------------------+------------------------------------------+
| oceanbase-ce | 3.1.3 | 10000292022032916.el7 | eab08e5d473bd4884fdf2ac4d7dff6a329b68abe |
+--------------+---------+-----------------------+------------------------------------------+
Repository integrity check ok
Parameter check ok
Open ssh connection ok
Remote oceanbase-ce-3.1.3-eab08e5d473bd4884fdf2ac4d7dff6a329b68abe repository install ok
Remote oceanbase-ce-3.1.3-eab08e5d473bd4884fdf2ac4d7dff6a329b68abe repository lib check !!
[WARN] 127.0.0.1 oceanbase-ce-3.1.3-eab08e5d473bd4884fdf2ac4d7dff6a329b68abe require: libmariadb.so.3Try to get lib-repository
Package oceanbase-ce-libs-3.1.3 is available.
install oceanbase-ce-libs-3.1.3 for local ok
Use oceanbase-ce-libs-3.1.3-c68c3aca8a1329a360fe5d65e1c3d4fa0f93f2d5 for oceanbase-ce-3.1.3-eab08e5d473bd4884fdf2ac4d7dff6a329b68abe
Remote oceanbase-ce-libs-3.1.3-c68c3aca8a1329a360fe5d65e1c3d4fa0f93f2d5 repository install ok
Remote oceanbase-ce-3.1.3-eab08e5d473bd4884fdf2ac4d7dff6a329b68abe repository lib check ok
Cluster status check ok
Initializes observer work home ok
obcluster deployed
Get local repositories and plugins ok
Open ssh connection ok
Load cluster param plugin ok
Check before start observer ok
[WARN] (127.0.0.1) clog and data use the same disk (/)Start observer ok
observer program health check ok
Connect to observer ok
Initialize cluster
Cluster bootstrap ok
Wait for observer init ok
+---------------------------------------------+
| observer |
+-----------+---------+------+-------+--------+
| ip | version | port | zone | status |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 3.1.3 | 2881 | zone1 | active |
+-----------+---------+------+-------+--------+obcluster running
Get local repositories and plugins ok
Open ssh connection ok
Connect to observer ok
Create tenant test ok
start ob cluster ...
Get local repositories and plugins ok
Open ssh connection ok
Load cluster param plugin ok
Cluster status check ok
Deploy "obcluster" is running
boot success!
#切換終端到docker容器
[root@rac04 ~]# docker exec -it oceanbase-ce bash
#檢查集群狀態(tài)
[root@61d0ccd3ea95 /]# obd cluster list
+------------------------------------------------------------+
| Cluster List |
+-----------+------------------------------+-----------------+
| Name | Configuration Path | Status (Cached) |
+-----------+------------------------------+-----------------+
| obcluster | /root/.obd/cluster/obcluster | running |
docker鏡像已經(jīng)部署好了一個集群——obcluster,這里不再部署。附上obd操作集群的常用命令
#啟動集群
obd cluster start 集群名
#停止集群
obd cluster stop 集群名
#重啟集群
obd cluster restart 集群名
#查看集群狀況
obd cluster list
obd cluster display 集群名
#查看集群配置,也可以根據(jù)模板,重新建一個配置文件,重新部署新集群
obd cluster edit-config 集群名
四、創(chuàng)建業(yè)務(wù)租戶、數(shù)據(jù)庫、表
連接數(shù)據(jù)庫,默認(rèn)root密碼為空
obclient -h127.0.0.1 -P2881 -uroot@sys -p -c -A -Doceanbase
-- 修改root密碼
alter user root identified by 'root';
4.1 創(chuàng)建租戶
檢查資源狀況
select zone,
concat(svr_ip, ':', svr_port) observer,
cpu_capacity,
cpu_total,
cpu_assigned,
cpu_assigned_percent,
mem_capacity/1024/1024,
mem_total/1024/1024,
mem_assigned/1024/1024,
mem_assigned_percent,
disk_total/1024/1024,
disk_assigned/1024/1024,
disk_assigned_percent,
unit_Num,
round('load', 2) 'load',
round('cpu_weight', 2) 'cpu_weight',
round('memory_weight', 2) 'mem_weight',
leader_count
from __all_virtual_server_stat
order by zone, svr_ip\G*************************** 1. row ***************************zone: zone1observer: 127.0.0.1:2882cpu_capacity: 14cpu_total: 14cpu_assigned: 11.5cpu_assigned_percent: 82mem_capacity/1024/1024: 4096.00000000mem_total/1024/1024: 4096.00000000mem_assigned/1024/1024: 3891.20000076mem_assigned_percent: 95disk_total/1024/1024: 27648.00000000
disk_assigned/1024/1024: 55296.00000000disk_assigned_percent: 200unit_Num: 2load: 0.00cpu_weight: 0.00mem_weight: 0.00leader_count: 1318
1 row in set, 3 warnings (0.001 sec)MySQL [oceanbase]> show parameters like 'system_memory'\G
*************************** 1. row ***************************zone: zone1svr_type: observersvr_ip: 127.0.0.1svr_port: 2882name: system_memorydata_type: NULLvalue: 4Ginfo: the memory reserved for internal use which cannot be allocated to any outer-tenant, and should be determined to guarantee every server functions normally. Range: [0M,)section: OBSERVERscope: CLUSTERsource: DEFAULT
edit_level: DYNAMIC_EFFECTIVE
1 row in set (0.002 sec)MySQL [oceanbase]> select * from __all_unit_config;
+----------------------------+----------------------------+----------------+-----------------+---------+---------+------------+------------+----------+----------+---------------+---------------------+
| gmt_create | gmt_modified | unit_config_id | name | max_cpu | min_cpu | max_memory | min_memory | max_iops | min_iops | max_disk_size | max_session_num |
+----------------------------+----------------------------+----------------+-----------------+---------+---------+------------+------------+----------+----------+---------------+---------------------+
| 2024-03-07 14:35:29.704258 | 2024-03-07 14:35:29.704258 | 1 | sys_unit_config | 5 | 2.5 | 1288490188 | 1073741824 | 10000 | 5000 | 28991029248 | 9223372036854775807 |
| 2024-03-07 14:35:40.537529 | 2024-03-07 14:35:40.537529 | 1001 | test_unit | 9 | 9 | 3006477108 | 3006477108 | 128 | 128 | 28991029248 | 64 |
+----------------------------+----------------------------+----------------+-----------------+---------+---------+------------+------------+----------+----------+---------------+---------------------+
2 rows in set (0.001 sec)MySQL [oceanbase]> select * from gv$unit;
+---------+----------------+------------------+------------------+--------------------+-------+-----------+-------------+-----------+----------+---------------------+-----------------------+---------+---------+------------+------------+----------+----------+---------------+---------------------+
| unit_id | unit_config_id | unit_config_name | resource_pool_id | resource_pool_name | zone | tenant_id | tenant_name | svr_ip | svr_port | migrate_from_svr_ip | migrate_from_svr_port | max_cpu | min_cpu | max_memory | min_memory | max_iops | min_iops | max_disk_size | max_session_num |
+---------+----------------+------------------+------------------+--------------------+-------+-----------+-------------+-----------+----------+---------------------+-----------------------+---------+---------+------------+------------+----------+----------+---------------+---------------------+
| 1 | 1 | sys_unit_config | 1 | sys_pool | zone1 | 1 | sys | 127.0.0.1 | 2882 | | 0 | 5 | 2.5 | 1288490188 | 1073741824 | 10000 | 5000 | 28991029248 | 9223372036854775807 |
| 1001 | 1001 | test_unit | 1001 | test_pool | zone1 | 1001 | test | 127.0.0.1 | 2882 | | 0 | 9 | 9 | 3006477108 | 3006477108 | 128 | 128 | 28991029248 | 64 |
+---------+----------------+------------------+------------------+--------------------+-------+-----------+-------------+-----------+----------+---------------------+-----------------------+---------+---------+------------+------------+----------+----------+---------------+---------------------+
2 rows in set (0.001 sec)-- 剩余的資源已經(jīng)不足,修改system_memory參數(shù)為2G,調(diào)小test租戶的資源占用
alter system set system_memory='2G';
alter resource unit test_unit min_cpu=1,max_cpu=2,min_memory='1G',max_memory='1G';-- 再次檢查資源
*************************** 1. row ***************************zone: zone1observer: 127.0.0.1:2882cpu_capacity: 14cpu_total: 14cpu_assigned: 3.5cpu_assigned_percent: 25mem_capacity/1024/1024: 6144.00000000mem_total/1024/1024: 6144.00000000mem_assigned/1024/1024: 2048.00000000mem_assigned_percent: 33disk_total/1024/1024: 27648.00000000
disk_assigned/1024/1024: 55296.00000000disk_assigned_percent: 200unit_Num: 2load: 0.00cpu_weight: 0.00mem_weight: 0.00leader_count: 1318
創(chuàng)建資源單元
CREATE resource unit u1 max_cpu=1, min_cpu=1, max_memory='1G', min_memory='1G', max_iops=10000,
min_iops=1000, max_session_num=1000000, max_disk_size='5G';
創(chuàng)建資源池
create resource pool pool1 unit='u1', unit_num=1, zone_list=('zone1') ;
創(chuàng)建mysql類型業(yè)務(wù)租戶,允許所有連接,關(guān)閉回收站
create tenant yw charset='utf8mb4',zone_list=('zone1'),resource_pool_list=('pool1'),comment='業(yè)務(wù)租戶1'
set ob_compatibility_mode=mysql,ob_tcp_invited_nodes='%',recyclebin = off;
檢查
MySQL [oceanbase]> select * from __all_tenant where tenant_name='yw'\G
*************************** 1. row ***************************gmt_create: 2024-03-07 15:50:54.994276gmt_modified: 2024-03-07 15:50:54.994276tenant_id: 1002tenant_name: ywreplica_num: -1zone_list: zone1primary_zone: RANDOMlocked: 0collation_type: 0info: 業(yè)務(wù)租戶1read_only: 0rewrite_merge_version: 0locality: FULL{1}@zone1logonly_replica_num: 0previous_locality: storage_format_version: 0
storage_format_work_version: 0default_tablegroup_id: -1compatibility_mode: 0drop_tenant_time: -1status: TENANT_STATUS_NORMALin_recyclebin: 0
1 row in set (0.002 sec)
4.2 創(chuàng)建數(shù)據(jù)庫、表
連接業(yè)務(wù)租戶yw
obclient -h127.0.0.1 -P2881 -uroot@yw -p -c -A -Doceanbase
alter user root identified by 'root';-- 創(chuàng)建數(shù)據(jù)庫
MySQL [oceanbase]> create database ywdb charset='utf8mb4' read write;
Query OK, 1 row affected (0.013 sec)
MySQL [oceanbase]> use ywdb
Database changed
MySQL [ywdb]> create table t1(name char(20));
Query OK, 0 rows affected (0.072 sec)
-- 創(chuàng)建分區(qū)表
MySQL [ywdb]> create table t3(id int(10),t3name char(20)) partition by hash(id) partitions 5;
Query OK, 0 rows affected (0.058 sec)
-- 創(chuàng)建表組
MySQL [ywdb]> create tablegroup tbgroup1 partition by hash partitions 5;
Query OK, 0 rows affected (0.019 sec)
-- 創(chuàng)建分區(qū)表并加入表組
MySQL [ywdb]> create table t4(t4id int(10)) tablegroup=tbgroup1 partition by hash(t4id) partitions 5;
Query OK, 0 rows affected (0.033 sec)
-- 將表加入表組
MySQL [ywdb]> alter table t3 tablegroup=tbgroup1;
Query OK, 0 rows affected (0.021 sec)
-- 查看表的創(chuàng)建語句
MySQL [ywdb]> SHOW CREATE TABLE t3;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t3 | CREATE TABLE `t3` (`id` int(10) DEFAULT NULL,`t3name` char(20) DEFAULT NULL
) DEFAULT CHARSET = utf8mb4 ROW_FORMAT = COMPACT COMPRESSION = 'zstd_1.3.8' REPLICA_NUM = 1 BLOCK_SIZE = 16384 USE_BLOOM_FILTER = FALSE TABLET_SIZE = 134217728 PCTFREE = 0 TABLEGROUP = 'tbgroup1'partition by hash(id)
(partition p0,
partition p1,
partition p2,
partition p3,
partition p4) |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.027 sec)
五、參考鏈接
Linux安裝Docker完整教程 - 哈哈哈嗝 - 博客園 (cnblogs.com)
Docker Hub 鏡像源 - 掘金 (juejin.cn)
快速體驗(yàn) OceanBase-OceanBase 數(shù)據(jù)庫-OceanBase文檔中心-分布式數(shù)據(jù)庫使用文檔