升级到 Ubuntu/Kubuntu 18.04 后我的 MongoDB 服务器似乎坏了。
我尝试重新安装 Mongo 但仍然无法像以前一样启动它:
$ sudo apt-get install mongodb-server
$ mongo --version
MongoDB shell version v3.6.3
git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
OpenSSL version: OpenSSL 1.1.0h 27 Mar 2018
allocator: tcmalloc
modules: none
build environment:
distarch: x86_64
target_arch: x86_64
状态:
$ sudo service mongodb status
● mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2018-10-07 14:30:40 BST; 17s ago
Docs: man:mongod(1)
Process: 5925 ExecStart=/usr/bin/mongod --unixSocketPrefix=${SOCKETPATH} --config ${CONF} $DAEMON_OPTS (code=exited, status=62)
Main PID: 5925 (code=exited, status=62)
Oct 07 14:30:38 lau-desktop systemd[1]: Started An object/document-oriented database.
Oct 07 14:30:40 lau-desktop systemd[1]: mongodb.service: Main process exited, code=exited, status=62/n/a
Oct 07 14:30:40 lau-desktop systemd[1]: mongodb.service: Failed with result 'exit-code'.
有任何想法吗?
编辑:
当我尝试安装 mongo 4 时,出现错误:
Preparing to unpack .../mongodb-org-server_4.0.3_amd64.deb ...
Unpacking mongodb-org-server (4.0.3) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-server_4.0.3_amd64.deb (--unpack):
trying to overwrite '/usr/bin/mongod', which is also in package mongodb-server-core 1:3.6.3-0ubuntu1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../mongodb-org-mongos_4.0.3_amd64.deb ...
Unpacking mongodb-org-mongos (4.0.3) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-mongos_4.0.3_amd64.deb (--unpack):
trying to overwrite '/usr/bin/mongos', which is also in package mongodb-server-core 1:3.6.3-0ubuntu1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../mongodb-org-tools_4.0.3_amd64.deb ...
Unpacking mongodb-org-tools (4.0.3) ...
dpkg: error processing archive /var/cache/apt/archives/mongodb-org-tools_4.0.3_amd64.deb (--unpack):
trying to overwrite '/usr/bin/bsondump', which is also in package mongo-tools 3.6.3-0ubuntu1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
/var/cache/apt/archives/mongodb-org-server_4.0.3_amd64.deb
/var/cache/apt/archives/mongodb-org-mongos_4.0.3_amd64.deb
/var/cache/apt/archives/mongodb-org-tools_4.0.3_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
编辑2:
$ sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies.
mongodb-org : Depends: mongodb-org-server but it is not installed
Depends: mongodb-org-mongos but it is not installed
Depends: mongodb-org-tools but it is not installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
编辑3:
$ mongo --versionMongoDB shell version v4.0.3
git version: 7ea530946fa7880364d88c8d8b6026bbc9ffa48c
OpenSSL version: OpenSSL 1.1.0h 27 Mar 2018
allocator: tcmalloc
modules: none
build environment:
distmod: ubuntu1804
distarch: x86_64
target_arch: x86_64
$ sudo service mongodb status
● mongodb.service
Loaded: masked (/dev/null; bad)
Active: failed (Result: exit-code) since Sun 2018-10-07 15:12:14 BST; 1h 7min ago
Main PID: 2232 (code=exited, status=62)
Oct 07 15:12:13 lau-desktop systemd[1]: Started An object/document-oriented database.
Oct 07 15:12:14 lau-desktop systemd[1]: mongodb.service: Main process exited, code=exited, status=62/n/a
Oct 07 15:12:14 lau-desktop systemd[1]: mongodb.service: Failed with result 'exit-code'.
答案1
继指导从 Mongo 官方网站,我已修复该问题。
步骤1:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E52529D4
第2步:
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
步骤3:
sudo apt-get update
步骤4:
sudo apt-get install -y mongodb-org=4.0.2 mongodb-org-server=4.0.2 mongodb-org-shell=4.0.2 mongodb-org-mongos=4.0.2 mongodb-org-tools=4.0.2
步骤5:
sudo service mongod start
第 6 步:
sudo service mongod status
● mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/etc/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2018-10-07 17:06:28 BST; 4min 24s ago
Main PID: 27797 (mongod)
Tasks: 26 (limit: 4915)
CGroup: /system.slice/mongod.service
└─27797 /usr/bin/mongod --quiet --config /etc/mongod.conf
Oct 07 17:06:28 lau-desktop systemd[1]: Started High-performance, schema-free document-oriented database.
Oct 07 17:06:28 lau-desktop mongod[27797]: 2018-10-07T17:06:28.337+0100 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS
lines 1-10/10 (END)
答案2
我也遇到了同样的问题。接受的答案对我不起作用,因为我正在尝试安装版本4.0.5
。我想分享我如何解决这个问题。
从错误消息中,我了解到 apt 正在尝试用最新版本(在撰写本文时)覆盖/usr/bin/bsondump
版本。之前,我确实删除了之前安装的 mongodb 版本。不知何故,包被遗留了下来。3.6.3
4.0.5
3.6.3
mongo-tools
因此,我只需删除[email protected]
。但是,由于 的安装[email protected]
未成功完成,我不得不重置apt
,然后才能对 进行任何操作apt
。
此命令撤消了损坏的包安装。
sudo dpkg --remove --force-remove-reinstreq mongodb-org
然后我只需运行以下命令即可删除[email protected]
sudo apt update # to refresh apt
sudo apt remove mongo-tools # to remove mongo-tools 3.6.3
最后,我重新运行以下命令来安装最新的 mongodb
sudo apt-get install -y mongodb-org
有效!