---------------
服務主要分爲stand_alone和super daemon兩種。
stand_alone:常駐在內存中的進程,可以獨立被啓動,啓動方式: `/etc/init.d/... start`
super daemon:由統一的`xinetd`管理,如果有客戶端需要,再喚起相應服務,結束之後服務關閉釋放系統資源,
啓動方式: `/etc/init.d/xinetd start`
(一)例如:啓動rsync(備份)服務
[root@linuxclient ~]# vim /etc/xinetd.d/rsync
service rsync
{
disable = no #將這裏改成no,讓rsync服務啓動起來
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
[root@linuxclient ~]# /etc/init.d/xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[root@linuxclient ~]# netstat -tnlp|grep 873
tcp 0 0 :::873 :::* LISTEN 8020/xinetd
這裏PID後面的就是`xinetd`而不是`rsync`
(二)實驗:修改配置文件(/etc/services/rsync)
service rsync
{
disable = no
bind = 127.0.0.1 #這是將此服務綁定在這個接口上
only_from = 127.0.0.0/8 #只開放此網段的源登錄
no_access = 127.0.0.{100,200} #不允許這兩個網段登錄
instances = UNLIMITED #鏈接次數無限制
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
service rsync
{
disable = no
bind = 192.168.70.150
only_from = 140.116.0.0/16
only_from += .edu.tw #+=是在原來的基礎上又增加的
instances = 10 #只有10條連接
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
[root@linuxclient ~]# netstat -tnpl |grep 873
tcp 0 0 :::873 :::* LISTEN 8354/xinetd
[root@linuxclient ~]# /etc/init.d/xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[root@linuxclient ~]# netstat -tnpl |grep 873
tcp 0 0 192.168.70.150:873 0.0.0.0:* LISTEN 8438/xinetd
tcp 0 0 127.0.0.1:873 0.0.0.0:* LISTEN 8438/xinetd
其中遇到個問題,原來我的文件中有`flags=IPv6`結果就不成功,默認是`IPv4`
[root@linuxclient ~]# lsof -i :873
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
xinetd 9050 root 5u IPv4 117101 0t0 TCP localhost.localdomain:rsync (LISTEN)
xinetd 9050 root 6u IPv4 117102 0t0 TCP linuxclient.com:rsync (LISTEN)
除了更改配置文件以外,如果想將IP源或者某個域設置成不可訪問或僅能訪問,也可以在`/etc/hosts.deny`和`/etc/hosts.allow`裏添加
(三)設置開機啓動運行級別
`chkconfig`
`ntsysv`(紅帽專有)