挂载硬盘

查看硬盘块:lsblk

准备挂载:fdisk /dev/vdb
命令注释:
F:查看未分区空间
n:创建新分区,p:创建为主分区,然后全默认
w:写出操作并退出

再次查看硬盘块:lsblk

格式化分区:mkfs.ext4 /dev/vdb1

创建挂载目录:mkdir -p /mnt/data

挂载:mount /dev/vdb1 /mnt/data

查看挂载信息:blkid /dev/vdb1

编辑自动挂载配置:vi /etc/fstab
添加内容(UUID需替换成上一步挂载信息中的UUID):
UUID=1234-5678-abcd-efgh /mnt/data ext4 defaults 0 2

测试挂载配置:mount -a

安装 Docker

安装 containerd

是 docker 的依赖项,下文中使用的 28.3.3 版本的 docker 推荐 containerd 版本为 1.7.x,而 Kylin 仓库中 containerd 只有 1.2.x,版本过旧导致无法与新版 docker 兼容。

首先卸载系统中的 containerd:yum remove -y containerd

去 Github 下载高版本二进制文件:https://github.com/containerd/containerd/releases

这里选用1.7.28版本,并根据 CPU 类型选择containerd-1.7.28-linux-amd64.tar.gz

下载后进行解压:tar -zxvf containerd-1.7.28-linux-amd64.tar.gz

得到bin目录,目录中有如下文件:

bin/
bin/containerd-stress
bin/ctr
bin/containerd
bin/containerd-shim
bin/containerd-shim-runc-v1
bin/containerd-shim-runc-v2

移动 bin 目录中的文件到执行目录:mv bin/* /usr/local/bin

创建 service 配置文件:vim /etc/systemd/system/containerd.service,官方模板:https://raw.githubusercontent.com/containerd/containerd/main/containerd.service

内容为:

# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target dbus.service

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd

Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target

创建后加载,并启动:

systemctl daemon-reload
systemctl start containerd
systemctl status containerd
systemctl enable containerd

检查版本:containerd --version
输出:

containerd github.com/containerd/containerd v1.7.28 b98a3aace656320842a23f4a392a33f46af97866

安装 Docker CE

下载 Docker CE 二进制包:http://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/

或者从官方地址下载:https://download.docker.com/linux/static/stable/ 也可以

这里选择28.3.3版本,解压:tar -zxvf docker-28.3.3.tgz

所有文件移动到可执行目录:mv docker/* /usr/bin/

创建 systemd 配置文件:vim /usr/lib/systemd/system/docker.service
文件内容:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target

添加可执行权限:chmod +x /usr/lib/systemd/system/docker.service

创建 docker 数据目录:mkdir -p /mnt/data/docker-data

创建 docker 配置文件:mkdir -p /etc/docker && vim /etc/docker/daemon.json
内容如下:

{
    "data-root":"/mnt/data/docker-data",
    "userland-proxy": false,
    "exec-opts": ["native.cgroupdriver=systemd"]
}


配置说明

  • data-root:数据目录
  • userland-proxy:网络管理方式,默认为true,一般用来兼容旧环境,现代 linux 一般不需要,设置为true时需要配置userland-proxy-path
  • exec-opts:额外启动参数
    • native.cgroupdriver=systemd:设置 Docker 用哪种 cgroup 驱动。
  • registry-mirrors:配置镜像地址,值为字符串数组,如:["https://registry.docker-cn.com"](该地址已停用)

native.cgroupdriver=systemd的详细说明:

"exec-opts": ["native.cgroupdriver=systemd"]

  • 作用:设置 Docker 用哪种 cgroup 驱动
  • Linux 下,cgroup(控制组)用来限制和管理容器的资源(CPU、内存等)。

Docker 有两种主要的 cgroup 驱动:

  1. cgroupfs(默认)

    • 直接使用内核的 cgroup 接口挂载点。
    • 但如果宿主机用 systemd 管理 cgroups,就会出现两个体系并存,容易冲突。
  2. systemd

    • Docker 让 systemd 来管理 cgroups。
    • 这和 Kubernetes(默认也用 systemd)一致,更加推荐。

👉 所以在 Kubernetes 环境 或使用 systemd 管理的 Linux 系统上,通常建议加:

"exec-opts": ["native.cgroupdriver=systemd"]

这样避免资源管理冲突,尤其是 kubelet 和 docker 的 cgroup driver 要一致,否则会报错。

userland-proxy其他说明:

如果端口映射后出现网络问题可以尝试添加如下设置:

  "userland-proxy": true,
  "userland-proxy-path": "/usr/bin/docker-proxy"

添加 docker 用户组:groupadd docker

重新加载服务,然后启动、设置开机自启:

systemctl daemon-reload
systemctl start docker
systemctl status docker
systemctl enable docker

测试 docker run

下载镜像:hello-world:linux

上传之后加载:docker load -i hello-world_linux.tar

然后执行 run 命令:docker run --rm hello-world:linux

成功运行并打印类似如下字样即为成功:

Hello from Docker!
This message shows that your installation appears to be working correctly.

安装人大金仓数据库

下载镜像:https://kingbase.com.cn/download.html ,根据处理器进行选择,这里选海光_Linux
得到文件:KingbaseES_V009R001C010B0004_x86_64_Docker.tar

使用md5sum 文件名计算文件 md5 值,并和官网进行对比,以验证文件完整性。

加载镜像:docker load -i KingbaseES_V009R001C010B0004_x86_64_Docker.tar

通过docker images可以查看到刚加载的镜像:

REPOSITORY                              TAG       IMAGE ID       CREATED        SIZE
kingbase_v009r001c010b0004_single_x86   v1        10ba6f33e228   2 months ago   754MB

创建数据库数据目录:mkdir -p /mnt/data/kingbase-data

启动容器:

docker run -tid --privileged \
-p 54321:54321 \
-v /mnt/data/kingbase-data:/home/kingbase/userdata/ \
-e NEED_START=yes  \
-e DB_USER=kingbase  \
-e DB_PASSWORD=your-password \
-e DB_MODE=mysql  \
-e ENCODING=utf8  \
--name kingbase  \
kingbase_v009r001c010b0004_single_x86:v1 /usr/sbin/init

To be continued.

标签: 信创

添加新评论