输入sudo systemctl status ssh后提示System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down
时间: 2023-06-13 21:06:49 浏览: 304
这个错误提示意味着你的系统没有使用systemd作为初始化进程。systemd是现代Linux系统的默认初始化系统。这通常会在较旧的系统上发生,或者在使用非标准的系统配置时发生。
在这种情况下,你可以尝试使用以下命令来查看SSH服务是否正在运行:
```
service ssh status
```
如果SSH服务正在运行,你应该看到服务的状态报告。如果服务未运行,你可以使用以下命令启动它:
```
service ssh start
```
如果你的系统使用的不是systemd,请确保使用正确的命令来管理系统服务。
相关问题
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
### 启动 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>
```
---
###
sudo systemctl start ssh 显示System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down
### 错误原因分析
在非 `systemd` 初始化系统的环境中运行 `systemctl` 命令时,会出现类似于 “System has not been booted with systemd as init system (PID 1)” 的错误消息[^1]。这是因为 `systemctl` 是专门为基于 `systemd` 的系统设计的工具,在其他初始化系统(如 `sysvinit`, `upstart` 或容器环境中的简化初始化进程)下无法正常工作。
当尝试在一个不支持 `systemd` 的环境下执行 `systemctl start ssh` 这样的操作时,由于缺少必要的 `systemd` 组件和服务总线连接,命令会失败并抛出上述错误信息[^2]。
---
### 解决方案
#### 方法一:切换到兼容的传统服务管理方式
如果当前操作系统使用的是传统初始化系统(例如 `SysVInit`),可以通过以下方法启动 SSH 服务:
```bash
service ssh start
```
此命令适用于大多数未采用 `systemd` 的 Linux 发行版,并通过调用 `/etc/init.d/ssh` 脚本来完成服务控制[^5]。
#### 方法二:手动启动 SSH 守护程序
可以直接运行 OpenSSH Server 提供的服务守护进程来绕过依赖于特定初始化框架的操作:
```bash
/usr/sbin/sshd
```
这种方式无需任何额外配置即可立即激活 SSH 服务器功能[^3]。
#### 方法三:修改 Docker 启动参数以启用完整的 Init 系统
对于运行在 Docker 容器内的场景,默认情况下容器不会继承宿主机完整的初始化流程,因此也无法直接利用 `systemd` 功能。要解决这一限制,可以调整创建容器时的相关选项允许其模拟 PID=1 行为以及加载对应单元文件的支持:
```bash
docker run --privileged -it --rm \
-v /sys/fs/cgroup:/sys/fs/cgroup:ro \
your_image_name bash
```
之后再安装必要软件包重新构建镜像或者进入交互模式测试效果如何改善了原有状况[^4]。
注意这种方法增加了资源消耗同时也可能带来安全风险,请谨慎评估实际需求后再决定是否采纳该策略。
---
### 注意事项
尽管存在多种途径能够缓解此类问题带来的困扰,但从长远来看建议尽量保持基础架构一致性以便维护便利性和稳定性考虑;另外针对某些特殊定制化场合则需权衡利弊做出最佳抉择。
阅读全文
相关推荐














