1.下载地址
    https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.3.tgz
    2.创建mongod用户用户组
    useradd -s /sbin/nologin -M mongod
    chattr file -i
    lsattr file 查看文件隐藏属性
    3.安装
    tar -zxvf mongo.tgz
    mv 移动到安装目录
    mkdir -p ./data/db-1 ./log ./tmp
    4.创建配置文件
    touch bin/mongodb.conf

    1. storage:
    2. dbPath: /usr/local/mongodb-4.0.3/data/db-1
    3. journal:
    4. enabled: true
    5. systemLog:
    6. destination: file
    7. logAppend: true
    8. path: /usr/local/mongodb-4.0.3/log/mongodb-1.log
    9. processManagement:
    10. fork: true
    11. pidFilePath: /usr/local/mongodb-4.0.3/tmp/mongod-1.pid
    12. net:
    13. port: 27017
    14. bindIp: 0.0.0.0
    15. # 配置副本集时解除注释
    16. # replication:
    17. # replSetName: "rs"
    18. # 创建用户后解除注释
    19. # security:
    20. # authorization: enabled
    21. # clusterAuthMode: "keyFile"
    22. # keyFile: /usr/local/mongodb-4.0.3/bin/keyfile

    5.创建mongodb数据库间通信所需密钥密钥
    openssl rand -base64 756 > keyfile
    chmod 600 keyfile

    6.启动mongodb
    ./mongod -f ./mongodb.conf

    6.连接mongodb,创建admin用户
    ./mongo
    use admin
    db.createUser({
    user: ‘admin’,
    pwd: ‘2b8ba2ded188’,
    roles:[{
    role: ‘root’,
    db: ‘admin’
    }]
    })
    7.开启副本集,需要至少三个mongdb服务
    配置文件开启参数,配置统一的副本集名称
    在主服务器上设置副本集配置

    1. conf={
    2. _id: "rs",
    3. members: [
    4. { _id: 0, host: "127.0.0.1:27017" },
    5. { _id: 1, host: "127.0.0.1:27018" },
    6. { _id: 2, host: "127.0.0.1:28019",arbiterOnly:true }
    7. ]
    8. }
    9. rs.initiate(conf)
    10. rs.status()
    1. ./mongodump -u admin -p=pwd -hip:port —authenticationDatabase admin -d 待备份数据库 -o 备份文件地址
    2. ./mongorestore -h 81.70.159.29:27017 -u admin -p 2b8ba2ded188 —authenticationDatabase admin -dir ./back/ns-platform -d ns-platform
    3. 重命名数据库

    https://blog.csdn.net/jackyrongvip/article/details/84771505?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link