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

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 云原生之使用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)]> 
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
30天前
|
关系型数据库 MySQL 数据库连接
docker拉取MySQL后数据库连接失败解决方案
通过以上方法,可以解决Docker中拉取MySQL镜像后数据库连接失败的常见问题。关键步骤包括确保容器正确启动、配置正确的环境变量、合理设置网络和权限,以及检查主机防火墙设置等。通过逐步排查,可以快速定位并解决连接问题,确保MySQL服务的正常使用。
245 82
|
8天前
|
Ubuntu 安全 Docker
Ubuntu下部署及操作Docker技巧
以上就是在Ubuntu下部署及操作Docker的具体步骤。但这只是冰山一角,Docker的魅力远不仅如此。你可以将其视为存放各种工具的小箱子,随时随地取用,极大地提升工作效率。你也可以私人订制,适应不同的开发环境,就像一个拥有各种口味冰淇淋的冰箱,满足各种各样的需求。好了,现在你已经掌握了基本的Docker运用技巧,快去尝试使用吧!记住,沉浸在探索中,你会找到无尽的乐趣和满满的收获。
57 23
|
26天前
|
SQL 数据库 Docker
【赵渝强老师】在Docker中运行达梦数据库
本文介绍了在Docker容器中部署达梦数据库(DM 8)的具体步骤,包括创建文件夹、下载安装包、导入镜像、启动容器、登录数据库及查看状态等操作。同时,通过视频讲解辅助理解。文中还分析了将数据库服务容器化的潜在问题,如数据安全性、硬件资源争用、网络带宽占用和额外隔离带来的挑战,指出数据库服务在生产环境中可能不适合容器化的原因。
【赵渝强老师】在Docker中运行达梦数据库
|
17天前
|
安全 API 算法框架/工具
大模型文件Docker镜像化部署技术详解
大模型文件Docker镜像化部署技术详解
157 2
|
29天前
|
JSON 运维 Ubuntu
在Docker上部署Ollama+AnythingLLM完成本地LLM Agent部署
通过以上步骤,您可以成功在Docker上部署Ollama和AnythingLLM,实现本地LLM Agent的功能。在部署过程中,确保环境和配置正确,以避免不必要的问题。希望本文能够帮助您顺利完成部署,并在本地环境中高效地使用LLM模型。
523 8
|
1月前
|
Docker Python 容器
Docker——阿里云服务器使用Docker部署python项目全程小记
本文记录了我在阿里云服务器上使用Docker部署python项目(flask为例)的全过程,在这里记录和分享一下,希望可以给大家提供一些参考。
140 0
|
14天前
|
存储 SQL 关系型数据库
docker部署n9e开源版本7.4.0
n9e开源版本7.4.0
29 0
|
24天前
|
关系型数据库 MySQL Java
【YashanDB知识库】原生mysql驱动配置连接崖山数据库
【YashanDB知识库】原生mysql驱动配置连接崖山数据库
【YashanDB知识库】原生mysql驱动配置连接崖山数据库
|
3月前
|
关系型数据库 MySQL 数据库连接
数据库连接工具连接mysql提示:“Host ‘172.23.0.1‘ is not allowed to connect to this MySQL server“
docker-compose部署mysql8服务后,连接时提示不允许连接问题解决
|
1月前
|
消息中间件 缓存 NoSQL
缓存与数据库的一致性方案,Redis与Mysql一致性方案,大厂P8的终极方案(图解+秒懂+史上最全)
缓存与数据库的一致性方案,Redis与Mysql一致性方案,大厂P8的终极方案(图解+秒懂+史上最全)

热门文章

最新文章