云原生之使用docker部署mongodb数据库

Posted 江湖有缘

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了云原生之使用docker部署mongodb数据库相关的知识,希望对你有一定的参考价值。

云原生之使用docker部署mongodb数据库

一、检查系统版本

[root@serer01 ~]# 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@serer01 ~]# 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 Wed 2022-10-19 23:36:56 CST; 2 weeks 1 days ago
     Docs: https://docs.docker.com
 Main PID: 1996 (dockerd)
   Memory: 131.3M
   CGroup: /system.slice/docker.service
           ├─1996 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
           ├─2222 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8080 -container-ip 172.17.0.2 -container-port 80
           └─2228 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8080 -container-ip 172.17.0.2 -container-port 80

Oct 19 23:36:53 serer01 dockerd[1996]: time="2022-10-19T23:36:53.139110884+08:00" level=warning msg="Error (Unable to complete atomic op...ing...."
Oct 19 23:36:53 serer01 dockerd[1996]: time="2022-10-19T23:36:53.439001238+08:00" level=info msg="Default bridge (docker0) is assigned w...address"
Oct 19 23:36:55 serer01 dockerd[1996]: time="2022-10-19T23:36:55.938480860+08:00" level=info msg="Loading containers: done."
Oct 19 23:36:56 serer01 dockerd[1996]: time="2022-10-19T23:36:56.113464686+08:00" level=info msg="Docker daemon" commit=e42327a graphdri...20.10.18
Oct 19 23:36:56 serer01 dockerd[1996]: time="2022-10-19T23:36:56.113624266+08:00" level=info msg="Daemon has completed initialization"
Oct 19 23:36:56 serer01 systemd[1]: Started Docker Application Container Engine.
Oct 19 23:36:56 serer01 dockerd[1996]: time="2022-10-19T23:36:56.229365844+08:00" level=info msg="API listen on /var/run/docker.sock"
Nov 02 23:40:39 serer01 dockerd[1996]: time="2022-11-02T23:40:39.275305033+08:00" level=info msg="Pull session cancelled"
Nov 02 23:40:51 serer01 dockerd[1996]: time="2022-11-02T23:40:51.760654450+08:00" level=error msg="Not continuing with pull after error:...anceled"
Nov 02 23:46:19 serer01 dockerd[1996]: time="2022-11-02T23:46:19.770889001+08:00" level=error msg="Not continuing with pull after error:...anceled"
Hint: Some lines were ellipsized, use -l to show in full.

三、检查docker版本

[root@serer01 ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.18
 API version:       1.41
 Go version:        go1.18.6
 Git commit:        b40c2f6
 Built:             Thu Sep  8 23:14:08 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.18
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.6
  Git commit:       e42327a
  Built:            Thu Sep  8 23:12:21 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

四、下载mongodb镜像

[root@node ~]#  docker pull mongo:latest
latest: Pulling from library/mongo
7b1a6ab2e44d: Already exists 
90eb44ebc60b: Pull complete 
5085b59f2efb: Pull complete 
c7499923d022: Pull complete 
019496b6c44a: Pull complete 
c0df4f407f69: Pull complete 
351daa315b6c: Pull complete 
a233e6240acc: Pull complete 
a3f57d6be64f: Pull complete 
dd1b5b345323: Pull complete 
Digest: sha256:5be752bc5f2ac4182252d0f15d74df080923aba39700905cb26d9f70f39e9702
Status: Downloaded newer image for mongo:latest
docker.io/library/mongo:latest

五、创建mongodb容器

1.创建数据目录

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

2.创建mongodb容器

[root@node mongo]# docker run -d --name mongo  -p 27217:27017 -v /data/mongo/db:/data/db mongo:latest --auth
19d67d93aa7202fd2d10801e0ae4c7a982c7f92971952df8505ffcdc228e0d14

3.查看mongodb容器状态

[root@node mongo]# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                                           NAMES
19d67d93aa72   mongo:latest   "docker-entrypoint.s…"   25 seconds ago   Up 24 seconds   0.0.0.0:27217->27017/tcp, :::27217->27017/tcp   mongo

4.查看容器运行日志

[root@node mongo]# docker logs mongo 
"t":"$date":"2022-11-04T01:16:50.961+00:00","s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"-","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"
"t":"$date":"2022-11-04T01:16:50.962+00:00","s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"main","msg":"Initialized wire specification","attr":"spec":"incomingExternalClient":"minWireVersion":0,"maxWireVersion":13,"incomingInternalClient":"minWireVersion":0,"maxWireVersion":13,"outgoing":"minWireVersion":0,"maxWireVersion":13,"isInternalClient":true
"t":"$date":"2022-11-04T01:16:50.962+00:00","s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"
"t":"$date":"2022-11-04T01:16:50.962+00:00","s":"I",  "c":"NETWORK",  "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."
"t":"$date":"2022-11-04T01:16:50.963+00:00","s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"
"t":"$date":"2022-11-04T01:16:50.964+00:00","s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":"service":"TenantMigrationDonorService","ns":"config.tenantMigrationDonors"
"t":"$date":"2022-11-04T01:16:50.964+00:00","s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":"service":"TenantMigrationRecipientService","ns":"config.tenantMigrationRecipients"
"t":"$date":"2022-11-04T01:16:50.964+00:00","s":"I",  "c":"CONTROL",  "id":5945603, "ctx":"main","msg":"Multi threading initialized"
"t":"$date":"2022-11-04T01:16:50.964+00:00","s":"I",  "c":"CONTROL",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":"pid":1,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"19d67d93aa72"
"t":"$date":"2022-11-04T01:16:50.964+00:00","s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":"buildInfo":"version":"5.0.5","gitVersion":"d65fd89df3fc039b5c55933c0f71d647a54510ae","openSSLVersion":"OpenSSL 1.1.1f  31 Mar 2020","modules":[],"allocator":"tcmalloc","environment":"distmod":"ubuntu2004","distarch":"x86_64","target_arch":"x86_64"
"t":"$date":"2022-11-04T01:16:50.964+00:00","s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":"os":"name":"Ubuntu","version":"20.04"
"t":"$date":"2022-11-04T01:16:50.964+00:00","s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":"options":"net":"bindIp":"*","security":"authorization":"enabled"
"t":"$date":"2022-11-04T01:16:50.965+00:00","s":"I",  "c":"STORAGE",  "id":22315,   "ctx":"initandlisten","msg":"Opening WiredTiger","attr":"config":"create,cache_size=3389M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),builtin_extension_config=(zstd=(compression_level=6)),file_manager=(close_idle_time=600,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],"
"t":"$date":"2022-11-04T01:16:51.125+00:00","s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":"message":"[1667524611:125665][1:0x7fb4e4883c80], txn-recover: [WT_VERB_RECOVERY_ALL] Set global recovery timestamp: (0, 0)"
"t":"$date":"2022-11-04T01:16:51.125+00:00","s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":"message":"[1667524611:125750][1:0x7fb4e4883c80], txn-recover: [WT_VERB_RECOVERY_ALL] Set global oldest timestamp: (0, 0)"
"t":"$date":"2022-11-04T01:16:51.127+00:00","s":"I",  "c":"STORAGE",  "id":4795906, "ctx":"initandlisten","msg":"WiredTiger opened","attr":"durationMillis":162
"t":"$date":"2022-11-04T01:16:51.127+00:00","s":"I",  "c":"RECOVERY", "id":23987,   "ctx":"initandlisten","msg":"WiredTiger recoveryTimestamp","attr":"recoveryTimestamp":"$timestamp":"t":0,"i":0
"t":"$date":"2022-11-04T01:16:51.158+00:00","s":"I",  "c":"STORAGE",  "id":4366408, "ctx":"initandlisten","msg":"No table logging settings modifications are required for existing WiredTiger tables","attr":"loggingEnabled":true
"t":"$date":"2022-11-04T01:16:51.159+00:00","s":"I",  "c":"STORAGE",  "id":22262,   "ctx":"initandlisten","msg":"Timestamp monitor starting"
"t":"$date":"2022-11-04T01:16:51.160+00:00","s":"W",  "c":"CONTROL",  "id":22178,   "ctx":"initandlisten","msg":"/sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'","tags":["startupWarnings"]
"t":"$date":"2022-11-04T01:16:51.160+00:00","s":"W",  "c":"CONTROL",  "id":22181,   "ctx":"initandlisten","msg":"/sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'","tags":["startupWarnings"]
"t":"$date":"2022-11-04T01:16:51.161+00:00","s":"I",  "c":"STORAGE",  "id":20320,   "ctx":"initandlisten","msg":"createCollection","attr":"namespace":"admin.system.version","uuidDisposition":"provided","uuid":"uuid":"$uuid":"7386e56b-6f15-4b9f-a80b-108729f9379a","options":"uuid":"$uuid":"7386e56b-6f15-4b9f-a80b-108729f9379a"
"t":"$date":"2022-11-04T01:16:51.164+00:00","s":"I",  "c":"INDEX",    "id":20345,   "ctx":"initandlisten","msg":"Index build: done building","attr":"buildUUID":null,"namespace":"admin.system.version","index":"_id_","commitTimestamp":null
"t":"$date":"2022-11-04T01:16:51.164+00:00","s":"I",  "c":"REPL",     "id":20459,   "ctx":"initandlisten","msg":"Setting featureCompatibilityVersion","attr":"newVersion":"5.0"
"t":"$date":"2022-11-04T01:16:51.164+00:00","s":"I",  "c":"NETWORK",  "id":4915702, "ctx":"initandlisten","msg":"Updated wire specification","attr":"oldSpec":"incomingExternalClient":"minWireVersion":0,"maxWireVersion":13,"incomingInternalClient":"minWireVersion":0,"maxWireVersion":13,"outgoing":"minWireVersion":0,"maxWireVersion":13,"isInternalClient":true,"newSpec":"incomingExternalClient":"minWireVersion":0,"maxWireVersion":13,"incomingInternalClient":"minWireVersion":13,"maxWireVersion":13,"outgoing":"minWireVersion":13,"maxWireVersion":13,"isInternalClient":true
"t":"$date":"2022-11-04T01:16:51.164+00:00","s":"I",  "c":"NETWORK",  "id":4915702, "ctx":"initandlisten","msg":"Updated wire specification","attr":"oldSpec":"incomingExternalClient":"minWireVersion":0,"maxWireVersion":13,"incomingInternalClient":"minWireVersion":13,"maxWireVersion":13,"outgoing":"minWireVersion":13,"maxWireVersion":13,"isInternalClient":true,"newSpec":"incomingExternalClient":"minWireVersion":0,"maxWireVersion":13,"incomingInternalClient":"minWireVersion":13,"maxWireVersion":13,"outgoing":"minWireVersion":13,"maxWireVersion":13,"isInternalClient":true
"t":"$date":"2022-11-04T01:16:51.164+00:00","s":"I",  "c":"STORAGE",  "id":5071100, "ctx":"initandlisten","msg":"Clearing temp directory"
"t":"$date":"2022-11-04T01:16:51.164+00:00","s":"I",  "c":"CONTROL",  "id":20536,   "ctx":"initandlisten","msg":"Flow Control is enabled on this deployment"
"t":"$date":"2022-11-04T01:16:51.165+00:00","s":"I",  "c":"FTDC",     "id":20625,   "ctx":"initandlisten","msg":"Initializing full-time diagnostic data capture","attr":"dataDirectory":"/data/db/diagnostic.data"
"t":"$date":"2022-11-04T01:16:51.165+00:00","s":"I",  "c":"STORAGE",  "id":20320,   "ctx":"initandlisten","msg":"createCollection","attr":"namespace":"local.startup_log","uuidDisposition":"generated","uuid"以上是关于云原生之使用docker部署mongodb数据库的主要内容,如果未能解决你的问题,请参考以下文章

猿创征文|云原生 | 24Docker运行数据库实战之MongoDB

云原生之使用docker部署Postgresql数据库

云原生之使用docker部署Postgresql数据库

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

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

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