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
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,042评论 6 490
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 89,996评论 2 384
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 156,674评论 0 345
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,340评论 1 283
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,404评论 5 384
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,749评论 1 289
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,902评论 3 405
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,662评论 0 266
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,110评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,451评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,577评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,258评论 4 328
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,848评论 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,726评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,952评论 1 264
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,271评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,452评论 2 348

推荐阅读更多精彩内容