免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 8374 | 回复: 21
打印 上一主题 下一主题

利用LFS SVN20090601打造一个强大的WEB服务器 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-06-09 11:31 |只看该作者 |倒序浏览
很久没来CU发帖了,最近因为工作需要加上个人兴趣,重做了一次LFS,这次利用SVN20090601最新版本,从头编译。
宿主系统是UBUNTU9服务器版,基本系统编译完成之后,加上了一些自己的设置,另外,加入了BLFS里面的一些软件包,例如:openssl,openssh,wget,unzip,以及一些常用工具命令,最主要的,是在此基础上,利用nginx/0.7.59,用FAST-CGI的方式,部署一个高性能的web服务器!

以下分享一下整个编译过程(这个过程根据人品好坏,需要花费的时间也不尽相同 ,不过一般至少需要花费2-3天以上。)
革命尚未成功,就不要放弃哦,哈哈!



  1. ubuntu9 Server,用163的升级镜像apt-get upgrade一下。安装LAMP服务器,因为我本身要在宿主系统上做php测试。
  2. 先安装个gd支持,嘿嘿。
  3. apt-get install php5-gd

  4. 安装编译lfs必须的工具
  5. apt-get install diff gawk glibc m4 make texinfo autoconf g++ gcc bison gawk


  6. mkdir /opt/work && cd /opt/work


  7. ///////////////// 检查环境 /////////////////

  8. cat > version-check.sh << "EOF"
  9. #!/bin/bash
  10. export LC_ALL=C

  11. # Simple script to list version numbers of critical development tools

  12. bash --version | head -n1 | cut -d" " -f2-4
  13. echo "/bin/sh -> `readlink -f /bin/sh`"
  14. echo -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3-
  15. bison --version | head -n1
  16. if [ -e /usr/bin/yacc ];
  17.   then echo "/usr/bin/yacc -> `readlink -f /usr/bin/yacc`";
  18.   else echo "yacc not found"; fi
  19. bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f1,6-
  20. echo -n "Coreutils: "; chown --version | head -n1 | cut -d")" -f2
  21. diff --version | head -n1
  22. find --version | head -n1
  23. gawk --version | head -n1
  24. if [ -e /usr/bin/awk ];
  25.   then echo "/usr/bin/awk -> `readlink -f /usr/bin/awk`";
  26.   else echo "awk not found"; fi
  27. gcc --version | head -n1
  28. /lib/libc.so.6 | head -n1 | cut -d" " -f1-7
  29. grep --version | head -n1
  30. gzip --version | head -n1
  31. cat /proc/version
  32. m4 --version | head -n1
  33. make --version | head -n1
  34. patch --version | head -n1
  35. echo Perl `perl -V:version`
  36. sed --version | head -n1
  37. tar --version | head -n1
  38. makeinfo --version | head -n1
  39. echo 'main(){}' > dummy.c && gcc -o dummy dummy.c
  40. if [ -x dummy ]; then echo "Compilation OK";
  41.   else echo "Compilation failed"; fi
  42. rm -f dummy.c dummy

  43. EOF

  44. bash version-check.sh


  45. export LFS=/mnt/lfs
  46. mkdir -pv $LFS
  47. mount -v -t ext3 /dev/sda3 $LFS
  48. mkdir -v $LFS/sources
  49. chmod -v a+wt $LFS/sources
  50. cd $LFS/sources

  51. 下载源码包
  52. 使用一个脚本,多线程下载
  53. #!/bin/sh

  54. if [ -z "$1" -o -z "$2" ]; then
  55.         echo "Usage: $0 <destination_dir> <url file>"
  56.         exit 1
  57. fi

  58. wget -N -r -nd -P $1 -i $2 -o wget.lfs.log



  59. 或者直接下载
  60. wget -i /opt/work/wget-list


  61. echo $LFS
  62. 如果路径不对,则重新设置
  63. export LFS=/mnt/lfs

  64. 创建工具链路径
  65. mkdir -v $LFS/tools

  66. 建立符号链接到宿主系统更目录
  67. ln -sv $LFS/tools /

  68. 为了安全,建立编译lfs的用户和组
  69. groupadd lfs
  70. useradd -s /bin/bash -g lfs -m -k /dev/null lfs

  71. 设置lfs用户密码为“lfs”
  72. passwd lfs

  73. 修改tools和sources目录权限
  74. chown -v lfs $LFS/tools
  75. chown -v lfs $LFS/sources

  76. 为lfs用户创建一个全新的shell环境
  77. su - lfs

  78. 设置lfs的用户环境
  79. cat > ~/.bash_profile << "EOF"
  80. exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
  81. EOF


  82. cat > ~/.bashrc << "EOF"
  83. set +h
  84. umask 022
  85. LFS=/mnt/lfs
  86. LC_ALL=POSIX
  87. LFS_TGT=$(uname -m)-lfs-linux-gnu
  88. PATH=/tools/bin:/bin:/usr/bin
  89. export LFS LC_ALL LFS_TGT PATH
  90. EOF


  91. 命令 exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash ,创建新的Bash实例,并保证这个实例的环境是完全干净的,除了设置 HOME,TERM,PS1几个变量以外。这能保证,我们的编译环境不被主系统中可能存在的环境变量所污染。我们使用的方法不太正规,但能完成任务。要深入地解释起来,最初的shell是 login(登陆) shell,读取 .bash_profile文件,而新的shell实例是non-login(非登陆) shell,它只读取.bashrc文件(随后创建的那一个).

  92. set +h 关掉bash的 "hash"功能。hash 通常是一个有用的特性,这时 bash 使用 hash 表(哈希表)来记住可执行文件的完整路径,以避免为了找到同一个文件而进行多次 `PATH' 搜索。然而,我们希望立刻就能使用新安装的工具。关掉hash功能,那些交互的命令(make,patch, sed,cp 等等)将总是使用新的程序。

  93. 把用户文件创建掩码(umask)设置为 022,保证新创建的文件和目录只能被文件的所有者执行写操作,而能被所有人读和执行。

  94. LFS 变量自然要设置成你加载 LFS 分区的位置。

  95. LC_ALL 变量控制某些软件包的本地化,使它们输出的信息遵守指定国家的规范。当你的主系统glibc版本低于2.2.4时,如果在第五章中把$LC_ALL设置成 "POSIX" 或 "C" 以外的值,当你退出第六章的chroot环境后,要再次进入就会有麻烦。设置成 "POSIX" (或"C",它们俩是相同的)我们保证在chroot环境中不会出现任何问题。

  96. 我们把 /tools/bin 附加到标准路径前面,是为了在安装过程中,总是能用到已经安装了的临时工具。

  97. CC, CXX, CPP, LD_LIBRARY_PATH 和 LD_PRELOAD 环境变量都有可能破坏我们的第五章工具链,因此这里取消它们的设置,以预防可能的问题。

  98. 下面source刚才准备的用户配置文件,准备开始编译临时工具链。

  99. source ~/.bash_profile


  100. cd $LFS/sources


  101. 开始编译工具链!先检查一下$LFS环境变量。
  102. echo $LFS

  103. 5.4. 编译binutils-2.19.1
  104. ----------------------------------------------

  105. tar -jxvf binutils-2.19.1.tar.bz2
  106. cd binutils-2.19.1
  107. mkdir -v ../binutils-build
  108. cd ../binutils-build

  109. ../binutils-2.19.1/configure --target=$LFS_TGT --prefix=/tools --disable-nls --disable-werror

  110. --target=$LFS_TGT: 因为LFS_TGT变量里面的机器描述和config.guess脚本返回的的稍微不同,这个开关告诉configure脚本来修正binutils构建交叉工具链。
  111. --prefix=/tools: 准备把Binutils程序安装到/tools目录。
  112. --disable-nls: 这个参数禁止了国际化(通常简称i18n)。我们的静态程序不需要国际化的特性,并且在静态连接时nls常常引起错误。
  113. --disable-werror: 避免当宿主系统编译器出现警告信息时导致编译停止。

  114. 编译
  115. make

  116. 如果宿主系统是64位,创建一条链接,以保证工具链的稳健
  117. case $(uname -m) in
  118.   x86_64) mkdir -v /tools/lib && ln -sv lib /tools/lib64 ;;
  119. esac

  120. 安装binutils包
  121. make install

  122. 5.5. 编译GCC-4.4.0
  123. ----------------------------------------------

  124. 另开一个终端,用root先行编译gmp和mpfr到宿主系统,因为gcc4.4依赖这两个东东!

  125. ../gcc-4.4.0/configure \
  126.     --target=$LFS_TGT --prefix=/tools \
  127.     --disable-nls --disable-shared --disable-multilib \
  128.     --disable-decimal-float --disable-threads \
  129.     --disable-libmudflap --disable-libssp \
  130.     --disable-libgomp --enable-languages=c

  131. 因为Glibc编译的时候依赖libgcc_eh.a这个库,所以需要建个软链接。

  132. ln -vs libgcc.a `$LFS_TGT-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/'`

  133. `/mnt/lfs/tools/bin/../lib/gcc/i686-lfs-linux-gnu/4.4.0/libgcc_eh.a' -> `libgcc.a'

  134. 也就是增加一个软链接
  135. /mnt/lfs/tools/lib/gcc/i686-lfs-linux-gnu/4.4.0/libgcc_eh.a到相同目录下的libgcc.a


  136. 5.6. 编译Linux-2.6.29.4头文件
  137. ----------------------------------------------

  138. Linux内核需要提供一些API给Glibc使用。

  139. tar -jxvf tar/linux-2.6.29.4.tar.bz2
  140. cd linux-2.6.29.4/

  141. make mrproper

  142. make headers_check
  143. make INSTALL_HDR_PATH=dest headers_install
  144. cp -rv dest/include/* /tools/include



  145. 5.7. Glibc-2.10.1
  146. ----------------------------------------------


  147. tar -jxvf tar/glibc-2.10.1.tar.bz2
  148. cd glibc-2.10.1/
  149. mkdir -v ../glibc-build
  150. cd ../glibc-build


  151. ../glibc-2.10.1/configure --prefix=/tools \
  152.     --host=$LFS_TGT --build=$(../glibc-2.10.1/scripts/config.guess) \
  153.     --disable-profile --enable-add-ons \
  154.     --enable-kernel=2.6.0 --with-headers=/tools/include \
  155.     libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes

  156. make && make install

  157. 5.8. 调整工具链
  158. ----------------------------------------------




  159. 5.9. Binutils-2.19.1 第二遍
  160. ----------------------------------------------

  161. mv binutils-build binutils-build-1
  162. cd binutils-2.19.1/
  163. mkdir -v ../binutils-build
  164. cd ../binutils-build

  165. CC="$LFS_TGT-gcc -B/tools/lib/" \
  166.    AR=$LFS_TGT-ar RANLIB=$LFS_TGT-ranlib \
  167.    ../binutils-2.19.1/configure --prefix=/tools \
  168.    --disable-nls --with-lib-path=/tools/lib

  169. make && make install

  170. 下面还要调整工具链,做些准备。
  171. make -C ld clean
  172. make -C ld LIB_PATH=/usr/lib:/lib
  173. cp -v ld/ld-new /tools/bin

  174. -C ld clean 表示清除ld目录编译后的文件
  175. make -C ld LIB_PATH=/usr/lib:/lib 表示使用新的lib路径,重新编译ld目录的代码。


  176. 5.10. GCC-4.4.0 第二遍
  177. ----------------------------------------------

  178. cd gcc-4.4.0/
  179. patch -Np1 -i ../patch/gcc-4.4.0-startfiles_fix-1.patch
  180. patching file gcc/gcc.c
  181. Hunk #1 succeeded at 6467 (offset 97 lines).


  182. cp -v gcc/Makefile.in{,.orig}
  183. sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in



  184. cp -v gcc/Makefile.in{,.tmp}
  185. sed 's/^XCFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in.tmp \
  186.   > gcc/Makefile.in



  187. for file in \
  188. $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
  189. do
  190.   cp -uv $file{,.orig}
  191.   sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
  192.   -e 's@/usr@/tools@g' $file.orig > $file
  193.   echo '
  194. #undef STANDARD_INCLUDE_DIR
  195. #define STANDARD_INCLUDE_DIR 0
  196. #define STANDARD_STARTFILE_PREFIX_1 ""
  197. #define STANDARD_STARTFILE_PREFIX_2 ""' >> $file
  198.   touch $file.orig
  199. done


  200. 准备mpfr-2.4.1和gmp-4.3.1目录。

  201. tar -jxvf ../tar/mpfr-2.4.1.tar.bz2
  202. mv -v mpfr-2.4.1 mpfr
  203. tar -jxvf ../tar/gmp-4.3.1.tar.bz2
  204. mv gmp-4.3.1 gmp

  205. 保存gcc第一次编译的目录
  206. move -v ../gcc-build ../gcc-build-1

  207. 新建一个gcc编译目录
  208. mkdir -v ../gcc-build
  209. cd ../gcc-build

  210. 这次编译gcc之前,先重设所有变量,替换默认值。

  211. CC="$LFS_TGT-gcc -B/tools/lib/" \
  212.     AR=$LFS_TGT-ar RANLIB=$LFS_TGT-ranlib \
  213.     ../gcc-4.4.0/configure --prefix=/tools \
  214.     --with-local-prefix=/tools --enable-clocale=gnu \
  215.     --enable-shared --enable-threads=posix \
  216.     --enable-__cxa_atexit --enable-languages=c,c++ \
  217.     --disable-libstdcxx-pch --disable-multilib \
  218.     --disable-bootstrap


  219. make && make install

  220. 为了兼容使用cc命令,做个软链接

  221. ln -vs gcc /tools/bin/cc

  222. 检测一下工具链是不是已经换过来了:

  223. echo 'main(){}' > dummy.c
  224. cc dummy.c
  225. readelf -l a.out | grep ': /tools'

  226. 如果没问题,会有下面的输出
  227. [Requesting program interpreter:
  228.     /tools/lib/ld-linux.so.2]

  229. 删掉刚刚的调试文件:
  230. rm -v dummy.c a.out


  231. 5.11. Tcl-8.5.7
  232. ----------------------------------------------

  233. tar -zxvf tar/tcl8.5.7-src.tar.gz

  234. cd tcl8.5.7/
  235. cd unix
  236. ./configure --prefix=/tools
  237. make
  238. TZ=UTC make test
  239. make install

  240. 令以安装的共享库可写,以便调试标记以后能够被移除。
  241. chmod -v u+w /tools/lib/libtcl8.5.so

  242. 安装tcl头文件,下一个包expect需要它们来编译。
  243. make install-private-headers

  244. 再做一个必要的符号链接
  245. ln -sv tclsh8.5 /tools/bin/tclsh


  246. 5.12. Expect-5.43.0
  247. ----------------------------------------------

  248. cd $LFS/sources
  249. tar -zxvf tar/expect-5.43.0.tar.gz
  250. cd expect-5.43/

  251. 首先,打个补丁,否则会导致gcc测试单元失败。
  252. patch -Np1 -i ../patch/expect-5.43.0-spawn-1.patch

  253. 再修复一个漏洞,是针对tcl最近修改的。
  254. patch -Np1 -i ../patch/expect-5.43.0-tcl_8.5.5_fix-1.patch

  255. 接下来,强制要求configure脚本使用/bin/stty替代/usr/local/bin/stty,因为它存在于宿主系统。
  256. 确保我们的测试单元工具到最后的工具链编译还是健全的。

  257. 准备Expect的编译

  258. ./configure --prefix=/tools --with-tcl=/tools/lib \
  259.   --with-tclinclude=/tools/include --with-x=no

  260. make
  261. make test
  262. 注:众所周知,Expect测试单元在某种宿主状态下通常可能失败,这不在我们的控制范围。
  263. 因此,这里的测试单元失败,不用感到吃惊,也不是什么关键问题。

  264. make SCRIPTS="" install

  265. libexpect-5.43.a 提供函数,使得Expect能够被当作Tcl的扩展,或者让Expect基于c/c++直接使用。


  266. 5.13. DejaGNU-1.4.4
  267. ----------------------------------------------

  268. cd $LFS/sources
  269. tar -zxvf tar/dejagnu-1.4.4.tar.gz
  270. cd dejagnu-1.4.4/
  271. ./configure --prefix=/tools
  272. make install

  273. 测试
  274. make check


  275. 5.14. Ncurses-5.7
  276. ----------------------------------------------

  277. cd $LFS/sources
  278. tar -zxvf tar/ncurses-5.7.tar.gz

  279. ./configure --prefix=/tools --with-shared \
  280.     --without-debug --without-ada --enable-overwrite

  281. --without-ada 确保Ncurses不会编译对Ada编译器的支持。
  282. 因为它存在宿主系统上,但一旦我们进入chroot环境就不可用了。

  283. --enable-overwrite 告诉Ncurses安装他的头文件到/tools/include,替换/tools/include/ncurses。
  284. 确保其他包能够顺利找到Ncurses的头文件。

  285. make
  286. make install


  287. 5.15. Bash-4.0
  288. ----------------------------------------------

  289. cd $LFS/sources
  290. tar -zxvf tar/bash-4.0.tar.gz
  291. cd bash-4.0/

  292. 打补丁,bash4出来之后发现的一些问题
  293. patch -Np1 -i ../patch/bash-4.0-fixes-2.patch

  294. ./configure --prefix=/tools --without-bash-malloc

  295. make
  296. make tests
  297. make install
  298. ln -vs bash /tools/bin/sh


  299. 5.16. Bzip2-1.0.5
  300. ----------------------------------------------

  301. cd $LFS/sources
  302. tar -zxvf tar/bzip2-1.0.5.tar.gz
  303. cd bzip2-1.0.5/
  304. make
  305. make PREFIX=/tools install


  306. 5.17. Coreutils-7.4
  307. ---------------------------------------------

  308. cd $LFS/sources
  309. tar -zxvf tar/coreutils-7.4.tar.gz
  310. cd coreutils-7.4/
  311. ./configure --prefix=/tools --enable-install-program=hostname
  312. make
  313. make RUN_EXPENSIVE_TESTS=yes check
  314. make install
  315. cp -v src/su /tools/bin/su-tools


  316. 5.18. Diffutils-2.8.1
  317. ---------------------------------------------

  318. cd $LFS/sources
  319. tar -zxvf tar/diffutils-2.8.1.tar.gz
  320. cd diffutils-2.8.1/

  321. ./configure --prefix=/tools
  322. make && make install


  323. 5.19. E2fsprogs-1.41.5
  324. ---------------------------------------------

  325. cd $LFS/sources
  326. tar -zxvf tar/e2fsprogs-1.41.5.tar.gz
  327. cd e2fsprogs-1.41.5/
  328. mkdir -v build
  329. cd build
  330. ../configure --prefix=/tools
  331. make
  332. make install-libs

  333. chmod -v u+w \
  334.     /tools/lib/{libblkid,libcom_err,libe2p,libext2fs,libss,libuuid}.a


  335. 5.20. Findutils-4.4.1
  336. ---------------------------------------------

  337. cd $LFS/sources
  338. tar -zxvf tar/findutils-4.4.1.tar.gz
  339. cd findutils-4.4.1/
  340. ./configure --prefix=/tools
  341. make
  342. make check
  343. make install



  344. 5.21. Gawk-3.1.6
  345. ---------------------------------------------

  346. cd $LFS/sources
  347. tar -jxvf tar/gawk-3.1.6.tar.bz2
  348. cd gawk-3.1.6/
  349. ./configure --prefix=/tools ac_cv_func_working_mktime=yes
  350. make
  351. make check
  352. make install



  353. 5.22. Gettext-0.17
  354. ---------------------------------------------

  355. cd $LFS/sources
  356. tar -zxvf tar/gettext-0.17.tar.gz
  357. cd gettext-0.17/
  358. cd gettext-tools
  359. ./configure --prefix=/tools --disable-shared

  360. make -C gnulib-lib
  361. make -C src msgfmt

  362. cp -v src/msgfmt /tools/bin



  363. 5.23. Grep-2.5.4
  364. ---------------------------------------------

  365. cd $LFS/sources
  366. tar -jxvf tar/grep-2.5.4.tar.bz2
  367. cd grep-2.5.4/

  368. ./configure --prefix=/tools \
  369.     --disable-perl-regexp \
  370.     --without-included-regex

  371. make
  372. make check
  373. make install


  374. 5.24. Gzip-1.3.12
  375. ---------------------------------------------

  376. cd $LFS/sources
  377. tar -zxvf tar/gzip-1.3.12.tar.gz
  378. cd gzip-1.3.12/

  379. for file in gzip.c lib/utimens.{c,h} ; do \
  380.    cp -v $file{,.orig}
  381.    sed 's/futimens/gl_&/' $file.orig > $file
  382. done


  383. ./configure --prefix=/tools

  384. make
  385. make check
  386. make install


  387. 5.25. M4-1.4.13
  388. ---------------------------------------------

  389. cd $LFS/sources
  390. tar -jxvf tar/m4-1.4.13.tar.bz2
  391. cd m4-1.4.13/
  392. ./configure --prefix=/tools
  393. make
  394. make check
  395. make install


  396. 5.26. Make-3.81
  397. ---------------------------------------------

  398. cd $LFS/sources
  399. tar -jxvf tar/make-3.81.tar.bz2
  400. cd make-3.81/
  401. ./configure --prefix=/tools
  402. make
  403. make check
  404. make install


  405. 5.27. Patch-2.5.9
  406. ---------------------------------------------

  407. cd $LFS/sources
  408. tar -zxvf tar/patch-2.5.9.tar.gz
  409. cd patch-2.5.9/
  410. patch -Np1 -i ../patch/patch-2.5.9-fixes-1.patch
  411. ./configure --prefix=/tools
  412. make
  413. make install


  414. 5.28. Perl-5.10.0
  415. ---------------------------------------------

  416. cd $LFS/sources
  417. tar -zxvf tar/perl-5.10.0.tar.gz
  418. cd perl-5.10.0/
  419. patch -Np1 -i ../patch/perl-5.10.0-consolidated-1.patch

  420. sh Configure -des -Dprefix=/tools \
  421.                   -Dstatic_ext='Data/Dumper Fcntl IO POSIX'

  422. make perl utilities ext/Errno/pm_to_blib

  423. cp -v perl pod/pod2man /tools/bin
  424. mkdir -pv /tools/lib/perl5/5.10.0
  425. cp -Rv lib/* /tools/lib/perl5/5.10.0


  426. 5.29. Sed-4.2
  427. ---------------------------------------------

  428. cd $LFS/sources
  429. tar -jxvf tar/sed-4.2.tar.bz2
  430. cd sed-4.2/

  431. ./configure --prefix=/tools
  432. make
  433. make check
  434. make install



  435. 5.30. Tar-1.22
  436. ---------------------------------------------

  437. cd $LFS/sources
  438. tar -jxvf tar/tar-1.22.tar.bz2
  439. cd tar-1.22/

  440. ./configure --prefix=/tools
  441. make
  442. make check
  443. make install


  444. 5.31. Texinfo-4.13a
  445. ---------------------------------------------

  446. cd $LFS/sources
  447. tar -zxvf tar/texinfo-4.13a.tar.gz
  448. cd texinfo-4.13/

  449. ./configure --prefix=/tools
  450. make
  451. make check
  452. make install


  453. 5.32. Util-linux-ng-2.14.2
  454. ---------------------------------------------

  455. cd $LFS/sources
  456. tar -jxvf tar/util-linux-ng-2.14.2.tar.bz2
  457. cd util-linux-ng-2.14.2/

  458. ./configure --prefix=/tools

  459. make -C disk-utils mkswap
  460. make -C mount mount umount
  461. make -C text-utils more

  462. cp -v disk-utils/mkswap mount/{,u}mount text-utils/more /tools/bin


  463. 5.33. Stripping
  464. ---------------------------------------------

  465. strip --strip-debug /tools/lib/*
  466. strip --strip-unneeded /tools/{,s}bin/*

  467. rm -rf /tools/{info,man}


  468. 5.34. Changing Ownership
  469. ---------------------------------------------
  470. exit
  471. 退出lfs用户shell环境

  472. 更改tools工具链的所有权为root,以免将来工具链被恶意提升权限。
  473. chown -R root:root $LFS/tools

  474. tools在lfs编译完成后可以被删除,但还是可以用来编译相同版本的lfs程序
  475. 如何保存工具链,全凭个人爱好!

复制代码

论坛徽章:
0
2 [报告]
发表于 2009-06-09 11:34 |只看该作者
继续,LFS第六章



  1. 构建LFS系统

  2. 6.1. 尽量简单的编译一个LFS系统雏形,尽量不要使用编译器优化参数,因为这带来的速度提升几乎可以忽略不计,但带来的坏处,可能导致程序运行不稳定。不要同时编译几个包,因为这样可能产生硬链接到/tools,如果tools目录被删除,可能会出现问题。

  3. 6.2. 准备虚拟内核文件系统

  4. export LFS=/mnt/lfs
  5. mkdir -pv $LFS/{dev,proc,sys}

  6. 建立初始设备节点(console和null设备)
  7. mknod -m 600 $LFS/dev/console c 5 1
  8. mknod -m 666 $LFS/dev/null c 1 3

  9. 挂载并绑定设备目录
  10. mount -v --bind /dev $LFS/dev

  11. 挂载虚拟内核文件系统
  12. mount -vt devpts devpts $LFS/dev/pts
  13. mount -vt tmpfs shm $LFS/dev/shm
  14. mount -vt proc proc $LFS/proc
  15. mount -vt sysfs sysfs $LFS/sys


  16. 6.3. 包管理
  17. 集中流行的包管理思想,LFS不提供包管理系统


  18. 6.4. 进入Chroot环境
  19. chroot "$LFS" /tools/bin/env -i \
  20.     HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
  21.     PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
  22.     /tools/bin/bash --login +h

  23. 用env -i 表示清空所有环境变量,只重设后面的几个。在这里也可以设置CFLAGS或者CXXFLAGS
  24. 进入chroot环境后,由于还没建立/etc/passwd 文件,所以shell提示符前面为:
  25. I have no name!:/#

  26. 到了这点上面,$LFS变量就可以不管了,因为接下来所有的工作都被限制在LFS文件系统里面了。
  27. Bash已经把$LFS当作root (/) 目录来处理了。


  28. 6.5. 增加目录

  29. 增加文件结构

  30. mkdir -pv /{bin,boot,etc/opt,home,lib,mnt,opt}
  31. mkdir -pv /{media/{floppy,cdrom},sbin,srv,var}
  32. install -dv -m 0750 /root
  33. install -dv -m 1777 /tmp /var/tmp
  34. mkdir -pv /usr/{,local/}{bin,include,lib,sbin,src}
  35. mkdir -pv /usr/{,local/}share/{doc,info,locale,man}
  36. mkdir -v  /usr/{,local/}share/{misc,terminfo,zoneinfo}
  37. mkdir -pv /usr/{,local/}share/man/man{1..8}
  38. for dir in /usr /usr/local; do
  39.   ln -sv share/{man,doc,info} $dir
  40. done
  41. case $(uname -m) in
  42. x86_64) ln -sv lib /lib64 && ln -sv lib /usr/lib64 ;;
  43. esac
  44. mkdir -v /var/{lock,log,mail,run,spool}
  45. mkdir -pv /var/{opt,cache,lib/{misc,locate},local}

  46. 以上文件夹结构,遵循Filesystem Hierarchy Standard (FHS)
  47. [url]http://www.pathname.com/fhs/[/url]


  48. 6.6. 增加必要的文件和软链接

  49. ln -sv /tools/bin/{bash,cat,echo,pwd,stty} /bin
  50. ln -sv /tools/bin/perl /usr/bin
  51. ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
  52. ln -sv /tools/lib/libstdc++.so{,.6} /usr/lib
  53. ln -sv bash /bin/sh

  54. touch /etc/mtab

  55. cat > /etc/passwd << "EOF"
  56. root:x:0:0:root:/root:/bin/bash
  57. bin:x:1:1:bin:/dev/null:/bin/false
  58. nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
  59. EOF


  60. cat > /etc/group << "EOF"
  61. root:x:0:
  62. bin:x:1:
  63. sys:x:2:
  64. kmem:x:3:
  65. tty:x:4:
  66. tape:x:5:
  67. daemon:x:6:
  68. floppy:x:7:
  69. disk:x:8:
  70. lp:x:9:
  71. dialout:x:10:
  72. audio:x:11:
  73. video:x:12:
  74. utmp:x:13:
  75. usb:x:14:
  76. cdrom:x:15:
  77. mail:x:34:
  78. nogroup:x:99:
  79. EOF


  80. 完整的glibc安装好之后,passwd和group文件已经建立,现在用户名和组可以生效了。
  81. exec /tools/bin/bash --login +h
  82. 使用+h参数,屏蔽bash的内部路径哈希。避免bash使用旧的文件路径,能够保证新编译的代码马上可以被利用。

  83. 建立一些空文件并赋予它们写权限,以便login, agetty, init以及其他一些程序能够记录系统日志及登陆信息
  84. touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
  85. chgrp -v utmp /var/run/utmp /var/log/lastlog
  86. chmod -v 664 /var/run/utmp /var/log/lastlog

  87. 注:
  88. /var/run/utmp 记录已经登陆的用户信息, /var/log/wtmp 记录所有登陆及注销信息,
  89. /var/log/lastlog 记录每个用户的最后登陆时间, /var/log/btmp 记录登陆失败信息。



  90. 6.7. Linux-2.6.29.4 API Headers

  91. cd /sources
  92. cd linux-2.6.29.4/
  93. make mrproper

  94. make headers_check
  95. make INSTALL_HDR_PATH=dest headers_install
  96. cp -rv dest/include/* /usr/include


  97. 6.8. Man-pages-3.21

  98. cd /sources
  99. tar -jxvf tar/man-pages-3.21.tar.bz2
  100. cd man-pages-3.21/
  101. make install


  102. 6.9. Glibc-2.10.1

  103. cd /sources/glibc-2.10.1/
  104. tar -jxvf ../tar/glibc-libidn-2.10.1.tar.bz2
  105. mv glibc-libidn-2.10.1 libidn

  106. 当执行glibc的make install的时候,会调用一个perl脚本进行测试,
  107. 现在的工具链还是指向/tools,测试会针对以前编译的glibc,
  108. 以下脚本可以让测试指向刚刚编译的glibc

  109. DL=$(readelf -l /bin/sh | sed -n 's@.*interpret.*/tools\(.*\)]$@\1@p')
  110. sed -i "s|libs -o|libs -L/usr/lib -Wl,-dynamic-linker=$DL -o|" \
  111.         scripts/test-installation.pl
  112. unset DL

  113. ldd命令自带了bash的特殊语法,为了避免其他的/bin/sh对ldd的影响,
  114. 最好把默认解释器改成/bin/bash,关于这个鸟问题,在BLFS 这本破书的shell章节中也提到了

  115. sed -i 's|@BASH@|/bin/bash|' elf/ldd.bash.in


  116. 修复一个make check可能出现的错误

  117. sed -i s/utf8/UTF-8/ libio/tst-fgetwc.c
  118. sed -i '/tst-fgetws-ENV/ a\
  119. tst-fgetwc-ENV = LOCPATH=$(common-objpfx)localedata' libio/Makefile

  120. mkdir -v ../glibc-build
  121. cd ../glibc-build

  122. 为x86机器增加必要的CFLAGS编译参数,-pipe加速编译,-O3提高程序的性能。

  123. case `uname -m` in
  124.   i?86) echo "CFLAGS += -march=i686 -mtune=native -O3 -pipe" > configparms ;;
  125. esac

  126. 准备编译
  127. ../glibc-2.10.1/configure --prefix=/usr \
  128.     --disable-profile --enable-add-ons \
  129.     --enable-kernel=2.6.0 --libexecdir=/usr/lib/glibc

  130. 开始编译,等N久!
  131. make

  132. 为防止编译测试的几个失败可能,从源码目录拷贝一个东东。
  133. cp -v ../glibc-2.10.1/iconvdata/gconv-modules iconvdata
  134. make -k check 2>&1 | tee glibc-check-log
  135. grep Error glibc-check-log
  136. 在测试posix/annexc的时候,有一个可忽略的错误。
  137. 这和宿主系统有关,这里不用理它。

  138. 虽然无关紧要,为了防止glibc安装阶段报错缺少说ld.so.conf,还是touch一个吧
  139. touch /etc/ld.so.conf

  140. make install


  141. 定义locale集合

  142. mkdir -pv /usr/lib/locale
  143. localedef -i cs_CZ -f UTF-8 cs_CZ.UTF-8
  144. localedef -i de_DE -f ISO-8859-1 de_DE
  145. localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
  146. localedef -i de_DE -f UTF-8 de_DE.UTF-8
  147. localedef -i en_HK -f ISO-8859-1 en_HK
  148. localedef -i en_PH -f ISO-8859-1 en_PH
  149. localedef -i en_US -f ISO-8859-1 en_US
  150. localedef -i en_US -f UTF-8 en_US.UTF-8
  151. localedef -i es_MX -f ISO-8859-1 es_MX
  152. localedef -i fa_IR -f UTF-8 fa_IR
  153. localedef -i fr_FR -f ISO-8859-1 fr_FR
  154. localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
  155. localedef -i fr_FR -f UTF-8 fr_FR.UTF-8
  156. localedef -i it_IT -f ISO-8859-1 it_IT
  157. localedef -i ja_JP -f EUC-JP ja_JP
  158. localedef -i tr_TR -f UTF-8 tr_TR.UTF-8
  159. localedef -i zh_CN -f GB18030 zh_CN.GB18030

  160. 其实这里我只要三个就可以了
  161. localedef -i en_US -f ISO-8859-1 en_US
  162. localedef -i en_US -f UTF-8 en_US.UTF-8
  163. localedef -i zh_CN -f GB18030 zh_CN.GB18030

  164. 安装其他没有执行localedef定义的语言包(可选)
  165. make localedata/install-locales


  166. 配置glibc
  167. 尽管当nsswitch.conf不存在或非法时,Glibc会默认产生,但在网络环境下,可能不是很理想。
  168. 所以还是创建一个吧,另外,时区也应该配置了。

  169. cat > /etc/nsswitch.conf << "EOF"
  170. # Begin /etc/nsswitch.conf

  171. passwd: files
  172. group: files
  173. shadow: files

  174. hosts: files dns
  175. networks: files

  176. protocols: files
  177. services: files
  178. ethers: files
  179. rpc: files

  180. # End /etc/nsswitch.conf
  181. EOF

  182. 选择时区
  183. tzselect


  184. 这里最后应该是 TZ='Asia/Shanghai';


  185. 增加/etc/localtime

  186. cp -v --remove-destination /usr/share/zoneinfo/Asia/Shanghai \
  187.     /etc/localtime

  188. 配置动态加载
  189. cat > /etc/ld.so.conf << "EOF"
  190. # Begin /etc/ld.so.conf

  191. /usr/local/lib
  192. /opt/lib

  193. # End /etc/ld.so.conf
  194. EOF




  195. 6.10. 重新调整工具链

  196. 先备份,然后用第五章里面调整过的工具链替换。
  197. mv -v /tools/bin/{ld,ld-old}
  198. mv -v /tools/$(gcc -dumpmachine)/bin/{ld,ld-old}
  199. mv -v /tools/bin/{ld-new,ld}
  200. ln -sv /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld

  201. 接下来,调整gcc的spec文件,以便指向新的动态链接库。

  202. gcc -dumpspecs | sed -e 's@/tools@@g' \
  203.     -e '/\*startfile_prefix_spec:/{n;s@.*@/usr/lib/ @}' \
  204.     -e '/\*cpp:/{n;s@$@ -isystem /usr/include@}' > \
  205.     `dirname $(gcc --print-libgcc-file-name)`/specs


  206. 最好仔细检查一下specs文件是不是真的修改了。

  207. 测试一下新的工具链
  208. echo 'main(){}' > dummy.c
  209. cc dummy.c -v -Wl,--verbose &> dummy.log
  210. readelf -l a.out | grep ': /lib'

  211. 应该出现以下提示
  212. [Requesting program interpreter: /lib/ld-linux.so.2]


  213. grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log
  214. 应该出现
  215. /usr/lib/crt1.o succeeded
  216. /usr/lib/crti.o succeeded
  217. /usr/lib/crtn.o succeeded

  218. 确保编译器使用了正确的头文件
  219. grep -B1 '^ /usr/include' dummy.log

  220. 应该输出
  221. #include <...> search starts here:
  222. /usr/include

  223. 再看看新的编译器是否使用了正确的查找路径
  224. grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'

  225. 应该输出
  226. SEARCH_DIR("/tools/i686-pc-linux-gnu/lib")
  227. SEARCH_DIR("/usr/lib")
  228. SEARCH_DIR("/lib");


  229. 再检查是不是使用了正确的libc
  230. grep "/lib.*/libc.so.6 " dummy.log

  231. 应该输出
  232. attempt to open /lib/libc.so.6 succeeded


  233. 最后一点,确认gcc使用了正确的动态链接器
  234. grep found dummy.log

  235. 应该输出
  236. found ld-linux.so.2 at /lib/ld-linux.so.2

  237. 如果一切都没问题,那么清楚测试文件
  238. rm -v dummy.c a.out dummy.log


  239. 6.11. Zlib-1.2.3

  240. cd /sources
  241. tar -xvf tar/zlib-1.2.3.tar.bz2
  242. cd zlib-1.2.3/

  243. ./configure --prefix=/usr --shared --libdir=/lib

  244. make
  245. make check
  246. make install

  247. 刚才的命令安装了一个.so文件在/lib目录,我们将它移动并重新链接到/usr/lib

  248. rm -v /lib/libz.so
  249. ln -sfv ../../lib/libz.so.1.2.3 /usr/lib/libz.so


  250. 编译静态链接库

  251. make clean
  252. ./configure --prefix=/usr
  253. make

  254. make check
  255. make install


  256. 修正静态链接库的权限
  257. chmod -v 644 /usr/lib/libz.a



  258. 6.12. Binutils-2.19.1

  259. cd /sources/binutils-2.19.1/

  260. 验证新的chroot环境内,PTYs工作是否正常
  261. expect -c "spawn ls"

  262. 正常应该输出
  263. spawn ls

  264. rm -fv etc/standards.info
  265. sed -i.bak '/^INFO/s/standards.info //' etc/Makefile.in

  266. sed -i -e 's/getline/get_line/' libiberty/testsuite/test-demangle.c

  267. mkdir -v ../binutils-build
  268. cd ../binutils-build

  269. ../binutils-2.19.1/configure --prefix=/usr \
  270.     --enable-shared

  271. make tooldir=/usr
  272. make check
  273. make tooldir=/usr install
  274. cp -v ../binutils-2.19.1/include/libiberty.h /usr/include


  275. 6.13. GMP-4.3.1

  276. cd /sources
  277. tar -xvf tar/gmp-4.3.1.tar.bz2
  278. cd gmp-4.3.1/

  279. ./configure --prefix=/usr --enable-cxx --enable-mpbsd
  280. make
  281. make check 2>&1 | tee gmp-check-log
  282. awk '/tests passed/{total+=$2} ; END{print total}' gmp-check-log
  283. make install

  284. mkdir -v /usr/share/doc/gmp-4.3.1
  285. cp    -v doc/{isa_abi_headache,configuration} doc/*.html \
  286.          /usr/share/doc/gmp-4.3.1


  287. 6.14. MPFR-2.4.1

  288. cd /sources
  289. tar -xvf tar/mpfr-2.4.1.tar.bz2
  290. cd mpfr-2.4.1/

  291. ./configure --prefix=/usr --enable-thread-safe

  292. make
  293. make check
  294. make install

  295. 安装帮助文档
  296. make html
  297. mkdir -p /usr/share/doc/mpfr-2.4.1
  298. find . -name \*.html -type f -exec cp -v \{} /usr/share/doc/mpfr-2.4.1 \;




  299. 6.15. GCC-4.4.0 (第三次编译gcc-4.4.0)

  300. 为了防止重复修改源码导致编译出错,删除以前的源码目录,重新弄一个!
  301. rm -rf /sources/gcc-4.4.0/

  302. cd /sources
  303. tar -jxvf tar/gcc-4.4.0.tar.bz2
  304. cd gcc-4.4.0

  305. sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in

  306. 在5.1.0 gcc4 第二遍的时候
  307. case `uname -m` in
  308.   i?86) sed -i 's/^XCFLAGS =$/& -fomit-frame-pointer/' \
  309.         gcc/Makefile.in ;;
  310. esac

  311. 这里也要做一次,呵呵。

  312. sed -i 's@\./fixinc\.sh@-c true@' gcc/Makefile.in


  313. mkdir -v ../gcc-build
  314. cd ../gcc-build


  315. ../gcc-4.4.0/configure --prefix=/usr \
  316.     --libexecdir=/usr/lib --enable-shared \
  317.     --enable-threads=posix --enable-__cxa_atexit \
  318.     --enable-clocale=gnu --enable-languages=c,c++ \
  319.     --disable-multilib --disable-bootstrap

  320. make
  321. make -k check

  322. ../gcc-4.4.0/contrib/test_summary

  323. make install

  324. 兼容链接
  325. ln -sv ../usr/bin/cpp /lib
  326. ln -sv gcc /usr/bin/cc

  327. 测试工具链
  328. echo 'main(){}' > dummy.c
  329. cc dummy.c -v -Wl,--verbose &> dummy.log
  330. readelf -l a.out | grep ': /lib'

  331. 正确输出
  332. [Requesting program interpreter: /lib/ld-linux.so.2]

  333. grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log
  334. 正确输出
  335. /usr/lib/gcc/i686-pc-linux-gnu/4.4.0/../../../crt1.o succeeded
  336. /usr/lib/gcc/i686-pc-linux-gnu/4.4.0/../../../crti.o succeeded
  337. /usr/lib/gcc/i686-pc-linux-gnu/4.4.0/../../../crtn.o succeeded


  338. 检查是否调用正确的头文件
  339. grep -B4 '^ /usr/include' dummy.log

  340. 正确应该有以下输出
  341. #include <...> search starts here:
  342. /usr/local/include
  343. /usr/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/include
  344. /usr/lib/gcc/i686-pc-linux-gnu/4.4.0/include-fixed
  345. /usr/include

  346. 检查搜索路径是否正确
  347. grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'

  348. 正常会输出
  349. SEARCH_DIR("/usr/i686-pc-linux-gnu/lib")
  350. SEARCH_DIR("/usr/local/lib")
  351. SEARCH_DIR("/lib")
  352. SEARCH_DIR("/usr/lib");

  353. 64位系统会输出
  354. SEARCH_DIR("/usr/x86_64-unknown-linux-gnu/lib64")
  355. SEARCH_DIR("/usr/local/lib64")
  356. SEARCH_DIR("/lib64")
  357. SEARCH_DIR("/usr/lib64")
  358. SEARCH_DIR("/usr/x86_64-unknown-linux-gnu/lib")
  359. SEARCH_DIR("/usr/local/lib")
  360. SEARCH_DIR("/lib")
  361. SEARCH_DIR("/usr/lib");


  362. 检查libc调用
  363. grep "/lib.*/libc.so.6 " dummy.log
  364. 正确输出
  365. attempt to open /lib/libc.so.6 succeeded

  366. 检查动态链接库
  367. grep found dummy.log
  368. 正确输出
  369. found ld-linux.so.2 at /lib/ld-linux.so.2


  370. 删除测试文件
  371. rm -v dummy.c a.out dummy.log


  372. 6.16. Berkeley DB-4.7.25

  373. cd /sources/
  374. tar -xvf tar/db-4.7.25.tar.gz
  375. cd db-4.7.25/
  376. patch -Np1 -i ../patch/db-4.7.25-upstream_fixes-1.patch

  377. cd build_unix
  378. ../dist/configure --prefix=/usr --enable-compat185 --enable-cxx

  379. make
  380. make docdir=/usr/share/doc/db-4.7.25 install

  381. 修复文档的所有权
  382. chown -Rv root:root /usr/share/doc/db-4.7.25



  383. 6.17. Sed-4.2

  384. cd /sources/
  385. rm -rf sed-4.2/

  386. tar -xvf tar/sed-4.2.tar.bz2
  387. cd sed-4.2/
  388. ./configure --prefix=/usr --bindir=/bin --enable-html

  389. make
  390. make check
  391. make install



  392. 6.18. E2fsprogs-1.41.5


  393. sed -i 's@/bin/rm@/tools&@' lib/blkid/test_probe.in
  394. mkdir -v build
  395. cd build

  396. ../configure --prefix=/usr --with-root-prefix="" \
  397.     --enable-elf-shlibs

  398. make
  399. make check
  400. make install
  401. make install-libs

  402. chmod -v u+w /usr/lib/{libblkid,libcom_err,libe2p,libext2fs,libss,libuuid}.a


  403. gunzip -v /usr/share/info/libext2fs.info.gz
  404. install-info --dir-file=/usr/share/info/dir \
  405.              /usr/share/info/libext2fs.info


  406. makeinfo -o      doc/com_err.info ../lib/et/com_err.texinfo
  407. install -v -m644 doc/com_err.info /usr/share/info
  408. install-info --dir-file=/usr/share/info/dir \
  409.              /usr/share/info/com_err.info

  410. install -v -m644 -D ../doc/libblkid.txt \
  411.         /usr/share/doc/e2fsprogs-1.41.5/libblkid.txt



  412. 6.19. Coreutils-7.4

  413. Intel硬件系统里面,当使用uname -p参数时,经常返回unknown,下面打个补丁。

  414. case `uname -m` in
  415. i?86 | x86_64) patch -Np1 -i ../patch/coreutils-7.4-uname-1.patch ;;
  416. esac

  417. POSIX标准需要coreutils程序识别多字节语言的字符边界效验。
  418. patch -Np1 -i ../patch/coreutils-7.4-i18n-1.patch

  419. 准备编译
  420. ./configure --prefix=/usr \
  421.     --enable-no-install-program=kill,uptime

  422. make

  423. make NON_ROOT_USERNAME=nobody check-root

  424. 准备用nobody用户完成下面的测试,这里建立一个临时组,将nobody加入这个组,进行测试
  425. echo "dummy:x:1000:nobody" >> /etc/group

  426. 修正权限
  427. chown -Rv nobody config.log {gnulib-tests,lib,src}/.deps

  428. 用nobody用户运行测试程序
  429. su-tools nobody -s /bin/bash -c "make RUN_EXPENSIVE_TESTS=yes check" || true

  430. 删除临时组
  431. sed -i '/dummy/d' /etc/group

  432. 安装coreutils包
  433. make install

  434. 将下面的命令移动到基于FHS的路径
  435. mv -v /usr/bin/{cat,chgrp,chmod,chown,cp,date,dd,df,echo} /bin
  436. mv -v /usr/bin/{false,ln,ls,mkdir,mknod,mv,pwd,rm} /bin
  437. mv -v /usr/bin/{rmdir,stty,sync,true,uname} /bin
  438. mv -v /usr/bin/chroot /usr/sbin

  439. LFS-Bootscripts包里的某些脚本,依赖于head,sleep和nice
  440. /usr目录在系统启动初期可能不可用,这些二进制文件需要放在root分区
  441. mv -v /usr/bin/{head,sleep,nice} /bin



  442. 6.20. Iana-Etc-2.30

  443. cd /sources/
  444. tar -xvf tar/iana-etc-2.30.tar.bz2
  445. cd iana-etc-2.30/
  446. make && make install



  447. 6.21. M4-1.4.13

  448. ./configure --prefix=/usr
  449. make
  450. make check
  451. make install


  452. 6.22. Bison-2.4.1

  453. tar -xvf tar/bison-2.4.1.tar.bz2
  454. cd bison-2.4.1/
  455. ./configure --prefix=/usr

  456. echo '#define YYENABLE_NLS 1' >> config.h
  457. make
  458. make check
  459. make install



  460. 6.23. Ncurses-5.7

  461. ./configure --prefix=/usr --with-shared --without-debug --enable-widec
  462. make
  463. make install

  464. mv -v /usr/lib/libncursesw.so.5* /lib
  465. ln -sfv ../../lib/libncursesw.so.5 /usr/lib/libncursesw.so


  466. for lib in ncurses form panel menu ; do \
  467.     rm -vf /usr/lib/lib${lib}.so ; \
  468.     echo "INPUT(-l${lib}w)" >/usr/lib/lib${lib}.so ; \
  469.     ln -sfv lib${lib}w.a /usr/lib/lib${lib}.a ; \
  470. done
  471. ln -sfv libncurses++w.a /usr/lib/libncurses++.a



  472. rm -vf /usr/lib/libcursesw.so
  473. echo "INPUT(-lncursesw)" >/usr/lib/libcursesw.so
  474. ln -sfv libncurses.so /usr/lib/libcurses.so
  475. ln -sfv libncursesw.a /usr/lib/libcursesw.a
  476. ln -sfv libncurses.a /usr/lib/libcurses.a


  477. mkdir -v       /usr/share/doc/ncurses-5.7
  478. cp -v -R doc/* /usr/share/doc/ncurses-5.7



  479. Note
  480. The instructions above don't create non-wide-character Ncurses libraries since no package installed by compiling from sources would link against them at runtime. If you must have such libraries because of some binary-only application, build them with the following commands:

  481. make distclean
  482. ./configure --prefix=/usr --with-shared --without-normal \
  483.   --without-debug --without-cxx-binding
  484. make sources libs
  485. cp -av lib/lib*.so.5* /usr/lib



  486. 6.24. Procps-3.2.8


  487. patch -Np1 -i ../patch/procps-3.2.8-watch_unicode-1.patch

  488. make
  489. make install


  490. 6.25. Grep-2.5.4

  491. patch -Np1 -i ../patch/grep-2.5.4-debian_fixes-1.patch


  492. ./configure --prefix=/usr \
  493.     --bindir=/bin \
  494.     --without-included-regex

  495. make
  496. make check || true
  497. make install


  498. 6.26. Readline-6.0


  499. sed -i '/MV.*old/d' Makefile.in
  500. sed -i '/{OLDSUFF}/c:' support/shlib-install

  501. ./configure --prefix=/usr --libdir=/lib

  502. make SHLIB_LIBS=-lncurses

  503. make install

  504. mv -v /lib/lib{readline,history}.a /usr/lib

  505. rm -v /lib/lib{readline,history}.so
  506. ln -sfv ../../lib/libreadline.so.6 /usr/lib/libreadline.so
  507. ln -sfv ../../lib/libhistory.so.6 /usr/lib/libhistory.so

  508. mkdir   -v       /usr/share/doc/readline-6.0
  509. install -v -m644 doc/*.{ps,pdf,html,dvi} \
  510.                  /usr/share/doc/readline-6.0



  511. 6.27. Bash-4.0


  512. patch -Np1 -i ../patch/bash-4.0-fixes-2.patch


  513. ./configure --prefix=/usr --bindir=/bin \
  514.     --htmldir=/usr/share/doc/bash-4.0 --without-bash-malloc \
  515.     --with-installed-readline

  516. make

  517. sed -i 's/LANG/LC_ALL/' tests/intl.tests
  518. sed -i 's@tests@& </dev/tty@' tests/run-test
  519. chown -Rv nobody ./

  520. su-tools nobody -s /bin/bash -c "make tests"

  521. make install

  522. exec /bin/bash --login +h



  523. 6.28. Libtool-2.2.6a

  524. ./configure --prefix=/usr
  525. make
  526. make check
  527. make install



  528. 6.29. Inetutils-1.6

  529. patch -Np1 -i ../patch/inetutils-1.6-no_server_man_pages-1.patch


  530. ./configure --prefix=/usr --libexecdir=/usr/sbin \
  531.     --localstatedir=/var --disable-ifconfig \
  532.     --disable-logger --disable-syslogd --disable-whois \
  533.     --disable-servers


  534. make
  535. make install
  536. mv -v /usr/bin/ping /bin




  537. 6.30. Perl-5.10.0

  538. echo "127.0.0.1 localhost $(hostname)" > /etc/hosts

  539. patch -Np1 -i ../patch/perl-5.10.0-consolidated-1.patch


  540. sed -i -e "s|BUILD_ZLIB\s*= True|BUILD_ZLIB = False|"           \
  541.        -e "s|INCLUDE\s*= ./zlib-src|INCLUDE    = /usr/include|" \
  542.        -e "s|LIB\s*= ./zlib-src|LIB        = /usr/lib|"         \
  543.     ext/Compress/Raw/Zlib/config.in


  544. sh Configure -des -Dprefix=/usr \
  545.                   -Dvendorprefix=/usr           \
  546.                   -Dman1dir=/usr/share/man/man1 \
  547.                   -Dman3dir=/usr/share/man/man3 \
  548.                   -Dpager="/usr/bin/less -isR"


  549. make
  550. make test
  551. make install




  552. 6.31. Autoconf-2.63

  553. ./configure --prefix=/usr

  554. make
  555. make check
  556. make install



  557. 6.32. Automake-1.11

  558. ./configure --prefix=/usr --docdir=/usr/share/doc/automake-1.11

  559. make
  560. make check
  561. 要check好久好久:(

  562. make install


  563. 6.33. Bzip2-1.0.5

  564. patch -Np1 -i ../patch/bzip2-1.0.5-install_docs-1.patch

  565. sed -i 's@\(ln -s -f \)$(PREFIX)/bin/@\1@' Makefile

  566. make -f Makefile-libbz2_so
  567. make clean

  568. make
  569. make PREFIX=/usr install

  570. cp -v bzip2-shared /bin/bzip2
  571. cp -av libbz2.so* /lib
  572. ln -sv ../../lib/libbz2.so.1.0 /usr/lib/libbz2.so
  573. rm -v /usr/bin/{bunzip2,bzcat,bzip2}
  574. ln -sv bzip2 /bin/bunzip2
  575. ln -sv bzip2 /bin/bzcat


复制代码


第六章需要做的工作太多了,下面继续!

论坛徽章:
0
3 [报告]
发表于 2009-06-09 11:35 |只看该作者
继续第六章



  1. 6.34. Diffutils-2.8.1

  2. patch -Np1 -i ../patch/diffutils-2.8.1-i18n-1.patch

  3. touch man/diff.1
  4. ./configure --prefix=/usr
  5. make
  6. make install



  7. 6.35. File-5.00


  8. sed -i -e '197,+1d' \
  9.        -e '189,+1d' \
  10.        -e 's/token$/tokens/' doc/file.man

  11. ./configure --prefix=/usr

  12. make
  13. make check
  14. make install


  15. 6.36. Gawk-3.1.6

  16. ./configure --prefix=/usr --libexecdir=/usr/lib \
  17.    ac_cv_func_working_mktime=yes

  18. make
  19. make check
  20. make install

  21. mkdir -v /usr/share/doc/gawk-3.1.6
  22. cp    -v doc/{awkforai.txt,*.{eps,pdf,jpg}} \
  23.          /usr/share/doc/gawk-3.1.6



  24. 6.37. GDBM-1.8.3

  25. ./configure --prefix=/usr

  26. make
  27. make install
  28. make install-compat



  29. 6.38. Findutils-4.4.1


  30. ./configure --prefix=/usr --libexecdir=/usr/lib/findutils \
  31.     --localstatedir=/var/lib/locate

  32. make
  33. make check
  34. make install

  35. mv -v /usr/bin/find /bin
  36. sed -i 's/find:=${BINDIR}/find:=\/bin/' /usr/bin/updatedb




  37. 6.39. Flex-2.5.35

  38. patch -Np1 -i ../patch/flex-2.5.35-gcc44-1.patch

  39. ./configure --prefix=/usr

  40. make
  41. make check
  42. make install

  43. ln -sv libfl.a /usr/lib/libl.a


  44. cat > /usr/bin/lex << "EOF"
  45. #!/bin/sh
  46. # Begin /usr/bin/lex

  47. exec /usr/bin/flex -l "$@"

  48. # End /usr/bin/lex
  49. EOF
  50. chmod -v 755 /usr/bin/lex


  51. mkdir -v /usr/share/doc/flex-2.5.35
  52. cp    -v doc/flex.pdf \
  53.          /usr/share/doc/flex-2.5.35



  54. 6.40. Gettext-0.17

  55. patch -Np1 -i ../patch/gettext-0.17-upstream_fixes-2.patch

  56. ./configure --prefix=/usr \
  57.             --docdir=/usr/share/doc/gettext-0.17

  58. make
  59. make check
  60. make install



  61. 6.41. Groff-1.20.1

  62. PAGE=A4 ./configure --prefix=/usr

  63. make
  64. make docdir=/usr/share/doc/groff-1.20.1 install

  65. ln -sv eqn /usr/bin/geqn
  66. ln -sv tbl /usr/bin/gtbl



  67. 6.42. Gzip-1.3.12

  68. sed -i 's/futimens/gl_&/' gzip.c lib/utimens.{c,h}
  69. sed -i 's/5 -)/5 - >\&3)/' zdiff.in

  70. ./configure --prefix=/usr --bindir=/bin

  71. make
  72. make check
  73. make install

  74. mv -v /bin/{gzexe,uncompress,zcmp,zdiff,zegrep} /usr/bin
  75. mv -v /bin/{zfgrep,zforce,zgrep,zless,zmore,znew} /usr/bin



  76. 6.43. IPRoute2-2.6.29-1

  77. make DESTDIR=

  78. make DESTDIR= SBINDIR=/sbin MANDIR=/usr/share/man \
  79.      DOCDIR=/usr/share/doc/iproute2-2.6.29-1 install

  80. mv -v /sbin/arpd /usr/sbin



  81. 6.44. Kbd-1.15

  82. patch -Np1 -i ../patch/kbd-1.15-backspace-1.patch

  83. sed -i -e '1i KEYCODES_PROGS = @KEYCODES_PROGS@' \
  84.     -e '1i RESIZECONS_PROGS = @RESIZECONS_PROGS@' src/Makefile.in

  85. var=OPTIONAL_PROGS
  86. sed -i "s/ifdef $var/ifeq (\$($var),yes)/" man/Makefile.in
  87. unset var

  88. ./configure --prefix=/usr --datadir=/lib/kbd

  89. make
  90. make install

  91. mv -v /usr/bin/{kbd_mode,loadkeys,openvt,setfont} /bin

  92. mkdir -v /usr/share/doc/kbd-1.15
  93. cp -R -v doc/* \
  94.          /usr/share/doc/kbd-1.15



  95. 6.45. Less-429

  96. ./configure --prefix=/usr --sysconfdir=/etc

  97. make
  98. make install



  99. 6.46. Make-3.81


  100. ./configure --prefix=/usr

  101. make
  102. make check
  103. make install


  104. 6.47. Man-DB-2.5.5

  105. patch -Np1 -i ../patch/man-db-2.5.5-fix_testsuite-1.patch

  106. ./configure --prefix=/usr --libexecdir=/usr/lib \
  107.     --sysconfdir=/etc --disable-setuid \
  108.     --with-browser=/usr/bin/lynx --with-col=/usr/bin/col \
  109.     --with-vgrind=/usr/bin/vgrind --with-grap=/usr/bin/grap

  110. make
  111. make check
  112. make install


  113. 6.48. Module-Init-Tools-3.8

  114. ./configure
  115. make check
  116. make clean

  117. ./configure --prefix=/ --enable-zlib --mandir=/usr/share/man

  118. make
  119. make INSTALL=install install


  120. 6.49. Patch-2.5.9

  121. patch -Np1 -i ../patch/patch-2.5.9-fixes-1.patch

  122. ./configure --prefix=/usr

  123. make
  124. make install



  125. 6.50. Psmisc-22.7

  126. ./configure --prefix=/usr --exec-prefix=""

  127. make
  128. make install

  129. mv -v /bin/pstree* /usr/bin
  130. ln -sv killall /bin/pidof


  131. 6.51. Shadow-4.1.4.1

  132. sed -i 's/groups$(EXEEXT) //' src/Makefile.in
  133. find man -name Makefile.in -exec sed -i 's/groups\.1 / /' {} \;

  134. sed -i -e 's/ ko//' -e 's/ zh_CN zh_TW//' man/Makefile.in

  135. sed -i -e 's@#ENCRYPT_METHOD DES@ENCRYPT_METHOD MD5@' \
  136.        -e 's@/var/spool/mail@/var/mail@' etc/login.defs



  137. Note
  138. If you chose to build Shadow with Cracklib support, run the following:

  139. sed -i 's@DICTPATH.*@DICTPATH\t/lib/cracklib/pw_dict@' \
  140.     etc/login.defs


  141. ./configure --sysconfdir=/etc

  142. make
  143. make install
  144. mv -v /usr/bin/passwd /bin

  145. pwconv
  146. grpconv

  147. passwd root




  148. 6.52. Sysklogd-1.5

  149. make
  150. make BINDIR=/sbin install


  151. cat > /etc/syslog.conf << "EOF"
  152. # Begin /etc/syslog.conf

  153. auth,authpriv.* -/var/log/auth.log
  154. *.*;auth,authpriv.none -/var/log/sys.log
  155. daemon.* -/var/log/daemon.log
  156. kern.* -/var/log/kern.log
  157. mail.* -/var/log/mail.log
  158. user.* -/var/log/user.log
  159. *.emerg *

  160. # End /etc/syslog.conf
  161. EOF



  162. 6.53. Sysvinit-2.86

  163. sed -i 's@Sending processes@& configured via /etc/inittab@g' \
  164.     src/init.c

  165. sed -i -e 's/utmpdump wall/utmpdump/' \
  166.        -e 's/mountpoint.1 wall.1/mountpoint.1/' src/Makefile

  167. make -C src
  168. make -C src install



  169. cat > /etc/inittab << "EOF"
  170. # Begin /etc/inittab

  171. id:3:initdefault:

  172. si::sysinit:/etc/rc.d/init.d/rc sysinit

  173. l0:0:wait:/etc/rc.d/init.d/rc 0
  174. l1:S1:wait:/etc/rc.d/init.d/rc 1
  175. l2:2:wait:/etc/rc.d/init.d/rc 2
  176. l3:3:wait:/etc/rc.d/init.d/rc 3
  177. l4:4:wait:/etc/rc.d/init.d/rc 4
  178. l5:5:wait:/etc/rc.d/init.d/rc 5
  179. l6:6:wait:/etc/rc.d/init.d/rc 6

  180. ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

  181. su:S016:once:/sbin/sulogin

  182. 1:2345:respawn:/sbin/agetty tty1 9600
  183. 2:2345:respawn:/sbin/agetty tty2 9600
  184. 3:2345:respawn:/sbin/agetty tty3 9600
  185. 4:2345:respawn:/sbin/agetty tty4 9600
  186. 5:2345:respawn:/sbin/agetty tty5 9600
  187. 6:2345:respawn:/sbin/agetty tty6 9600

  188. # End /etc/inittab
  189. EOF





  190. 6.54. Tar-1.22

  191. ./configure --prefix=/usr --bindir=/bin --libexecdir=/usr/sbin

  192. make
  193. make check
  194. make install



  195. 6.55. Texinfo-4.13a

  196. ./configure --prefix=/usr

  197. make
  198. make check
  199. make install
  200. make TEXMF=/usr/share/texmf install-tex


  201. cd /usr/share/info
  202. rm dir
  203. for f in *
  204. do install-info $f dir 2>/dev/null
  205. done



  206. 6.56. Udev-142



  207. tar -xvf ../tar/udev-config-20090523.tar.bz2

  208. install -dv /lib/{firmware,udev/devices/{pts,shm}}
  209. mknod -m0666 /lib/udev/devices/null c 1 3
  210. mknod -m0600 /lib/udev/devices/kmsg c 1 11
  211. ln -sv /proc/self/fd /lib/udev/devices/fd
  212. ln -sv /proc/self/fd/0 /lib/udev/devices/stdin
  213. ln -sv /proc/self/fd/1 /lib/udev/devices/stdout
  214. ln -sv /proc/self/fd/2 /lib/udev/devices/stderr
  215. ln -sv /proc/kcore /lib/udev/devices/core

  216. ./configure --prefix=/usr \
  217.             --exec-prefix= \
  218.             --sysconfdir=/etc

  219. make
  220. make install

  221. install -m644 -v rules/packages/64-*.rules \
  222.     /lib/udev/rules.d/

  223. install -m644 -v rules/packages/40-pilot-links.rules \
  224.     /lib/udev/rules.d/

  225. install -m644 -v rules/packages/40-isdn.rules \
  226.     /lib/udev/rules.d/

  227. cd udev-config-20090523
  228. make install

  229. make install-doc

  230. make install-extra-doc

  231. cd ..
  232. install -m644 -v -D docs/writing_udev_rules/index.html \
  233.     /usr/share/doc/udev-142/index.html




  234. 6.57. Util-linux-ng-2.14.2


  235. sed -e 's@etc/adjtime@var/lib/hwclock/adjtime@g' \
  236.     -i $(grep -rl '/etc/adjtime' .)
  237. mkdir -pv /var/lib/hwclock

  238. ./configure --enable-arch --enable-partx --enable-write

  239. make
  240. make install



  241. 6.58. Vim-7.2


  242. patch -Np1 -i ../patch/vim-7.2-fixes-4.patch

  243. echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h

  244. ./configure --prefix=/usr --enable-multibyte

  245. make
  246. make test
  247. make install

  248. ln -sv vim /usr/bin/vi
  249. for L in  /usr/share/man/{,*/}man1/vim.1; do
  250.     ln -sv vim.1 $(dirname $L)/vi.1
  251. done

  252. ln -sv ../vim/vim72/doc /usr/share/doc/vim-7.2


  253. cat > /etc/vimrc << "EOF"
  254. " Begin /etc/vimrc

  255. set nocompatible
  256. set backspace=2
  257. syntax on
  258. if (&term == "iterm") || (&term == "putty")
  259.   set background=dark
  260. endif

  261. " End /etc/vimrc
  262. EOF


  263. 6.59. About Debugging Symbols

  264. 调试符号优化
  265. [url]http://www.linuxfromscratch.org/hints/downloads/files/optimization.txt.[/url]


  266. 6.60. Stripping Again

  267. logout

  268. chroot $LFS /tools/bin/env -i \
  269.     HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
  270.     PATH=/bin:/usr/bin:/sbin:/usr/sbin \
  271.     /tools/bin/bash --login

  272. /tools/bin/find /{,usr/}{bin,lib,sbin} -type f \
  273.   -exec /tools/bin/strip --strip-debug '{}' ';'



  274. 6.61. Cleaning Up

  275. /tools目录不再需要了,可以删除。

复制代码

论坛徽章:
0
4 [报告]
发表于 2009-06-09 11:39 |只看该作者
工具链利用完毕,现在开始进入干净的LFS ”临时“ 系统!



  1. chroot "$LFS" /usr/bin/env -i \
  2.     HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
  3.     PATH=/bin:/usr/bin:/sbin:/usr/sbin \
  4.     /bin/bash --login



  5. 7.2. LFS-Bootscripts-20090523

  6. tar -xvf tar/lfs-bootscripts-20090523.tar.bz2
  7. cd lfs-bootscripts-20090523/

  8. make install



  9. 7.4. Configuring the setclock Script


  10. cat > /etc/sysconfig/clock << "EOF"
  11. # Begin /etc/sysconfig/clock

  12. UTC=1

  13. # Set this to any options you might need to give to hwclock,
  14. # such as machine hardware clock type for Alphas.
  15. CLOCKPARAMS=

  16. # End /etc/sysconfig/clock
  17. EOF



  18. 7.5. Configuring the Linux Console


  19. cat > /etc/sysconfig/console << "EOF"
  20. # Begin /etc/sysconfig/console

  21. #KEYMAP=""
  22. #FONT=""

  23. # End /etc/sysconfig/console
  24. EOF



  25. 7.7. Creating the /etc/inputrc File


  26. cat > /etc/inputrc << "EOF"
  27. # Begin /etc/inputrc
  28. # Modified by Chris Lynn <[email]roryo@roryo.dynup.net[/email]>

  29. # Allow the command prompt to wrap to the next line
  30. set horizontal-scroll-mode Off

  31. # Enable 8bit input
  32. set meta-flag On
  33. set input-meta On

  34. # Turns off 8th bit stripping
  35. set convert-meta Off

  36. # Keep the 8th bit for display
  37. set output-meta On

  38. # none, visible or audible
  39. set bell-style none

  40. # All of the following map the escape sequence of the value
  41. # contained in the 1st argument to the readline specific functions
  42. "\eOd": backward-word
  43. "\eOc": forward-word

  44. # for linux console
  45. "\e[1~": beginning-of-line
  46. "\e[4~": end-of-line
  47. "\e[5~": beginning-of-history
  48. "\e[6~": end-of-history
  49. "\e[3~": delete-char
  50. "\e[2~": quoted-insert

  51. # for xterm
  52. "\eOH": beginning-of-line
  53. "\eOF": end-of-line

  54. # for Konsole
  55. "\e[H": beginning-of-line
  56. "\e[F": end-of-line

  57. # End /etc/inputrc
  58. EOF


  59. cat > /etc/profile << "EOF"
  60. # Begin /etc/profile

  61. export LANG=en_US.UTF-8

  62. # End /etc/profile
  63. EOF



  64. echo "HOSTNAME=LFS61" > /etc/sysconfig/network


  65. cat > /etc/hosts << "EOF"
  66. # Begin /etc/hosts (network card version)

  67. 127.0.0.1 localhost
  68. 10.10.10.8 LFS61

  69. # End /etc/hosts (network card version)
  70. EOF



  71. for NIC in /sys/class/net/* ; do
  72.     INTERFACE=${NIC##*/} udevadm test --action=add $NIC
  73. done


  74. cat /etc/udev/rules.d/70-persistent-net.rules


  75. cd /etc/sysconfig/network-devices
  76. mkdir -v ifconfig.eth0
  77. cat > ifconfig.eth0/ipv4 << "EOF"
  78. ONBOOT=yes
  79. SERVICE=ipv4-static
  80. IP=10.10.10.8
  81. GATEWAY=10.10.10.7
  82. PREFIX=24
  83. BROADCAST=10.10.0.255
  84. EOF



  85. cat > /etc/resolv.conf << "EOF"
  86. # Begin /etc/resolv.conf

  87. domain gelin.com
  88. nameserver 202.96.128.68
  89. nameserver 202.96.128.166

  90. # End /etc/resolv.conf
  91. EOF



  92. cat > /etc/fstab << "EOF"
  93. # Begin /etc/fstab

  94. # file system  mount-point  type   options         dump  fsck
  95. #                                                        order

  96. /dev/sda3     /            ext3  defaults        1     1
  97. #/dev/<yyy>     swap         swap   pri=1           0     0
  98. proc           /proc        proc   defaults        0     0
  99. sysfs          /sys         sysfs  defaults        0     0
  100. devpts         /dev/pts     devpts gid=4,mode=620  0     0
  101. tmpfs          /dev/shm     tmpfs  defaults        0     0
  102. # End /etc/fstab
  103. EOF



  104. cat > /etc/bashrc << "EOF"
  105. # Begin /etc/bashrc
  106. # Written for Beyond Linux From Scratch
  107. # by James Robertson <[email]jameswrobertson@earthlink.net[/email]>
  108. # updated by Bruce Dubbs <[email]bdubbs@linuxfromscratch.org[/email]>

  109. # System wide aliases and functions.

  110. # System wide environment variables and startup programs should go into
  111. # /etc/profile.  Personal environment variables and startup programs
  112. # should go into ~/.bash_profile.  Personal aliases and functions should
  113. # go into ~/.bashrc

  114. # Provides a colored /bin/ls command.  Used in conjunction with code in
  115. # /etc/profile.

  116. alias ls='ls --color=auto'

  117. # Provides prompt for non-login shells, specifically shells started
  118. # in the X environment. [Review the LFS archive thread titled
  119. # PS1 Environment Variable for a great case study behind this script
  120. # addendum.]

  121. NORMAL="\[\e[0m\]"
  122. GRAY="\[\e[1;30m\]"
  123. GREEN="\[\e[1;32m\]"
  124. if [[ $EUID == 0 ]] ; then
  125.   PS1="$GRAY[\u@\h $NORMAL\w$GRAY]# $NORMAL"
  126. else
  127.   PS1="$GREEN[\u@\h $NORMAL\w$GREEN]\$ $NORMAL"
  128. fi

  129. # End /etc/bashrc
  130. EOF



  131. cat .bash_profile
  132. source ~/.bashrc


  133. [root@LFS61 ~]# cat .bashrc
  134. # Begin ~/.bashrc
  135. # Written for Beyond Linux From Scratch
  136. # by James Robertson <[email]jameswrobertson@earthlink.net[/email]>

  137. # Personal aliases and functions.

  138. # Personal environment variables and startup programs should go in
  139. # ~/.bash_profile.  System wide environment variables and startup
  140. # programs are in /etc/profile.  System wide aliases and functions are
  141. # in /etc/bashrc.

  142. if [ -f "/etc/bashrc" ] ; then
  143.   source /etc/bashrc
  144. fi

  145. alias ll='ls -l'
  146. alias rm='rm -i'
  147. alias cp='cp -i'
  148. alias mv='mv -i'

  149. # End ~/.bashrc









  150. 编译安装hdparm

  151. cd /mnt/lfs/sources/
  152. wget [url]http://nchc.dl.sourceforge.net/sourceforge/hdparm/hdparm-9.6.tar.gz[/url]


  153. make
  154. make binprefix=/usr install




  155. 编译内核

  156. 内核编译,我是利用了ubuntu9的最新内核配置文件,在此基础上精简编译的。关于内核的裁减和优化编译,这又是另外一个课题了,有兴趣的朋友,可以一起探讨





  157. 安装grub

  158. 由于我的系统引导,是利用ubuntu安装的grub,所以这次我就没再安装grub了,关于grub的安装,请参考LFS6.3等类似手册,这里不再多说了。



  159. 退出chroot环境

  160. logout

  161. 卸载虚拟文件系统
  162. umount -v $LFS/dev/pts
  163. umount -v $LFS/dev/shm
  164. umount -v $LFS/dev
  165. umount -v $LFS/proc
  166. umount -v $LFS/sys


  167. 如果挂载了其他分区,要先卸载他们,再卸载LFS文件系统本身

  168. umount -v $LFS/usr
  169. umount -v $LFS/home
  170. umount -v $LFS


  171. 最后卸载LFS文件系统本身
  172. umount -v $LFS


  173. 重启系统
  174. shutdown -r now


复制代码

论坛徽章:
0
5 [报告]
发表于 2009-06-09 11:42 |只看该作者
下面进入BLFS的课题,接下来的工作,可以根据自己的需求,编译一些软件包。我需要远程配置,所以先安装openSSH,而openSSH依赖于openssl,所以先弄上她,呵呵。



  1. 安装openssl-0.9.8k
  2. [url]http://www.linuxfromscratch.org/blfs/view/cvs/postlfs/openssl.html[/url]

  3. [url]http://www.openssl.org/source/openssl-0.9.8k.tar.gz[/url]
  4. [url]http://anduin.linuxfromscratch.org/files/BLFS/BLFS-ca-bundle-20090409.tar.bz2[/url]
  5. [url]http://www.linuxfromscratch.org/patches/blfs/svn/openssl-0.9.8k-fix_manpages-1.patch[/url]


  6. patch -Np1 -i ../openssl-0.9.8k-fix_manpages-1.patch
  7. tar -vxf ../BLFS-ca-bundle-20090409.tar.bz2
  8. ./config --prefix=/usr --openssldir=/etc/ssl shared zlib-dynamic
  9. make

  10. make MANDIR=/usr/share/man install

  11. cp -v -r certs /etc/ssl

  12. install -v -d -m755 /usr/share/doc/openssl-0.9.8k

  13. cp -v -r doc/{HOWTO,README,*.{txt,html,gif}} \
  14.     /usr/share/doc/openssl-0.9.8k



  15. for pem in /etc/ssl/certs/*.pem
  16. do
  17.    cat $pem
  18.    echo ""
  19. done > /etc/ssl/ca-bundle.crt





  20. openssh


  21. [url]http://sunsite.ualberta.ca/pub/OpenBSD/OpenSSH/portable/openssh-5.1p1.tar.gz[/url]



  22. install -v -m700 -d /var/lib/sshd
  23. chown -v root:sys /var/lib/sshd
  24. groupadd -g 50 sshd
  25. useradd -c 'sshd PrivSep' -d /var/lib/sshd -g sshd \
  26.     -s /bin/false -u 50 sshd


  27. sed -i 's@-lcrypto@/usr/lib/libcrypto.a -ldl@' configure


  28. ./configure --prefix=/usr --sysconfdir=/etc/ssh --datadir=/usr/share/sshd \
  29.     --libexecdir=/usr/lib/openssh --with-md5-passwords \
  30.     --with-privsep-path=/var/lib/sshd

  31. make

  32. make tests 2>&1 | tee check.log
  33. grep FATAL check.log


  34. make install

  35. install -v -m755 -d /usr/share/doc/openssh-5.1p1

  36. install -v -m644 INSTALL LICENCE OVERVIEW README* WARNING.RNG \
  37.     /usr/share/doc/openssh-5.1p1




  38. echo "PermitRootLogin yes" >> /etc/ssh/sshd_config

  39. sed 's@d/login@d/sshd@g' /etc/pam.d/login > /etc/pam.d/sshd

  40. chmod 644 /etc/pam.d/sshd


  41. [url]http://www.linuxfromscratch.org/blfs/downloads/svn/blfs-bootscripts-20090302.tar.bz2[/url]

  42. make install-sshd

  43. root:/sources/blfs-bootscripts-20090302# make install-sshd
  44. install -d -m 755 /etc/rc.d/rc{0,1,2,3,4,5,6,sysinit}.d
  45. install -d -m 755 /etc/rc.d/init.d
  46. install -d -m 755 /etc/sysconfig
  47. install -m 754 blfs/init.d/sshd       /etc/rc.d/init.d/
  48. ln -sf  ../init.d/sshd /etc/rc.d/rc0.d/K30sshd
  49. ln -sf  ../init.d/sshd /etc/rc.d/rc1.d/K30sshd
  50. ln -sf  ../init.d/sshd /etc/rc.d/rc2.d/K30sshd
  51. ln -sf  ../init.d/sshd /etc/rc.d/rc3.d/S30sshd
  52. ln -sf  ../init.d/sshd /etc/rc.d/rc4.d/S30sshd
  53. ln -sf  ../init.d/sshd /etc/rc.d/rc5.d/S30sshd
  54. ln -sf  ../init.d/sshd /etc/rc.d/rc6.d/K30sshd


  55. 安装unzip
  56. [url]http://downloads.sourceforge.net/infozip/unzip552.tar.gz[/url]
  57. [url]http://www.linuxfromscratch.org/patches/blfs/svn/unzip-5.52-security_fix-1.patch[/url]
  58. [url]http://www.linuxfromscratch.org/patches/blfs/svn/unzip-5.52-security_fix-2.patch[/url]


  59. tar -xvf unzip552.tar.gz
  60. cd unzip552/
  61. patch -Np1 -i ../unzip-5.52-security_fix-1.patch
  62. patch -Np1 -i ../unzip-5.52-security_fix-2.patch


  63. make -f unix/Makefile LOCAL_UNZIP=-D_FILE_OFFSET_BITS=64 linux
  64. make prefix=/usr install



  65. 安装wget
  66. [url]http://www.linuxfromscratch.org/blfs/view/cvs/basicnet/wget.html[/url]


  67. [url]http://ftp.gnu.org/gnu/wget/wget-1.11.4.tar.bz2[/url]



  68. ./configure --prefix=/usr --sysconfdir=/etc
  69. make
  70. make install
  71. install-info --info-dir=/usr/share/info /usr/share/info/wget.info


复制代码

论坛徽章:
0
6 [报告]
发表于 2009-06-09 11:44 |只看该作者
最后,进入我们的应用阶段——编译安装nginx和fast-cgi,打造一个高性能的php运行环境(相同配置,比apache效率至少高3倍以上,这是我的测试结论,希望大家有兴趣的做完之后,也来测试测试。)



  1. 安装ngnix
  2. 先备份lfs基本系统
  3. tar --exclude=/sources --exclude=/proc --exclude=/sys \
  4. --create --absolute-names --preserve-permissions --bzip2 \
  5. --verbose --totals \
  6. --file /sources/lfs-stage4.$(date +%Y%m%d%s).tar.bz2 /




  7. cd /sources

  8. mkdir lnmp

  9. 一、下载软件
  10. cat > soft-list << "EOF"
  11. [url]http://sysoev.ru/nginx/nginx-0.7.59.tar.gz[/url]
  12. [url]http://www.php.net/get/php-5.2.9.tar.gz/from/this/mirror[/url]
  13. [url]http://www.libgd.org/releases/gd-2.0.35.tar.bz2[/url]
  14. [url]ftp://xmlsoft.org/libxml2/libxml2-2.6.32.tar.gz[/url]
  15. [url]ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz[/url]
  16. [url]ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.2.37.tar.bz2[/url]
  17. [url]http://ftp.twaren.net/Unix/NonGNU/freetype/freetype-2.3.9.tar.gz[/url]
  18. [url]http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.33.zip/from/http://mysql.mirror.redwire.net/[/url]
  19. [url]http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.tar.gz[/url]
  20. [url]http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0[/url]
  21. [url]http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0[/url]
  22. [url]http://pecl.php.net/get/memcache-2.2.5.tgz[/url]
  23. [url]http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0[/url]
  24. [url]ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz[/url]
  25. [url]http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2[/url]
  26. [url]http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz[/url]
  27. [url]http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz[/url]
  28. [url]http://pecl.php.net/get/imagick-2.2.2.tgz[/url]
  29. EOF


  30. wget -N -r -nd -P . -i soft-list -o wget.lnmp.log




  31. 二、安装PHP 5.2.8(FastCGI模式)
  32.   1、编译安装PHP 5.2.8所需的支持库:

  33. tar zxvf libiconv-1.13.tar.gz
  34. cd libiconv-1.13/
  35. ./configure --prefix=/usr/local
  36. make
  37. make install
  38. cd ../

  39. tar -zxvf freetype-2.3.9.tar.gz
  40. cd freetype-2.3.9/
  41. ./configure --prefix=/opt/lnmp/freetype2
  42. make
  43. make install
  44. cd ../

  45. tar -jxvf libpng-1.2.37.tar.bz2
  46. cd libpng-1.2.37/
  47. ./configure --prefix=/opt/lnmp/libpng
  48. make
  49. make install
  50. cd ../

  51. tar zxvf jpegsrc.v6b.tar.gz
  52. cd jpeg-6b/
  53. ./configure --enable-static --enable-shared --prefix=/opt/lnmp/jpeg-6b
  54. mkdir -pv /opt/lnmp/jpeg-6b/include
  55. mkdir -pv /opt/lnmp/jpeg-6b/lib
  56. mkdir -pv /opt/lnmp/jpeg-6b/bin/
  57. mkdir -pv /opt/lnmp/jpeg-6b/man/man1
  58. make
  59. make install
  60. make install-lib
  61. cd ../


  62. tar -zxvf libxml2-2.7.3.tar.gz
  63. cd libxml2-2.7.3
  64. ./configure --prefix=/opt/lnmp/libxml
  65. make
  66. make install
  67. cd ../


  68. tar zxvf libmcrypt-2.5.8.tar.gz
  69. cd libmcrypt-2.5.8/
  70. ./configure
  71. make
  72. make install
  73. /sbin/ldconfig
  74. cd libltdl/
  75. ./configure --enable-ltdl-install
  76. make
  77. make install
  78. cd ../../

  79. tar zxvf mhash-0.9.9.9.tar.gz
  80. cd mhash-0.9.9.9/
  81. ./configure
  82. make
  83. make install
  84. cd ../

  85. ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
  86. ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
  87. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
  88. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
  89. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
  90. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
  91. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
  92. ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
  93. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

  94. tar zxvf mcrypt-2.6.8.tar.gz
  95. cd mcrypt-2.6.8/
  96. /sbin/ldconfig
  97. ./configure --with-libmcrypt-prefix=/usr/local/
  98. make
  99. make install
  100. cd ../

  101. tar -jxvf gd-2.0.35.tar.bz2
  102. cd gd-2.0.35
  103. ./configure --prefix=/opt/lnmp/gd2 --with-jpeg=/opt/lnmp/jpeg-6b --with-png=/opt/lnmp/libpng --with-freetype=/opt/lnmp/freetype2
  104. make

  105. make报错
  106. 说缺少png.h
  107. 在Makefile里面,CPPFLAGS最后,加上-I/opt/lnmp/libpng/include

  108. CPPFLAGS = -I/opt/lnmp/freetype2/include/freetype2 -I/opt/lnmp/freetype2/include -I/opt/lnmp/freetype2/include  -I/opt/lnmp/jpeg-6b/include -I/opt/lnmp/libpng/include

  109. 再make

  110. make install
  111. cd ../

  112. 2、编译安装MySQL 5.1.33

  113. /usr/sbin/groupadd mysql
  114. /usr/sbin/useradd -g mysql mysql
  115. unzip mysql-5.1.33.zip
  116. cd mysql-5.1.33/
  117. ./configure --prefix=/opt/lnmp/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase
  118. make && make install
  119. chmod +w /opt/lnmp/mysql
  120. chown -R mysql:mysql /opt/lnmp/mysql
  121. cp support-files/my-medium.cnf /opt/lnmp/mysql/my.cnf
  122. cd ../

  123. ①、以mysql用户帐号的身份建立数据表:

  124. /opt/lnmp/mysql/bin/mysql_install_db --basedir=/opt/lnmp/mysql --datadir=/opt/lnmp/mysql/data --user=mysql


  125. ②、启动MySQL(最后的&表示在后台运行)

  126. /opt/lnmp/mysql/bin/mysqld_safe --defaults-file=/opt/lnmp/mysql/my.cnf &



  127. 注!!

  128. MySQL编译安装,初始化数据库的时候出现:
  129. unknown option '--skip-federated' 错误。

  130. #vi /etc/my.cnf
  131. #skip-federated 将此行注释掉
  132. 即可。
  133. 或者编译的时候加上如下参数:
  134. --with-plugins=all



  135. 3、编译安装PHP(FastCGI模式)

  136. tar zxvf php-5.2.9.tar.gz
  137. cd php-5.2.9/


  138. ./configure --prefix=/opt/lnmp/php --with-config-file-path=/opt/lnmp/php/etc --with-mysql=/opt/lnmp/mysql --with-mysqli=/opt/lnmp/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir=/opt/lnmp/freetype2 --with-jpeg-dir=/opt/lnmp/jpeg-6b --with-png-dir=/opt/lnmp/libpng  --with-zlib-dir=/usr --with-gd=/opt/lnmp/gd2 --enable-gd-native-ttf --with-openssl --with-mhash --with-mcrypt --with-libxml-dir=/opt/lnmp/libxml --with-xmlrpc --enable-ftp --enable-sockets --enable-mbstring=all --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect


  139. make ZEND_EXTRA_LIBS='-liconv'
  140. make install
  141. cp php.ini-dist /opt/lnmp/php/etc/php.ini
  142. cd ext/gd

  143. ./configure --with-jpeg-dir=/opt/lnmp/jpeg-6b/ --with-png-dir=/opt/lnmp/libpng/ --with-zlib-dir --with-ttf --with-freetype-dir=/opt/lnmp/freetype2/ --with-php-config=/opt/lnmp/php/bin/php-config

  144. --------------------------------------------------------------------------------

  145.   4、编译安装PHP5扩展模块

  146. tar zxvf memcache-2.2.5.tgz
  147. cd memcache-2.2.5/
  148. /opt/lnmp/php/bin/phpize
  149. ./configure --with-php-config=/opt/lnmp/php/bin/php-config
  150. make
  151. make install
  152. cd ../

  153. tar jxvf eaccelerator-0.9.5.3.tar.bz2
  154. cd eaccelerator-0.9.5.3/
  155. /opt/lnmp/php/bin/phpize
  156. ./configure --enable-eaccelerator=shared --with-php-config=/opt/lnmp/php/bin/php-config
  157. make
  158. make install
  159. cd ../

  160. tar zxvf PDO_MYSQL-1.0.2.tgz
  161. cd PDO_MYSQL-1.0.2/
  162. /opt/lnmp/php/bin/phpize
  163. ./configure --with-php-config=/opt/lnmp/php/bin/php-config --with-pdo-mysql=/opt/lnmp/mysql
  164. make
  165. make install
  166. cd ../

  167. tar zxvf ImageMagick.tar.gz
  168. cd ImageMagick-6.5.1-2/
  169. ./configure --prefix=/opt/lnmp/imagemagick
  170. make
  171. make install
  172. cd ../

  173. tar zxvf imagick-2.2.2.tgz
  174. cd imagick-2.2.2/
  175. /opt/lnmp/php/bin/phpize
  176. ./configure --with-imagick=/opt/lnmp/imagemagick --with-php-config=/opt/lnmp/php/bin/php-config
  177. make
  178. make install
  179. cd ../



  180. 5、修改php.ini文件
  181. 手工修改:查找/opt/lnmp/php/etc/php.ini中的extension_dir = "./"
  182. 修改为extension_dir = "/opt/lnmp/php/lib/php/extensions/no-debug-non-zts-20060613/"
  183. 并在此行后增加以下几行,然后保存:

  184.         extension = "memcache.so"
  185.   extension = "pdo_mysql.so"
  186.   extension = "imagick.so"
  187.     extension = "gd.so"

  188. 再查找output_buffering = Off
  189. 修改为output_buffering = On



  190. 6、配置eAccelerator加速PHP:

  191. mkdir -p /opt/lnmp/eaccelerator_cache
  192. vi /opt/lnmp/php/etc/php.ini

  193. 按shift+g键跳到配置文件的最末尾,加上以下配置信息:

  194. 引用
  195. [eaccelerator]
  196. zend_extension="/opt/lnmp/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
  197. eaccelerator.shm_size="128"
  198. eaccelerator.cache_dir="/opt/lnmp/eaccelerator_cache"
  199. eaccelerator.enable="1"
  200. eaccelerator.optimizer="1"
  201. eaccelerator.check_mtime="1"
  202. eaccelerator.debug="0"
  203. eaccelerator.filter=""
  204. eaccelerator.shm_max="0"
  205. eaccelerator.shm_ttl="300"
  206. eaccelerator.shm_prune_period="120"
  207. eaccelerator.shm_only="0"
  208. eaccelerator.compress="1"
  209. eaccelerator.compress_level="9"


  210. 修改配置文件:

  211. vi /etc/sysctl.conf

  212. 输入以下内容:

  213. 引用
  214. kernel.shmmax = 134217728
  215. kernel.shmmax = 134217728
  216. net.ipv4.tcp_fin_timeout = 30
  217. net.ipv4.tcp_keepalive_time = 300
  218. net.ipv4.tcp_syncookies = 1
  219. net.ipv4.tcp_tw_reuse = 1
  220. net.ipv4.tcp_tw_recycle = 1
  221. net.ipv4.ip_local_port_range = 5000    65000


  222. 然后执行以下命令使配置生效:

  223. /sbin/sysctl -p


  224. --------------------------------------------------------------------------------

  225. 7、创建www用户和组,以及供222.222.222.222和[url]www.test.com[/url]两个虚拟主机使用的目录:

  226. /usr/sbin/groupadd www
  227. /usr/sbin/useradd -g www www
  228. mkdir -p /opt/webroot/mypic
  229. chmod +w /opt/webroot/mypic
  230. chown -R www:www /opt/webroot/mypic
  231. mkdir -p /opt/webroot/www
  232. chmod +w /opt/webroot/www
  233. chown -R www:www /opt/webroot/www



  234. 三、安装Nginx 0.7.59
  235.   1、安装Nginx所需的pcre库:

  236. tar zxvf pcre-7.8.tar.gz
  237. cd pcre-7.8/
  238. ./configure --prefix=/opt/lnmp/pcre
  239. make && make install
  240. cd ../

  241. 2、安装Nginx
  242. cp -R /sources/lnmp/pcre-7.8 /opt/lnmp/pcre-7.8
  243. tar -zxvf nginx-0.7.59.tar.gz
  244. cd nginx-0.7.59/
  245. ./configure --user=www --group=www --prefix=/opt/lnmp/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/opt/lnmp/pcre-7.8/
  246. make && make install
  247. cd ../

  248. 3、创建Nginx日志目录

  249. mkdir -p /opt/webroot/logs
  250. chmod +w /opt/webroot/logs
  251. chown -R www:www /opt/webroot/logs


  252. 4、创建Nginx配置文件

  253. ①、在/opt/lnmp/nginx/conf/目录中创建nginx.conf文件:

  254. rm -f /opt/lnmp/nginx/conf/nginx.conf

  255. vi /opt/lnmp/nginx/conf/nginx.conf


  256. user  www www;
  257. worker_processes 8;
  258. error_log  /opt/webroot/logs/nginx_error.log  crit;
  259. pid        /opt/lnmp/nginx/nginx.pid;

  260. #Specifies the value for maximum file descriptors that can be opened by this process.
  261. worker_rlimit_nofile 51200;

  262. events
  263. {
  264.   use epoll;
  265.   worker_connections 51200;
  266. }

  267. http
  268. {
  269.   include       mime.types;
  270.   default_type  application/octet-stream;

  271.   #charset  gb2312;
  272.       
  273.   server_names_hash_bucket_size 128;
  274.   client_header_buffer_size 32k;
  275.   large_client_header_buffers 4 32k;
  276.   client_max_body_size 8m;
  277.       
  278.   sendfile on;
  279.   tcp_nopush     on;

  280.   keepalive_timeout 60;

  281.   tcp_nodelay on;

  282.   fastcgi_connect_timeout 300;
  283.   fastcgi_send_timeout 300;
  284.   fastcgi_read_timeout 300;
  285.   fastcgi_buffer_size 64k;
  286.   fastcgi_buffers 4 64k;
  287.   fastcgi_busy_buffers_size 128k;
  288.   fastcgi_temp_file_write_size 128k;

  289.   gzip on;
  290.   gzip_min_length  1k;
  291.   gzip_buffers     4 16k;
  292.   gzip_http_version 1.0;
  293.   gzip_comp_level 2;
  294.   gzip_types       text/plain application/x-javascript text/css application/xml;
  295.   gzip_vary on;

  296.   #limit_zone  crawler  $binary_remote_addr  10m;

  297.   server
  298.   {
  299.     listen       80;
  300.     server_name  222.222.222.222;
  301.     index index.html index.htm index.php;
  302.     root  /opt/webroot/mypic;

  303.     #limit_conn   crawler  20;   
  304.                              
  305.     location ~ .*\.(php|php5)?$
  306.     {      
  307.       #fastcgi_pass  unix:/tmp/php-cgi.sock;
  308.       fastcgi_pass  127.0.0.1:10080;
  309.       fastcgi_index index.php;
  310.       include fcgi.conf;
  311.     }
  312.    
  313.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  314.     {
  315.       expires      30d;
  316.     }

  317.     location ~ .*\.(js|css)?$
  318.     {
  319.       expires      1h;
  320.     }   

  321.     log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
  322.               '$status $body_bytes_sent "$http_referer" '
  323.               '"$http_user_agent" $http_x_forwarded_for';
  324.     access_log  /opt/webroot/logs/access.log  access;
  325.       }

  326.   server
  327.   {
  328.     listen       80;
  329.     server_name  [url]www.test.com[/url];
  330.     index index.html index.htm index.php;
  331.     root  /opt/webroot/www;

  332.     location ~ .*\.(php|php5)?$
  333.     {      
  334.       #fastcgi_pass  unix:/tmp/php-cgi.sock;
  335.       fastcgi_pass  127.0.0.1:10080;
  336.       fastcgi_index index.php;
  337.       include fcgi.conf;
  338.     }

  339.     log_format  wwwlogs  '$remote_addr - $remote_user [$time_local] "$request" '
  340.                '$status $body_bytes_sent "$http_referer" '
  341.                '"$http_user_agent" $http_x_forwarded_for';
  342.     access_log  /opt/webroot/logs/wwwlogs.log  wwwlogs;
  343.   }

  344.   server
  345.   {
  346.     listen  80;
  347.     server_name  status.test.com;

  348.     location / {
  349.     stub_status on;
  350.     access_log   off;
  351.     }
  352.   }
  353. }




  354. wget [url]http://www.lighttpd.net/download/spawn-fcgi-1.6.2.tar.gz[/url]
  355. tar -zxf spawn-fcgi-1.6.2.tar.gz
  356. cd spawn-fcgi-1.6.2/
  357. ./configure --prefix=/opt/lnmp/fastcgi
  358. make && make install



  359. 启动php-cgi进程,监听127.0.0.1的10080端口,进程数为64(如果服务器内存小于3GB,可以只开启25个进程),用户为www:

  360. /opt/lnmp/fastcgi/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 64 -u www -f /opt/lnmp/php/bin/php-cgi



  361. vi /opt/lnmp/nginx/conf/fcgi.conf

  362. fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
  363. fastcgi_param  SERVER_SOFTWARE    nginx;

  364. fastcgi_param  QUERY_STRING       $query_string;
  365. fastcgi_param  REQUEST_METHOD     $request_method;
  366. fastcgi_param  CONTENT_TYPE       $content_type;
  367. fastcgi_param  CONTENT_LENGTH     $content_length;

  368. fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
  369. fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
  370. fastcgi_param  REQUEST_URI        $request_uri;
  371. fastcgi_param  DOCUMENT_URI       $document_uri;
  372. fastcgi_param  DOCUMENT_ROOT      $document_root;
  373. fastcgi_param  SERVER_PROTOCOL    $server_protocol;

  374. fastcgi_param  REMOTE_ADDR        $remote_addr;
  375. fastcgi_param  REMOTE_PORT        $remote_port;
  376. fastcgi_param  SERVER_ADDR        $server_addr;
  377. fastcgi_param  SERVER_PORT        $server_port;
  378. fastcgi_param  SERVER_NAME        $server_name;

  379. # PHP only, required if PHP was built with --enable-force-cgi-redirect
  380. fastcgi_param  REDIRECT_STATUS    200;



  381. 5、启动Nginx

  382. ulimit -SHn 51200
  383. /opt/lnmp/nginx/sbin/nginx




  384. 六、在不停止Nginx服务的情况下平滑变更Nginx配置
  385.   1、修改/opt/lnmp/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:

  386. /opt/lnmp/nginx/sbin/nginx -t

  387.   如果屏幕显示以下两行信息,说明配置文件正确:
  388.   the configuration file /opt/lnmp/nginx/conf/nginx.conf syntax is ok
  389.   the configuration file /opt/lnmp/nginx/conf/nginx.conf was tested successfully

  390.   2、这时,输入以下命令查看Nginx主进程号:

  391. ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'

  392.   屏幕显示的即为Nginx主进程号,例如:
  393.   6302
  394.   这时,执行以下命令即可使修改过的Nginx配置文件生效:

  395. kill -HUP 6302

  396.   或者无需这么麻烦,找到Nginx的Pid文件:

  397. kill -HUP `cat /opt/lnmp/nginx/nginx.pid`



  398. 将以下命令加入启动脚本

  399. ulimit -SHn 51200
  400. /opt/lnmp/fastcgi/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 64 -u www -f /opt/lnmp/php/bin/php-cgi
  401. /opt/lnmp/nginx/sbin/nginx

  402. /sbin/sysctl -p


  403. 为了方便大家阅读,一下附上笔记附件!

复制代码

LFS+NGINX.rar

22.64 KB, 下载次数: 94

论坛徽章:
0
7 [报告]
发表于 2009-06-09 11:56 |只看该作者
由于是subversion的开发者版本,所以官方几乎每天都有更新
地址是http://www.linuxfromscratch.org/lfs/view/development/index.html

为了方便大家参考,我将SVN-20090601打包发上来了。

LFS-SVN-20090601.rar

435.14 KB, 下载次数: 75

论坛徽章:
0
8 [报告]
发表于 2009-06-09 14:48 |只看该作者
太好了。

论坛徽章:
0
9 [报告]
发表于 2009-06-09 14:49 |只看该作者
顶一下,辛苦

论坛徽章:
381
CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
10 [报告]
发表于 2009-06-09 14:50 |只看该作者
即使是LFS编译成功了,生产环境谁敢用啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP