mongod
我遇到一个问题,下载 MongoDB 后无法使用 cmd 连接到 MongoDB 服务器。
这是使用时终端显示的内容mongod
:
$ mongod
{"t":{"$date":"2021-11-29T19:51:43.327-08:00"},"s":"I", "c":"NETWORK", "id":4915701, "ctx":"-","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":13},"outgoing":{"minWireVersion":0,"maxWireVersion":13},"isInternalClient":true}}}
{"t":{"$date":"2021-11-29T19:51:43.330-08:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"-","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2021-11-29T19:51:43.330-08:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-11-29T19:51:43.330-08:00"},"s":"I", "c":"NETWORK", "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
{"t":{"$date":"2021-11-29T19:51:43.332-08:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-11-29T19:51:43.332-08:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","ns":"config.tenantMigrationDonors"}}
{"t":{"$date":"2021-11-29T19:51:43.332-08:00"},"s":"I", "c":"REPL", "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","ns":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2021-11-29T19:51:43.332-08:00"},"s":"I", "c":"CONTROL", "id":5945603, "ctx":"main","msg":"Multi threading initialized"}
{"t":{"$date":"2021-11-29T19:51:43.332-08:00"},"s":"I", "c":"CONTROL", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":24007,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"Lufarius777"}}
{"t":{"$date":"2021-11-29T19:51:43.332-08:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"5.0.4","gitVersion":"62a84ede3cc9a334e8bc82160714df71e7d3a29e","openSSLVersion":"OpenSSL 1.1.1f 31 Mar 2020","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu2004","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2021-11-29T19:51:43.332-08:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"20.04"}}}
{"t":{"$date":"2021-11-29T19:51:43.332-08:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2021-11-29T19:51:43.333-08:00"},"s":"I", "c":"STORAGE", "id":22270, "ctx":"initandlisten","msg":"Storage engine to use detected by data files","attr":{"dbpath":"/data/db","storageEngine":"wiredTiger"}}
{"t":{"$date":"2021-11-29T19:51:43.333-08:00"},"s":"I", "c":"STORAGE", "id":22297, "ctx":"initandlisten","msg":"Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem","tags":["startupWarnings"]}
{"t":{"$date":"2021-11-29T19:51:43.333-08:00"},"s":"I", "c":"STORAGE", "id":22315, "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=2424M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),builtin_extension_config=(zstd=(compression_level=6)),file_manager=(close_idle_time=600,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],"}}
{"t":{"$date":"2021-11-29T19:51:43.993-08:00"},"s":"W", "c":"STORAGE", "id":22347, "ctx":"initandlisten","msg":"Failed to start up WiredTiger under any compatibility version. This may be due to an unsupported upgrade or downgrade."}
{"t":{"$date":"2021-11-29T19:51:43.993-08:00"},"s":"F", "c":"STORAGE", "id":28595, "ctx":"initandlisten","msg":"Terminating.","attr":{"reason":"95: Operation not supported"}}
{"t":{"$date":"2021-11-29T19:51:43.993-08:00"},"s":"F", "c":"-", "id":23091, "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":28595,"file":"src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp","line":687}}
{"t":{"$date":"2021-11-29T19:51:43.993-08:00"},"s":"F", "c":"-", "id":23092, "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}
我尝试过多次卸载/清除并重新安装 MongoDB。在完成以下操作后,我能够连接...
正在卸载 MongoDB...
sudo service mongod stop
sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
sudo apt-get purge mongodb mongodb-clients mongodb-server mongodb-dev
sudo apt-get purge mongodb-10gen
sudo apt-get autoremove
正在卸载指南针...
sudo dpkg --remove mongodb-compass
然后我转到 MongoDB 文档进行安装:“Ubuntu 版 MongodDB 社区版”,具体来说是 20.0.04 LTS(“Focal”)......我已经
nick@777:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
我根据文档执行以下操作......
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
mongod-db 安装输出:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
mongodb-database-tools mongodb-mongosh mongodb-org-database mongodb-org-database-tools-extra mongodb-org-mongos mongodb-org-server mongodb-org-shell
mongodb-org-tools
The following NEW packages will be installed:
mongodb-database-tools mongodb-mongosh mongodb-org mongodb-org-database mongodb-org-database-tools-extra mongodb-org-mongos mongodb-org-server mongodb-org-shell
mongodb-org-tools
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/147 MB of archives.
After this operation, 467 MB of additional disk space will be used.
Selecting previously unselected package mongodb-database-tools.
(Reading database ... 254976 files and directories currently installed.)
Preparing to unpack .../0-mongodb-database-tools_100.5.1_amd64.deb ...
Unpacking mongodb-database-tools (100.5.1) ...
Selecting previously unselected package mongodb-mongosh.
Preparing to unpack .../1-mongodb-mongosh_1.1.4_amd64.deb ...
Unpacking mongodb-mongosh (1.1.4) ...
Selecting previously unselected package mongodb-org-shell.
Preparing to unpack .../2-mongodb-org-shell_5.0.4_amd64.deb ...
Unpacking mongodb-org-shell (5.0.4) ...
Selecting previously unselected package mongodb-org-server.
Preparing to unpack .../3-mongodb-org-server_5.0.4_amd64.deb ...
Unpacking mongodb-org-server (5.0.4) ...
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack .../4-mongodb-org-mongos_5.0.4_amd64.deb ...
Unpacking mongodb-org-mongos (5.0.4) ...
Selecting previously unselected package mongodb-org-database-tools-extra.
Preparing to unpack .../5-mongodb-org-database-tools-extra_5.0.4_amd64.deb ...
Unpacking mongodb-org-database-tools-extra (5.0.4) ...
Selecting previously unselected package mongodb-org-database.
Preparing to unpack .../6-mongodb-org-database_5.0.4_amd64.deb ...
Unpacking mongodb-org-database (5.0.4) ...
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack .../7-mongodb-org-tools_5.0.4_amd64.deb ...
Unpacking mongodb-org-tools (5.0.4) ...
Selecting previously unselected package mongodb-org.
Preparing to unpack .../8-mongodb-org_5.0.4_amd64.deb ...
Unpacking mongodb-org (5.0.4) ...
Setting up mongodb-mongosh (1.1.4) ...
Setting up mongodb-org-server (5.0.4) ...
Adding system user `mongodb' (UID 128) ...
Adding new user `mongodb' (UID 128) with group `nogroup' ...
Not creating home directory `/home/mongodb'.
addgroup: The group `mongodb' already exists as a system group. Exiting.
Adding user `mongodb' to group `mongodb' ...
Adding user mongodb to group mongodb
Done.
Setting up mongodb-org-shell (5.0.4) ...
Setting up mongodb-database-tools (100.5.1) ...
Setting up mongodb-org-mongos (5.0.4) ...
Setting up mongodb-org-database-tools-extra (5.0.4) ...
Setting up mongodb-org-database (5.0.4) ...
Setting up mongodb-org-tools (5.0.4) ...
Setting up mongodb-org (5.0.4) ...
Processing triggers for man-db (2.9.1-1)
...
使用以下方法验证 mongod 版本mongod --version
db version v5.0.4
Build Info: {
"version": "5.0.4",
"gitVersion": "62a84ede3cc9a334e8bc82160714df71e7d3a29e",
"openSSLVersion": "OpenSSL 1.1.1f 31 Mar 2020",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "ubuntu2004",
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
我在使用以下方法检查状态时也得到了此输出sudo systemctl status mongod
sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2021-11-29 20:24:04 PST; 5s ago
Docs: https://docs.mongodb.org/manual
Process: 32312 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=14)
Main PID: 32312 (code=exited, status=14)
Nov 29 20:24:04 Lufarius777 systemd[1]: Started MongoDB Database Server.
Nov 29 20:24:04 Lufarius777 systemd[1]: mongod.service: Main process exited, code=exited, status=14/n/a
Nov 29 20:24:04 Lufarius777 systemd[1]: mongod.service: Failed with result 'exit-code'.
我真的不知道终端是否显示了该命令的正确输出mongod
我还尝试使用以下命令停止/重新启动该服务
sudo systemctl stop mongod
sudo systemctl restart mongod
任何帮助都将非常有助于结束这场噩梦,谢谢!
答案1
在根目录(计算机文件夹)中创建目录 /data/db。然后使用以下命令启动 MongoDBsudo mongod
希望这可以帮助