我想分享一个我在 Rasberry Pi 上安装 mongoDB 副本集时遇到的问题,希望有人能给我一些帮助。我的目标是做我之前做过的here;但这次我想使用 Raspberry Pi OS 而不是 Ubuntu。
我已经到了安装mongoDB的地步了。
这是我的环境:
root@raspberrypi:~ # uname -a
Linux raspberrypi 5.10.17-v8+ #1403 SMP PREEMPT Mon Feb 22 11:37:54 GMT 2021 aarch64 GNU/Linux
root@raspberrypi:~ #
root@raspberrypi:~ # mongo --version
MongoDB shell version v4.4.4
Build Info: {
"version": "4.4.4",
"gitVersion": "8db30a63db1a9d84bdcad0c83369623f708e0397",
"openSSLVersion": "OpenSSL 1.1.1d 10 Sep 2019",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "ubuntu1804",
"distarch": "aarch64",
"target_arch": "aarch64"
}
}
root@raspberrypi:~ #
这是第一台服务器的配置文件:
root@raspberrypi:~ # cat /home/mongodb/mongo-One.cfg
storage:
dbPath: /mnt/mongoDB-One/DB_Data
journal:
enabled: true
net:
bindIp: localhost,192.168.10.116
port: 22330
systemLog:
destination: file
path: /mnt/mongoDB-One/DB_Data/mongod.log
logAppend: true
replication:
replSetName: mngoRepSet
root@raspberrypi:~ #
服务器(打算)在启动时启动,使用 systemd。
这是systemd服务文件:
pi@raspberrypi:~ $ cat /lib/systemd/system/mongod-One.service
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target
Wants=network-online.target
[Service]
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/mongod --config /home/mongodb/mongo-One.cfg
PIDFile=/var/run/mongodb/mongod.pid
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings
[Install]
WantedBy=multi-user.target
pi@raspberrypi:~ $
这是出现问题的时候。
首先,我们可以通过运行以下命令来检查 mongod-One 服务是否在系统启动期间没有启动,正如它应该启动的那样。
pi@raspberrypi:~ $ systemctl status mongod-One
● mongod-One.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod-One.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2021-03-20 12:51:15 JST; 3min 50s ago
Docs: https://docs.mongodb.org/manual
Process: 534 ExecStart=/usr/bin/mongod --config /home/mongodb/mongo-One.cfg (code=exited, status=48)
Main PID: 534 (code=exited, status=48)
Mar 20 12:51:14 raspberrypi systemd[1]: Started MongoDB Database Server.
Mar 20 12:51:15 raspberrypi systemd[1]: mongod-One.service: Main process exited, code=exited, status=48/n/a
Mar 20 12:51:15 raspberrypi systemd[1]: mongod-One.service: Failed with result 'exit-code'.
pi@raspberrypi:~ $
接下来进一步看,这里是日志文件内容:
root@raspberrypi:~ # cat /mnt/mongoDB-One/DB_Data/mongod.log
{"t":{"$date":"2021-03-20T12:51:15.782+09:00"},"s":"I", "c":"CONTROL", "id":23285, "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2021-03-20T12:51:15.838+09:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-03-20T12:51:15.839+09: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-03-20T12:51:15.842+09:00"},"s":"W", "c":"ASIO", "id":22601, "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2021-03-20T12:51:15.846+09:00"},"s":"I", "c":"STORAGE", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":534,"port":22330,"dbPath":"/mnt/mongoDB-One/DB_Data","architecture":"64-bit","host":"raspberrypi"}}
{"t":{"$date":"2021-03-20T12:51:15.847+09:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.4","gitVersion":"8db30a63db1a9d84bdcad0c83369623f708e0397","openSSLVersion":"OpenSSL 1.1.1d 10 Sep 2019","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu1804","distarch":"aarch64","target_arch":"aarch64"}}}}
{"t":{"$date":"2021-03-20T12:51:15.847+09:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"PRETTY_NAME=\"Debian GNU/Linux 10 (buster)\"","version":"Kernel 5.10.17-v8+"}}}
{"t":{"$date":"2021-03-20T12:51:15.847+09:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"config":"/home/mongodb/mongo-One.cfg","net":{"bindIp":"localhost,192.168.10.116","port":22330},"replication":{"replSetName":"mngoRepSet"},"storage":{"dbPath":"/mnt/mongoDB-One/DB_Data","journal":{"enabled":true}},"systemLog":{"destination":"file","logAppend":true,"path":"/mnt/mongoDB-One/DB_Data/mongod.log"}}}}
{"t":{"$date":"2021-03-20T12:51:15.862+09:00"},"s":"E", "c":"STORAGE", "id":20568, "ctx":"initandlisten","msg":"Error setting up listener","attr":{"error":{"code":9001,"codeName":"SocketException","errmsg":"Cannot assign requested address"}}}
{"t":{"$date":"2021-03-20T12:51:15.863+09:00"},"s":"I", "c":"REPL", "id":4784900, "ctx":"initandlisten","msg":"Stepping down the ReplicationCoordinator for shutdown","attr":{"waitTimeMillis":10000}}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I", "c":"COMMAND", "id":4784901, "ctx":"initandlisten","msg":"Shutting down the MirrorMaestro"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I", "c":"SHARDING", "id":4784902, "ctx":"initandlisten","msg":"Shutting down the WaitForMajorityService"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I", "c":"NETWORK", "id":4784905, "ctx":"initandlisten","msg":"Shutting down the global connection pool"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I", "c":"REPL", "id":4784907, "ctx":"initandlisten","msg":"Shutting down the replica set node executor"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I", "c":"NETWORK", "id":4784918, "ctx":"initandlisten","msg":"Shutting down the ReplicaSetMonitor"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I", "c":"SHARDING", "id":4784921, "ctx":"initandlisten","msg":"Shutting down the MigrationUtilExecutor"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I", "c":"CONTROL", "id":4784925, "ctx":"initandlisten","msg":"Shutting down free monitoring"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I", "c":"STORAGE", "id":4784927, "ctx":"initandlisten","msg":"Shutting down the HealthLog"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I", "c":"STORAGE", "id":4784929, "ctx":"initandlisten","msg":"Acquiring the global lock for shutdown"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I", "c":"-", "id":4784931, "ctx":"initandlisten","msg":"Dropping the scope cache for shutdown"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I", "c":"FTDC", "id":4784926, "ctx":"initandlisten","msg":"Shutting down full-time data capture"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I", "c":"CONTROL", "id":20565, "ctx":"initandlisten","msg":"Now exiting"}
{"t":{"$date":"2021-03-20T12:51:15.878+09:00"},"s":"I", "c":"CONTROL", "id":23138, "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":48}}
root@raspberrypi:~ #
问题当然是:为什么mongod-One服务没有按预期启动?
日志中显示的错误似乎表明发生错误时 IP 地址不可用,但查看服务文件设置不应发生这种情况。
这里还有一条信息可能有用:
如果我使用这个命令,在启动结束后,手动启动服务,那么它就可以工作了。
root@raspberrypi:~ # systemctl start mongod-One
我也能够对其他服务器(所有服务器都有相同的问题)执行相同的操作,并最终初始化一个副本集。
在网上搜索显示了一些类似的问题,但没有找到解决方案。