sudo systemctl status mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down aidlux@localhost:~$ ps aux | grep mongod aidlux 3899 0.0 0.0 3740 416 pts/7 S<+ 2023 0:00 tail -f /var/log/mongodb/mongod.log aidlux 8241 0.0 0.0 4736 564 pts/9 S<+ 2023 0:00 grep --color=auto mongod aidlux@localhost:~$ sudo systemctl start mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is downsudo systemctl status mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down aidlux@localhost:~$ ps aux | grep mongod aidlux 3899 0.0 0.0 3740 416 pts/7 S<+ 2023 0:00 tail -f /var/log/mongodb/mongod.log aidlux 8241 0.0 0.0 4736 564 pts/9 S<+ 2023 0:00 grep --color=auto mongod aidlux@localhost:~$ sudo systemctl start mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is downsudo systemctl status mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down aidlux@localhost:~$ ps aux | grep mongod aidlux 3899 0.0 0.0 3740 416 pts/7 S<+ 2023 0:00 tail -f /var/log/mongodb/mongod.log aidlux 8241 0.0 0.0 4736 564 pts/9 S<+ 2023 0:00 grep --color=auto mongod aidlux@localhost:~$ sudo systemctl start mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is downsudo systemctl status mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down aidlux@localhost:~$ ps aux | grep mongod aidlux 3899 0.0 0.0 3740 416 pts/7 S<+ 2023 0:00 tail -f /var/log/mongodb/mongod.log aidlux 8241 0.0 0.0 4736 564 pts/9 S<+ 2023 0:00 grep --color=auto mongod aidlux@localhost:~$ sudo systemctl start mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is downsudo systemctl status mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down aidlux@localhost:~$ ps aux | grep mongod aidlux 3899 0.0 0.0 3740 416 pts/7 S<+ 2023 0:00 tail -f /var/log/mongodb/mongod.log aidlux 8241 0.0 0.0 4736 564 pts/9 S<+ 2023 0:00 grep --color=auto mongod aidlux@localhost:~$ sudo systemctl start mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is downsudo systemctl status mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down aidlux@localhost:~$ ps aux | grep mongod aidlux 3899 0.0 0.0 3740 416 pts/7 S<+ 2023 0:00 tail -f /var/log/mongodb/mongod.log aidlux 8241 0.0 0.0 4736 564 pts/9 S<+ 2023 0:00 grep --color=auto mongod aidlux@localhost:~$ sudo systemctl start mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is downsudo systemctl status mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down aidlux@localhost:~$ ps aux | grep mongod aidlux 3899 0.0 0.0 3740 416 pts/7 S<+ 2023 0:00 tail -f /var/log/mongodb/mongod.log aidlux 8241 0.0 0.0 4736 564 pts/9 S<+ 2023 0:00 grep --color=auto mongod aidlux@localhost:~$ sudo systemctl start mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is downsudo systemctl status mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down aidlux@localhost:~$ ps aux | grep mongod aidlux 3899 0.0 0.0 3740 416 pts/7 S<+ 2023 0:00 tail -f /var/log/mongodb/mongod.log aidlux 8241 0.0 0.0 4736 564 pts/9 S<+ 2023 0:00 grep --color=auto mongod aidlux@localhost:~$ sudo systemctl start mongod System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down
时间: 2025-07-04 21:03:13 浏览: 11
### 启动 MongoDB 服务而不使用 systemd 的方法
在某些环境中,如 Windows Subsystem for Linux(WSL),系统未使用 `systemd` 作为初始化系统,因此无法通过 `systemctl` 管理服务。在这种情况下,可以通过直接运行 MongoDB 的可执行文件来启动数据库服务。
#### 直接启动 MongoDB 进程
由于 WSL 没有使用 `systemd` 作为 PID 1,因此需要手动启动 MongoDB 进程[^1]。可以使用以下命令:
```bash
mongod --bind_ip 127.0.0.1 --port 27017 --dbpath /data/db --logpath /var/log/mongodb.log --fork
```
- `--bind_ip`:指定 MongoDB 监听的 IP 地址。
- `--port`:设置 MongoDB 使用的端口,默认为 27017。
- `--dbpath`:指定数据库存储路径,需确保该目录存在并具有写权限。
- `--logpath`:定义日志文件路径。
- `--fork`:以后台模式运行 MongoDB。
如果 `/data/db` 不存在,需要手动创建并赋予适当的权限:
```bash
sudo mkdir -p /data/db
sudo chown -R $USER /data/db
```
#### 验证 MongoDB 是否成功运行
使用 `ps` 命令检查 MongoDB 进程是否存在:
```bash
ps aux | grep mongod
```
如果看到类似如下输出,则表明 MongoDB 已经成功运行:
```
user 12345 0.1 0.2 123456 7890 ? Ssl 10:00 0:00 mongod --bind_ip 127.0.0.1 ...
```
#### 测试 MongoDB 连接
可以使用 `telnet` 或 `mongo` shell 来测试是否能够连接到 MongoDB:
```bash
telnet 127.0.0.1 27017
```
或者使用 MongoDB Shell:
```bash
mongosh "mongodb://localhost:27017"
```
#### 自动化脚本简化操作
为了方便重复启动 MongoDB,可以创建一个启动脚本 `start-mongo.sh`:
```bash
#!/bin/bash
# 创建数据目录(如果不存在)
mkdir -p /data/db
# 设置权限
chown -R $USER /data/db
# 启动 MongoDB
mongod --bind_ip 127.0.0.1 --port 27017 --dbpath /data/db --logpath /var/log/mongodb.log --fork
```
赋予脚本执行权限并运行:
```bash
chmod +x start-mongo.sh
./start-mongo.sh
```
#### 日志与故障排查
查看 MongoDB 日志可以帮助定位启动失败的原因:
```bash
tail -f /var/log/mongodb.log
```
如果出现错误信息如 `Address already in use`,可以尝试终止占用端口的进程:
```bash
lsof -i :27017
kill -9 <PID>
```
---
###
阅读全文
相关推荐

















