萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

Leafnode 架設個人 Usenet 新聞伺服器完整教學

為什麼選擇 Leafnode?

完整新聞伺服器 (INN, CNews) 功能過剩、設定複雜、資源佔用大。Leafnode 專為單機/小型站點設計:

  • 極輕量 (二進位 < 200KB)、設定簡單 (單一設定檔)。
  • 離線閱讀優化:只下載訂閱群組、文章過期自動清理。
  • 標準 NNTP 協定,相容所有新聞閱讀軟體 (slrn, tin, knode, Thunderbird, Pan...)。
  • 不適合:高流量站點、多伺服器叢集、需完整 Usenet 存檔。

安裝部署步驟 (v1.4+)

1. 取得與編譯

# 官網: 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)

2. 建立 news 使用者

id news || useradd -r -s /sbin/nologin -d /var/spool/news news

3. 設定檔 /etc/leafnode/config (或 /usr/lib/leafnode/config)

# 上游新聞伺服器 (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

4. 設定 NNTP 服務啟動方式

方案 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

5. 初始化群組清單

su -s /bin/bash -c "fetch" news
# 首次執行下載 active 清單,視群組數量與頻寬可能需數分鐘

6. 訂閱群組並下載文章

  1. 啟動新聞閱讀器 (slrn, tin, knode, Pan...)。
  2. 連線 localhost (或設定 NNTPSERVER=localhost 環境變數)。
  3. 訂閱欲閱讀群組,**並進入群組瀏覽** (Leafnode 依「進入群組」判斷興趣)。
  4. 再次執行 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 (輪詢/備援)。
  • 離線撰寫回覆: Leafnode 支援本地發文,上線時自動送出 (需設定 posthost)。
  • 跨機器共用: 區網其他機器設定 NNTPSERVER=leafnode-host 即可共用快取。
  • 備份/遷移: 備份 /var/spool/news/ (文章、interesting.groups、overview 索引)。

常見問題

問題解決
連線被拒檢查 inetd/xinetd/systemd socket 是否啟用、防火牆 119 埠、server 設定正確
fetch 失敗檢查上游伺服器位址、認證、網路連通、DNS
群組不更新未進入群組瀏覽、interesting.groups 無對應檔案、texpire 未執行
效能下降執行 texpire -w 重組概覽索引、檢查磁碟空間
copyright © 萬盛學電腦網 all rights reserved