mongodb4.0 安装

下载:

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.9.tgz

解压缩

tar -zxvf mongodb-linux-x86_64-4.0.9.tgz

mv mongodb-linux-x86_64-4.0.9 ../mongodb

mkdir -p /data/mongodb/{data,logs,etc}

 

编辑配置文件

vi /data/mongodb/etc/mongod.conf 

    # where to write logging data.
    systemLog:
      destination: file
      logAppend: true
      path: /data/mongodb/logs/mongod.log

    # Where and how to store data.
    storage:
      dbPath: /data/mongodb/data
      journal:
        enabled: true
    #  engine:
    #  mmapv1:
    #  wiredTiger:

    # how the process runs
    processManagement:
      fork: true  # fork and run in background
      pidFilePath: /data/mongodb/run/mongod.pid  # location of pidfile

    # network interfaces
    net:
      port: 27017
      bindIp: 0.0.0.0  # Listen to local interface only, comment to listen on all interfaces.

    #security:

 

cat  /lib/systemd/system/mongod.service

    [Unit]
    Description=High-performance, schema-free document-oriented database
    After=network.target
    Documentation=https://docs.mongodb.org/manual

    [Service]
    User=root
    Group=root
    Environment="OPTIONS=-f /data/mongodb/etc/mongod.conf"
    ExecStart=/data/mongodb/bin/mongod $OPTIONS
    ExecStartPre=/usr/bin/mkdir -p /data/mongodb/data
    PermissionsStartOnly=true
    PIDFile=/data/mongodb/run/mongod.pid
    Type=forking
    # file size
    LimitFSIZE=infinity
    # cpu time
    LimitCPU=infinity
    # virtual memory size
    LimitAS=infinity
    # open files
    LimitNOFILE=64000
    # processes/threads
    LimitNPROC=64000
    # locked memory
    LimitMEMLOCK=infinity
    # total threads (user+kernel)
    TasksMax=infinity
    TasksAccounting=false
    # Recommended limits for for mongod as specified in
    # http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

    [Install]
    WantedBy=multi-user.target

 

授权

use admin
db.createUser({ user: "root", pwd: "Abcd,1234", roles: [{ role: "root", db: "admin" }] })

use im_db_v2
db.createUser({ user: "mongoadmin", pwd: "abc123456789", roles: [ { role: "readWrite", db: "im_db_v2" }]})

db.auth("mongoadmin","abc123456789")
db.im_db_v2.insert({"name":"baby"})

 

配置文件添加

security:
authorization: enabled

 



重启mongodb

systemctl  restart  mongod

 

posted @ 2019-05-30 09:43  fengjian1585  阅读(221)  评论(0编辑  收藏  举报