IRC 服务器搭建完全指南 / 第 2 章:服务器软件安装
第 2 章:服务器软件安装
选对服务端软件是成功的一半。本章对比三大主流 IRC 服务端,并提供详细的安装步骤。
2.1 主流服务端对比
2.1.1 概览
| 特性 | UnrealIRCd 6 | InspIRCd 4 | Ergo 2.x |
|---|---|---|---|
| 开发语言 | C | C++ | Go |
| 许可证 | GPL-2.0 | GPL-2.0 | MIT |
| IRCv3 支持 | 良好 | 良好 | 优秀 |
| 内置服务 | ❌ 需要 Anope/Atheme | ❌ 需要 Anope/Atheme | ✅ 内置 |
| 配置格式 | 自定义 + YAML | XML + YAML | YAML |
| 模块系统 | C 模块 | C++ 模块 | Go 原生 |
| 内存占用 | ~20MB | ~30MB | ~15MB |
| 适用场景 | 中大型网络 | 大型网络/灵活需求 | 小型网络/快速部署 |
| 文档质量 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
| 社区活跃度 | 高 | 高 | 中等 |
| TLS 支持 | ✅ | ✅ | ✅ |
| WebSocket | ✅ | ✅ | ✅ |
2.1.2 选型建议
你是新手,想要快速上手?
├── 是 → Ergo(内置服务,零依赖,5 分钟上手)
└── 否 → 你需要多服务器互联?
├── 是 → InspIRCd(模块化设计,适合大型网络)
└── 否 → 你需要丰富的第三方模块?
├── 是 → UnrealIRCd(生态系统最成熟)
└── 否 → Ergo(轻量现代)
2.2 Ergo 安装
Ergo(原名 Oragono)是用 Go 编写的现代 IRC 服务端,内置 NickServ、ChanServ 等服务,非常适合快速部署。
2.2.1 系统准备
# 更新系统(Debian/Ubuntu)
sudo apt update && sudo apt upgrade -y
# 安装基础工具
sudo apt install -y curl wget unzip
# 创建 IRC 用户(安全最佳实践)
sudo useradd -r -m -s /bin/bash ergo
sudo su - ergo
2.2.2 下载与安装
# 进入工作目录
cd /home/ergo
# 下载最新版本(以 2.14.0 为例,请检查最新版本)
VERSION="2.14.0"
curl -LO "https://github.com/ergochat/ergo/releases/download/v${VERSION}/ergo-${VERSION}-linux-amd64.zip"
# 解压
unzip "ergo-${VERSION}-linux-amd64.zip"
cd ergo-${VERSION}-linux-amd64
# 验证文件
ls -la
# 应该看到: ergo ergo.yaml docs/ languages/ ...
2.2.3 初始化配置
# 生成默认配置文件
./ergo initdb
# 编辑主配置文件
nano ergo.yaml
最小可用配置 (ergo.yaml 关键部分):
# 服务器网络信息
network:
name: "MyIRCNet"
server:
name: "irc.example.com"
# 密码(可选,用于服务器互联)
# password: "$argon2id$..."
listeners:
# 标准 IRC 端口
"127.0.0.1:6667":
# 生产环境建议只监听 TLS
# TLS 端口
":6697":
tls:
cert: "/home/ergo/certs/server.crt"
key: "/home/ergo/certs/server.key"
# WebSocket 端口(可选)
":8080":
websocket: true
# 数据库
datastore:
path: "ircd.db"
# 日志
logging:
- method: "file"
filename: "ircd.log"
level: "info"
# 注册账户的限制
accounts:
registration:
enabled: true
cooldown: "24h"
# 频道设置
channels:
defaultModes: "+nt"
2.2.4 生成自签名 TLS 证书
# 创建证书目录
mkdir -p /home/ergo/certs
# 生成自签名证书(测试用)
openssl req -x509 -newkey rsa:4096 \
-keyout /home/ergo/certs/server.key \
-out /home/ergo/certs/server.crt \
-days 365 -nodes \
-subj "/CN=irc.example.com"
# 设置权限
chmod 600 /home/ergo/certs/server.key
chmod 644 /home/ergo/certs/server.crt
2.2.5 启动与测试
# 前台启动(测试)
./ergo run
# 后台启动
nohup ./ergo run > /dev/null 2>&1 &
# 测试连接(使用 weechat 或命令行)
# 如果安装了 irssi:
irssi -c localhost -p 6697 --ssl
2.2.6 创建 systemd 服务
# /etc/systemd/system/ergo.service
[Unit]
Description=Ergo IRC Server
After=network.target
[Service]
Type=simple
User=ergo
Group=ergo
WorkingDirectory=/home/ergo/ergo-2.14.0-linux-amd64
ExecStart=/home/ergo/ergo-2.14.0-linux-amd64/ergo run
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
# 启用并启动
sudo systemctl daemon-reload
sudo systemctl enable ergo
sudo systemctl start ergo
# 查看状态
sudo systemctl status ergo
sudo journalctl -u ergo -f
2.3 UnrealIRCd 安装
UnrealIRCd 是最流行的 IRC 服务端之一,功能丰富,模块生态成熟。
2.3.1 从包管理器安装(推荐)
# Debian/Ubuntu - 添加 UnrealIRCd 官方仓库
curl https://www.unrealircd.org/downloads/packages.asc | sudo apt-key add -
echo "deb https://www.unrealircd.org/downloads/Linux/deb stable main" | \
sudo tee /etc/apt/sources.list.d/unrealircd.list
sudo apt update
sudo apt install unrealircd
2.3.2 从源码编译
# 安装编译依赖
sudo apt install -y build-essential libssl-dev libcurl4-openssl-dev \
libpcre3-dev zlib1g-dev libtre-dev
# 下载源码
VERSION="6.1.4"
cd /tmp
wget "https://www.unrealircd.org/downloads/UnrealIRCd-${VERSION}.tar.gz"
tar xzf "UnrealIRCd-${VERSION}.tar.gz"
cd "UnrealIRCd-${VERSION}"
# 配置(指定安装目录)
./configure --prefix=/home/unrealircd/unrealircd
# 编译
make -j$(nproc)
# 安装
make install
2.3.3 UnrealIRCd 配置
# 进入配置目录
cd /home/unrealircd/unrealircd/conf
# 复制示例配置
cp examples/example.conf unrealircd.conf
# 编辑配置
nano unrealircd.conf
最小配置示例 (unrealircd.conf):
/* 服务器基本信息 */
me {
name "irc.example.com";
info "My IRC Server";
sid "001";
}
/* 管理员信息 */
admin {
"Alice";
"alice [email protected]";
};
/* 监听端口 */
listen {
ip *;
port 6667;
options { clients; }
}
listen {
ip *;
port 6697;
options { clients; tls; }
}
/* TLS 配置 */
tls {
certificate "/home/unrealircd/unrealircd/conf/tls/server.crt";
key "/home/unrealircd/unrealircd/conf/tls/server.key";
protocols "TLSv1.2 TLSv1.3";
ciphers "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384";
}
/* 网络信息 */
network {
name "MyIRCNet";
default-server 127.0.0.1;
services-server "services.example.com";
}
/* 操作类(权限组) */
operclass netadmin {
permissions {
chat;
channel;
client;
immune;
kill;
mass;
server;
misc;
route;
}
};
/* 管理员账户 */
oper alice {
class clients;
operclass netadmin;
password "$argon2id$..."; /* 使用 ./unrealircd mkpasswd 生成 */
mask { *@127.0.0.1; *@192.168.1.0/24; };
vhost staff.example.com;
swhois "Server Administrator";
}
/* 允许连接 */
allow {
mask *@*;
class clients;
maxperip 3;
}
/* 频道设置 */
set {
kline-address "[email protected]";
modes-on-join "+nt";
modef-default-unsettime 10;
}
2.3.4 UnrealIRCd 启动
# 验证配置
/home/unrealircd/unrealircd/unrealircd start -check
# 启动
/home/unrealircd/unrealircd/unrealircd start
# 查看日志
tail -f /home/unrealircd/unrealircd/logs/unrealircd.log
2.4 InspIRCd 安装
InspIRCd 以模块化设计著称,每个功能都是独立模块,适合需要高度定制的场景。
2.4.1 从包管理器安装
# Debian/Ubuntu
sudo apt install inspircd
# 或使用官方仓库获取最新版本
curl -sL https://repos.inspircd.org/keys.asc | sudo apt-key add -
echo "deb [arch=amd64] https://repos.inspircd.org/debian stable main" | \
sudo tee /etc/apt/sources.list.d/inspircd.list
sudo apt update
sudo apt install inspircd
2.4.2 从源码编译
# 安装依赖
sudo apt install -y build-essential pkg-config \
libssl-dev libgnutls28-dev libmysqlclient-dev
# 克隆源码
git clone https://github.com/inspircd/inspircd.git
cd inspircd
git checkout v4.0.0 # 选择稳定版本
# 配置
./configure --prefix=/opt/inspircd --enable-extras=m_ssl_openssl
# 编译与安装
make -j$(nproc)
make install
2.4.3 InspIRCd 配置
InspIRCd 使用 XML 格式的配置文件:
<!-- /opt/inspircd/conf/inspircd.conf -->
<!-- 服务器信息 -->
<server name="irc.example.com"
description="My IRC Server"
id="001"
network="MyIRCNet">
<!-- 管理员信息 -->
<admin name="Alice"
nick="Alice"
email="[email protected]">
<!-- 绑定端口 -->
<bind address="0.0.0.0"
port="6667"
type="clients">
<bind address="0.0.0.0"
port="6697"
type="clients"
ssl="openssl">
<!-- TLS 配置 -->
<openssl certfile="/opt/inspircd/conf/certs/server.crt"
keyfile="/opt/inspircd/conf/certs/server.key"
min="tls1.2">
<!-- 性能配置 -->
<performance netbuffersize="10240"
somaxconn="128"
softlimit="1024"
quietbursts="yes"
nouserdns="no">
<!-- 日志配置 -->
<log method="file"
type="*"
level="default"
target="/opt/inspircd/logs/ircd.log">
<!-- 允许连接 -->
<allow pattern="*"
timeout="3"
flood="20"
threshold="1"
pingfreq="120"
sendq="262144"
recvq="8192"
localmax="3"
globalmax="5">
<!-- 加载模块 -->
<module name="ssl_openssl">
<module name="sasl">
<module name="cap">
<module name="ircv3">
<module name="server_time">
<module name="websocket">
2.4.4 InspIRCd systemd 服务
# /etc/systemd/system/inspircd.service
[Unit]
Description=InspIRCd Internet Relay Chat Server
After=network.target
[Service]
Type=forking
User=inspircd
ExecStart=/opt/inspircd/bin/inspircd start
ExecStop=/opt/inspircd/bin/inspircd stop
ExecReload=/opt/inspircd/bin/inspircd reload
PIDFile=/opt/inspircd/data/inspircd.pid
Restart=on-failure
[Install]
WantedBy=multi-user.target
2.5 服务端管理基础
2.5.1 常用管理命令
所有服务端通用的 IRC 管理命令:
# 重载配置
/REHASH # UnrealIRCd
/RELOAD # InspIRCd
/DIE # 关闭服务器(危险!)
# 查看连接信息
/ADMIN # 查看管理员信息
/MOTD # 查看每日消息
/LUSERS # 查看在线用户统计
/LINKS # 查看服务器互联拓扑
2.5.2 日志查看
# UnrealIRCd
tail -f /home/unrealircd/unrealircd/logs/unrealircd.log
# InspIRCd
tail -f /opt/inspircd/logs/ircd.log
# Ergo
tail -f /home/ergo/ergo-2.14.0-linux-amd64/ircd.log
# systemd 管理的服务
sudo journalctl -u ergo -f
sudo journalctl -u inspircd -f
sudo journalctl -u unrealircd -f
2.5.3 验证安装
安装完成后,用以下步骤验证:
# 1. 检查端口监听
ss -tlnp | grep -E '6667|6697'
# 2. 使用 netcat 测试 TCP 连接
echo "NICK test" | nc -w 5 localhost 6667
# 3. 使用 openssl 测试 TLS
openssl s_client -connect localhost:6697
# 4. 使用 IRC 客户端连接
weechat
/server add myirc localhost/6697 -ssl
/connect myirc
2.6 ⚠️ 注意事项
| 事项 | 说明 |
|---|---|
| 防火墙 | 确保开放 6667/TCP 和 6697/TCP 端口 |
| 用户隔离 | 不要用 root 运行 IRC 服务端 |
| TLS 优先 | 生产环境应强制使用 TLS(6697),禁用明文(6667) |
| 版本选择 | 始终使用最新稳定版,关注安全公告 |
| 配置备份 | 修改配置前先备份原始文件 |
| 资源限制 | 使用 ulimit 或 systemd 限制最大连接数 |
# 防火墙配置示例(ufw)
sudo ufw allow 6697/tcp comment "IRC TLS"
sudo ufw allow 6667/tcp comment "IRC plaintext"
sudo ufw allow 8080/tcp comment "IRC WebSocket"
# 资源限制(/etc/security/limits.conf)
ergo soft nofile 65536
ergo hard nofile 65536
扩展阅读
下一章: 第 3 章:核心配置详解 — 深入理解配置文件结构,掌握端口监听、服务器信息、管理员权限等核心配置。