完整新聞伺服器 (INN, CNews) 功能過剩、設定複雜、資源佔用大。Leafnode 專為單機/小型站點設計:
# 官網: ftp://ftp.troll.no/pub/freebies/leafnode-1.4.tar.gz
tar xzf leafnode-1.4.tar.gz
cd leafnode-1.4
./configure && make && make install
# Debian/Ubuntu: apt install leafnode
# RHEL/CentOS: yum install leafnode (EPEL)
id news || useradd -r -s /sbin/nologin -d /var/spool/news news
# 上游新聞伺服器 (ISP 提供)
server = news.isp.com
# 可選:認證
# username = myuser
# password = mypass
# 文章過期天數 (全域)
expire = 7
# 個別群組過期 (可覆蓋全域)
# groupexpire comp.lang.python 14
# groupexpire alt.binaries.* 2
# 連接埠 (預設 119)
# port = 119
# 記錄檔
# logfile = /var/log/leafnode.log
方案 A:inetd/xinetd (傳統,按需啟動)
# /etc/inetd.conf
nntp stream tcp nowait news /usr/sbin/tcpd /usr/local/sbin/leafnode
# /etc/xinetd.d/leafnode
service nntp
{
disable = no
socket_type = stream
protocol = tcp
port = 119
user = news
server = /usr/local/sbin/leafnode
wait = no
}
方案 B:systemd socket activation (現代)
# /etc/systemd/system/leafnode.socket
[Unit]
Description=Leafnode NNTP Socket
[Socket]
ListenStream=119
Accept=yes
[Install]
WantedBy=sockets.target
# /etc/systemd/system/leafnode@.service
[Unit]
Description=Leafnode NNTP Service
[Service]
ExecStart=/usr/local/sbin/leafnode
User=news
StandardInput=socket
啟用:systemctl enable --now leafnode.socket
su -s /bin/bash -c "fetch" news
# 首次執行下載 active 清單,視群組數量與頻寬可能需數分鐘
localhost (或設定 NNTPSERVER=localhost 環境變數)。fetch 下載實際文章。# /etc/cron.d/leafnode (以 news 身份執行)
# 每天 19:00 清理過期文章
0 19 * * * news /usr/local/sbin/texpire
# 每小時下載新文章 (視需求調整)
0 * * * * news /usr/local/sbin/fetch
# 每週重組資料庫 (效能優化)
0 3 * * 0 news /usr/local/sbin/texpire -w
server = news.isp1.com, news.isp2.com (輪詢/備援)。posthost)。NNTPSERVER=leafnode-host 即可共用快取。/var/spool/news/ (文章、interesting.groups、overview 索引)。| 問題 | 解決 |
|---|---|
| 連線被拒 | 檢查 inetd/xinetd/systemd socket 是否啟用、防火牆 119 埠、server 設定正確 |
| fetch 失敗 | 檢查上游伺服器位址、認證、網路連通、DNS |
| 群組不更新 | 未進入群組瀏覽、interesting.groups 無對應檔案、texpire 未執行 |
| 效能下降 | 執行 texpire -w 重組概覽索引、檢查磁碟空間 |