https://blog.csdn.net/a5546868001/article/details/124426391?spm=1001.2014.3001.5502
实践一完成
https://blog.csdn.net/u014609263/article/details/124544196
实践练习一(必选):OceanBase Docker 体验:实验过程间附件markdown
目录
OceanBase Docker 体验
主机环境
IP | 192.168.122.1 |
---|---|
Os | CentOS Linux release 7.9.2009 (Core) |
内存 | 16g |
Cpu | 4core |
Docker环境检查
查看docker版本(若docker未安装,则进行下面的docker安装)
[root@localhost ~]# docker --version
Docker version 1.13.1, build 7d71120/1.13.1
安装docker
yum install docker -y
启动docker服务
systemctl start docker
设置docker开机启动
systemctl enable docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]#
检查docker进程
systemctl status docker
查看docker版本
[root@localhost ~]# docker --version
Docker version 1.13.1, build 7d71120/1.13.1
使用Docker镜像安装OceanBase
查询可用oceanbase的可用镜像
执行命令:docker search oceanbase
docker search oceanbase
下载镜像
下载docker镜像 obpilot/oceanbase-ce 也可以下载oceanbase/obce-mini
执行命令:docker images 查看当前本地可用镜像(无任何可用镜像)
docker pull obpilot/oceanbase-ce
查看镜像
docker images
运行容器
docker run -itd -m 8G -p 2881:2881 -p 2883:2883 --name obcluster obpilot/oceanbase-ce:latest
查看进程
docker ps
进入容器
docker exec -it obcluster bash
OBD 命令部署OB集群
启动OB服务
obd cluster list
obd cluster start obdemo
查看OB集群运行状态
obd cluster display obdemo
OceanBase初体验
连接OceanBase集群
集群名obce-single可以从ob配置文件获取
obclient -h127.1 -uroot@sys#obce-single -P2883 -prootPWD123 -c -A oceanbase
查看集群资源
SELECT * FROM __all_server\G; – 查看集群状态
SELECT svr_ip,svr_port, cpu_total, mem_total/1024/1024/1024,
disk_total/1024/1024/1024, zone FROM __all_virtual_server_stat;
– 查询系统总计资源
– 查询租户已分配资源:
SELECT sum(c.max_cpu), sum(c.max_memory)/1024/1024/1024 FROM __all_resource_pool as a, __all_unit_config AS c
WHERE a.unit_config_id=c.unit_config_id;
Note:资源池cpu共14c/4g 租户已用 5c/1G 新建租户最大可用为 9c/3g(超分会报错)
资源分配
CREATE RESOURCE UNIT u1 max_cpu = 4, max_memory = ‘1G’, min_memory = ‘1G’, max_iops = 10000, min_iops = 10000, max_session_num = 30000, max_disk_size = ‘4G’; --创建资源单元(4c/1G 硬盘大小为4G)
SELECT * FROM __all_unit_config; – 查看资源规格
CREATE RESOURCE POOL pool1 UNIT = ‘u1’, UNIT_NUM = 1,ZONE_LIST = (‘zone1’); – 创建资源池
CREATE TENANT IF NOT EXISTS obtest charset=‘utf8mb4’, replica_num=1, zone_list=(‘zone1’), primary_zone=‘zone1’, resource_pool_list=(‘pool1’); – 创建租户
select tenant_id,tenant_name,primary_zone from __all_tenant; – 查看租户
登录业务租户创建业务用户
登录新建租户,创建用户
obclient -h127.1 -uroot@obtest#obce-single -P2883 -c -A oceanbase
CREATE USER ‘obuser1’ IDENTIFIED BY ‘abc123’;
grant all on . to ‘obuser1’ WITH GRANT OPTION;
业用户登录OB集群创建业务表
obclient -h127.1 -u obuser1@obtest#obce-single -P2883 -pabc123 -c -A
MySQL [(none)]> create database demo;
Query OK, 1 row affected (0.064 sec)
MySQL [(none)]> use demo;
Database changed
MySQL [demo]> create table t1(id int(4) primary key, name varchar(20));
Query OK, 0 rows affected (0.100 sec)
MySQL [demo]> insert into t1 select 1,‘tom’;
Query OK, 1 row affected (0.025 sec)
MySQL [demo]> select * from t1;
±—±-----+
id name
±—±-----+
1 tom
±—±-----+
1 row in set (0.009 sec)
root@dbabackup:/data/run_scripts# docker --version
Docker version 20.10.14, build a224086
#下载 镜像并查看
root@dbabackup:/data/run_scripts#docker pull oceanbase/oceanbase-ce
#开始启动容器
docker run -p 2881:2881 --name oceanbase-ce -d -e OB_HOME_PATH="/root/obce" -e OB_TENANT_NAME=“obmysql” oceanbase/oceanbase-ce
#进入容器
docker exec -it oceanbase-ce /bin/bash
#list OBD deployment config
obd cluster list
####start use oceanbase cluster
ob-mysql mysql
ob-mysql root
ob-mysql test
[root@be5b79ccd2d9 ~]# obd cluster display obcluster
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 | 3.1.3 | 2881 | zone1 | active |
±----------±--------±-----±------±-------+
##查看集群状态
##查看系统总计资源
##查看租户已分配资源
##创建资源单元
##查看资源规格
##创建租户、用户
##创建库、表
MySQL [oceanbase]> select tenant_id,tenant_name,primary_zone from __all_tenant;
±----------±------------±-------------+
| tenant_id | tenant_name | primary_zone |
±----------±------------±-------------+
| 1 | sys | zone1 |
| 1001 | obmysql | RANDOM |
±----------±------------±-------------+
2 rows in set (0.003 sec)
[root@be5b79ccd2d9 ~]# obd cluster obcluster status
Usage: obd cluster [options]
Available commands:
autodeploy Deploy a cluster automatically by using a simple configuration file.
change-repo Change repository for a deployed component
check4ocp Check Whether OCP Can Take Over Configurations in Use
chst Change Deployment Configuration Style
deploy Deploy a cluster by using the current deploy configuration or a deploy yaml file.
destroy Destroy a deployed cluster.
display Display the information for a cluster.
edit-config Edit the configuration file for a specific deployment.
list List all the deployments.
redeploy Redeploy a started cluster.
reload Reload a started cluster.
restart Restart a started cluster.
start Start a deployed cluster.
stop Stop a started cluster.
tenant Create or drop a tenant.
upgrade Upgrade a cluster.
Options:
-h, --help Show help and exit.
-v, --verbose Activate verbose output.
[root@be5b79ccd2d9 ~]# obd cluster list
±-----------------------------------------------------------+
| Cluster List |
±----------±-----------------------------±----------------+
| Name | Configuration Path | Status (Cached) |
±----------±-----------------------------±----------------+
| obcluster | /root/.obd/cluster/obcluster | running |
±----------±-----------------------------±----------------+
[root@be5b79ccd2d9 ~]# obd cluster start obcluster
Get local repositories and plugins ok
Open ssh connection ok
Load cluster param plugin ok
Cluster status check ok
Deploy “obcluster” is running
查看OceanBase集群所有节点可用资源情况
select a.zone,concat(a.svr_ip,’:’,a.svr_port) observer, cpu_total, (cpu_total-cpu_assigned) cpu_free,
round(mem_total/1024/1024/1024) mem_total_gb, round((mem_total-mem_assigned)/1024/1024/1024) mem_free_gb,
round(disk_total/1024/1024/1024) disk_total_gb,
substr(a.build_version,1,6) version,usec_to_time(b.start_service_time) start_service_time
from __all_virtual_server_stat a join __all_server b on (a.svr_ip=b.svr_ip and a.svr_port=b.svr_port)
order by a.zone, a.svr_ip;
±------±---------------±----------±---------±-------------±------------±--------------±--------±---------------------------+
| zone | observer | cpu_total | cpu_free | mem_total_gb | mem_free_gb | disk_total_gb | version | start_service_time |
±------±---------------±----------±---------±-------------±------------±--------------±--------±---------------------------+
| zone1 | 127.0.0.1:2882 | 16 | 2.5 | 13 | 1 | 10 | 3.1.3_ | 2022-06-23 16:33:07.584955 |
±------±---------------±----------±---------±-------------±------------±--------------±--------±---------------------------+
1 row in set (0.011 sec)
####查看集群资源池具体使用情况
select t1.name resource_pool_name, t2.name
unit_config_name, t2.max_cpu, t2.min_cpu,
round(t2.max_memory/1024/1024/1024) max_mem_gb, round(t2.min_memory/1024/1024/1024) min_mem_gb,
t3.unit_id, t3.zone, concat(t3.svr_ip,’:’,t3.svr_port
) observer,t4.tenant_id, t4.tenant_name
from __all_resource_pool t1 join __all_unit_config t2 on (t1.unit_config_id=t2.unit_config_id)
join __all_unit t3 on (t1.resource_pool_id
= t3.resource_pool_id
)
left join __all_tenant t4 on (t1.tenant_id=t4.tenant_id)
order by t1.resource_pool_id
, t2.unit_config_id
, t3.unit_id
;
±-------------------±-----------------±--------±--------±-----------±-----------±--------±------±---------------±----------±------------+
| resource_pool_name | unit_config_name | max_cpu | min_cpu | max_mem_gb | min_mem_gb | unit_id | zone | observer | tenant_id | tenant_name |
±-------------------±-----------------±--------±--------±-----------±-----------±--------±------±---------------±----------±------------+
| sys_pool | sys_unit_config | 5 | 2.5 | 4 | 3 | 1 | zone1 | 127.0.0.1:2882 | 1 | sys |
| obmysql_pool | obmysql_unit | 11 | 11 | 9 | 9 | 1001 | zone1 | 127.0.0.1:2882 | 1001 | obmysql |
±-------------------±-----------------±--------±--------±-----------±-----------±--------±------±---------------±----------±------------+
###查看OB集群资源单元unit配置情况
select unit_config_id,name,max_cpu,min_cpu,round(max_memory/1024/1024/1024) max_mem_gb,
round(min_memory/1024/1024/1024) min_mem_gb, round(max_disk_size/1024/1024/1024) max_disk_size_gb
from __all_unit_config
order by unit_config_id;
±---------------±----------------±--------±--------±-----------±-----------±-----------------+
| unit_config_id | name | max_cpu | min_cpu | max_mem_gb | min_mem_gb | max_disk_size_gb |
±---------------±----------------±--------±--------±-----------±-----------±-----------------+
| 1 | sys_unit_config | 5 | 2.5 | 4 | 3 | 10 |
| 1001 | obmysql_unit | 11 | 11 | 9 | 9 | 10 |
±---------------±----------------±--------±--------±-----------±-----------±-----------------+
###集群初始化参数配置
mysql -h127.1 -uroot@sys -P2881 -p -c -A
Enter password:
– observer log自清理设置
alter system set enable_syslog_recycle=true;
alter system set max_syslog_file_count=10;
show parameters where name in (‘enable_syslog_recycle’, ‘max_syslog_file_count’);
mysql -h127.1 -uroot@sys -P2881 -p -c -A
Enter password:
– observer log自清理设置
alter system set enable_syslog_recycle=true;
alter system set max_syslog_file_count=10;
show parameters where name in (‘enable_syslog_recycle’, ‘max_syslog_file_count’);
基于redhat 7.9 版本进行的体验记录。
11111n’and/**/extractvalue(1,concat(char(126),md5(1351854573)))and’
1111111111111111111111111test11