2021-06-10 搭建easy-mock服务器

1.Docker 安装 MongoDB

我们可以用 docker search mongo 命令来查看可用版本:

[root@localhost ~]# docker search mongo
NAME                                DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mongo                               MongoDB document databases provide high avai…   7875                [OK]                
mongo-express                       Web-based MongoDB admin interface, written w…   953                 [OK]                
tutum/mongodb                       MongoDB Docker image – listens in port 27017…   229                                     [OK]
bitnami/mongodb                     Bitnami MongoDB Docker Image                    150                                     [OK]
mongoclient/mongoclient             Official docker image for Mongoclient, featu…   100                                     [OK]
mongooseim/mongooseim               Small docker image for MongooseIM - robust a…   19                                      
cvallance/mongo-k8s-sidecar         Kubernetes side car to setup and maintain a …   19                                      [OK]
frodenas/mongodb                    A Docker Image for MongoDB                      18                                      [OK]
arm64v8/mongo                       MongoDB document databases provide high avai…   13                                      
webhippie/mongodb                   Docker images for MongoDB                       9                                       [OK]
centos/mongodb-32-centos7           MongoDB NoSQL database server                   9                                       
istepanov/mongodump                 Docker image with mongodump running as a cro…   8                                       [OK]
circleci/mongo                      CircleCI images for MongoDB                     8                                       [OK]
centos/mongodb-36-centos7           MongoDB NoSQL database server                   7                                       
centos/mongodb-26-centos7           MongoDB NoSQL database server                   5                                       
eses/mongodb_exporter               mongodb exporter for prometheus                 4                                       [OK]
neowaylabs/mongodb-mms-agent        This Docker image with MongoDB Monitoring Ag…   4                                       [OK]
centos/mongodb-34-centos7           MongoDB NoSQL database server                   3                                       
andreasleicher/mongo-azure-backup   a docker container to backup a mongodb using…   2                                       [OK]
ansibleplaybookbundle/mongodb-apb   An APB to deploy MongoDB.                       1                                       [OK]
openshift/mongodb-24-centos7        DEPRECATED: A Centos7 based MongoDB v2.4 ima…   1                                       
ekesken/mongo                       docker image for mongo that is configurable …   1                                       [OK]
martel/mongo-replica-ctrl           A dockerized controller for a Mongo db repli…   0                                       [OK]
phenompeople/mongodb                 MongoDB is an open-source, document databas…   0                                       [OK]
ccitest/mongo                       CircleCI test images for Mongo                  0                                       [OK]

2. 取最新版的 MongoDB 镜像

这里我们拉取官方的最新版本的镜像:

[root@localhost ~]# docker pull mongo:latest
latest: Pulling from library/mongo
01bf7da0a88c: Pull complete 
f3b4a5f15c7a: Pull complete 
57ffbe87baa1: Pull complete 
77d5e5c7eab9: Pull complete 
43798cf18b45: Pull complete 
67349a81f435: Pull complete 
590845b1f17c: Pull complete 
1f2ff17242ce: Pull complete 
6f11b2ce0594: Pull complete 
91532386f4ec: Pull complete 
705ef0ab262e: Pull complete 
e6238126b609: Pull complete 
Digest: sha256:419ee9e6676031a18186f20f6bcebb2c0a52cb386502293563dc7ff2968a1b89
Status: Downloaded newer image for mongo:latest
docker.io/library/mongo:latest

3.查看本地镜像

使用以下命令来查看是否已安装了 mongo:

[root@localhost ~]# docker images
REPOSITORY            TAG                                IMAGE ID            CREATED             SIZE
mongo                 latest                             07630e791de3        4 weeks ago         449MB
easysoft/zentao       latest                             cb1719c4795e        7 months ago        638MB
redis                 latest                             16ecd2772934        7 months ago        104MB
redmine               latest                             c04c9119abaf        10 months ago       542MB
tomcat                7.0.105-jdk8-openjdk-slim-buster   ec2aed81b8d5        10 months ago       304MB
nginx                 latest                             08393e824c32        10 months ago       132MB
mysql                 5.7                                718a6da099d8        10 months ago       448MB
tomcat                8.5-jdk8-corretto                  37f0795eefdb        10 months ago       373MB
tomcat                latest                             9a9ad4f631f8        10 months ago       647MB
portainer/portainer   latest                             62771b0b9b09        10 months ago       79.1MB
hello-world           latest                             bf756fb1ae65        17 months ago       13.3kB
tomcat                8.0.53-jre8-slim                   7645ae5b5797        2 years ago         223MB

4. 添加账户

[root@localhost ~]# docker exec -it mongo mongo admin
MongoDB shell version v4.4.6
connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("da1e0a68-1b5a-4b3f-9c88-df1e1da3076f") }
MongoDB server version: 4.4.6
---
The server generated these startup warnings when booting: 
        2021-06-10T04:36:43.781+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
        2021-06-10T04:36:43.782+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
        2021-06-10T04:36:43.782+00:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
---
---
        Enable MongoDB's free cloud-based monitoring service, which will then receive and display
        metrics about your deployment (disk utilization, CPU, operation statistics, etc).

        The monitoring data will be available on a MongoDB website with a unique URL accessible to you
        and anyone you share the URL with. MongoDB may use this information to make product
        improvements and to suggest MongoDB products and deployment options to you.

        To enable free monitoring, run the following command: db.enableFreeMonitoring()
        To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> db.createUser({ user:'admin',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
Successfully added user: {
    "user" : "admin",
    "roles" : [
        {
            "role" : "userAdminAnyDatabase",
            "db" : "admin"
        },
        "readWriteAnyDatabase"
    ]
}
> db.auth('admin', '123456')
1
> exit

你可能感兴趣的:(2021-06-10 搭建easy-mock服务器)