云原生之使用Docker部署Mariadb数据库

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介: 云原生之使用Docker部署Mariadb数据库

一、检查本地系统版本

[root@node axu]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

二、检查docker版本

[root@node ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-11-04 09:12:32 CST; 2h 32min ago
     Docs: https://docs.docker.com
 Main PID: 10162 (dockerd)
    Tasks: 25
   Memory: 686.5M
   CGroup: /system.slice/docker.service
           ├─10162 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
           ├─21803 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 27217 -container-ip 172.17.0.2 -container-port 27017
           └─21808 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 27217 -container-ip 172.17.0.2 -container-port 27017

Nov 04 09:12:32 node dockerd[10162]: time="2022-11-04T09:12:32.748322724+08:00" level=info msg="Daemon has completed initialization"
Nov 04 09:12:32 node systemd[1]: Started Docker Application Container Engine.
Nov 04 09:12:32 node dockerd[10162]: time="2022-11-04T09:12:32.783184105+08:00" level=info msg="API listen on /var/run/docker.sock"
Nov 04 09:14:43 node dockerd[10162]: time="2022-11-04T09:14:43.271577933+08:00" level=warning msg="Failed to allocate and map port 27017... in use"
Nov 04 09:14:43 node dockerd[10162]: time="2022-11-04T09:14:43.307093238+08:00" level=error msg="23b76c34a23fc0a5927af983429afc38073dd8e...ntainer"
Nov 04 09:14:43 node dockerd[10162]: time="2022-11-04T09:14:43.307154453+08:00" level=error msg="Handler for POST /v1.41/containers/23b76c34a23f...
Nov 04 09:16:17 node dockerd[10162]: time="2022-11-04T09:16:17.615100281+08:00" level=info msg="ignoring event" container=c6c46f42573372...kDelete"
Nov 04 09:31:27 node dockerd[10162]: time="2022-11-04T09:31:27.346146621+08:00" level=info msg="Attempting next endpoint for pull after ...unknown"
Nov 04 09:41:33 node dockerd[10162]: time="2022-11-04T09:41:33.324562841+08:00" level=error msg="Not continuing with pull after error: c...anceled"
Nov 04 10:00:54 node dockerd[10162]: time="2022-11-04T10:00:54.645415843+08:00" level=info msg="Attempting next endpoint for pull after ...unknown"
Hint: Some lines were ellipsized, use -l to show in full.

三、检查docker状态

[root@node ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-11-04 09:12:32 CST; 2h 32min ago
     Docs: https://docs.docker.com
 Main PID: 10162 (dockerd)
    Tasks: 25
   Memory: 686.5M
   CGroup: /system.slice/docker.service
           ├─10162 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
           ├─21803 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 27217 -container-ip 172.17.0.2 -container-port 27017
           └─21808 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 27217 -container-ip 172.17.0.2 -container-port 27017

Nov 04 09:12:32 node dockerd[10162]: time="2022-11-04T09:12:32.748322724+08:00" level=info msg="Daemon has completed initialization"
Nov 04 09:12:32 node systemd[1]: Started Docker Application Container Engine.
Nov 04 09:12:32 node dockerd[10162]: time="2022-11-04T09:12:32.783184105+08:00" level=info msg="API listen on /var/run/docker.sock"
Nov 04 09:14:43 node dockerd[10162]: time="2022-11-04T09:14:43.271577933+08:00" level=warning msg="Failed to allocate and map port 27017... in use"
Nov 04 09:14:43 node dockerd[10162]: time="2022-11-04T09:14:43.307093238+08:00" level=error msg="23b76c34a23fc0a5927af983429afc38073dd8e...ntainer"
Nov 04 09:14:43 node dockerd[10162]: time="2022-11-04T09:14:43.307154453+08:00" level=error msg="Handler for POST /v1.41/containers/23b76c34a23f...
Nov 04 09:16:17 node dockerd[10162]: time="2022-11-04T09:16:17.615100281+08:00" level=info msg="ignoring event" container=c6c46f42573372...kDelete"
Nov 04 09:31:27 node dockerd[10162]: time="2022-11-04T09:31:27.346146621+08:00" level=info msg="Attempting next endpoint for pull after ...unknown"
Nov 04 09:41:33 node dockerd[10162]: time="2022-11-04T09:41:33.324562841+08:00" level=error msg="Not continuing with pull after error: c...anceled"
Nov 04 10:00:54 node dockerd[10162]: time="2022-11-04T10:00:54.645415843+08:00" level=info msg="Attempting next endpoint for pull after ...unknown"
Hint: Some lines were ellipsized, use -l to show in full.

四、下载mariadb镜像

[root@node ~]# docker pull mariadb
Using default tag: latest
latest: Pulling from library/mariadb
Digest: sha256:0f04ae6f30c5a3295fb7cc9be5780c15ff21d6028f999b19f5803114c1e8559e
Status: Downloaded newer image for mariadb:latest
docker.io/library/mariadb:latest

五、创建mariadb容器

1.创建数据目录

[root@node ~]# mkdir /data/mariadb
[root@node ~]# cd /data/mariadb/
[root@node mariadb]# 

2.创建mariadb容器

[root@node mariadb]# docker run -d   --name my-mariadb --restart always -v /data/mariadb/db:/var/lib/mysql -p 3548:3306 --env MARIADB_USER=admin --env MARIADB_PASSWORD=admin --env MARIADB_ROOT_PASSWORD=admin mariadb:latest
e9b8757eaaf6eb632101a30f9b27c113eaae63e8410a67ed92e76e434c8a81ea

3.查看容器状态

[root@node mariadb]# docker ps
CONTAINER ID   IMAGE            COMMAND                  CREATED          STATUS          PORTS                                           NAMES
e9b8757eaaf6   mariadb:latest   "docker-entrypoint.s…"   36 seconds ago   Up 35 seconds   0.0.0.0:3548->3306/tcp, :::3548->3306/tcp       my-mariadb

六、查看mariadb容器运行日志

[root@node mariadb]# docker logs my-mariadb 
2022-11-04 03:56:12+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.6.5+maria~focal started.
2022-11-04 03:56:12+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-11-04 03:56:12+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.6.5+maria~focal started.
2022-11-04  3:56:12 0 [Note] mariadbd (server 10.6.5-MariaDB-1:10.6.5+maria~focal) starting as process 1 ...
2022-11-04  3:56:12 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-11-04  3:56:12 0 [Note] InnoDB: Number of pools: 1
2022-11-04  3:56:12 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
2022-11-04  3:56:12 0 [Note] mariadbd: O_TMPFILE is not supported on /tmp (disabling future attempts)
2022-11-04  3:56:12 0 [Note] InnoDB: Using Linux native AIO
2022-11-04  3:56:12 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
2022-11-04  3:56:12 0 [Note] InnoDB: Completed initialization of buffer pool
2022-11-04  3:56:12 0 [Note] InnoDB: 128 rollback segments are active.
2022-11-04  3:56:12 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2022-11-04  3:56:12 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2022-11-04  3:56:12 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2022-11-04  3:56:12 0 [Note] InnoDB: 10.6.5 started; log sequence number 42335; transaction id 14
2022-11-04  3:56:12 0 [Note] Plugin 'FEEDBACK' is disabled.
2022-11-04  3:56:12 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2022-11-04  3:56:12 0 [Warning] You need to use --log-bin to make --expire-logs-days or --binlog-expire-logs-seconds work.
2022-11-04  3:56:12 0 [Note] Server socket created on IP: '0.0.0.0'.
2022-11-04  3:56:12 0 [Note] Server socket created on IP: '::'.
2022-11-04  3:56:12 0 [Note] InnoDB: Buffer pool(s) load completed at 221104  3:56:12
2022-11-04  3:56:12 0 [Warning] 'proxies_priv' entry '@% root@ac860c2aa163' ignored in --skip-name-resolve mode.
2022-11-04  3:56:12 0 [Note] mariadbd: ready for connections.
Version: '10.6.5-MariaDB-1:10.6.5+maria~focal'  socket: '/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution

七、测试访问mariadb

[root@node mariadb]# mysql -h 192.168.3.166 -P3548 -uroot -padmin
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.6.5-MariaDB-1:10.6.5+maria~focal mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> 
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
7天前
|
人工智能 API 数据安全/隐私保护
使用 Docker 一键免费部署 63.8k 的私人 ChatGPT 网页应用
NextChat 是一个可以在 GitHub 上一键免费部署的私人 ChatGPT 网页应用,支持 GPT3、GPT4 和 Gemini Pro 模型。该项目在 GitHub 上获得了 63.8k 的 star 数。部署简单,只需拉取 Docker 镜像并运行容器,设置 API Key 后即可使用。此外,NextChat 还提供了预设角色的面具功能,方便用户快速创建对话。
57 22
使用 Docker 一键免费部署 63.8k 的私人 ChatGPT 网页应用
|
18天前
|
SQL 关系型数据库 数据库
国产数据实战之docker部署MyWebSQL数据库管理工具
【10月更文挑战第23天】国产数据实战之docker部署MyWebSQL数据库管理工具
58 4
国产数据实战之docker部署MyWebSQL数据库管理工具
|
8天前
|
运维 开发者 Docker
Docker Compose:简化容器化应用的部署与管理
Docker Compose:简化容器化应用的部署与管理
|
8天前
|
Docker 微服务 容器
使用Docker Compose实现微服务架构的快速部署
使用Docker Compose实现微服务架构的快速部署
19 1
|
17天前
|
监控 Cloud Native 持续交付
云原生技术深度解析:重塑现代应用开发与部署范式####
本文深入探讨了云原生技术的核心概念、关键技术组件及其在现代软件开发中的重要性。通过剖析容器化、微服务架构、持续集成/持续部署(CI/CD)等关键技术,本文旨在揭示云原生技术如何促进应用的敏捷性、可扩展性和高可用性,进而推动企业数字化转型进程。不同于传统摘要仅概述内容要点,本部分将融入具体案例分析,直观展示云原生技术在实际应用中的显著成效与挑战应对策略,为读者提供更加丰富、立体的理解视角。 ####
|
20天前
|
消息中间件 Linux RocketMQ
在Red Hat Enterprise Linux 9上使用Docker快速安装并部署
通过以上步骤,你可以在Red Hat Enterprise Linux 9上使用Docker快速安装并部署RocketMQ。这种方法不仅简化了安装过程,还提供了一个灵活的环境来管理和扩展消息队列系统。RocketMQ作为一款高性能的分布式消息系统,通过Docker可以实现快速部署和高效管理。
48 2
|
8天前
|
前端开发 开发者 Docker
深入探索Docker Compose:简化多容器应用的部署
深入探索Docker Compose:简化多容器应用的部署
33 0
|
11天前
|
监控 Cloud Native 微服务
云端漫步:探索云原生应用的构建与部署
【10月更文挑战第32天】在数字时代的浪潮中,云原生技术如同一艘航船,承载着企业的梦想驶向未知的海洋。本文将带你领略云原生应用的魅力,从基础概念到实战操作,我们将一步步揭开云原生的神秘面纱,体验它如何简化开发、加速部署,并提升系统的可扩展性与可靠性。让我们一起启航,探索云原生的世界!
|
7天前
|
SQL 关系型数据库 MySQL
12 PHP配置数据库MySQL
路老师分享了PHP操作MySQL数据库的方法,包括安装并连接MySQL服务器、选择数据库、执行SQL语句(如插入、更新、删除和查询),以及将结果集返回到数组。通过具体示例代码,详细介绍了每一步的操作流程,帮助读者快速入门PHP与MySQL的交互。
23 1
|
9天前
|
SQL 关系型数据库 MySQL
go语言数据库中mysql驱动安装
【11月更文挑战第2天】
24 4