【问题标题】:Install multiple versions of MongoDB on linux在linux上安装多个版本的MongoDB
【发布时间】:2017-09-10 16:37:52
【问题描述】:

我们如何在 Ubuntu 16.04 上设置多个版本的 MongoDB?

MongoDB 3.4.1 已经在我的系统上启动并运行,并且想为其他应用程序设置 MongoDB 2.6。因为我们在 MongoDB 2.6 上运行的应用程序具有与 MongoDB 3.4 不兼容的 DB 驱动程序,因此希望在同一 linux 服务器上运行两个 MongoDB 版本。

尝试点击以下链接,但未能成功。

  1. How can I install two versions of mongodb parallely in Ubuntu 12.04 ?
  2. multiple versions of Mongo
  3. multiple instances of Mongo DB on same server

【问题讨论】:

    标签: linux mongodb ubuntu-16.04


    【解决方案1】:

    为此,您的系统上必须有两个版本的 MongoDB。

    例如,假设您已将 2.6 版本的二进制文件下载到 /opt/mongo/26/ 和另一个版本的 /opt/mongo/34/,您可以在不同的端口上运行这两个版本的数据库守护程序:

    /opt/mongo/26/mongod --dbpath /data/26/ --port 27017
    /opt/mongo/34/mongod --dbpath /data/34/ --port 28018
    

    【讨论】:

      【解决方案2】:

      这就是我的工作。

      1。选择版本:

      2。安装和配置

      我使用的是 Ubuntu 20.04,我想安装 mongodb Community ver 2.6.12

      安装:

          $ cd ~/Downloads
          $ curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.12.tgz
          $ tar -zxvf mongodb-linux-x86_64-2.6.12.tgz
          $ mv mongodb-linux-x86_64-2.6.12 2.6.12
          $ cd /opt && mkdir -p mongodb
          $ cd ~/Downloads
          $ cp -R 2.6.12 /opt/mongodb
          $ cp /mongod.conf /opt/mongodb/2.6.12/
      

      配置:

      版本 3.0 不同,所以我用谷歌搜索了它。这就是我所拥有的。

      systemLog:
         destination: file
         path: "/var/log/mongodb/mongodb.log"
         logAppend: true
      storage:
         journal:
            enabled: true
      processManagement:
         fork: true
      net:
         bindIp: 127.0.0.1
         port: 27018
      setParameter:
         enableLocalhostAuthBypass: false
      

      在这个文件中,您需要将 systemLog.path、net.port 和 net.bindIp 更改为您自己的。一件重要的事情是我们不能使用相同的端口同时运行 2 个版本。所以这里我为旧版本设置了27018

      把它放在任何你想要的地方,我做到了:

      $ cp ~/mongod.conf /opt/mongodb/2.6.12/
      

      不要运行这个,因为它会覆盖当前的 mongodb 版本命令

      $ export PATH=/opt/mongodb/2.6.12/bin:$PATH
      

      创建数据和日志目录并设置权限。

      $ mkdir -p /data/db
      $ mkdir -p /var/log/mongodb
      

      跑步:

      现在你可以用命令启动 2.6 版本了。

      $ /opt/mongodb/2.6.12/bin/mongod --fork --dbpath /data/db --config /opt/mongodb/2.6.12/mongod.conf
      

      它太长了,不是吗?所以用别名使它更短。

      $ sudo nano ~/.bash_profile
      or
      $ sudo nano ~/.bashrc
      

      并将其添加到文件中

      alias mongo26="/opt/mongodb/2.6.12/bin/mongo --port 27018"
      alias mongoRestore26="/opt/mongodb/2.6.12/bin/mongorestore --port 27018"
      alias mongoDump26="/opt/mongodb/2.6.12/bin/mongodump --port 27018"
      alias startMongo26="/opt/mongodb/2.6.12/bin/mongod --fork --dbpath /data/db --config /opt/mongodb/2.6.12/mongod.conf"
      alias stopMongo26="/opt/mongodb/2.6.12/bin/mongod --dbpath /data/db --shutdown"
      
      alias nanoMongo="nano /opt/mongodb/2.6.12/mongod.conf"
      alias tailMongo="tail -f /var/log/mongodb/mongod.log"
      alias tailMongo26="tail -f /var/log/mongodb/mongodb.log"
      

      应用这些别名

      $ source ~/.bash_profile
      or
      $ source ~/.bashrc
      

      现在我们可以简单地启动 mongodb 2.6 版了

      $ startMongo26
      about to fork child process, waiting until server is ready for connections.
      forked process: 1049481
      child process started successfully, parent exiting
      

      运行 shell 版本 2.6

      $ mongo26
      MongoDB shell version: 2.6.12
      connecting to: 127.0.0.1:27018/test
      >
      

      运行shell当前版本

      $ mongo
      MongoDB shell version v4.4.3
      connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
      Implicit session: session { "id" : UUID("3ae6094f-86dc-4741-aa72-1e48efc5273a") }
      MongoDB server version: 4.4.3
      >
      

      3.疑难解答

      • 无法从startMongo26 开始,请查看/var/log/mongodb/mongod.log 的日志
      about to fork child process, waiting until server is ready for connections.
      forked process: 1049890
      ERROR: child process failed, exited with error number 100
      

      /var/log/mongodb/mongod.log查看日志

      • 如果日志有这一行:
      2021-02-26T15:51:13.493-0700 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
      

      这是因为您当前的用户没有运行和写入此目录的权限。您可以将权限设置为 /data/db 或更改目录。我改成了~/datamongo

      $ /opt/mongodb/2.6.12/bin/mongod --fork --dbpath ~/datamongo --config /opt/mongodb/2.6.12/mongod.conf
      
      • /var/log/mongodb/mongodb.log 上的错误执行相同操作

      stopMongo26 无法关闭

      There doesn't seem to be a server running with dbpath: /data/db
      

      这样做:

      $ mongo26
      MongoDB shell version: 2.6.12
      connecting to: 127.0.0.1:27018/test
      > use admin
      switched to db admin
      > db.shutdownServer()
      2021-02-26T15:45:19.738-0700 DBClientCursor::init call() failed
      server should be down...
      2021-02-26T15:45:19.742-0700 trying reconnect to 127.0.0.1:27018 (127.0.0.1) failed
      2021-02-26T15:45:19.742-0700 warning: Failed to connect to 127.0.0.1:27018, reason: errno:111 Connection refused
      2021-02-26T15:45:19.742-0700 reconnect 127.0.0.1:27018 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27018 (127.0.0.1), connection attempt failed
      

      按照我的指示一步一步做,你会没事的。祝你好运,享受!!!

      【讨论】:

        猜你喜欢
        • 2016-10-21
        • 1970-01-01
        • 1970-01-01
        • 2017-09-22
        • 2017-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多