嵌入式linux系统网络超级服务器构建指南(for arm)
来源:互联网 发布:手机电视直播软件 编辑:程序博客网 时间:2024/04/29 01:38
嵌入式linux系统网络超级服务器构建指南
作者:张海涛
时间:2007年8月31日
email:zhtsir@gmail.com
my-blog:http://blog.csdn.net/zht_sir
操作环境:
pc i686 + fc6 + arm-linux-gcc-3.4.6
目标板 atrm9200 + armlinux-2.6.18.8
1 super-server介绍
super-server是一个特殊的监控程序,由它负责监听所有启用的网络服务的端口号。当某个端口接收到服务请求,super-server首先启动响应的网络监控程序,软后将服务请求传递给该网络监控程序以便提供服务。
linux主要有两个internet super-server可用:inetd和xinetd
2 inetd
inetd在系统引导时启动,并从/etc/inetd.conf的配置文件中取得需要管理的服务的列表。inetd除了调用inetd.conf中配置的服务序外,还有许多有inetd自己处理的一般服务,称为内部服务。这些服务包括简单第产生字符串chargen,返回系统日期时间的daytime等服务。
(1) inetd获得,可以从ftp://ftp.uk.linux.org/pub/linux/Networking/netkit/netkit-base-0.17.tar.gz上下载。
(2) 解压配置
#CC=arm-linux-gcc ./configure --prefix=/usr/local/arm
1) Compiler arm-linux-gcc does not exist or cannot compile C; try another.
configure line 110: ./__conftest || exit 1
改为:#./__conftest || exit 1
2) This package needs BSD signal semantics to run.
configure line 190: ./__conftest || exit 1
改为:#./__conftest || exit 1
3) Checking for snprintf implementation... missing
configure line 300: ./__conftest || exit 1
改为:#./__conftest || exit 1
以上错误的是由于arm-linux-gcc编译生成的二进制文件在PC机上不能执行所致。
(3) 编译
#make
(4) 安装
1) 将inetd/inetd拷贝到目标板的/usr/sbin目录下。
2) 将etc.sample/inetd.conf拷贝到arm-linux的/etc目录下。
3) 修改目标板/etc/inittab文件,为inetd加入一行设定,以便系统启动后就运行inetd。
::respawn:/usr/sbin/inetd -i
(5) inetd配置文件inetd.conf
该文件中的每一行都是由以下几个字段组成的:
service type protocol wait user server cmdline
字段的含义如下:
1) service
给出服务的名称,可以通过/etc/services文件查到,还包括了该服务的协议好端口号。
2) type
指定一个套接字类型,或者是stream(基于连接的协议),或者是dgram(基于数据报的协议)。
3) protocol
服务所使用的传输协议,必须是/etc/protocols文件中能找到的有效协议。
4) wait
该选项只用于dgram套接字。其值可以是wait或nowait。如果指定为wait那么对于指定的端口inetd任何时候只
执行一次服务器程序。否则的话,在执行了指定的服务器程序以后,它将立刻在这个端口上技术监听。
对于“单线程”服务器程序,需指定为wait。对于“多线程”服务器程序允许无限量的例程并发运行,所以
可以指定为nowait。
5) user
用户登陆id,程序执行时由本id的用户拥有该进程。
6) server
给出执行的服务器程序的路径。内部服务用关键字internal标记。
7) cmdline
这是传给服务器程序的命令行。该命令可以被执行的服务器名开始,可以包含需要传递给它的任何参数。
如果使用TCP包裹程序,需要在这里指定服务器程序的全路径名。如果不是,你可以用它在进程列表中显
示的服务器名来指定它。
(6) inetd.conf样例
#
# inetd services
ftp stream tcp nowait root /usr/sbin/ftpd in.ftpd -l
telnet stream tcp nowait root /usr/sbin/telnetd in.telnetd -b/etc/issue
#finger stream tcp nowait bin /usr/sbin/fingerd in.fingerd
#tftp dgram udp wait nobody /usr/sbin/tftpd in.tftpd
#tftp dgram udp wait nobody /usr/sbin/tftpd in.tftpd /boot/diskless
#login stream tcp nowait root /usr/sbin/rlogind in.rlogind
#shell stream tcp nowait root /usr/sbin/rshd in.rshd
#exec stream tcp nowait root /usr/sbin/rexecd in.rexecd
#
# inetd internal services
#
daytime stream tcp nowait root internal
daytime dgram udp nowait root internal
time stream tcp nowait root internal
time dgram udp nowait root internal
echo stream tcp nowait root internal
echo dgram udp nowait root internal
discard stream tcp nowait root internal
discard dgram udp nowait root internal
chargen stream tcp nowait root internal
chargen dgram udp nowait root internal
3 xinetd
在某些系统上使用xinetd会比inetd还好,因为xinetd还允许某种安全许可,提供多种登陆能力并能够避免拒绝访问攻击。
(1) inetd获得,可以从http://www.xinetd.org上下载。目前版本为2.3.14。也可以通过下载cvs版本,下载方法如下:
cvs -d :pserver:anonymous@cvs.xinetd.org:/cvs/xinetd login
执行后将询问口令,直接回车,在执行下面的命令
cvs -d :pserver:anonymous@cvs.xinetd.org:/cvs/xinetd co xinetd
(2) 解压配置
#CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/home/zht/redhatzht/sources/arm-network
/xinetd-2.3.14/install
其中/home/zht/redhatzht/sources/arm-network/xinetd-2.3.14/install 为xinetd源码所在目录。
(3) 编译
#make
(4) 安装
1) 将install/sbin/xinetd拷贝到目标板的/usr/sbin目录下。
2) 将xinetd/sample.conf拷贝到arm-linux的/etc/xinetd.conf文件中。
3) 修改目标板/etc/inittab文件,为xinetd加入一行设定,以便系统启动后就运行xinetd。
::once:/usr/sbin/xinetd
xinetd只能被启动成监控程序,如果xinetd终止,init无法再次启动xinetd。
(5) xinetd配置文件/etc/xinetd.conf
与inetd相比xinetd的配置有所不同,而不是更复杂,inetd所有的服务都依赖与一个主配置文件,而xinetd不
仅可以通过/etc/xinetd.conf主配置文件进行配置,并且对于附加的服务配置可以通过独立的配置文件进行配置。
以下为默认配置:
defaults
{
only_from = localhost
instances = 60
log_type = SYSLOG authpriv info
log_on_success = HOST PID
log_on_failure = HOST
cps = 25 30
}
includedir /etc/xinetd.d
默认配置选项含义如下:
1) only_from
用于指定允许连接的IP地址和主机名
2) instances
xinetd允许运行的服务器的最大数
3) log_type SYSLOG|FILE
设置你使用的录入类型,有两个选项SYSLOG和file。设置SYSLOG,将把日志信息写到系统日志中,设置为FILE, 将把日志信息写入到指定的文件中。
4) log_on_success
当一个用户连接成功时,可以通过该选项指定录入信息的类型,该选项有一些子选项如下:
HOST 录入远程主机IP地址
PID 录入新的服务器进程ID
DURATION 录入所有的会话时间日志
TRAFFIC 使能该选项,将录入输入输出的字节数,该选项对网络管理员会有帮助
5) log_on_failure
对连接失败的记录信息类型,该选项的自选项如下:
HOST 录入远程主机IP地址
ATTEMPT 记录所有企图访问的服务
cps 用于限制连接访问率,该选项有两个值,第一个值为每秒钟允许的连接数,
第二个值为在短时间内连接连接次数的上限,超过该值服务器将禁用。
以下为具体服务配置样例:
service ftp
{
socket_type = stream
wait = no
user = root
server = /usr/sbin/vsftpd
server_args = /etc/vsftpd/vsftpd.conf
log_on_success += DURATION USERID
log_on_failure += USERID
nice = 10
disable = no
}
service ftp为服务器的名称
ftp配置选项含义如下:
1) socket_type
服务套接字类型,如stream,dgram,raw,seqpacket
2) wait
用于指定服务为单线程还是多线程,yes表示服务为单线程,no表示服务为多线程。
3) user
设置运行服务的用户名称。
4) server
设置服务程序的路径。
5) server_args
设置传递给服务程序的命令选项。
6) nice
设置服务的优先级,也可以用于限制服务器的资源使用。
7) disable
服务使能选项。
(6) xinetd.conf样例
#
# Sample configuration file for xinetd
#
defaults
{
instances = 25
log_type = FILE /var/log/servicelog
log_on_success = HOST PID
log_on_failure = HOST
only_from = 128.138.193.0 128.138.204.0 128.138.209.0 128.138.243.0
only_from = localhost 192.231.139.0/24
disabled = tftp
}
#
# Group 1: BSD services
#
# Shell, login, exec, comsat, talk, ntalk
#
service login
{
socket_type = stream
protocol = tcp
wait = no
user = root
server = /usr/etc/in.rlogind
log_type = SYSLOG local4 info
}
service shell
{
socket_type = stream
wait = no
user = root
instances = UNLIMITED
flags = IDONLY
log_on_success += USERID
server = /usr/etc/in.rshd
}
service exec
{
socket_type = stream
wait = no
user = root
server = /usr/etc/in.rexecd
}
service comsat
{
socket_type = dgram
wait = yes
user = nobody
group = tty
server = /usr/etc/in.comsat
}
service talk
{
socket_type = dgram
wait = yes
user = root
server = /usr/etc/in.talkd
}
4 参考资料
构建嵌入式linux系统
linux网络管理员指南 第二版
Linux Network Administrator's Guide 3rd Edition.pdf.chm
- 嵌入式linux系统网络超级服务器构建指南(for arm)
- 嵌入式Linux系统之网络启动指南
- 构建嵌入式LINUX系统
- 构建嵌入式Linux系统
- 构建嵌入式Linux系统
- 嵌入式linux系统ARM网络培训系列教学视频
- 构建ARM Linux系统实践
- 构建ARM Linux系统实践
- 构建嵌入式Linux系统说明
- 构建嵌入式Linux系统读书笔记
- 嵌入式系统/ARM技术:基于Linux的嵌入式网络摄像机设计
- 《嵌入式系统Linux内核开发实战指南(ARM平台)》书评
- 《嵌入式系统Linux内核开发实战指南(ARM平台)》前言及网友问答
- 嵌入式web服务器lighttpd的交叉编译及配置(for arm-linux)
- 手动构建小于10M的类嵌入式Linux系统step by step实做指南
- 基于ARM+LINUX的无线视频采集系统设计----------搭建嵌入式web服务器
- 嵌入式linux系统网络配置
- 基于ARM的嵌入式linux系统设计
- PHP文件上传的原理及实现
- ADODB 入门(一)
- VC中基于 Windows 的精确定时
- 水晶报表动态加载字段
- ADODB 入门(二)
- 嵌入式linux系统网络超级服务器构建指南(for arm)
- 用PHP5进行三层开发
- 用PHP5进行三层开发(二)
- 查询文本框(1)
- 在C#中,string str = null 与 string str = “” 请尽量使用文字或图象说明其中的区别。
- web2.0与soa :web2.0简介
- wxMenu的一个demo
- Oracle 之 bulk collect 的用法
- linux tar命令