Web服务移植thttpd在ARM移植精品资料.doc
《Web服务移植thttpd在ARM移植精品资料.doc》由会员分享,可在线阅读,更多相关《Web服务移植thttpd在ARM移植精品资料.doc(23页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、thttpd在ARM移植1 下载并解压:下载地址为: 下载的是最新的2.25b解压: rootBinnary source# tar -xvzf thttpd-2.25b.tar.gz2 交叉编译thttpd rootBinnary source # cd thttpd-2.25brootBinnary thttpd-2.25b # CC=/armtools/bin/arm-linux-gcc ./configure -host=arm-linuxrootBinnary thttpd-2.25b # make3 安装与配置3.1 拷贝thttpd二进制可执行文件到根文件系统/usr/sbin/
2、目录中 rootBinnary thttpd-2.25b # cp thttpd /fs/usr/sbin/3.2 拷贝thttpd配置文件rootBinnary thttpd-2.25b # cp contrib/redhat-rpm/thttpd.conf /fs/etc/3.3在开发板上为thttpd创建一个独立的用户:httpd,并用此用户创建httpd服务的根目录html root/root#adduser httpd(在ARM开发板上去添加用户)Changing password for httpdEnter the new password (minimum of 5, maxi
3、mum of 8 characters)Please use a combination of upper and lower case letters and numbers.Enter new password:Bad password: too short.Warning: weak password (continuing).Re-enter new password:passwd786: password for httpd changed by user rootPassword changed.root/root#exitprocess -/bin/login (pid 787)
4、 exited. Scheduling it for restart.starting pid 790, tty : /bin/login192.168.1.2 login: httpdPassword:Processing /etc/profile.Set search library path in /etc/profileSet user path in /etc/profileSet PS1 in /etc/profileDonehttpd/home/httpd #mkdir html 3.4 拷贝测试网页到httpd服务的根目(可选,测试之用): rootBinnary thttpd
5、-2.25b # cp index.html /fs/home/httpd/html/我是动态编译所以查看一下需要的动态库 rootBinnary thttpd-2.25b # /armtools/bin/arm-linux-readelf -d thttpdDynamic section at offset 0x12014 contains 21 entries:Tag Type Name/Value0x00000001 (NEEDED) Shared library: libcrypt.so.10x00000001 (NEEDED) Shared library: libc.so.60x0
6、000000c (INIT) 0x95480x0000000d (FINI) 0x165640x00000004 (HASH) 0x81280x00000005 (STRTAB) 0x8c140x00000006 (SYMTAB) 0x84940x0000000a (STRSZ) 1066 (bytes)0x0000000b (SYMENT) 16 (bytes)0x00000015 (DEBUG) 0x00x00000003 (PLTGOT) 0x220e40x00000002 (PLTRELSZ) 872 (bytes)0x00000014 (PLTREL) REL0x00000017 (
7、JMPREL) 0x91e00x00000011 (REL) 0x91a00x00000012 (RELSZ) 64 (bytes)0x00000013 (RELENT) 8 (bytes)0x6ffffffe (VERNEED) 0x91300x6fffffff (VERNEEDNUM) 20x6ffffff0 (VERSYM) 0x903e0x00000000 (NULL) 0x0虽然这里只列出了需要libcrypt 和 libc 这两个动态库,但是想要运行thttpd还需要libnss_files 动态库,具体原因如下解释: rootBinnary thttpd-2.25b$ cp -d
8、 /armtools/arm-linux/lib/libnss_files* /fs/lib/你可以在启动文件里增加thttpd的启动命令:thttpd -C /etc/thttpd.conf注意只有root有启动权限!4、增加对CGI的支持默认配置下,thttpd不可以运行GCI(特别是动态编译的CGI程序)要想使用CGI支持功能,必须更改thttpd.conf的配置:# This section overrides defaultsdir=/home/httpd/html#chroot#屏蔽chroot是为了运行动态编译的CGIuser=httpd# default = nobodylog
9、file=/var/log/thttpd.logpidfile=/var/run/thttpd.pid# This section _documents_ defaults in effectport=80port参数用于更改端口号(可不改,若还运行了别的WEB服务器,则需用不同端口)# nosymlink# default = !chroot#symlinks# novhostcgipat=/cgi-bin/*声明CGI程序的目录,是以dir为根目录的路径# nothrottles# host=0.0.0.0# charset=iso-8859-1移植完成,可以测试了(只需在WEB浏览器中键
10、入开发板的IP地址即可)。在建立 embedded Linux 系统 (root filesystem) 时,链接库相依 (library dependencies)是相当重要的目。当 root filesystem 缺少必要的 library 时,程序当然是无法执行的,甚致系统也会无法顺利启动。在建构 embedded Linux 系统时,应具备的正确观念与基本能力。我们把如何找出所需的 library方法整理出 3 项的基本要点,依照这 3 种基本款来加入 library 将能解决几乎所有的 library dependency 问题,这 3 种项基本要点为:(1) 先利用 cross t
11、oolchain 的 objdump 观察NEEDED的项目,加入 library。(2) 再检查这些 library 是否相依其它 library。(3) 最后要检视应用程序是否使用到需要特定 library 的service。要点 1. 跟 2. 对大家来说没有什么问题,要点 3. 在我们的 training 课程里,我们以建构 thttpd (embedded Web server) 的实际案例来做讲解。关于建构 thttpd 的案例thttpd 使用到 NSS (Name Service Switch),因此若没有将 libnss_SERVICE.so 加到 root filesyst
12、em,thttpd 在执行时可能会遇到一些奇怪的问题。举个例子,当 thttpd 透过 /etc/passwd 去寻找 (查询) UNIX user 时,会用到 libnss_files.so (不读 /etc/shadow),因此会看到以下的错误讯息:unknown user - root出现这个错误的原因是 thttpd 读不到 root 使用者,要深入探讨这个问题的原理,必须从以下的程序代码片断开始探讨: 403 /* If were root and were going to become another user, get the uid /gid 404 * now. 405 *
13、/ 406 if ( getuid() = 0 ) 407 408 pwd = getpwnam( user ); 409 if ( pwd = (struct passwd*) 0 ) 410 411 syslog( LOG_CRIT, unknown user - %.80s, user ); 412 (void) fprintf( stderr, %s: unknown user - %sn, argv0, user ); 413 exit( 1 ); 414 415 uid = pwd-pw_uid; 416 gid = pwd-pw_gid; 417 这段程序代码是 thttpd 2
14、.25b 的程序片断,位于 thttpd.c 的 main() 函数里。关于 libnss_SERVICE.so 的议题,Jollen 打算另外再做讨论,因为还会与 libc 有关系。在这里我们由系统建构的角度来看这个问题。因为我们已经习惯用 objdump 来观察程序的相依 library,所以当 objdump 的画面跟我们预期的不同时,经常一时无法反应过来。例如,以下的讯息是我们所预期的:# /armtools/bin/arm-linux-objdump -x thttpd|more.Dynamic Section: NEEDED libcrypt.so.1 NEEDED libnss_
15、files.so.2 NEEDED libc.so.6.但是实际的讯息却是像这样的:#/armtools/bin/arm-linux-objdump -x thttpd|more.Dynamic Section: NEEDED libcrypt.so.1 NEEDED libc.so.6.我们可以用一知半解的思考逻辑来解决问题:thttpd 呼叫到 getpwnam() 函数,此函数由 libnss_compat 提供,因此解决方案是把 libnss_files.so 加到 root filesystem 里即可。且慢!前面才讲到 libnss_compat,怎么后面是把 libnss_fil
16、es 加到 root filesystem?是这样的,libnss_compat 用来读 /etc/shadow,但是现在我们只需要由 /etc/passwd 读 Unix user,所以使用 libnss_files.so 就行了。执行 thttpd 的话,再加上指定 username 的参数来执行:# thttpd -p 80 -d /var/www -u rootlibnss_SERVICE.so 是包含在 glibc 里的链接库,因此可以直接由 cross toolchain 里取得,不必再另行建置。有关 NSS (Name Service Switch) 可参考以下网页:http:/
17、www.gnu.org/software/libc/manual/html_node/Name-Service-Switch.htmlhttp:/mirrors.usc.edu/pub/gnu/Manuals/glibc-2.2.3/html_chapter/libc_28.html此处我们以service的角度来探讨这个问题:因为 thttpd 使用到 Name Service Switch,所以需要加入 libnss_SERVICE.so。另外一种探讨的角度是:由 programming 的角度来思考。如果要读 shadow passwd 的话,是使用 libnss_compat.so。B
18、oa程序的移植1、下载Boa源码 下载地址: http:/www.boa.org/ 目前最新发行版本: 0.94.13 (几年没更新版本了) 下载 boa-0.94.13.tar.gz,注意:若从boa上下载的是boa-0.94.13.tar.tar,解压方式一样 解压: rootBinnary source# tar xzf boa-0.94.13.tar.gz2、生成Makefile文件进入boa-0.94.13,直接运行src/configure文件 rootBinnary src#CC=/armtools/bin/arm-linux-gcc ./configure#3、修改Makefi
19、le文件(注意:必须用cross-2.95.3, 如使用3.4.1、4.1.1等等会出错) #CC = /armtools/bin/arm-linux-gcc #CPP = /armtools/bin/arm-linux-gcc -E4、交叉编译 rootBinnary src# make5、去除调试信息,减小体积。(可选) rootBinnary src# /armtools/bin/arm-linux-strip boa6、将编译好的程序放入根文件系统的/bin目录下。 rootBinnary src# cp boa /fs/bin/ 二、配置BoaBoa需要在/etc目录下建立一个boa
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Web服务移植thttpd在ARM移植 精品资料 Web 服务 移植 thttpd ARM 精品 资料
限制150内