原 人大金仓KingBase KES官方Docker版使用
Tags: 原创Docker人大金仓KingbaseES
下载
下载: https://www.kingbase.com.cn/xzzx/index.htm
文档:https://bbs.kingbase.com.cn/kingbase-html/v9/install-updata/install-docker/index.html
安装使用
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 85 86 87 88 89 90 91 | -- V8R6 wget https://kingbase.oss-cn-beijing.aliyuncs.com/KESV8R3/05.Docker%E7%89%88%E6%9C%AC/kdb_x86_64_V008R006C008B0020.tar -- V9R1 wget https://kingbase.oss-cn-beijing.aliyuncs.com/KESV8R3/05.Docker%E7%89%88%E6%9C%AC/kdb_x86_64_V009R001C001B0030.tar docker load -i kdb_x86_64_V008R006C008B0020.tar docker load -i kdb_x86_64_V009R001C001B0030.tar docker run -idt --privileged --name kingbase -p ${hostport}:${containerport} \ –v ${hostpath}:${containerpath} \ -e NEED_START=${need_start} \ -e DB_USER=${username} \ -e DB_PASSWORD=${passwd} \ -e DB_MODE=${dbmode} \ -e ENCODING=${encoding} \ kingbase_v008r006c008b0020_single_x86:v1 \ /usr/sbin/init 数据库默认用户名:system 数据库默认密码:123456 数据库默认data目录:/home/kingbase/userdata/data 金仓数据库镜像:kingbase:v1 设置数据库data目录的持久化路径时, 需要如下设置: -v 选项冒号左侧宿主机挂载目录(e.g /mnt/data)权限需要设置755的权限(chmod -R 755 /mnt/data),不然会报权限(Permission denied)错误。 -v 选项冒号右侧为容器内的挂载路径需要设置为/home/kingbase/userdata,不然data目录无法持久化。 -0- 容器启动后,数据库即开始运行,用户无须手动启动数据库(数据库配置正确/或者处于初始态) -- 示例 docker run -tid --privileged \ -p 4321:54321 \ -v /mnt/data:/home/kingbase/userdata/ \ -e NEED_START=yes \ -e DB_USER=kingbase \ -e DB_PASSWORD=123456 \ -e DB_MODE=oracle \ --name kingbase \ kingbase:v1 /usr/sbin/init eb970ee84a8db48351a467782051a719d506da35d43f2b42385e42c1ac5bf8bb [root /home/kingbase]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES eb970ee84a8d kingbase:v1 "/bin/bash /home/kin…" 3 seconds ago Up 2 seconds 0.0.0.0:4321->54321/tcp kingbase -- 命令示例 V8 docker rm -f kingbasev8r6 docker run -idt --privileged --name kingbasev8r6 -h kingbasev8r6 \ -p 4321:54321 \ -e NEED_START=yes \ -e DB_USER=system \ -e DB_PASSWORD=lhr \ -e DB_MODE=oracle \ kingbase_v008r006c008b0020_single_x86:v1 \ /usr/sbin/init docker logs -f kingbasev8r6 docker start kingbasev8r6 docker exec -it kingbasev8r6 ksql -Usystem -d test -p54321 docker exec -it kingbasev8r6 bash ksql -Usystem -d test -p54321 -- 命令示例 V9 docker rm -f kingbasev9r1 docker run -idt --privileged --name kingbasev9r1 -h kingbasev9r1 \ -p 4322:54321 \ -e NEED_START=yes \ -e DB_USER=system \ -e DB_PASSWORD=lhr \ -e DB_MODE=oracle \ kingbase_v009r001c001b0030_single_x86:v1 \ /usr/sbin/init docker logs -f kingbasev9r1 docker start kingbasev9r1 docker exec -it kingbasev9r1 ksql -Usystem -d test -p54321 docker exec -it kingbasev9r1 bash ksql -Usystem -d test -p54321 -- 授权 cat /home/kingbase/install/kingbase/etc/license.dat -- 关闭启动 /home/kingbase/install/kingbase/bin/sys_ctl -D /home/kingbase/userdata/data/ stop /home/kingbase/install/kingbase/bin/sys_ctl -D /home/kingbase/userdata/data/ start -- 兼容模式 cat /home/kingbase/userdata/data/initdb.conf |grep mode |
选项介绍
1. 使用-p 选项绑定端口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [root@hunter-h12-252 /home/kingbase]# docker run -tid --privileged \ -p 4321:54321 \ -v /mnt/data:/home/kingbase/userdata/ \ --name kingbase \ kingbase:v1 \ /usr/sbin/init eb970ee84a8db48351a467782051a719d506da35d43f2b42385e42c1ac5bf8bb [root@hunter-h12-252 /home/kingbase]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES eb970ee84a8d kingbase:v1 "/bin/bash /home/kin…" 3 seconds ago Up 2 seconds 0.0.0.0:4321->54321/tcp kingbase 将容器内部端口绑定到宿主机端口4321上,在宿主机内连接该数据库 宿主机可成功访问对应数据库 |
1 2 3 4 5 6 7 8 | [root@hunter-h12-xxx /home/kingbase/single-docker]# ./kingbase/bin/ksql -Usystem -d test -h 10.10.12.252 -p 4321 Password for user system: ksql (V8.0) Type "help" for help. WARNING:License file will expire in 30 days. test=# |
2. 使用-v 选项挂载目录
使用-v 可以将容器内数据目录(/home/kingbase/userdata/)挂载到宿主机 设置数据库data目录的持久化路径时, 需要如下设置: -v 选项冒号左侧宿主机挂载目录(e.g /mnt/data)权限需要设置755的权限(chmod -R 755 /mnt/data),不然会报权限(Permission denied)错误。 -v 选项冒号右侧为容器内的挂载路径需要设置为/home/kingbase/userdata,不然data目录无法持久化。
1 2 3 4 5 6 7 | [root@hunter-h12-252 /home/kingbase]# docker run -tid --privileged \ -p 4321:54321 \ -v /mnt/data:/home/kingbase/userdata/ \ --name kingbase \ kingbase:v1 \ /usr/sbin/init eb970ee84a8db48351a467782051a719d506da35d43f2b42385e42c1ac5bf8bb |
查看挂载是否生效
1 2 | [root@hunter-h12-252 /home/kingbase/single-docker]# docker inspect -f ‘{{.Mounts}}’ kingbase ‘[{bind /mnt/data /home/kingbase/userdata/ true rprivate}]’ |
持久化数据挂载成功
进入容器
1 2 3 | [root@hunter-h12-252 /home/kingbase]# docker exec -it kingbase /bin/bash [kingbase@b8e0dd156b75 ~]$ |
3. DB_USER: 数据库用户
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | docker run -tid --privileged -p 4321:54321 \ -v /mnt/data:/home/kingbase/userdata/ \ -e DB_USER=kingbase \ --name kingbase \ kingbase:v1 \ /usr/sbin/init df874e55bd7fe25f7302f581e0012c6466d9113d2ec58d83e4c14a3a5e307dd2 [kingbase@df874e55bd7f ~]$ ksql -Ukingbase -d test ksql (V8.0) Type "help" for help. WARNING:License file will expire in 30 days. test=# |
4. DB_PASSWORD: 数据库初始密码
1 2 3 4 5 6 7 8 | [root@hunter-h12-252 /home/kingbase]# docker run -tid --privileged \ -p 4321:54321 \ -v /mnt/data:/home/kingbase/userdata/ \ -e DB_USER=kingbase \ -e DB_PASSWORD=123 \ --name kingbase \ kingbase:v1 /usr/sbin/init fcc86e2fcb0cb1487d49d65b0482aa115a4f579fa3dafcabe48b63e5903cfceb |
容器外访问,输入更改后的密码,访问成功
1 2 3 4 5 6 7 8 | [root@hunter-h12-252 /home/kingbase]# ./kingbase/bin/ksql -Ukingbase -dtest -p4321 -h 10.10.12.252 Password for user kingbase: ksql (V8.0) Type "help" for help. WARNING:License file will expire in 30 days. test=# |
5. DB_MODE: 数据库模式
数据库模式: 支持oracle/pg(enable_ci仅支持no)/mysql (请确认对应镜像内数据库版本支持的数据库模式之后再进行配置)
1 2 3 4 5 6 7 8 9 10 11 | [root@hunter-h12-252 /home/kingbase]# docker run -tid --privileged \ -p 4321:54321 \ -v /mnt/data:/home/kingbase/userdata/ \ -e DB_MODE=oracle \ --name kingbase kingbase:v1 \ /usr/sbin/init b5844c77f5cdc64ffab138dbd2c4f6a3b91d3215c77fffdbc9fbbbc5befbc2b4 [root@hunter-h12-252 /home/kingbase]# docker exec -it kingbase /bin/bash [kingbase@b5844c77f5cd ~]$ cat /home/kingbase/userdata/data/initdb.conf |grep mode --dbmode=oracle [kingbase@b5844c77f5cd ~]$ |
6. NEED_START: 进入容器后是否启动数据库
yes(默认 启动数据库)/ no(不启动数据库)
7. ENCODING: 数据库启动的字符集
支持utf8(默认)