认识系统服务(daemons)
---------------
服务主要分为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`(红帽专有)
---------------
服务主要分为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`(红帽专有)