随着Internet技术的兴起,在嵌入式设备的管理与交互中,基于Web方式的应用成为目前的主流,这种程序结构也就是大家非常熟悉的B/S结构,即在嵌入式设备上运行一个支持脚本或CGI功能的Web服务器,能够生成动态页面,在用户端只需要通过Web浏览器就可以对嵌入式设备进行管理和监控,非常方便实用。本节主要介绍这种应用的开发和移植工作。 用户首先需要在嵌入式设备上成功移植支持脚本或CGI功能的Web服务器,然后才能进行应用程序的开发。 1、嵌入式Web服务器移植 由于嵌入式设备资源一般都比较有限,并且也不需要能同时处理很多用户的请求,因此不会使用Linux下最常用的如Apache等服务器,而需要使用一些专门为嵌入式设备设计的Web服务器,这些Web服务器在存贮空间和运行时所占有的内存空间上都会非常适合于嵌入式应用场合。
典型的嵌入式Web服务器有Boa (),它们和Apache等高性能的Web服务器主要的区别在于它们一般是单进程服务器,只有在完成一个用户请求后才能响应另一个用户的请求,而无法并发响应,但这在嵌入式设备的应用场合里已经足够了。 我们绍比较常用的Boa服务器的移植。 Boa是一个非常小巧的Web服务器,可执行代码只有约60KB。它是一个单任务Web服务器,只能依次完成用户的请求,而不会fork出新的进程来处理并发连接请求。但Boa支持CGI,能够为CGI程序fork出一个进程来执行。Boa的设计目标是速度和安全,在其站点公布的性能测试中,Boa的性能要好于Apache服务器。
(1) 虚拟机ubuntu上boa配置:
1 下载源码
解压
# tar xzvf boa-0.94-13.tar.gz
2 编译源代码
进入源码目录的src子目录
# cd boa-0.94.13/src
生成Makefile文件
# ./configure
在编译之前
修改boa.c文件(第226行)注释掉即
//DIE('"icky Linux Kernel bug!");
修改src/compat.h文件:
#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff 改为
#define TIMEZONE_OFFSET(foo) foo->tm_gmtoff
修改src/log.c:73注释掉:
//DIE("unable to dup2 the error log");
然后运行make进行编译,得到的可执行程序为boa,将调试信息剥去,得到的最后程序只有约60KB大小。
# make
# arm-linux-strip boa(也可不做)
3 配置Boa Webserver环境
Boa Webserver的配置文件是boa.conf。该文件需要被放置在/etc/boa目录下(因为该文件的默认目录为/src/defines.h文件的SERVER_ROOT定义, 默认目录为/etc/boa)。如果不改变defines.h对其的定义,则需要对boa.conf 稍做修改:
a 将boa.conf复制到/etc/boa目录下:
# sudo mkdir /etc/boa
# sudo cp boa.conf /etc/boa
b 修改boa.conf
-
# Port: The port Boa runs on. The default port for http servers is 80.
-
# If it is less than 1024, the server must be started as root.
-
-
Port 80
-
-
# Listen: the Internet address to bind(2) to. If you leave it out,
-
# it takes the behavior before 0.93.17.2, which is to bind to all
-
# addresses (INADDR_ANY). You only get one \"Listen\" directive,
-
# if you want service on multiple IP addresses, you have three choices:
-
# 1. Run boa without a \"Listen\" directive
-
# a. All addresses are treated the same; makes sense if the addresses
-
# are localhost, ppp, and eth0.
-
# b. Use the VirtualHost directive below to point requests to different
-
# files. Should be good for a very large number of addresses (web
-
# hosting clients).
-
# 2. Run one copy of boa per IP address, each has its own configuration
-
# with a \"Listen\" directive. No big deal up to a few tens of addresses.
-
# Nice separation between clients.
-
# The name you provide gets run through inet_aton(3), so you have to use dotted
-
# quad notation. This configuration is too important to trust some DNS.
-
-
#Listen 192.68.0.5
-
-
# User: The name or UID the server should run as.
-
# Group: The group name or GID the server should run as.
-
-
User 0 //改过后
-
Group 0 //改过后
-
-
# ServerAdmin: The email address where server problems should be sent.
-
# Note: this is not currently used, except as an environment variable
-
# for CGIs.
-
-
#ServerAdmin root@localhost
-
-
# ErrorLog: The location of the error log file. If this does not start
-
# with /, it is considered relative to the server root.
-
# Set to /dev/null if you don\'t want errors logged.
-
# If unset, defaults to /dev/stderr
-
-
ErrorLog /var/log/boa/error_log
-
# Please NOTE: Sending the logs to a pipe (\'|\'), as shown below,
-
# is somewhat experimental and might fail under heavy load.
-
# \"Usual libc implementations of printf will stall the whole
-
# process if the receiving end of a pipe stops reading.\"
-
#ErrorLog \"|/usr/sbin/cronolog --symlink=/var/log/boa/error_log /var/log/boa/error-%Y%m%d.log\"
-
-
# AccessLog: The location of the access log file. If this does not
-
# start with /, it is considered relative to the server root.
-
# Comment out or set to /dev/null (less effective) to disable
-
# Access logging.
-
-
AccessLog /var/log/boa/access_log
-
# Please NOTE: Sending the logs to a pipe (\'|\'), as shown below,
-
# is somewhat experimental and might fail under heavy load.
-
# \"Usual libc implementations of printf will stall the whole
-
# process if the receiving end of a pipe stops reading.\"
-
#AccessLog \"|/usr/sbin/cronolog --symlink=/var/log/boa/access_log /var/log/boa/access-%Y%m%d.log\"
-
-
# UseLocaltime: Logical switch. Uncomment to use localtime
-
# instead of UTC time
-
#UseLocaltime
-
-
# VerboseCGILogs: this is just a logical switch.
-
# It simply notes the start and stop times of cgis in the error log
-
# Comment out to disable.
-
-
#VerboseCGILogs
-
-
# ServerName: the name of this server that should be sent back to
-
# clients if different than that returned by gethostname + gethostbyname
-
-
ServerName www.rxlinux.com //改过后:直接去掉前面#即可
-
-
# VirtualHost: a logical switch.
-
# Comment out to disable.
-
# Given DocumentRoot /var/www, requests on interface \'A\' or IP \'IP-A\'
-
# become /var/www/IP-A.
-
# Example: http://localhost/ becomes /var/www/127.0.0.1
-
#
-
# Not used until version 0.93.17.2. This \"feature\" also breaks commonlog
-
# output rules, it prepends the interface number to each access_log line.
-
# You are expected to fix that problem with a postprocessing script.
-
-
#VirtualHost
-
-
# DocumentRoot: The root directory of the HTML documents.
-
# Comment out to disable server non user files.
-
-
DocumentRoot /www //改过后
-
-
# UserDir: The name of the directory which is appended onto a user\'s home
-
# directory if a ~user request is recieved.
-
-
UserDir public_html
-
-
# DirectoryIndex: Name of the file to use as a pre-written HTML
-
# directory index. Please MAKE AND USE THESE FILES. On the
-
# fly creation of directory indexes can be _slow_.
-
# Comment out to always use DirectoryMaker
-
-
DirectoryIndex index.html
-
-
# DirectoryMaker: Name of program used to create a directory listing.
-
# Comment out to disable directory listings. If both this and
-
# DirectoryIndex are commented out, accessing a directory will give
-
# an error (though accessing files in the directory are still ok).
-
-
DirectoryMaker /usr/lib/boa/boa_indexer
-
-
# DirectoryCache: If DirectoryIndex doesn\'t exist, and DirectoryMaker
-
# has been commented out, the the on-the-fly indexing of Boa can be used
-
# to generate indexes of directories. Be warned that the output is
-
# extremely minimal and can cause delays when slow disks are used.
-
# Note: The DirectoryCache must be writable by the same user/group that
-
# Boa runs as.
-
-
# DirectoryCache /var/spool/boa/dircache
-
-
# KeepAliveMax: Number of KeepAlive requests to allow per connection
-
# Comment out, or set to 0 to disable keepalive processing
-
-
KeepAliveMax 1000
-
-
# KeepAliveTimeout: seconds to wait before keepalive connection times out
-
-
KeepAliveTimeout 10
-
-
# MimeTypes: This is the file that is used to generate mime type pairs
-
# and Content-Type fields for boa.
-
# Set to /dev/null if you do not want to load a mime types file.
-
# Do *not* comment out (better use
-
-
MimeTypes /dev/null //改过后
-
-
# DefaultType: MIME type used if the file extension is unknown, or there
-
# is no file extension.
-
-
DefaultType text/plain
-
-
# CGIPath: The value of the $PATH environment variable given to CGI progs.
-
-
CGIPath /bin:/usr/bin:/www/cgi-bin //改过后
-
-
# SinglePostLimit: The maximum allowable number of bytes in
-
# a single POST. Default is normally 1MB.
-
-
# AddType: adds types without editing mime.types
-
# Example: AddType type extension [extension ...]
-
-
# Uncomment the next line if you want .cgi files to execute from anywhere
-
#AddType application/x-httpd-cgi cgi
-
-
# Redirect, Alias, and ScriptAlias all have the same semantics -- they
-
# match the beginning of a request and take appropriate action. Use
-
# Redirect for other servers, Alias for the same server, and ScriptAlias
-
# to enable directories for script execution.
-
-
# Redirect allows you to tell clients about documents which used to exist in
-
# your server\'s namespace, but do not anymore. This allows you to tell the
-
# clients where to look for the relocated document.
-
# Example: Redirect /bar http://elsewhere/feh/bar
-
-
# Aliases: Aliases one path to another.
-
# Example: Alias /path1/bar /path2/foo
-
-
Alias /doc /usr/doc
-
-
# ScriptAlias: Maps a virtual path to a directory for serving scripts
-
# Example: ScriptAlias /htbin/ /www/htbin/
-
-
ScriptAlias /cgi-bin/ /www/cgi-bin/ //改过后
c 根据修改后的boa.conf创建对应的目录或文件:
# sudo mkdir -p /www/cgi-bin
#sudo mkdir -p /var/log/boa
并修改权限
sudo chmod 777 /var/log/boa
在boa目录下建error_log,access_log 文件并修改权限
#sudo chmod 777 error_log
#sudo chmod 777 access_log
d boa测试
1 静态网页测试
在www目录下编辑一个test.html文件:
测试程序
BOA静态网页测试成功!
#cd boa-0.94.13/src
执行:
#sudo ./boa (一定要加sudo命令)
测试结果:
(二)tiny 6410开发板移植
步骤和上面类似,只不过编译器在Makefile中改成了boa-0.94.13/src下的Makefile文件,CC = gcc 和CPP = gcc -E 修改为CC=arm-linux-gcc 和 CPP = arm-linux-gcc -E
然后make,把生成的boa,boa_indexer拷贝到开发板新建的目录/etc/boa,中,同时修改后的boa.conf也拷贝到这里,然后在建立error_log,access_log文件在开发板var/log/boa
下,然后把虚拟机www目录里面的都拷贝到开发板顶层目录www下,然后在开发板,/etc/boa/下执行./boa最终效果和上面一样。
阅读(2257) | 评论(0) | 转发(1) |