在嵌入式Linux系統(OK6410)中移植Boa 服務器


OK6410的Boa服務器移植:

<一> Boa的編譯

1. 從 www.boa.org 下載 Boa 服務器的最新版:boa-0.94.13.tar.gz。

2. 解壓:tar xzf boa-0.94.13.tar.gz

3. 進入解壓后的文件夾 boa-0.94.13內部的 src文件夾,對源文件進行如下修改

1     由於arm-linux-gcc 編譯器版本過高,對語法的支持有一些改變,所以需要修改compat.h中的
2      #define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff
3 為:
4 
5      #define TIMEZONE_OFFSET(foo) foo->tm_gmtoff
6 不然在編譯的時候會提示如下錯誤:
7     util.c: 100: 1: pasting “t” and “->” does not give a valid preprocessing token make: [util.o] Error1
View Code
 1 將boa.c 文件225-227三行的文件注釋掉
 2  if (setuid(0) != -1) {
 3                         DIE(”icky Linux kernel bug!”);
 4         }
 5  6 /*
 7          if (setuid(0) != -1) {
 8                         DIE(”icky Linux kernel bug!”);
 9                 }
10 */
11 
12 ,否則,但以root權限啟動boa服務器的時候,會出現以下錯誤:boa.c:226 - icky Linux kernel bug!: 
View Code

4. 然后生成Makefile:./configure

5. 修改生成的Makefile:默認生成的Makefile針對x86平台,我們的目標是針對嵌入式平台,所以需要修改編譯器.

1 更改Makefile的31行和32行:
2 CC = gcc 
3 CPP = gcc -E
4 更改為
5 CC = arm-linux-gcc
6 CPP = arm-linux-gcc -E
更改Makefile

6. 在當前目錄下編譯Boa源文件: make

7. 將生成好的boa可執行文件去掉冗余信息: arm-linux-strip boa. 如下圖為strip 前后boa的大小對比。

<二> 將Boa移植到OK6410中

1. 修改boa.conf配置文件:

 1 (1) 修改25行的port端口,用來設置服務器監聽的端口:
 2 # Port: The port Boa runs on.  The default port for http servers is 80.
 3 # If it is less than 1024, the server must be started as root.
 4 
 5 Port 80
 6 (2) 注釋43行的監聽IP地址:默認監聽該主機上的所有IP地址
 7 #Listen 192.68.0.5
 8 (3) 修改53、54行的user和Group 啟動的UID和GID,使其以root身份啟動
 9 #  User: The name or UID the server should run as.
10 # Group: The group name or GID the server should run as.
11 
12 User root
13 Group root
14 (4) 修改116行的DocumentRoot地址,即客戶端要顯示的HTML頁面存放位置
15 # DocumentRoot: The root directory of the HTML documents.
16 # Comment out to disable server non user files.
17 
18 DocumentRoot /usr/local/boa
19 (5) 修改輸入網頁輸入主機IP時要顯示的頁面:這里設為index.html
20  # DirectoryIndex: Name of the file to use as a pre-written HTML
21 # directory index.  Please MAKE AND USE THESE FILES.  On the
22 # fly creation of directory indexes can be _slow_.
23 # Comment out to always use DirectoryMaker
24 
25 DirectoryIndex index.html
26 (6) 修改CGI程序存放的位置:以http://IP/cgi-bin/cginame 的方式運行cgi 程序時將在/usr/local/boa/cgi-bin 目錄下尋找該程序
27 # ScriptAlias: Maps a virtual path to a directory for serving scripts
28 # Example: ScriptAlias /htbin/ /www/htbin/
29 
30 ScriptAlias /cgi-bin/ /usr/local/boa/cgi-bin/

2. 將配置文件boa.conf 移動到OK6410的 /etc/boa/ 目錄下。

3. 創建/var/log/boa/ 目錄,這樣Boa服務器啟動時會在該目錄下創建日志文件。

4. 將Linux系統上/etc/mime.types 文件復制到OK6410的/etc 目錄下,否則Boa服務器啟動不起來。

5. 將生成的boa文件移植到嵌入式板中的/sbin目錄下並更改腳本文件 /etc/init.d/rcS, 新增一行: /sbin/boa ,確保boa服務器隨系統上電自啟動。

 

這里一定要注意:有時候boa服務器並不能隨系統啟動,運行 /sbin/boa 命令會提示:
gethostbyname:: Success
這種情況下要修改boa.conf 文件
    將
#ServerName  www.your.org.here
    改為      
ServerName  www.your.org.here
即去掉注釋即可

 

 <三> 測試Boa服務器:

1. 靜態頁面測試:

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>Boa 靜態網頁測試</title>
 6 </head>
 7 
 8 <body>
 9     <h1>  Welcome to Boa sever! </h1>
10 </body>
11 </html>

2. CGI  程序測試:

 1 #include <stdio.h>
 2 int  main()
 3 {
 4     printf("Content-type: text/html\n\n");
 5     printf("<html>\n");
 6     printf("<head>\n");
 7     printf("<title>CGI Output</title>\n");
 8     printf("</head>\n");
 9 
10     printf("<body>");
11     printf("<h1> Hello, world. </h1>");
12     printf("</body>");
13     printf("</html>\n");
14    return 0;
15 } 

至此,Boa服務器移植完成。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM