meta-balena:实践指南
2026-09-12
2026-09-12 0
准备试用picosnitch之前,先别急着安装;这个项目提供的是监视每个可执行文件的网络流量。从日常自动化的使用方式看,输入边界、依赖和失败处理如果不清楚就很难稳定复用是采用前必须回答的问题。我建议用一项范围明确的真实任务完成最小试跑,重点记录配置时间、输出质量、异常信息和维护痕迹,再与现有方案比较。对愿意先做小范围验证并复查原始文档的团队来说,这个仓库值得继续验证;只求即装即用的人则要先看维护成本。

Picosnitch
|
picosnitch webui browse and chart past connections |
picosnitch tui browse past connections in a terminal |
picosnitch top live event feed |
More 屏幕截图和 picosnitch 屏幕截图 gallery. 中的简短演示视频
安装
建议安装系统范围的 pipx 安装。它适用于 Python >= 3.12 的每个 Linux 发行版,并且内核足够新,可以运行现代 libbpf CO-RE 程序。
sudo pipx install picosnitch --global
sudo picosnitch systemd
sudo systemctl enable --now picosnitch
pipx >= 1.5.0(这是添加 --global 标志时的情况);如果您还没有,请参阅 pipx 安装sudo picosnitch systemd 写入 /usr/lib/systemd/system/picosnitch.servicesudo pipx install 'picosnitch[sql]' --global 安装可选的 MariaDB / MySQL / PostgreSQL 驱动程序,用于 远程日志记录用途
sudo systemctl启用|禁用 picosnitch:重新启动时自动启动
-sudo systemctl启动|停止|重新启动 picosnitch:守护进程生命周期
sudo picosnitch start|停止|重新启动sudo picosnitch start-no-daemonpicosnitch webui:用于浏览过去连接的网页 UI
PICOSNITCH_HOST / PICOSNITCH_PORT 环境变量覆盖picosnitch tui:用于浏览过去连接的终端UIsudo picosnitch top:实时事件源(需要 root 来读取守护进程的事件套接字;如果守护进程未运行,则启动和停止其自己的守护进程)picosnitch status:显示守护进程pid和systemd服务状态picosnitch help:完全使用配置
配置存储在 /etc/picosnitch/config.toml 中,并在首次运行时使用默认值创建。
[database]
enabled = true # write connection logs to /var/lib/picosnitch/picosnitch.db (SQLite)
retention_days = 30 # how many days to keep connection logs in the local database
# (the remote database is append-only; see [database.remote])
write_limit_seconds = 10 # minimum time between connection log entries
# increasing it groups traffic into larger time windows, decreasing
# disk writes, time precision, and database size
text_log = false # also write a CSV connection log to /var/log/picosnitch/conn.log
[database.remote] # optional: also write connection logs to an external SQL server
# used for off-system / tamper-evident logs (see Logging below).
# mirrors the local SQLite schema (connections, executables,
# domains, addresses).
# set `client` to "mariadb", "psycopg", "psycopg2", or "pymysql";
# add the rest of the connection parameters as key/value pairs and
# optionally `connections_table` to override the default; this lets
# multiple hosts share one server with a `connections` table each
# while reusing the shared `executables`/`domains`/`addresses`
[data]
owner = "root" # owner for files in /var/lib/picosnitch, /var/log/picosnitch,
group = "root" # and /var/cache/picosnitch
mode = "0644" # mode applied to those files (directories add execute bits)
# config.toml stays root:root 0600 because it can contain credentials
[log]
addresses = true # log remote addresses for each connection
commands = true # log command line args for each executable
ports = true # log local and remote ports for each connection
ignore_ports = [] # list of ints; matching connections are omitted from the log
ignore_domains = [] # list of strings in reverse-dns notation (matches all subdomains)
ignore_ips = [] # list of IPs/CIDRs (e.g. "192.168.0.0/16")
ignore_sha256 = [] # list of executable sha256 hashes
# the process name, executable, and hash are still recorded
[desktop]
user = "" # username to send notifications to; defaults to $SUDO_UID
notifications = true # show desktop notifications via notify-send (libnotify)
geoip_lookup = true # annotate remote addresses with a country code in the TUI/webui
# uses the DB-IP Country Lite CSV cached under /var/cache/picosnitch
[monitoring]
every_exe = false # check every running executable, not just ones that open sockets
# these are treated as "connections" with a port of -1
# experimental; expect occasional errors for short-lived processes
# if you only want process logs (no hashes), see execsnoop / forkstat
exec_ring_buffer_pages = 256 # power of two pages sizing the exec event ring buffer
# network traffic is aggregated in-kernel, it does not use this
# only change this if you are seeing missed-event errors
conn_map_max_entries = 65536 # size of the in-kernel per-connection aggregation map
# only raise this if you see near-capacity eviction warnings
# rlimit_nofile = 65536 # optional int; raises RLIMIT_NOFILE for the daemon
# picosnitch caches one file descriptor per (device, inode);
# set this if you see "Too many open files" errors
# st_dev_mask = 0 # optional int; masks the device number reported for opened fds
# auto-detected at startup; only set this to override the default
# for filesystems that reuse inodes across subvolumes (e.g. btrfs)
[virustotal]
api_key = "" # VirusTotal API key, leave blank to disable
file_upload = false # upload the executable when its hash isn't already known
# leave false to only submit hashes
request_limit_seconds = 15 # seconds between requests (free-tier quota)
重新启动 picosnitch 以使任何配置更改生效。
日志记录
Picosnitch 将其磁盘状态划分到 FHS 目录中。所有默认值均采用 systemd 单元(该单元也在首次启动时创建这些单元)。
| 路径 | 内容 |
|---|---|
/etc/picosnitch/config.toml |
配置 |
/var/lib/picosnitch/picosnitch.db |
SQLite 连接日志(由 picosnitch tui 和 picosnitch webui 读取) |
/var/lib/picosnitch/state.json |
已知的可执行文件 + sha256 哈希值,用于决定何时通知 |
/var/log/picosnitch/exe.log |
新可执行通知的历史记录 |
/var/log/picosnitch/error.log |
错误(也作为桌面通知出现) |
/var/log/picosnitch/conn.log |
可选 CSV 连接日志(通过 [database].text_log = true 启用) |
/var/cache/picosnitch/ |
DB-IP Country Lite 数据库,每月刷新 |
/run/picosnitch/picosnitch.pid |
pid 文件(世界可读,由 picosnitch status 使用) |
/run/picosnitch/events.sock |
picosnitch top 消耗的实时事件套接字 |
[database.remote] 可用于另外将每个连接传送到 MariaDB、MySQL 或 PostgreSQL 服务器。它镜像本地 SQLite 架构(connections、executables、domains、addresses);仅 connections 表名可以被覆盖(通过 connections_table),这允许多个主机共享一台服务器,每个服务器都有一个 connections 表,同时重用共享引用表。 Picosnitch 从不更新或删除远程行(不保留,不进行垃圾收集),因此它旨在保留日志 的系统外副本 [;仅授予 CREATE(首次运行)、INSERT 和 SELECT(id 查找),以便受监控主机上的对手无法重写或删除 picosnitch 的系统外日志。
如果现有远程 executables 表缺少 key_hash 列,则守护程序会报告过时的架构并保持不变;备份并重新创建远程表以启用远程日志记录。
conn.log 是一个 CSV,具有以下字段(逗号、换行符、回车符和 NUL 字符从值中删除):entry time, sent bytes, received bytes, event count, executable path, process name, cmdline, sha256, parent executable, parent name, parent cmdline, parent sha256, grandparent executable, grandparent name, grandparent cmdline, grandparent sha256, user id, address family, protocol, local port, remote port, local address, remote address, domain, network namespace。
error.log 中的条目通常由异常大量的新进程或连接触发,由在 picosnitch 可以打开文件描述符之前退出的极其短暂的进程触发,或者在对新的可执行文件进行哈希处理时挂起系统。意外的条目值得调查,因为 picosnitch 的设计目的是在进程偏离其正常观察路径时显示错误。
限制
[database.remote] 作为连接日志的系统外副本,并考虑使用单独的 router/firewall 进行确认。st_dev_mask = 0)。error.log 中的条目。[monitoring].exec_ring_buffer_pages 来缓解。相反,大量新连接会填满内核聚合映射,通过提高 [monitoring].conn_map_max_entries 可以缓解这种情况。