OceanBase Docker安装体验
Tags: DockerOBCPOceanBase数据库Docker镜像
说明
相关连接:
https://open.oceanbase.com/blog/10900159
https://open.oceanbase.com/answer/detail?id=13700695
练习目的
本次练习目的是通过 OceanBase Docker 容器,快速的体验 OceanBase 的 自动化部署过程,以及了解 OceanBase 集群安装成功后的目录特点和使用方法。
练习条件
- 有笔记本或服务器,内存至少12G 。
- 操作系统不限,能安装 Docker 环境即可。
练习内容
请记录并分享下列内容:
- (必选)下载Docker 镜像:https://hub.docker.com/repository/docker/obpilot/oceanbase-ce 。
- (必选)使用 OBD 命令完成后续的 OceanBase 集群部署。
- (必选)创建一个业务租户、一个业务数据库,以及一些表等。
安装Docker
参考:https://www.xmmup.com/dbbao2centos7anzhuangdocker.html
Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。CentOS 7 的内核一般都是3.10的,而CentOS 6.X 的内核一般都是2.6,在2.6的内核下,Docker运行会比较卡,所以一般会选择升级到3.10版本。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 1、卸载掉旧版本的 Docker: yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine 2、执行以下安装命令去安装依赖包: 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 yum -y install docker-ce docker-ce-cli containerd.io # 若执行报错,则配置yum源 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo systemctl start docker systemctl status docker 3、检查版本 docker version docker info |
也可以一键安装Docker:
1 2 | curl -fsSL get.docker.com -o get-docker.sh sh get-docker.sh |
安装完成:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | [root@lhrdocker ~]# docker ps Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? [root@lhrdocker ~]# systemctl start docker systemctl status docker[root@lhrdocker ~]# systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since Wed 2020-06-24 13:12:56 CST; 1s ago Docs: https://docs.docker.com Main PID: 9348 (dockerd) Memory: 38.4M CGroup: /system.slice/docker.service └─9348 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.403432651+08:00" level=info msg="ccResolverWrappe...e=grpc Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.403438749+08:00" level=info msg="ClientConn switc...e=grpc Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.422565741+08:00" level=info msg="Loading containe...tart." Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.498364397+08:00" level=info msg="Default bridge (...dress" Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.586263842+08:00" level=info msg="Loading containe...done." Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.614176483+08:00" level=warning msg="Not using nat...erlay2 Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.614312232+08:00" level=info msg="Docker daemon" c....03.12 Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.614366802+08:00" level=info msg="Daemon has compl...ation" Jun 24 13:12:56 lhrdocker dockerd[9348]: time="2020-06-24T13:12:56.700953028+08:00" level=info msg="API listen on /v....sock" Jun 24 13:12:56 lhrdocker systemd[1]: Started Docker Application Container Engine. Hint: Some lines were ellipsized, use -l to show in full. |
Oceanbase docker版本体验
下载ob docker镜像
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 | -- 下载 docker pull obpilot/oceanbase-ce:latest docker run -itd -m 10G -p 2881:2881 -p 2883:2883 --name oceanbase-ce obpilot/oceanbase-ce:latest 配置文件:/home/admin/.obd/cluster/obdemo/config.yaml docker exec -it oceanbase-ce bash -- 进入容器后,可以看看 readme.md 文档,然后启动集群: -- 查看集群列表 obd cluster list -- 启动集群 obd cluster start obdemo ps -ef|grep ob netstat -tulnp | grep 88 admin 用户的密码是 : adminPWD123 . 您可以使用 sudo yum 安装软件包。 -- create an oceanbase mysql tenant obclient -h127.1 -uroot@sys#obce-single -P2883 -prootPWD123 -c -A oceanbase alter resource unit sys_unit_config min_cpu=5; CREATE resource unit S4C1G max_cpu=4, min_cpu=4, max_memory='1G', min_memory='1G', max_iops=10000, min_iops=1000, max_session_num=1000000, max_disk_size='1024G'; CREATE resource pool my_pool unit = 'S4C1G', unit_num = 1; 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'; exit; -- log in to the obmysql tenant obclient -h 127.1 -uroot@obmysql#obdemo -P2883 -p -c -A test empty password. show databases; |
地址:https://hub.docker.com/r/obpilot/oceanbase-ce
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 | [root@docker35 ~]# docker pull obpilot/oceanbase-ce Using default tag: latest latest: Pulling from obpilot/oceanbase-ce 7a0437f04f83: Already exists 615dc48ac9f1: Pull complete b10c1cdae3af: Pull complete 4f4fb700ef54: Pull complete c0f6c94a6a6a: Pull complete 792630f35e24: Pull complete Digest: sha256:7ac28415cf27ba19cb47acb67a55ebf9848ad73a63d80b7e2e85d653233dbaeb Status: Downloaded newer image for obpilot/oceanbase-ce:latest docker.io/obpilot/oceanbase-ce:latest [root@docker35 ~]# docker images | grep oceanbase obpilot/oceanbase-ce latest 943379e0b05b 4 weeks ago 2.25GB obpilot/oceanbase-ce <none> c3ac45532094 4 months ago 2.24GB oceanbase/obce-mini latest 1a5ca6d233a7 4 months ago 690MB [root@docker35 ~]# docker run -itd -m 10G -p 2881:2881 -p 2883:2883 --name oceanbase-ce obpilot/oceanbase-ce:latest docker: Error response from daemon: Conflict. The container name "/oceanbase-ce" is already in use by container "2a86c75456b5509b21e5e6981ba5fd53826c2f630d7b06d3145140436f024db3". You have to remove (or rename) that container to be able to reuse that name. See 'docker run --help'. [root@docker35 ~]# docker rm -f oceanbase-ce oceanbase-ce [root@docker35 ~]# docker run -itd -m 10G -p 2881:2881 -p 2883:2883 --name oceanbase-ce obpilot/oceanbase-ce:latest 0209306f10bf1c49fb58ffee65ac2b17f3ce3c0b4c2884eca57f3af5464babf4 [root@docker35 ~]# [root@docker35 ~]# docker exec -it oceanbase-ce bash |
使用obd工具查看集群及启动
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 54 55 56 57 58 59 60 61 62 63 | [root@docker35 ~]# docker exec -it oceanbase-ce bash [admin@0209306f10bf ~]$ obd cluster list +------------------------------------------------------------+ | Cluster List | +--------+---------------------------------+-----------------+ | Name | Configuration Path | Status (Cached) | +--------+---------------------------------+-----------------+ | obdemo | /home/admin/.obd/cluster/obdemo | deployed | +--------+---------------------------------+-----------------+ [admin@0209306f10bf ~]$ obd cluster start obdemo Get local repositories and plugins ok Open ssh connection ok Cluster param config check ok Check before start observer ok Check before start obproxy ok 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.1 | 2881 | zone1 | active | +-----------+---------+------+-------+--------+ Start obproxy ok obproxy program health check ok Connect to obproxy ok Initialize cluster +---------------------------------------------+ | obproxy | +-----------+------+-----------------+--------+ | ip | port | prometheus_port | status | +-----------+------+-----------------+--------+ | 127.0.0.1 | 2883 | 2884 | active | +-----------+------+-----------------+--------+ obdemo running [admin@0209306f10bf ~]$ obd cluster list +------------------------------------------------------------+ | Cluster List | +--------+---------------------------------+-----------------+ | Name | Configuration Path | Status (Cached) | +--------+---------------------------------+-----------------+ | obdemo | /home/admin/.obd/cluster/obdemo | running | +--------+---------------------------------+-----------------+ [admin@0209306f10bf ~]$ ps -ef|grep ob admin 859 0 99 07:10 ? 00:05:12 /home/admin/oceanbase-ce/bin/observer -r 127.0.0.1:2882:2881 -o __min_full_resource_pool_memory=268435456,memory_limit=8G,system_memory=4G,stack_size=512K,cpu_count=16,cache_wash_threshold=1G,workers_per_cpu_quota=10,schema_history_expire_time=1d,net_thread_count=4,major_freeze_duty_time=Disable,minor_freeze_times=10,enable_separate_sys_clog=0,enable_merge_by_turn=False,datafile_size=5G,enable_syslog_wf=False,enable_syslog_recycle=True,max_syslog_file_count=4,root_password=rootPWD123 -z zone1 -p 2881 -P 2882 -n obce-single -c 1 -d /home/admin/oceanbase-ce/store -i lo -l ERROR admin 1475 0 14 07:11 ? 00:00:01 /home/admin/obproxy/bin/obproxy -o enable_strict_kernel_release=False,enable_cluster_checkout=False,automatic_match_work_thread=False,work_thread_num=12,xflush_log_level=ERROR,monitor_log_level=ERROR,syslog_level=ERROR,log_dir_size_threshold=1G,enable_compression_protocol=False --listen_port 2883 --prometheus_listen_port 2884 --rs_list 127.0.0.1:2881 --cluster_name obce-single admin 1525 0 0 07:11 pts/1 00:00:00 bash /home/admin/obproxy/obproxyd.sh /home/admin/obproxy 127.0.0.1 2883 daemon admin 1552 23 0 07:11 pts/1 00:00:00 grep --color=auto ob [admin@0209306f10bf ~]$ [admin@0209306f10bf ~]$ netstat -tulnp | grep 88 tcp 0 0 0.0.0.0:2881 0.0.0.0:* LISTEN 859/observer tcp 0 0 0.0.0.0:2882 0.0.0.0:* LISTEN 859/observer tcp 0 0 0.0.0.0:2883 0.0.0.0:* LISTEN 1475/obproxy tcp 0 0 0.0.0.0:2884 0.0.0.0:* LISTEN 1475/obproxy |
登录ob数据库并创建租户
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | [admin@0209306f10bf ~]$ obclient -h127.1 -uroot@sys#obce-single -P2883 -prootPWD123 -c -A oceanbase Welcome to the OceanBase. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.6.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:52:05) Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [oceanbase]> show databases; +--------------------+ | Database | +--------------------+ | oceanbase | | information_schema | | mysql | | SYS | | LBACSYS | | ORAAUDITOR | | test | +--------------------+ 7 rows in set (0.005 sec) |
创建资源单元、资源池、租户
1 2 3 4 5 6 7 8 9 10 | MySQL [oceanbase]> CREATE resource unit S4C1G max_cpu=4, min_cpu=4, max_memory='1G', min_memory='1G', max_iops=10000, min_iops=1000, max_session_num=1000000, max_disk_size='1024G'; Query OK, 0 rows affected (0.006 sec) MySQL [oceanbase]> CREATE resource pool my_pool unit = 'S4C1G', unit_num = 1; Query OK, 0 rows affected (0.011 sec) MySQL [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 (0.612 sec) MySQL [oceanbase]> |
登录obmysql tenant并创建数据库及表等
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | [admin@0209306f10bf ~]$ obclient -h 127.1 -uroot@obmysql#obce-single -P2883 -p -c -A test Enter password: Welcome to the OceanBase. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.6.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:52:05) Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [test]> show databases; +--------------------+ | Database | +--------------------+ | oceanbase | | information_schema | | mysql | | test | +--------------------+ 4 rows in set (0.017 sec) MySQL [test]> create database lhrdb charset utf8mb4; Query OK, 1 row affected (0.168 sec) MySQL [test]> use lhrdb; Database changed MySQL [lhrdb]> source /tmp/mysql_employees.sql Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected, 1 warning (0.004 sec) Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected (0.001 sec) ..... MySQL [lhrdb]> show tables; +-----------------+ | Tables_in_lhrdb | +-----------------+ | departments | | job_grades | | jobs | | late | | locations | +-----------------+ 5 rows in set (0.018 sec) MySQL [lhrdb]> select * from jobs; +------------+---------------------------------+------------+------------+ | job_id | job_title | min_salary | max_salary | +------------+---------------------------------+------------+------------+ | AC_ACCOUNT | Public Accountant | 4200 | 9000 | | AC_MGR | Accounting Manager | 8200 | 16000 | | AD_ASST | Administration Assistant | 3000 | 6000 | | AD_PRES | President | 20000 | 40000 | | AD_VP | Administration Vice President | 15000 | 30000 | | FI_ACCOUNT | Accountant | 4200 | 9000 | | FI_MGR | Finance Manager | 8200 | 16000 | | HR_REP | Human Resources Representative | 4000 | 9000 | | IT_PROG | Programmer | 4000 | 10000 | | MK_MAN | Marketing Manager | 9000 | 15000 | | MK_REP | Marketing Representative | 4000 | 9000 | | PR_REP | Public Relations Representative | 4500 | 10500 | | PU_CLERK | Purchasing Clerk | 2500 | 5500 | | PU_MAN | Purchasing Manager | 8000 | 15000 | | SA_MAN | Sales Manager | 10000 | 20000 | | SA_REP | Sales Representative | 6000 | 12000 | | SH_CLERK | Shipping Clerk | 2500 | 5500 | | ST_CLERK | Stock Clerk | 2000 | 5000 | | ST_MAN | Stock Manager | 5500 | 8500 | +------------+---------------------------------+------------+------------+ 19 rows in set (0.003 sec) |
远程登录:
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 | C:\Users\lhrxxt>mysql -uroot@obmysql -P2881 -c -A -h192.168.66.35 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3221487662 Server version: 5.7.25 OceanBase 3.1.1 (r4-8c615943cbd25a6f7b8bdfd8677a13a21709a05e) (Built Oct 21 2021 10:52:05) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [(none)]> show databases; +--------------------+ | Database | +--------------------+ | oceanbase | | information_schema | | mysql | | test | | lhrdb | +--------------------+ 5 rows in set (0.06 sec) MySQL [(none)]> select * from mysql.user; +------+------------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------------------+-----------------------+------------------+ | host | user | password | select_priv | insert_priv | update_priv | delete_priv | create_priv | drop_priv | reload_priv | shutdown_priv | process_priv | file_priv | grant_priv | reference_priv | index_priv | alter_priv | show_db_priv | super_priv | create_tmp_table_priv | lock_tables_priv | execute_priv | repl_slave_priv | repl_client_priv | create_view_priv | show_view_priv | create_routine_priv | alter_routine_priv | create_user_priv | event_priv | trigger_priv | create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin | authentication_string | password_expired | +------+------------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------------------+-----------------------+------------------+ | % | root | | Y | Y | Y | Y | Y | Y | N | N | Y | Y | Y | N | Y | Y | Y | Y | N | N | N | N | N | Y | Y | N | N | Y | N | N | N | | | | | 0 | 0 | 0 | 0 | ob_native_password | | | | % | ORAAUDITOR | *9753e2cf9d2dcd5e13c052f581c310ac70c62723 | Y | Y | Y | Y | Y | Y | N | N | Y | Y | Y | N | Y | Y | Y | Y | N | N | N | N | N | Y | Y | N | N | Y | N | N | N | | | | | 0 | 0 | 0 | 0 | ob_native_password | | | +------+------------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------------------+-----------------------+------------------+ 2 rows in set (0.09 sec) |
总结
OB的docker版本比较简单。可以体验MySQL租户,缺点是不能体验Oracle租户。