• centos7安装MongoDB4.0(yum安装)


    1.添加 yum repo

        vi /etc/yum.repos.d/mongodb-org-4.0.repo

      添加如下内容  

        [mongodb-org-4.0]
        name=MongoDB Repository
        baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
        gpgcheck=1
        enabled=1
        gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc

      保存退出

    2.查看 repolist

      yum repolist all|grep mongodb

    3.yum安装

      yum install -y mongodb-org

    4.启动/查看服务

      systemctl start mongod.service

      systemctl status mongod.service

    5.查看端口状态

      netstat -ntlp

    6.运行

      mongo --host 127.0.0.1:27017

      db

      show dbs

    7.配置远程连接

      编辑 mongod.conf 配置

        cp /etc/mongod.conf /etc/mongod.conf.bak

        vi /etc/mongod.conf

        将 bindIp: 127.0.0.1 改成 bindIp: 0.0.0.0,注意 tab 和空格对齐

      开放端口   

        firewall-cmd --zone=public --add-port=27017/tcp --permanent

        firewall-cmd --reload

        firewall-cmd --zone=public --query-port=27017/tcp

      重启服务

        systemctl restart mongod.service

     8.设置登录认证

      创建管理员用户

        use admin

        db.createUser(

          {

            user: "user",

            pwd: "pwd",

            roles: [ { role: "root", db: "admin" } ]

          }

         )

      创建普通用户

        use demo

        db.createUser(

          {

            user: "user",

            pwd: "pwd",

            roles: [ { role: "readWrite", db: "demo" } ]

          }

         )

      创建访客   

        use demo

        db.createUser(

          {

            user: "guest",

            pwd: "pwd",

            roles: [ { role: "read", db: "demo" } ]

          }

         )

      编辑 mongod.conf 配置,开启认证

        vi /etc/mongod.conf

        找到 #security: ,改成如下开启安全认证:

        security:

            authorization: enabled

      重启服务

        systemctl restart mongod.service

    参考文章:

      https://blog.csdn.net/u010279498/article/details/89556660 yum安装及配置

      https://blog.csdn.net/jianleking/article/details/79715097 开启安全认证

      https://www.cnblogs.com/niwotaxuexiba/p/10642202.html 开启安全认证

  • 相关阅读:
    Spark学习笔记2(spark所需环境配置
    Spark学习笔记1(初始spark
    zookeeper基本讲解及基本命令和配置 (转)
    计算机网络面试常考(转载)
    C++面试笔试题汇总
    复杂指针解析
    如何限制一个类对象只在栈(堆)上分配空间?
    虚函数实现机制
    C++内存分配方式详解
    C++中指针和引用的区别(转载)
  • 原文地址:https://www.cnblogs.com/tarencez/p/10880125.html
Copyright © 2020-2023  润新知