字
字节笔记本
2026年2月22日
TinyIce:轻量级高性能 Icecast 流媒体服务器
TinyIce 是一个轻量级、高性能且安全的 Icecast2 兼容流媒体服务器,使用 Go 语言编写。它设计为自包含、易于部署,并为管理员和听众提供现代化的 Web 界面。
项目简介
TinyIce 由 DatanoiseTV 开发维护,截至目前在 GitHub 上已获得 231+ stars。该项目旨在解决传统流媒体服务器配置复杂、资源占用高的问题,提供了一个即开即用的音频直播解决方案。
核心特性
架构优势
- 海量并发支持:采用共享环形缓冲区架构,单个流可支持数十万听众,内存分配接近零
- 即时部署:单二进制文件,所有资源(模板、图标)内嵌
- 零配置安全:首次运行时自动生成唯一的安全凭证
- 多租户支持:创建多个管理员用户,每个用户只能管理自己的挂载点
高级功能
- 零停机更新:支持
SO_REUSEPORT,可在旧版本运行时启动新版本 - 流健康监控:实时检测下游丢包和缓冲区跳过,在仪表板显示健康百分比
- 即时启动:听众连接时接收 64KB 音频突发,消除传统服务器的"缓冲"延迟
- 边缘中继:从其他服务器拉取流,支持自动重连和流内 ICY 元数据解析
安全与监控
- 安全加固:Salted bcrypt 密码哈希、CSRF 保护、HTTP 资源加固
- 自动 HTTPS:内置 ACME (Let's Encrypt) 支持,零配置 SSL 证书
- 实时洞察:SSE 驱动的仪表板,硬件加速流量图表
- Prometheus 监控:内置指标端点和结构化日志
技术栈
- Go 1.21+:核心开发语言
- SQLite:播放历史数据持久化
- 纯 Go 转码器:MP3/Opus 格式支持,无需外部依赖
- SSE (Server-Sent Events):实时数据推送
- ACME 协议:自动 SSL 证书管理
安装指南
预构建二进制文件
bash
# 下载二进制文件(以 Linux amd64 为例)
curl -LJO "https://github.com/DatanoiseTV/tinyice/releases/latest/download/tinyice-linux-amd64"
curl -LJO "https://github.com/DatanoiseTV/tinyice/releases/latest/download/checksums.txt"
# 验证 SHA256 校验和
sha256sum tinyice-linux-amd64
# 安装到用户目录
mkdir -p ~/.local/bin
mv tinyice-linux-amd64 ~/.local/bin/tinyice
chmod +x ~/.local/bin/tinyice从源码构建
bash
# 需要 Go 1.21 或更高版本
go build -o tinyice快速开始
首次运行
bash
./tinyice首次运行时会自动生成配置文件 tinyice.json 和唯一的安全凭证:
text
FIRST RUN: SECURE CREDENTIALS GENERATED
Admin Password: your_admin_password_here
Default Source Password: your_source_password_here
Live Mount Password: your_livemount_password_here请务必保存这些密码!
开始流媒体传输
使用编码器(如 BUTT)配置:
- 服务器类型:Icecast 2
- 地址:your-server-ip
- 端口:8000
- 密码:[生成的源密码]
- 挂载点:/live
配置示例
json
{
"bind_host": "0.0.0.0",
"port": "8000",
"base_url": "https://radio.example.com",
"page_title": "TinyIce",
"page_subtitle": "Live Streaming Server powered by Go",
"use_https": true,
"auto_https": true,
"https_port": "443",
"acme_email": "admin@example.com",
"domains": ["radio.example.com"],
"max_listeners": 100,
"directory_listing": true,
"autodjs": [
{
"name": "24/7 Chill",
"mount": "/chill",
"music_dir": "/music/chill",
"format": "mp3",
"bitrate": 128,
"enabled": true,
"loop": true,
"mpd_enabled": true,
"mpd_port": "6600"
}
]
}高级功能
Auto-HTTPS (Let's Encrypt)
json
{
"use_https": true,
"auto_https": true,
"port": "80",
"https_port": "443",
"domains": ["radio.example.com"],
"acme_email": "admin@example.com"
}非 Root 用户绑定 80/443 端口 (Linux)
bash
sudo setcap 'cap_net_bind_service=+ep' ./tinyice
./tinyice -port 80 -https-port 443内置转码
TinyIce 包含纯 Go 转码器,可将单个输入流转码为多种格式/比特率:
- 128kbps MP3(桌面端)
- 64kbps Opus(移动端)
AutoDJ 自动化
- 多实例编排:在单个服务器上管理多个独立 AutoDJ
- 递归音乐库:支持整个目录树或特定曲目
- MPD 协议支持:每个实例可暴露专用 MPD 服务器
- 精确节奏控制:帧精确的比特流 pacing
播放器嵌入
html
<iframe
src="https://your-server.com/embed/<stream_name>"
width="100%"
height="80"
frameborder="0"
scrolling="no">
</iframe>监控与可观测性
Prometheus 指标
- 听众数:总数和每挂载点计数
- 吞吐量:进出字节数和丢包数
- 系统:内存使用、goroutine 数量、GC 统计、运行时间
Grafana 仪表板
示例配置位于仓库的 monitoring/ 目录:
grafana-dashboard.jsonprometheus.yml
典型应用场景
- 全球边缘分发:作为轻量级边缘节点卸载主工作室带宽
- 多 DJ 社区电台:在一台服务器上托管多个独立电台
- 私人家庭流媒体:在 Raspberry Pi 或家庭服务器上运行
- 自定义音频应用:利用 SSE 元数据和 JSON API 构建现代播放器
项目链接
- GitHub 仓库:https://github.com/DatanoiseTV/tinyice
- Go Report Card:https://goreportcard.com/report/github.com/DatanoiseTV/tinyice
- 许可证:Apache License 2.0
相关项目
- abletonlink-go - Ableton Link 音频流示例
分享: