云原生之使用Docker部署Mariadb数据库
【摘要】 云原生之使用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)]>
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)