Chinaunix首页 | 论坛 | 博客
  • 博客访问: 202516
  • 博文数量: 35
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 385
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-16 18:53
个人简介

只要心够决,没有什么不可以!!!

文章存档

2013年(35)

我的朋友

分类: 嵌入式

2013-05-08 17:49:53

    随着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
 

点击(此处)折叠或打开


  1. # Port: The port Boa runs on. The default port for http servers is 80.
  2. # If it is less than 1024, the server must be started as root.

  3. Port 80

  4. # Listen: the Internet address to bind(2) to. If you leave it out,
  5. # it takes the behavior before 0.93.17.2, which is to bind to all
  6. # addresses (INADDR_ANY). You only get one \"Listen\" directive,
  7. # if you want service on multiple IP addresses, you have three choices:
  8. # 1. Run boa without a \"Listen\" directive
  9. # a. All addresses are treated the same; makes sense if the addresses
  10. # are localhost, ppp, and eth0.
  11. # b. Use the VirtualHost directive below to point requests to different
  12. # files. Should be good for a very large number of addresses (web
  13. # hosting clients).
  14. # 2. Run one copy of boa per IP address, each has its own configuration
  15. # with a \"Listen\" directive. No big deal up to a few tens of addresses.
  16. # Nice separation between clients.
  17. # The name you provide gets run through inet_aton(3), so you have to use dotted
  18. # quad notation. This configuration is too important to trust some DNS.

  19. #Listen 192.68.0.5

  20. # User: The name or UID the server should run as.
  21. # Group: The group name or GID the server should run as.

  22. User 0 //改过后
  23. Group 0 //改过后

  24. # ServerAdmin: The email address where server problems should be sent.
  25. # Note: this is not currently used, except as an environment variable
  26. # for CGIs.

  27. #ServerAdmin root@localhost

  28. # ErrorLog: The location of the error log file. If this does not start
  29. # with /, it is considered relative to the server root.
  30. # Set to /dev/null if you don\'t want errors logged.
  31. # If unset, defaults to /dev/stderr

  32. ErrorLog /var/log/boa/error_log
  33. # Please NOTE: Sending the logs to a pipe (\'|\'), as shown below,
  34. # is somewhat experimental and might fail under heavy load.
  35. # \"Usual libc implementations of printf will stall the whole
  36. # process if the receiving end of a pipe stops reading.\"
  37. #ErrorLog \"|/usr/sbin/cronolog --symlink=/var/log/boa/error_log /var/log/boa/error-%Y%m%d.log\"

  38. # AccessLog: The location of the access log file. If this does not
  39. # start with /, it is considered relative to the server root.
  40. # Comment out or set to /dev/null (less effective) to disable
  41. # Access logging.

  42. AccessLog /var/log/boa/access_log
  43. # Please NOTE: Sending the logs to a pipe (\'|\'), as shown below,
  44. # is somewhat experimental and might fail under heavy load.
  45. # \"Usual libc implementations of printf will stall the whole
  46. # process if the receiving end of a pipe stops reading.\"
  47. #AccessLog \"|/usr/sbin/cronolog --symlink=/var/log/boa/access_log /var/log/boa/access-%Y%m%d.log\"

  48. # UseLocaltime: Logical switch. Uncomment to use localtime
  49. # instead of UTC time
  50. #UseLocaltime

  51. # VerboseCGILogs: this is just a logical switch.
  52. # It simply notes the start and stop times of cgis in the error log
  53. # Comment out to disable.

  54. #VerboseCGILogs

  55. # ServerName: the name of this server that should be sent back to
  56. # clients if different than that returned by gethostname + gethostbyname

  57. ServerName www.rxlinux.com //改过后:直接去掉前面#即可

  58. # VirtualHost: a logical switch.
  59. # Comment out to disable.
  60. # Given DocumentRoot /var/www, requests on interface \'A\' or IP \'IP-A\'
  61. # become /var/www/IP-A.
  62. # Example: http://localhost/ becomes /var/www/127.0.0.1
  63. #
  64. # Not used until version 0.93.17.2. This \"feature\" also breaks commonlog
  65. # output rules, it prepends the interface number to each access_log line.
  66. # You are expected to fix that problem with a postprocessing script.

  67. #VirtualHost

  68. # DocumentRoot: The root directory of the HTML documents.
  69. # Comment out to disable server non user files.

  70. DocumentRoot /www //改过后

  71. # UserDir: The name of the directory which is appended onto a user\'s home
  72. # directory if a ~user request is recieved.

  73. UserDir public_html

  74. # DirectoryIndex: Name of the file to use as a pre-written HTML
  75. # directory index. Please MAKE AND USE THESE FILES. On the
  76. # fly creation of directory indexes can be _slow_.
  77. # Comment out to always use DirectoryMaker

  78. DirectoryIndex index.html

  79. # DirectoryMaker: Name of program used to create a directory listing.
  80. # Comment out to disable directory listings. If both this and
  81. # DirectoryIndex are commented out, accessing a directory will give
  82. # an error (though accessing files in the directory are still ok).

  83. DirectoryMaker /usr/lib/boa/boa_indexer

  84. # DirectoryCache: If DirectoryIndex doesn\'t exist, and DirectoryMaker
  85. # has been commented out, the the on-the-fly indexing of Boa can be used
  86. # to generate indexes of directories. Be warned that the output is
  87. # extremely minimal and can cause delays when slow disks are used.
  88. # Note: The DirectoryCache must be writable by the same user/group that
  89. # Boa runs as.

  90. # DirectoryCache /var/spool/boa/dircache

  91. # KeepAliveMax: Number of KeepAlive requests to allow per connection
  92. # Comment out, or set to 0 to disable keepalive processing

  93. KeepAliveMax 1000

  94. # KeepAliveTimeout: seconds to wait before keepalive connection times out

  95. KeepAliveTimeout 10

  96. # MimeTypes: This is the file that is used to generate mime type pairs
  97. # and Content-Type fields for boa.
  98. # Set to /dev/null if you do not want to load a mime types file.
  99. # Do *not* comment out (better use

  100. MimeTypes /dev/null //改过后

  101. # DefaultType: MIME type used if the file extension is unknown, or there
  102. # is no file extension.

  103. DefaultType text/plain

  104. # CGIPath: The value of the $PATH environment variable given to CGI progs.

  105. CGIPath /bin:/usr/bin:/www/cgi-bin //改过后

  106. # SinglePostLimit: The maximum allowable number of bytes in
  107. # a single POST. Default is normally 1MB.

  108. # AddType: adds types without editing mime.types
  109. # Example: AddType type extension [extension ...]

  110. # Uncomment the next line if you want .cgi files to execute from anywhere
  111. #AddType application/x-httpd-cgi cgi

  112. # Redirect, Alias, and ScriptAlias all have the same semantics -- they
  113. # match the beginning of a request and take appropriate action. Use
  114. # Redirect for other servers, Alias for the same server, and ScriptAlias
  115. # to enable directories for script execution.

  116. # Redirect allows you to tell clients about documents which used to exist in
  117. # your server\'s namespace, but do not anymore. This allows you to tell the
  118. # clients where to look for the relocated document.
  119. # Example: Redirect /bar http://elsewhere/feh/bar

  120. # Aliases: Aliases one path to another.
  121. # Example: Alias /path1/bar /path2/foo

  122. Alias /doc /usr/doc

  123. # ScriptAlias: Maps a virtual path to a directory for serving scripts
  124. # Example: ScriptAlias /htbin/ /www/htbin/

  125. 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最终效果和上面一样。
阅读(2249) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~