Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> Linux資訊 >> 更多Linux

動手做:在 xinetd 中註冊一項新服務

Red Hat Linux 7.0 改用 xinetd 來啟動部分守護進程,但相關資料不多,第一次設定時很容易摸不著頭緒。以下以 proFTPd 為例,把整個流程走一遍。

一、先看主設定檔

# cat /etc/xinetd.conf

內容大致如下:

defaults
{
    instances = 60
    log_type = SYSLOG authpriv
    log_on_success = HOST PID
    log_on_failure = HOST RECORD
}
includedir /etc/xinetd.d

defaults 段落定義全域預設值,通常不必更動。真正要留意的是最後一行:includedir /etc/xinetd.d——這代表各服務的個別設定檔都放在該目錄底下。

走進 /etc/xinetd.d 看一下,會看到 chargen、daytime、echo、finger、linuxconf-web、ntalk、rexec、rlogin、rsh、swat、talk、telnet、tftp、time 等現成的設定檔,每個對應一項服務。

二、事先調整 proFTPd 自身設定

在建立 xinetd 設定檔之前,先把 proftpd 本身的組態改好,需要動 /usr/local/etc/proftpd.conf 的兩處:

一、把 ServerType standalone 改成 ServerType inetd;
二、把 Group nogroup 改成 Group nobody。

第一行決定 proftpd 是「自己常駐」還是「由 xinetd 按需拉起」,不改的話兩邊會互相打架。

三、建立 /etc/xinetd.d/proftpd

以 root 身分在該目錄下編輯新檔 proftpd:

# default: on
# description: The proftpd server serves proftpd sessions
service proftpd
{
    disable = no
    port = 21
    socket_type = stream
    protocol = tcp
    user = root
    server = /usr/local/sbin/in.proftpd
    type = UNLISTED
    wait = no
}

逐行說明:前兩行是註解。service proftpd 定義服務名稱。disable = no 表示啟用(改成 yes 即停用)。port = 21 指定連接埠,若 proftpd.conf 裡改過埠號,這裡要同步。socket_type = stream 為串流式。protocol = tcp 指定協定。user = root 是啟動該服務的使用者。server 指向實際執行檔路徑。type = UNLISTED 表示這不是 /etc/services 中的標準服務,所以必須自訂 port。wait = no 表示不等啟動完成,立即接受下一個連線。

四、讓設定生效並驗證

存檔後執行:

# killall -HUP xinetd

送出 HUP 訊號讓 xinetd 重讀設定,不必重開機。接著試連:

# ftp localhost

能拿到登入提示就代表成功。若還是不行,回頭對照該目錄裡其他服務的設定檔,逐項比對 socket_type、user、server 這幾個容易出錯的欄位。

重點回顧

整個遷移過程,實質上就是把過去寫在 /etc/inetd.conf 裡的一行設定,拆成 /etc/xinetd.d/ 下的一個獨立檔案。服務一多,這種「一服務一檔」的組織方式反而更好維護,也能對單一服務做更細緻的連線數、存取來源與日誌控制。

Copyright © Linux教程網 All Rights Reserved