# CrowdSec 卸载

## CrowdSec + Firewall Bouncer 完整卸载指南（干净版）

##### 适用场景

同时存在：

- apt 安装（如 crowdsec, crowdsec-firewall-bouncer-nftables）
- 手动安装（install.sh / 二进制复制）

出现问题：

- 多路径二进制（/usr/bin、/usr/local/bin、/usr/sbin）
- 服务启动失败
- bouncer 未注册 / 配置丢失

{{< steps >}}
{{< step >}}

**停止所有相关服务**

```bash
systemctl stop crowdsec 2>/dev/null
systemctl stop crowdsec-firewall-bouncer 2>/dev/null

systemctl disable crowdsec 2>/dev/null
systemctl disable crowdsec-firewall-bouncer 2>/dev/null
```

{{< /step >}}
{{< step >}}

**卸载 apt 安装（核心）**

```bash
apt purge crowdsec crowdsec-firewall-bouncer-nftables -y
apt autoremove -y
```

{{< /step >}}
{{< step >}}

**查找所有副本**

```bash
whereis crowdsec
whereis crowdsec-firewall-bouncer
```

或更彻底：

```bash
find / -name "crowdsec*" 2>/dev/null
```

{{< /step >}}
{{< step >}}

**删除所有可能路径（非常关键）**

```bash
rm -f /usr/bin/crowdsec
rm -f /usr/local/bin/crowdsec

rm -f /usr/bin/cscli
rm -f /usr/local/bin/cscli

rm -f /usr/bin/crowdsec-firewall-bouncer
rm -f /usr/local/bin/crowdsec-firewall-bouncer
rm -f /usr/sbin/crowdsec-firewall-bouncer
```

{{< /step >}}
{{< step >}}

**删除所有配置 / 数据 / 日志**

```bash
rm -f /etc/systemd/system/crowdsec.service
rm -f /etc/systemd/system/crowdsec-firewall-bouncer.service

rm -f /lib/systemd/system/crowdsec.service
rm -f /lib/systemd/system/crowdsec-firewall-bouncer.service

systemctl daemon-reload
```

{{< /step >}}
{{< step >}}

**删除 systemd 残留**

```bash
rm -f /etc/systemd/system/crowdsec.service
rm -f /etc/systemd/system/crowdsec-firewall-bouncer.service

rm -f /lib/systemd/system/crowdsec.service
rm -f /lib/systemd/system/crowdsec-firewall-bouncer.service

systemctl daemon-reload
```

{{< /step >}}
{{< step >}}

**清理 CrowdSec 内部注册（如仍存在）**

```bash
cscli bouncers list
```

如果还有：

```bash
cscli bouncers delete firewall-bouncer
```
如果 `cscli` 已删除，这步可以跳过

{{< /step >}}
{{< step >}}

清理防火墙规则(非常重要)

{{< tabs "firewall" >}}
{{< tab "nftables" >}}

```bash
nft list ruleset | grep crowdsec
```

如果存在：

```bash
nft delete table ip crowdsec
```

{{< /tab >}}
{{< tab "IPtables" >}}

```bash
iptables -L | grep crowdsec
```

清理：

```bash
iptables -F crowdsec
iptables -X crowdsec
```

{{< /tab >}}
{{< /tabs >}}

{{< /step >}}
{{< step >}}

**最终"干净状态验证"（必须全部通过）**

**无任何二进制**

```bash
which crowdsec
which cscli
which crowdsec-firewall-bouncer
```

预期结果: 无输出

---

**无 apt 包**

```
dpkg -l | grep crowdsec
```

预期结果: 无输出

---

**无服务**

```bash
systemctl status crowdsec
systemctl status crowdsec-firewall-bouncer
```

预期结果: Unit not found

---

**无目录**
```bash
ls /etc/crowdsec
```

预期结果:

```
No such file or directory
```

---

**无 API 端口**

```bash
ss -lntp | grep 8080
```

预期结果:无输出

---

**无防火墙规则**

```bash
nft list ruleset | grep crowdsec
```

预期结果:无输出

{{< /step >}}
{{< /steps >}}