参考: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、卸载掉旧版本的 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:
curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh
安装完成:
[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.
-- 下载
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
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
[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
[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 ~]$ 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)
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]>
[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)
OB的docker版本比较简单。可以体验MySQL租户,缺点是不能体验Oracle租户。