在 linux 上安装 MongoDB 的多个版本
Install multiple versions of MongoDB on linux
我们如何在 Ubuntu 16.04 上设置 MongoDB 的多个版本?
MongoDB 3.4.1 已经在我的系统上 运行ning 了,我想为其他应用程序设置 MongoDB 2.6。因为我们在 MongoDB 2.6 上的应用程序 运行ning 具有与 MongoDB 3.4 不兼容的数据库驱动程序,因此需要 运行 两个 MongoDB 版本在同一 linux服务器。
尝试按照以下 link 但未能成功。
- 如何在 Ubuntu 12.04 中并行安装两个版本的 mongodb
?
- multiple versions of Mongo
- multiple instances of Mongo DB on same server
为此,您的系统上必须有两个版本的 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
我就是这样做的。
1。选择版本:
- 社区:https://www.mongodb.com/download-center/community/releases/archive
- 企业:https://www.mongodb.com/download-center/enterprise/releases/archive
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 的配置选项与版本 >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.Troubleshooting
- 无法从
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
按照我的指示一步一步做,你会没事的。祝你好运,享受!!!
我们如何在 Ubuntu 16.04 上设置 MongoDB 的多个版本?
MongoDB 3.4.1 已经在我的系统上 运行ning 了,我想为其他应用程序设置 MongoDB 2.6。因为我们在 MongoDB 2.6 上的应用程序 运行ning 具有与 MongoDB 3.4 不兼容的数据库驱动程序,因此需要 运行 两个 MongoDB 版本在同一 linux服务器。
尝试按照以下 link 但未能成功。
- 如何在 Ubuntu 12.04 中并行安装两个版本的 mongodb ?
- multiple versions of Mongo
- multiple instances of Mongo DB on same server
为此,您的系统上必须有两个版本的 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
我就是这样做的。
1。选择版本:
- 社区:https://www.mongodb.com/download-center/community/releases/archive
- 企业:https://www.mongodb.com/download-center/enterprise/releases/archive
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 的配置选项与版本 >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.Troubleshooting
- 无法从
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
按照我的指示一步一步做,你会没事的。祝你好运,享受!!!