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

本文涉及的产品
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
简介: 云原生之使用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)]> 
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
3月前
|
应用服务中间件 网络安全 nginx
手把手教你使用 Docker 部署 Nginx 教程
本文详解Nginx核心功能与Docker部署优势,涵盖镜像拉取、容器化部署(快速、挂载、Compose)、HTTPS配置及常见问题处理,助力高效搭建稳定Web服务。
1358 4
|
4月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
881 152
|
3月前
|
应用服务中间件 Linux nginx
在虚拟机Docker环境下部署Nginx的步骤。
以上就是在Docker环境下部署Nginx的步骤。需要注意,Docker和Nginix都有很多高级用法和细节需要掌握,以上只是一个基础入门级别的教程。如果你想要更深入地学习和使用它们,请参考官方文档或者其他专业书籍。
180 5
|
3月前
|
存储 NoSQL Redis
手把手教你用 Docker 部署 Redis
Redis是高性能内存数据库,支持多种数据结构,适用于缓存、消息队列等场景。本文介绍如何通过Docker快速拉取轩辕镜像并部署Redis,涵盖快速启动、持久化存储及docker-compose配置,助力开发者高效搭建稳定服务。
998 7
|
3月前
|
存储 搜索推荐 数据库
🚀 RAGFlow Docker 部署全流程教程
RAGFlow是开源的下一代RAG系统,融合向量数据库与大模型,支持全文检索、插件化引擎切换,适用于企业知识库、智能客服等场景。支持Docker一键部署,提供轻量与完整版本,助力高效搭建私有化AI问答平台。
2416 8
|
3月前
|
存储 关系型数据库 MySQL
MySQL Docker 容器化部署全指南
MySQL是一款开源关系型数据库,广泛用于Web及企业应用。Docker容器化部署可解决环境不一致、依赖冲突问题,实现高效、隔离、轻量的MySQL服务运行,支持数据持久化与快速迁移,适用于开发、测试及生产环境。
631 6
|
存储 Cloud Native 数据处理
从嵌入式状态管理到云原生架构:Apache Flink 的演进与下一代增量计算范式
本文整理自阿里云资深技术专家、Apache Flink PMC 成员梅源在 Flink Forward Asia 新加坡 2025上的分享,深入解析 Flink 状态管理系统的发展历程,从核心设计到 Flink 2.0 存算分离架构,并展望未来基于流批一体的通用增量计算方向。
388 0
从嵌入式状态管理到云原生架构:Apache Flink 的演进与下一代增量计算范式
|
5月前
|
运维 监控 Cloud Native
从本土到全球,云原生架构护航灵犀互娱游戏出海
本文内容整理自「 2025 中企出海大会·游戏与互娱出海分论坛」,灵犀互娱基础架构负责人朱晓靖的演讲内容,从技术层面分享云原生架构护航灵犀互娱游戏出海经验。
528 17
|
5月前
|
运维 监控 Cloud Native
从本土到全球,云原生架构护航灵犀互娱游戏出海
内容整理自「 2025 中企出海大会·游戏与互娱出海分论坛」,灵犀互娱基础架构负责人朱晓靖的演讲内容,从技术层面分享云原生架构护航灵犀互娱游戏出海经验。