歡迎您光臨本站 註冊首頁

利用LFS SVN20090601打造一個強大的WEB伺服器

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

利用LFS SVN20090601打造一個強大的WEB伺服器

很久沒來CU發帖了,最近因為工作需要加上個人興趣,重做了一次LFS,這次利用SVN20090601最新版本,從頭編譯。
宿主系統是UBUNTU9伺服器版,基本系統編譯完成之後,加上了一些自己的設置,另外,加入了BLFS裡面的一些軟體包,例如:openssl,openssh,wget,unzip,以及一些常用工具命令,最主要的,是在此基礎上,利用nginx/0.7.59,用FAST-CGI的方式,部署一個高性能的web伺服器!

以下分享一下整個編譯過程(這個過程根據人品好壞,需要花費的時間也不盡相同:em30: ,不過一般至少需要花費2-3天以上。)
革命尚未成功,就不要放棄哦,哈哈!



ubuntu9 Server,用163的升級鏡像apt-get upgrade一下。安裝LAMP伺服器,因為我本身要在宿主系統上做php測試。
先安裝個gd支持,嘿嘿。
apt-get install php5-gd

安裝編譯lfs必須的工具
apt-get install diff gawk glibc m4 make texinfo autoconf g++ gcc bison gawk


mkdir /opt/work && cd /opt/work


///////////////// 檢查環境 /////////////////

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

# Simple script to list version numbers of critical development tools

bash --version | head -n1 | cut -d" " -f2-4
echo "/bin/sh -> `readlink -f /bin/sh`"
echo -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3-
bison --version | head -n1
if [ -e /usr/bin/yacc ];
  then echo "/usr/bin/yacc -> `readlink -f /usr/bin/yacc`";
  else echo "yacc not found"; fi
bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f1,6-
echo -n "Coreutils: "; chown --version | head -n1 | cut -d")" -f2
diff --version | head -n1
find --version | head -n1
gawk --version | head -n1
if [ -e /usr/bin/awk ];
  then echo "/usr/bin/awk -> `readlink -f /usr/bin/awk`";
  else echo "awk not found"; fi
gcc --version | head -n1
/lib/libc.so.6 | head -n1 | cut -d" " -f1-7
grep --version | head -n1
gzip --version | head -n1
cat /proc/version
m4 --version | head -n1
make --version | head -n1
patch --version | head -n1
echo Perl `perl -V:version`
sed --version | head -n1
tar --version | head -n1
makeinfo --version | head -n1
echo 'main(){}' > dummy.c && gcc -o dummy dummy.c
if [ -x dummy ]; then echo "Compilation OK";
  else echo "Compilation failed"; fi
rm -f dummy.c dummy

EOF

bash version-check.sh


export LFS=/mnt/lfs
mkdir -pv $LFS
mount -v -t ext3 /dev/sda3 $LFS
mkdir -v $LFS/sources
chmod -v a+wt $LFS/sources
cd $LFS/sources

下載源碼包
使用一個腳本,多線程下載
#!/bin/sh

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

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



或者直接下載
wget -i /opt/work/wget-list


echo $LFS
如果路徑不對,則重新設置
export LFS=/mnt/lfs

創建工具鏈路徑
mkdir -v $LFS/tools

建立符號鏈接到宿主系統更目錄
ln -sv $LFS/tools /

為了安全,建立編譯lfs的用戶和組
groupadd lfs
useradd -s /bin/bash -g lfs -m -k /dev/null lfs

設置lfs用戶密碼為「lfs」
passwd lfs

修改tools和sources目錄許可權
chown -v lfs $LFS/tools
chown -v lfs $LFS/sources

為lfs用戶創建一個全新的shell環境
su - lfs

設置lfs的用戶環境
cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
EOF


cat > ~/.bashrc << "EOF"
set +h
umask 022
LFS=/mnt/lfs
LC_ALL=POSIX
LFS_TGT=$(uname -m)-lfs-linux-gnu
PATH=/tools/bin:/bin:/usr/bin
export LFS LC_ALL LFS_TGT PATH
EOF


命令 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文件(隨後創建的那一個).

set +h 關掉bash的 "hash"功能。hash 通常是一個有用的特性,這時 bash 使用 hash 表(哈希表)來記住可執行文件的完整路徑,以避免為了找到同一個文件而進行多次 `PATH' 搜索。然而,我們希望立刻就能使用新安裝的工具。關掉hash功能,那些交互的命令(make,patch, sed,cp 等等)將總是使用新的程序。

把用戶文件創建掩碼(umask)設置為 022,保證新創建的文件和目錄只能被文件的所有者執行寫操作,而能被所有人讀和執行。

LFS 變數自然要設置成你載入 LFS 分區的位置。

LC_ALL 變數控制某些軟體包的本地化,使它們輸出的信息遵守指定國家的規範。當你的主系統glibc版本低於2.2.4時,如果在第五章中把$LC_ALL設置成 "POSIX" 或 "C" 以外的值,當你退出第六章的chroot環境后,要再次進入就會有麻煩。設置成 "POSIX" (或"C",它們倆是相同的)我們保證在chroot環境中不會出現任何問題。

我們把 /tools/bin 附加到標準路徑前面,是為了在安裝過程中,總是能用到已經安裝了的臨時工具。

CC, CXX, CPP, LD_LIBRARY_PATH 和 LD_PRELOAD 環境變數都有可能破壞我們的第五章工具鏈,因此這裡取消它們的設置,以預防可能的問題。

下面source剛才準備的用戶配置文件,準備開始編譯臨時工具鏈。

source ~/.bash_profile


cd $LFS/sources


開始編譯工具鏈!先檢查一下$LFS環境變數。
echo $LFS

5.4. 編譯binutils-2.19.1
----------------------------------------------

tar -jxvf binutils-2.19.1.tar.bz2
cd binutils-2.19.1
mkdir -v ../binutils-build
cd ../binutils-build

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

--target=$LFS_TGT: 因為LFS_TGT變數裡面的機器描述和config.guess腳本返回的的稍微不同,這個開關告訴configure腳本來修正binutils構建交叉工具鏈。
--prefix=/tools: 準備把Binutils程序安裝到/tools目錄。
--disable-nls: 這個參數禁止了國際化(通常簡稱i18n)。我們的靜態程序不需要國際化的特性,並且在靜態連接時nls常常引起錯誤。
--disable-werror: 避免當宿主系統編譯器出現警告信息時導致編譯停止。

編譯
make

如果宿主系統是64位,創建一條鏈接,以保證工具鏈的穩健
case $(uname -m) in
  x86_64) mkdir -v /tools/lib && ln -sv lib /tools/lib64 ;;
esac

安裝binutils包
make install

5.5. 編譯GCC-4.4.0
----------------------------------------------

另開一個終端,用root先行編譯gmp和mpfr到宿主系統,因為gcc4.4依賴這兩個東東!

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

因為Glibc編譯的時候依賴libgcc_eh.a這個庫,所以需要建個軟鏈接。

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

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

也就是增加一個軟鏈接
/mnt/lfs/tools/lib/gcc/i686-lfs-linux-gnu/4.4.0/libgcc_eh.a到相同目錄下的libgcc.a


5.6. 編譯Linux-2.6.29.4頭文件
----------------------------------------------

Linux內核需要提供一些API給Glibc使用。

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

make mrproper

make headers_check
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /tools/include



5.7. Glibc-2.10.1
----------------------------------------------


tar -jxvf tar/glibc-2.10.1.tar.bz2
cd glibc-2.10.1/
mkdir -v ../glibc-build
cd ../glibc-build


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

make && make install

5.8. 調整工具鏈
----------------------------------------------




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

mv binutils-build binutils-build-1
cd binutils-2.19.1/
mkdir -v ../binutils-build
cd ../binutils-build

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

make && make install

下面還要調整工具鏈,做些準備。
make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib
cp -v ld/ld-new /tools/bin

-C ld clean 表示清除ld目錄編譯后的文件
make -C ld LIB_PATH=/usr/lib:/lib 表示使用新的lib路徑,重新編譯ld目錄的代碼。


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

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


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



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



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


準備mpfr-2.4.1和gmp-4.3.1目錄。

tar -jxvf ../tar/mpfr-2.4.1.tar.bz2
mv -v mpfr-2.4.1 mpfr
tar -jxvf ../tar/gmp-4.3.1.tar.bz2
mv gmp-4.3.1 gmp

保存gcc第一次編譯的目錄
move -v ../gcc-build ../gcc-build-1

新建一個gcc編譯目錄
mkdir -v ../gcc-build
cd ../gcc-build

這次編譯gcc之前,先重設所有變數,替換默認值。

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


make && make install

為了兼容使用cc命令,做個軟鏈接

ln -vs gcc /tools/bin/cc

檢測一下工具鏈是不是已經換過來了:

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

如果沒問題,會有下面的輸出
[Requesting program interpreter:
    /tools/lib/ld-linux.so.2]

刪掉剛剛的調試文件:
rm -v dummy.c a.out


5.11. Tcl-8.5.7
----------------------------------------------

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

cd tcl8.5.7/
cd unix
./configure --prefix=/tools
make
TZ=UTC make test
make install

令以安裝的共享庫可寫,以便調試標記以後能夠被移除。
chmod -v u+w /tools/lib/libtcl8.5.so

安裝tcl頭文件,下一個包expect需要它們來編譯。
make install-private-headers

再做一個必要的符號鏈接
ln -sv tclsh8.5 /tools/bin/tclsh


5.12. Expect-5.43.0
----------------------------------------------

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

首先,打個補丁,否則會導致gcc測試單元失敗。
patch -Np1 -i ../patch/expect-5.43.0-spawn-1.patch

再修復一個漏洞,是針對tcl最近修改的。
patch -Np1 -i ../patch/expect-5.43.0-tcl_8.5.5_fix-1.patch

接下來,強制要求configure腳本使用/bin/stty替代/usr/local/bin/stty,因為它存在於宿主系統。
確保我們的測試單元工具到最後的工具鏈編譯還是健全的。

準備Expect的編譯

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

make
make test
註:眾所周知,Expect測試單元在某種宿主狀態下通常可能失敗,這不在我們的控制範圍。
因此,這裡的測試單元失敗,不用感到吃驚,也不是什麼關鍵問題。

make SCRIPTS="" install

libexpect-5.43.a 提供函數,使得Expect能夠被當作Tcl的擴展,或者讓Expect基於c/c++直接使用。


5.13. DejaGNU-1.4.4
----------------------------------------------

cd $LFS/sources
tar -zxvf tar/dejagnu-1.4.4.tar.gz
cd dejagnu-1.4.4/
./configure --prefix=/tools
make install

測試
make check


5.14. Ncurses-5.7
----------------------------------------------

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

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

--without-ada 確保Ncurses不會編譯對Ada編譯器的支持。
因為它存在宿主系統上,但一旦我們進入chroot環境就不可用了。

--enable-overwrite 告訴Ncurses安裝他的頭文件到/tools/include,替換/tools/include/ncurses。
確保其他包能夠順利找到Ncurses的頭文件。

make
make install


5.15. Bash-4.0
----------------------------------------------

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

打補丁,bash4出來之後發現的一些問題
patch -Np1 -i ../patch/bash-4.0-fixes-2.patch

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

make
make tests
make install
ln -vs bash /tools/bin/sh


5.16. Bzip2-1.0.5
----------------------------------------------

cd $LFS/sources
tar -zxvf tar/bzip2-1.0.5.tar.gz
cd bzip2-1.0.5/
make
make PREFIX=/tools install


5.17. Coreutils-7.4
---------------------------------------------

cd $LFS/sources
tar -zxvf tar/coreutils-7.4.tar.gz
cd coreutils-7.4/
./configure --prefix=/tools --enable-install-program=hostname
make
make RUN_EXPENSIVE_TESTS=yes check
make install
cp -v src/su /tools/bin/su-tools


5.18. Diffutils-2.8.1
---------------------------------------------

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

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


5.19. E2fsprogs-1.41.5
---------------------------------------------

cd $LFS/sources
tar -zxvf tar/e2fsprogs-1.41.5.tar.gz
cd e2fsprogs-1.41.5/
mkdir -v build
cd build
../configure --prefix=/tools
make
make install-libs

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


5.20. Findutils-4.4.1
---------------------------------------------

cd $LFS/sources
tar -zxvf tar/findutils-4.4.1.tar.gz
cd findutils-4.4.1/
./configure --prefix=/tools
make
make check
make install



5.21. Gawk-3.1.6
---------------------------------------------

cd $LFS/sources
tar -jxvf tar/gawk-3.1.6.tar.bz2
cd gawk-3.1.6/
./configure --prefix=/tools ac_cv_func_working_mktime=yes
make
make check
make install



5.22. Gettext-0.17
---------------------------------------------

cd $LFS/sources
tar -zxvf tar/gettext-0.17.tar.gz
cd gettext-0.17/
cd gettext-tools
./configure --prefix=/tools --disable-shared

make -C gnulib-lib
make -C src msgfmt

cp -v src/msgfmt /tools/bin



5.23. Grep-2.5.4
---------------------------------------------

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

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

make
make check
make install


5.24. Gzip-1.3.12
---------------------------------------------

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

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


./configure --prefix=/tools

make
make check
make install


5.25. M4-1.4.13
---------------------------------------------

cd $LFS/sources
tar -jxvf tar/m4-1.4.13.tar.bz2
cd m4-1.4.13/
./configure --prefix=/tools
make
make check
make install


5.26. Make-3.81
---------------------------------------------

cd $LFS/sources
tar -jxvf tar/make-3.81.tar.bz2
cd make-3.81/
./configure --prefix=/tools
make
make check
make install


5.27. Patch-2.5.9
---------------------------------------------

cd $LFS/sources
tar -zxvf tar/patch-2.5.9.tar.gz
cd patch-2.5.9/
patch -Np1 -i ../patch/patch-2.5.9-fixes-1.patch
./configure --prefix=/tools
make
make install


5.28. Perl-5.10.0
---------------------------------------------

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

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

make perl utilities ext/Errno/pm_to_blib

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


5.29. Sed-4.2
---------------------------------------------

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

./configure --prefix=/tools
make
make check
make install



5.30. Tar-1.22
---------------------------------------------

cd $LFS/sources
tar -jxvf tar/tar-1.22.tar.bz2
cd tar-1.22/

./configure --prefix=/tools
make
make check
make install


5.31. Texinfo-4.13a
---------------------------------------------

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

./configure --prefix=/tools
make
make check
make install


5.32. Util-linux-ng-2.14.2
---------------------------------------------

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

./configure --prefix=/tools

make -C disk-utils mkswap
make -C mount mount umount
make -C text-utils more

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


5.33. Stripping
---------------------------------------------

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

rm -rf /tools/{info,man}


5.34. Changing Ownership
---------------------------------------------
exit
退出lfs用戶shell環境

更改tools工具鏈的所有權為root,以免將來工具鏈被惡意提升許可權。
chown -R root:root $LFS/tools

tools在lfs編譯完成後可以被刪除,但還是可以用來編譯相同版本的lfs程序
如何保存工具鏈,全憑個人愛好!

《解決方案》

繼續,LFS第六章



構建LFS系統

6.1. 盡量簡單的編譯一個LFS系統雛形,盡量不要使用編譯器優化參數,因為這帶來的速度提升幾乎可以忽略不計,但帶來的壞處,可能導致程序運行不穩定。不要同時編譯幾個包,因為這樣可能產生硬鏈接到/tools,如果tools目錄被刪除,可能會出現問題。

6.2. 準備虛擬內核文件系統

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

建立初始設備節點(console和null設備)
mknod -m 600 $LFS/dev/console c 5 1
mknod -m 666 $LFS/dev/null c 1 3

掛載並綁定設備目錄
mount -v --bind /dev $LFS/dev

掛載虛擬內核文件系統
mount -vt devpts devpts $LFS/dev/pts
mount -vt tmpfs shm $LFS/dev/shm
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys


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


6.4. 進入Chroot環境
chroot "$LFS" /tools/bin/env -i \
    HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
    /tools/bin/bash --login +h

用env -i 表示清空所有環境變數,只重設後面的幾個。在這裡也可以設置CFLAGS或者CXXFLAGS
進入chroot環境后,由於還沒建立/etc/passwd 文件,所以shell提示符前面為:
I have no name!:/#

到了這點上面,$LFS變數就可以不管了,因為接下來所有的工作都被限制在LFS文件系統裡面了。
Bash已經把$LFS當作root (/) 目錄來處理了。


6.5. 增加目錄

增加文件結構

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

以上文件夾結構,遵循Filesystem Hierarchy Standard (FHS)
http://www.pathname.com/fhs/


6.6. 增加必要的文件和軟鏈接

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

touch /etc/mtab

cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/dev/null:/bin/false
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
EOF


cat > /etc/group << "EOF"
root:x:0:
bin:x:1:
sys:x:2:
kmem:x:3:
tty:x:4:
tape:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
mail:x:34:
nogroup:x:99:
EOF


完整的glibc安裝好之後,passwd和group文件已經建立,現在用戶名和組可以生效了。
exec /tools/bin/bash --login +h
使用+h參數,屏蔽bash的內部路徑哈希。避免bash使用舊的文件路徑,能夠保證新編譯的代碼馬上可以被利用。

建立一些空文件並賦予它們寫許可權,以便login, agetty, init以及其他一些程序能夠記錄系統日誌及登陸信息
touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
chgrp -v utmp /var/run/utmp /var/log/lastlog
chmod -v 664 /var/run/utmp /var/log/lastlog

註:
/var/run/utmp 記錄已經登陸的用戶信息, /var/log/wtmp 記錄所有登陸及註銷信息,
/var/log/lastlog 記錄每個用戶的最後登陸時間, /var/log/btmp 記錄登陸失敗信息。



6.7. Linux-2.6.29.4 API Headers

cd /sources
cd linux-2.6.29.4/
make mrproper

make headers_check
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /usr/include


6.8. Man-pages-3.21

cd /sources
tar -jxvf tar/man-pages-3.21.tar.bz2
cd man-pages-3.21/
make install


6.9. Glibc-2.10.1

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

當執行glibc的make install的時候,會調用一個perl腳本進行測試,
現在的工具鏈還是指向/tools,測試會針對以前編譯的glibc,
以下腳本可以讓測試指向剛剛編譯的glibc

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

ldd命令自帶了bash的特殊語法,為了避免其他的/bin/sh對ldd的影響,
最好把默認解釋器改成/bin/bash,關於這個鳥問題,在BLFS 這本破書的shell章節中也提到了

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


修復一個make check可能出現的錯誤

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

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

為x86機器增加必要的CFLAGS編譯參數,-pipe加速編譯,-O3提高程序的性能。

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

準備編譯
../glibc-2.10.1/configure --prefix=/usr \
    --disable-profile --enable-add-ons \
    --enable-kernel=2.6.0 --libexecdir=/usr/lib/glibc

開始編譯,等N久!
make

為防止編譯測試的幾個失敗可能,從源碼目錄拷貝一個東東。
cp -v ../glibc-2.10.1/iconvdata/gconv-modules iconvdata
make -k check 2>&1 | tee glibc-check-log
grep Error glibc-check-log
在測試posix/annexc的時候,有一個可忽略的錯誤。
這和宿主系統有關,這裡不用理它。

雖然無關緊要,為了防止glibc安裝階段報錯缺少說ld.so.conf,還是touch一個吧
touch /etc/ld.so.conf

make install


定義locale集合

mkdir -pv /usr/lib/locale
localedef -i cs_CZ -f UTF-8 cs_CZ.UTF-8
localedef -i de_DE -f ISO-8859-1 de_DE
localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
localedef -i de_DE -f UTF-8 de_DE.UTF-8
localedef -i en_HK -f ISO-8859-1 en_HK
localedef -i en_PH -f ISO-8859-1 en_PH
localedef -i en_US -f ISO-8859-1 en_US
localedef -i en_US -f UTF-8 en_US.UTF-8
localedef -i es_MX -f ISO-8859-1 es_MX
localedef -i fa_IR -f UTF-8 fa_IR
localedef -i fr_FR -f ISO-8859-1 fr_FR
localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
localedef -i fr_FR -f UTF-8 fr_FR.UTF-8
localedef -i it_IT -f ISO-8859-1 it_IT
localedef -i ja_JP -f EUC-JP ja_JP
localedef -i tr_TR -f UTF-8 tr_TR.UTF-8
localedef -i zh_CN -f GB18030 zh_CN.GB18030

其實這裡我只要三個就可以了
localedef -i en_US -f ISO-8859-1 en_US
localedef -i en_US -f UTF-8 en_US.UTF-8
localedef -i zh_CN -f GB18030 zh_CN.GB18030

安裝其他沒有執行localedef定義的語言包(可選)
make localedata/install-locales


配置glibc
儘管當nsswitch.conf不存在或非法時,Glibc會默認產生,但在網路環境下,可能不是很理想。
所以還是創建一個吧,另外,時區也應該配置了。

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

passwd: files
group: files
shadow: files

hosts: files dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

# End /etc/nsswitch.conf
EOF

選擇時區
tzselect


這裡最後應該是 TZ='Asia/Shanghai';


增加/etc/localtime

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

配置動態載入
cat > /etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf

/usr/local/lib
/opt/lib

# End /etc/ld.so.conf
EOF




6.10. 重新調整工具鏈

先備份,然後用第五章裡面調整過的工具鏈替換。
mv -v /tools/bin/{ld,ld-old}
mv -v /tools/$(gcc -dumpmachine)/bin/{ld,ld-old}
mv -v /tools/bin/{ld-new,ld}
ln -sv /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld

接下來,調整gcc的spec文件,以便指向新的動態鏈接庫。

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


最好仔細檢查一下specs文件是不是真的修改了。

測試一下新的工具鏈
echo 'main(){}' > dummy.c
cc dummy.c -v -Wl,--verbose &> dummy.log
readelf -l a.out | grep ': /lib'

應該出現以下提示



grep -o '/usr/lib.*/crt.*succeeded' dummy.log
應該出現
/usr/lib/crt1.o succeeded
/usr/lib/crti.o succeeded
/usr/lib/crtn.o succeeded

確保編譯器使用了正確的頭文件
grep -B1 '^ /usr/include' dummy.log

應該輸出
#include <...> search starts here:
/usr/include

再看看新的編譯器是否使用了正確的查找路徑
grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'

應該輸出
SEARCH_DIR("/tools/i686-pc-linux-gnu/lib")
SEARCH_DIR("/usr/lib")
SEARCH_DIR("/lib");


再檢查是不是使用了正確的libc
grep "/lib.*/libc.so.6 " dummy.log

應該輸出
attempt to open /lib/libc.so.6 succeeded


最後一點,確認gcc使用了正確的動態鏈接器
grep found dummy.log

應該輸出
found ld-linux.so.2 at /lib/ld-linux.so.2

如果一切都沒問題,那麼清楚測試文件
rm -v dummy.c a.out dummy.log


6.11. Zlib-1.2.3

cd /sources
tar -xvf tar/zlib-1.2.3.tar.bz2
cd zlib-1.2.3/

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

make
make check
make install

剛才的命令安裝了一個.so文件在/lib目錄,我們將它移動並重新鏈接到/usr/lib

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


編譯靜態鏈接庫

make clean
./configure --prefix=/usr
make

make check
make install


修正靜態鏈接庫的許可權
chmod -v 644 /usr/lib/libz.a



6.12. Binutils-2.19.1

cd /sources/binutils-2.19.1/

驗證新的chroot環境內,PTYs工作是否正常
expect -c "spawn ls"

正常應該輸出
spawn ls

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

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

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

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

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


6.13. GMP-4.3.1

cd /sources
tar -xvf tar/gmp-4.3.1.tar.bz2
cd gmp-4.3.1/

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

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


6.14. MPFR-2.4.1

cd /sources
tar -xvf tar/mpfr-2.4.1.tar.bz2
cd mpfr-2.4.1/

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

make
make check
make install

安裝幫助文檔
make html
mkdir -p /usr/share/doc/mpfr-2.4.1
find . -name \*.html -type f -exec cp -v \{} /usr/share/doc/mpfr-2.4.1 \;




6.15. GCC-4.4.0 (第三次編譯gcc-4.4.0)

為了防止重複修改源碼導致編譯出錯,刪除以前的源碼目錄,重新弄一個!
rm -rf /sources/gcc-4.4.0/

cd /sources
tar -jxvf tar/gcc-4.4.0.tar.bz2
cd gcc-4.4.0

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

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

這裡也要做一次,呵呵。

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


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


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

make
make -k check

../gcc-4.4.0/contrib/test_summary

make install

兼容鏈接
ln -sv ../usr/bin/cpp /lib
ln -sv gcc /usr/bin/cc

測試工具鏈
echo 'main(){}' > dummy.c
cc dummy.c -v -Wl,--verbose &> dummy.log
readelf -l a.out | grep ': /lib'

正確輸出


grep -o '/usr/lib.*/crt.*succeeded' dummy.log
正確輸出
/usr/lib/gcc/i686-pc-linux-gnu/4.4.0/../../../crt1.o succeeded
/usr/lib/gcc/i686-pc-linux-gnu/4.4.0/../../../crti.o succeeded
/usr/lib/gcc/i686-pc-linux-gnu/4.4.0/../../../crtn.o succeeded


檢查是否調用正確的頭文件
grep -B4 '^ /usr/include' dummy.log

正確應該有以下輸出
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.4.0/include
/usr/lib/gcc/i686-pc-linux-gnu/4.4.0/include-fixed
/usr/include

檢查搜索路徑是否正確
grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'

正常會輸出
SEARCH_DIR("/usr/i686-pc-linux-gnu/lib")
SEARCH_DIR("/usr/local/lib")
SEARCH_DIR("/lib")
SEARCH_DIR("/usr/lib");

64位系統會輸出
SEARCH_DIR("/usr/x86_64-unknown-linux-gnu/lib64")
SEARCH_DIR("/usr/local/lib64")
SEARCH_DIR("/lib64")
SEARCH_DIR("/usr/lib64")
SEARCH_DIR("/usr/x86_64-unknown-linux-gnu/lib")
SEARCH_DIR("/usr/local/lib")
SEARCH_DIR("/lib")
SEARCH_DIR("/usr/lib");


檢查libc調用
grep "/lib.*/libc.so.6 " dummy.log
正確輸出
attempt to open /lib/libc.so.6 succeeded

檢查動態鏈接庫
grep found dummy.log
正確輸出
found ld-linux.so.2 at /lib/ld-linux.so.2


刪除測試文件
rm -v dummy.c a.out dummy.log


6.16. Berkeley DB-4.7.25

cd /sources/
tar -xvf tar/db-4.7.25.tar.gz
cd db-4.7.25/
patch -Np1 -i ../patch/db-4.7.25-upstream_fixes-1.patch

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

make
make docdir=/usr/share/doc/db-4.7.25 install

修復文檔的所有權
chown -Rv root:root /usr/share/doc/db-4.7.25



6.17. Sed-4.2

cd /sources/
rm -rf sed-4.2/

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

make
make check
make install



6.18. E2fsprogs-1.41.5


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

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

make
make check
make install
make install-libs

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


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


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

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



6.19. Coreutils-7.4

Intel硬體系統裡面,當使用uname -p參數時,經常返回unknown,下面打個補丁。

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

POSIX標準需要coreutils程序識別多位元組語言的字元邊界效驗。
patch -Np1 -i ../patch/coreutils-7.4-i18n-1.patch

準備編譯
./configure --prefix=/usr \
    --enable-no-install-program=kill,uptime

make

make NON_ROOT_USERNAME=nobody check-root

準備用nobody用戶完成下面的測試,這裡建立一個臨時組,將nobody加入這個組,進行測試
echo "dummy:x:1000:nobody" >> /etc/group

修正許可權
chown -Rv nobody config.log {gnulib-tests,lib,src}/.deps

用nobody用戶運行測試程序
su-tools nobody -s /bin/bash -c "make RUN_EXPENSIVE_TESTS=yes check" || true

刪除臨時組
sed -i '/dummy/d' /etc/group

安裝coreutils包
make install

將下面的命令移動到基於FHS的路徑
mv -v /usr/bin/{cat,chgrp,chmod,chown,cp,date,dd,df,echo} /bin
mv -v /usr/bin/{false,ln,ls,mkdir,mknod,mv,pwd,rm} /bin
mv -v /usr/bin/{rmdir,stty,sync,true,uname} /bin
mv -v /usr/bin/chroot /usr/sbin

LFS-Bootscripts包里的某些腳本,依賴於head,sleep和nice
/usr目錄在系統啟動初期可能不可用,這些二進位文件需要放在root分區
mv -v /usr/bin/{head,sleep,nice} /bin



6.20. Iana-Etc-2.30

cd /sources/
tar -xvf tar/iana-etc-2.30.tar.bz2
cd iana-etc-2.30/
make && make install



6.21. M4-1.4.13

./configure --prefix=/usr
make
make check
make install


6.22. Bison-2.4.1

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

echo '#define YYENABLE_NLS 1' >> config.h
make
make check
make install



6.23. Ncurses-5.7

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

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


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



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


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



Note
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:

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



6.24. Procps-3.2.8


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

make
make install


6.25. Grep-2.5.4

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


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

make
make check || true
make install


6.26. Readline-6.0


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

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

make SHLIB_LIBS=-lncurses

make install

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

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

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



6.27. Bash-4.0


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


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

make

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

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

make install

exec /bin/bash --login +h



6.28. Libtool-2.2.6a

./configure --prefix=/usr
make
make check
make install



6.29. Inetutils-1.6

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


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


make
make install
mv -v /usr/bin/ping /bin




6.30. Perl-5.10.0

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

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


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


sh Configure -des -Dprefix=/usr \
                  -Dvendorprefix=/usr           \
                  -Dman1dir=/usr/share/man/man1 \
                  -Dman3dir=/usr/share/man/man3 \
                  -Dpager="/usr/bin/less -isR"


make
make test
make install




6.31. Autoconf-2.63

./configure --prefix=/usr

make
make check
make install



6.32. Automake-1.11

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

make
make check
要check好久好久:(

make install


6.33. Bzip2-1.0.5

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

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

make -f Makefile-libbz2_so
make clean

make
make PREFIX=/usr install

cp -v bzip2-shared /bin/bzip2
cp -av libbz2.so* /lib
ln -sv ../../lib/libbz2.so.1.0 /usr/lib/libbz2.so
rm -v /usr/bin/{bunzip2,bzcat,bzip2}
ln -sv bzip2 /bin/bunzip2
ln -sv bzip2 /bin/bzcat




第六章需要做的工作太多了,下面繼續!
《解決方案》

繼續第六章



6.34. Diffutils-2.8.1

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

touch man/diff.1
./configure --prefix=/usr
make
make install



6.35. File-5.00


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

./configure --prefix=/usr

make
make check
make install


6.36. Gawk-3.1.6

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

make
make check
make install

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



6.37. GDBM-1.8.3

./configure --prefix=/usr

make
make install
make install-compat



6.38. Findutils-4.4.1


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

make
make check
make install

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




6.39. Flex-2.5.35

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

./configure --prefix=/usr

make
make check
make install

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


cat > /usr/bin/lex << "EOF"
#!/bin/sh
# Begin /usr/bin/lex

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

# End /usr/bin/lex
EOF
chmod -v 755 /usr/bin/lex


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



6.40. Gettext-0.17

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

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

make
make check
make install



6.41. Groff-1.20.1

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

make
make docdir=/usr/share/doc/groff-1.20.1 install

ln -sv eqn /usr/bin/geqn
ln -sv tbl /usr/bin/gtbl



6.42. Gzip-1.3.12

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

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

make
make check
make install

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



6.43. IPRoute2-2.6.29-1

make DESTDIR=

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

mv -v /sbin/arpd /usr/sbin



6.44. Kbd-1.15

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

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

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

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

make
make install

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

mkdir -v /usr/share/doc/kbd-1.15
cp -R -v doc/* \
         /usr/share/doc/kbd-1.15



6.45. Less-429

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

make
make install



6.46. Make-3.81


./configure --prefix=/usr

make
make check
make install


6.47. Man-DB-2.5.5

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

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

make
make check
make install


6.48. Module-Init-Tools-3.8

./configure
make check
make clean

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

make
make INSTALL=install install


6.49. Patch-2.5.9

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

./configure --prefix=/usr

make
make install



6.50. Psmisc-22.7

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

make
make install

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


6.51. Shadow-4.1.4.1

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

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

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



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

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


./configure --sysconfdir=/etc

make
make install
mv -v /usr/bin/passwd /bin

pwconv
grpconv

passwd root




6.52. Sysklogd-1.5

make
make BINDIR=/sbin install


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

auth,authpriv.* -/var/log/auth.log
*.*;auth,authpriv.none -/var/log/sys.log
daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log
*.emerg *

# End /etc/syslog.conf
EOF



6.53. Sysvinit-2.86

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

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

make -C src
make -C src install



cat > /etc/inittab << "EOF"
# Begin /etc/inittab

id:3:initdefault:

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

l0:0:wait:/etc/rc.d/init.d/rc 0
l1:S1:wait:/etc/rc.d/init.d/rc 1
l2:2:wait:/etc/rc.d/init.d/rc 2
l3:3:wait:/etc/rc.d/init.d/rc 3
l4:4:wait:/etc/rc.d/init.d/rc 4
l5:5:wait:/etc/rc.d/init.d/rc 5
l6:6:wait:/etc/rc.d/init.d/rc 6

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

su:S016:once:/sbin/sulogin

1:2345:respawn:/sbin/agetty tty1 9600
2:2345:respawn:/sbin/agetty tty2 9600
3:2345:respawn:/sbin/agetty tty3 9600
4:2345:respawn:/sbin/agetty tty4 9600
5:2345:respawn:/sbin/agetty tty5 9600
6:2345:respawn:/sbin/agetty tty6 9600

# End /etc/inittab
EOF





6.54. Tar-1.22

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

make
make check
make install



6.55. Texinfo-4.13a

./configure --prefix=/usr

make
make check
make install
make TEXMF=/usr/share/texmf install-tex


cd /usr/share/info
rm dir
for f in *
do install-info $f dir 2>/dev/null
done



6.56. Udev-142



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

install -dv /lib/{firmware,udev/devices/{pts,shm}}
mknod -m0666 /lib/udev/devices/null c 1 3
mknod -m0600 /lib/udev/devices/kmsg c 1 11
ln -sv /proc/self/fd /lib/udev/devices/fd
ln -sv /proc/self/fd/0 /lib/udev/devices/stdin
ln -sv /proc/self/fd/1 /lib/udev/devices/stdout
ln -sv /proc/self/fd/2 /lib/udev/devices/stderr
ln -sv /proc/kcore /lib/udev/devices/core

./configure --prefix=/usr \
            --exec-prefix= \
            --sysconfdir=/etc

make
make install

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

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

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

cd udev-config-20090523
make install

make install-doc

make install-extra-doc

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




6.57. Util-linux-ng-2.14.2


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

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

make
make install



6.58. Vim-7.2


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

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

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

make
make test
make install

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

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


cat > /etc/vimrc << "EOF"
" Begin /etc/vimrc

set nocompatible
set backspace=2
syntax on
if (&term == "iterm") || (&term == "putty")
  set background=dark
endif

" End /etc/vimrc
EOF


6.59. About Debugging Symbols

調試符號優化
http://www.linuxfromscratch.org/hints/downloads/files/optimization.txt.


6.60. Stripping Again

logout

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

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



6.61. Cleaning Up

/tools目錄不再需要了,可以刪除。

《解決方案》

工具鏈利用完畢,現在開始進入乾淨的LFS 」臨時「 系統!:em03:



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



7.2. LFS-Bootscripts-20090523

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

make install



7.4. Configuring the setclock Script


cat > /etc/sysconfig/clock << "EOF"
# Begin /etc/sysconfig/clock

UTC=1

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

# End /etc/sysconfig/clock
EOF



7.5. Configuring the Linux Console


cat > /etc/sysconfig/console << "EOF"
# Begin /etc/sysconfig/console

#KEYMAP=""
#FONT=""

# End /etc/sysconfig/console
EOF



7.7. Creating the /etc/inputrc File


cat > /etc/inputrc << "EOF"
# Begin /etc/inputrc
# Modified by Chris Lynn <roryo@roryo.dynup.net>

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

# Enable 8bit input
set meta-flag On
set input-meta On

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

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

# none, visible or audible
set bell-style none

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

# for linux console
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert

# for xterm
"\eOH": beginning-of-line
"\eOF": end-of-line

# for Konsole
"\e[H": beginning-of-line
"\e[F": end-of-line

# End /etc/inputrc
EOF


cat > /etc/profile << "EOF"
# Begin /etc/profile

export LANG=en_US.UTF-8

# End /etc/profile
EOF



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


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

127.0.0.1 localhost
10.10.10.8 LFS61

# End /etc/hosts (network card version)
EOF



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


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


cd /etc/sysconfig/network-devices
mkdir -v ifconfig.eth0
cat > ifconfig.eth0/ipv4 << "EOF"
ONBOOT=yes
SERVICE=ipv4-static
IP=10.10.10.8
GATEWAY=10.10.10.7
PREFIX=24
BROADCAST=10.10.0.255
EOF



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

domain gelin.com
nameserver 202.96.128.68
nameserver 202.96.128.166

# End /etc/resolv.conf
EOF



cat > /etc/fstab << "EOF"
# Begin /etc/fstab

# file system  mount-point  type   options         dump  fsck
#                                                        order

/dev/sda3     /            ext3  defaults        1     1
#/dev/<yyy>     swap         swap   pri=1           0     0
proc           /proc        proc   defaults        0     0
sysfs          /sys         sysfs  defaults        0     0
devpts         /dev/pts     devpts gid=4,mode=620  0     0
tmpfs          /dev/shm     tmpfs  defaults        0     0
# End /etc/fstab
EOF



cat > /etc/bashrc << "EOF"
# Begin /etc/bashrc
# Written for Beyond Linux From Scratch
# by James Robertson <jameswrobertson@earthlink.net>
# updated by Bruce Dubbs <bdubbs@linuxfromscratch.org>

# System wide aliases and functions.

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

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

alias ls='ls --color=auto'

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

NORMAL="\[\e"
GRAY="\[\e"
GREEN="\[\e"
if [[ $EUID == 0 ]] ; then
  PS1="$GRAY[\u@\h $NORMAL\w$GRAY]# $NORMAL"
else
  PS1="$GREEN[\u@\h $NORMAL\w$GREEN]\$ $NORMAL"
fi

# End /etc/bashrc
EOF



cat .bash_profile
source ~/.bashrc


# cat .bashrc
# Begin ~/.bashrc
# Written for Beyond Linux From Scratch
# by James Robertson <jameswrobertson@earthlink.net>

# Personal aliases and functions.

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

if [ -f "/etc/bashrc" ] ; then
  source /etc/bashrc
fi

alias ll='ls -l'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# End ~/.bashrc









編譯安裝hdparm

cd /mnt/lfs/sources/
wget http://nchc.dl.sourceforge.net/sourceforge/hdparm/hdparm-9.6.tar.gz


make
make binprefix=/usr install




編譯內核

內核編譯,我是利用了ubuntu9的最新內核配置文件,在此基礎上精簡編譯的。關於內核的裁減和優化編譯,這又是另外一個課題了,有興趣的朋友,可以一起探討





安裝grub

由於我的系統引導,是利用ubuntu安裝的grub,所以這次我就沒再安裝grub了,關於grub的安裝,請參考LFS6.3等類似手冊,這裡不再多說了。



退出chroot環境

logout

卸載虛擬文件系統
umount -v $LFS/dev/pts
umount -v $LFS/dev/shm
umount -v $LFS/dev
umount -v $LFS/proc
umount -v $LFS/sys


如果掛載了其他分區,要先卸載他們,再卸載LFS文件系統本身

umount -v $LFS/usr
umount -v $LFS/home
umount -v $LFS


最後卸載LFS文件系統本身
umount -v $LFS


重啟系統
shutdown -r now


《解決方案》

下面進入BLFS的課題,接下來的工作,可以根據自己的需求,編譯一些軟體包。我需要遠程配置,所以先安裝openSSH,而openSSH依賴於openssl,所以先弄上她,呵呵。



安裝openssl-0.9.8k
http://www.linuxfromscratch.org/blfs/view/cvs/postlfs/openssl.html

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


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

make MANDIR=/usr/share/man install

cp -v -r certs /etc/ssl

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

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



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





openssh


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



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


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


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

make

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


make install

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

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




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

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

chmod 644 /etc/pam.d/sshd


http://www.linuxfromscratch.org/blfs/downloads/svn/blfs-bootscripts-20090302.tar.bz2

make install-sshd

root:/sources/blfs-bootscripts-20090302# make install-sshd
install -d -m 755 /etc/rc.d/rc{0,1,2,3,4,5,6,sysinit}.d
install -d -m 755 /etc/rc.d/init.d
install -d -m 755 /etc/sysconfig
install -m 754 blfs/init.d/sshd       /etc/rc.d/init.d/
ln -sf  ../init.d/sshd /etc/rc.d/rc0.d/K30sshd
ln -sf  ../init.d/sshd /etc/rc.d/rc1.d/K30sshd
ln -sf  ../init.d/sshd /etc/rc.d/rc2.d/K30sshd
ln -sf  ../init.d/sshd /etc/rc.d/rc3.d/S30sshd
ln -sf  ../init.d/sshd /etc/rc.d/rc4.d/S30sshd
ln -sf  ../init.d/sshd /etc/rc.d/rc5.d/S30sshd
ln -sf  ../init.d/sshd /etc/rc.d/rc6.d/K30sshd


安裝unzip
http://downloads.sourceforge.net/infozip/unzip552.tar.gz
http://www.linuxfromscratch.org/patches/blfs/svn/unzip-5.52-security_fix-1.patch
http://www.linuxfromscratch.org/patches/blfs/svn/unzip-5.52-security_fix-2.patch


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


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



安裝wget
http://www.linuxfromscratch.org/blfs/view/cvs/basicnet/wget.html


http://ftp.gnu.org/gnu/wget/wget-1.11.4.tar.bz2



./configure --prefix=/usr --sysconfdir=/etc
make
make install
install-info --info-dir=/usr/share/info /usr/share/info/wget.info


《解決方案》

最後,進入我們的應用階段——編譯安裝nginx和fast-cgi,打造一個高性能的php運行環境(相同配置,比apache效率至少高3倍以上,這是我的測試結論,希望大家有興趣的做完之後,也來測試測試。)



安裝ngnix
先備份lfs基本系統
tar --exclude=/sources --exclude=/proc --exclude=/sys \
--create --absolute-names --preserve-permissions --bzip2 \
--verbose --totals \
--file /sources/lfs-stage4.$(date +%Y%m%d%s).tar.bz2 /




cd /sources

mkdir lnmp

一、下載軟體
cat > soft-list << "EOF"
http://sysoev.ru/nginx/nginx-0.7.59.tar.gz
http://www.php.net/get/php-5.2.9.tar.gz/from/this/mirror
http://www.libgd.org/releases/gd-2.0.35.tar.bz2
ftp://xmlsoft.org/libxml2/libxml2-2.6.32.tar.gz
ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.2.37.tar.bz2
http://ftp.twaren.net/Unix/NonGNU/freetype/freetype-2.3.9.tar.gz
http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.33.zip/from/http://mysql.mirror.redwire.net/
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.tar.gz
http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0
http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0
http://pecl.php.net/get/memcache-2.2.5.tgz
http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz
http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2
http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
http://pecl.php.net/get/imagick-2.2.2.tgz
EOF


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




二、安裝PHP 5.2.8(FastCGI模式)
  1、編譯安裝PHP 5.2.8所需的支持庫:

tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13/
./configure --prefix=/usr/local
make
make install
cd ../

tar -zxvf freetype-2.3.9.tar.gz
cd freetype-2.3.9/
./configure --prefix=/opt/lnmp/freetype2
make
make install
cd ../

tar -jxvf libpng-1.2.37.tar.bz2
cd libpng-1.2.37/
./configure --prefix=/opt/lnmp/libpng
make
make install
cd ../

tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
./configure --enable-static --enable-shared --prefix=/opt/lnmp/jpeg-6b
mkdir -pv /opt/lnmp/jpeg-6b/include
mkdir -pv /opt/lnmp/jpeg-6b/lib
mkdir -pv /opt/lnmp/jpeg-6b/bin/
mkdir -pv /opt/lnmp/jpeg-6b/man/man1
make
make install
make install-lib
cd ../


tar -zxvf libxml2-2.7.3.tar.gz
cd libxml2-2.7.3
./configure --prefix=/opt/lnmp/libxml
make
make install
cd ../


tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../

tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure --with-libmcrypt-prefix=/usr/local/
make
make install
cd ../

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

make報錯
說缺少png.h
在Makefile裡面,CPPFLAGS最後,加上-I/opt/lnmp/libpng/include

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

再make

make install
cd ../

2、編譯安裝MySQL 5.1.33

/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
unzip mysql-5.1.33.zip
cd mysql-5.1.33/
./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
make && make install
chmod +w /opt/lnmp/mysql
chown -R mysql:mysql /opt/lnmp/mysql
cp support-files/my-medium.cnf /opt/lnmp/mysql/my.cnf
cd ../

①、以mysql用戶帳號的身份建立數據表:

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


②、啟動MySQL(最後的&表示在後台運行)

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



注!!

MySQL編譯安裝,初始化資料庫的時候出現:
unknown option '--skip-federated' 錯誤。

#vi /etc/my.cnf
#skip-federated 將此行註釋掉
即可。
或者編譯的時候加上如下參數:
--with-plugins=all



3、編譯安裝PHP(FastCGI模式)

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


./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


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

./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

--------------------------------------------------------------------------------

  4、編譯安裝PHP5擴展模塊

tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/opt/lnmp/php/bin/phpize
./configure --with-php-config=/opt/lnmp/php/bin/php-config
make
make install
cd ../

tar jxvf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3/
/opt/lnmp/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/opt/lnmp/php/bin/php-config
make
make install
cd ../

tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/opt/lnmp/php/bin/phpize
./configure --with-php-config=/opt/lnmp/php/bin/php-config --with-pdo-mysql=/opt/lnmp/mysql
make
make install
cd ../

tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure --prefix=/opt/lnmp/imagemagick
make
make install
cd ../

tar zxvf imagick-2.2.2.tgz
cd imagick-2.2.2/
/opt/lnmp/php/bin/phpize
./configure --with-imagick=/opt/lnmp/imagemagick --with-php-config=/opt/lnmp/php/bin/php-config
make
make install
cd ../



5、修改php.ini文件
手工修改:查找/opt/lnmp/php/etc/php.ini中的extension_dir = "./"
修改為extension_dir = "/opt/lnmp/php/lib/php/extensions/no-debug-non-zts-20060613/"
並在此行后增加以下幾行,然後保存:

        extension = "memcache.so"
  extension = "pdo_mysql.so"
  extension = "imagick.so"
    extension = "gd.so"

再查找output_buffering = Off
修改為output_buffering = On



6、配置eAccelerator加速PHP:

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

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

引用

zend_extension="/opt/lnmp/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/opt/lnmp/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="300"
eaccelerator.shm_prune_period="120"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"


修改配置文件:

vi /etc/sysctl.conf

輸入以下內容:

引用
kernel.shmmax = 134217728
kernel.shmmax = 134217728
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000    65000


然後執行以下命令使配置生效:

/sbin/sysctl -p


--------------------------------------------------------------------------------

7、創建www用戶和組,以及供222.222.222.222和www.test.com兩個虛擬主機使用的目錄:

/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /opt/webroot/mypic
chmod +w /opt/webroot/mypic
chown -R www:www /opt/webroot/mypic
mkdir -p /opt/webroot/www
chmod +w /opt/webroot/www
chown -R www:www /opt/webroot/www



三、安裝Nginx 0.7.59
  1、安裝Nginx所需的pcre庫:

tar zxvf pcre-7.8.tar.gz
cd pcre-7.8/
./configure --prefix=/opt/lnmp/pcre
make && make install
cd ../

2、安裝Nginx
cp -R /sources/lnmp/pcre-7.8 /opt/lnmp/pcre-7.8
tar -zxvf nginx-0.7.59.tar.gz
cd nginx-0.7.59/
./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/
make && make install
cd ../

3、創建Nginx日誌目錄

mkdir -p /opt/webroot/logs
chmod +w /opt/webroot/logs
chown -R www:www /opt/webroot/logs


4、創建Nginx配置文件

①、在/opt/lnmp/nginx/conf/目錄中創建nginx.conf文件:

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

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


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

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

events
{
  use epoll;
  worker_connections 51200;
}

http
{
  include       mime.types;
  default_type  application/octet-stream;

  #charset  gb2312;
      
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;
      
  sendfile on;
  tcp_nopush     on;

  keepalive_timeout 60;

  tcp_nodelay on;

  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;

  gzip on;
  gzip_min_length  1k;
  gzip_buffers     4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-javascript text/css application/xml;
  gzip_vary on;

  #limit_zone  crawler  $binary_remote_addr  10m;

  server
  {
    listen       80;
    server_name  222.222.222.222;
    index index.html index.htm index.php;
    root  /opt/webroot/mypic;

    #limit_conn   crawler  20;   
                             
    location ~ .*\.(php|php5)?$
    {      
      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      fastcgi_pass  127.0.0.1:10080;
      fastcgi_index index.php;
      include fcgi.conf;
    }
   
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }

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

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

  server
  {
    listen       80;
    server_name  www.test.com;
    index index.html index.htm index.php;
    root  /opt/webroot/www;

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

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

  server
  {
    listen  80;
    server_name  status.test.com;

    location / {
    stub_status on;
    access_log   off;
    }
  }
}




wget http://www.lighttpd.net/download/spawn-fcgi-1.6.2.tar.gz
tar -zxf spawn-fcgi-1.6.2.tar.gz
cd spawn-fcgi-1.6.2/
./configure --prefix=/opt/lnmp/fastcgi
make && make install



啟動php-cgi進程,監聽127.0.0.1的10080埠,進程數為64(如果伺服器內存小於3GB,可以只開啟25個進程),用戶為www:

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



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

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

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



5、啟動Nginx

ulimit -SHn 51200
/opt/lnmp/nginx/sbin/nginx




六、在不停止Nginx服務的情況下平滑變更Nginx配置
  1、修改/opt/lnmp/nginx/conf/nginx.conf配置文件后,請執行以下命令檢查配置文件是否正確:

/opt/lnmp/nginx/sbin/nginx -t

  如果屏幕顯示以下兩行信息,說明配置文件正確:
  the configuration file /opt/lnmp/nginx/conf/nginx.conf syntax is ok
  the configuration file /opt/lnmp/nginx/conf/nginx.conf was tested successfully

  2、這時,輸入以下命令查看Nginx主進程號:

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

  屏幕顯示的即為Nginx主進程號,例如:
  6302
  這時,執行以下命令即可使修改過的Nginx配置文件生效:

kill -HUP 6302

  或者無需這麼麻煩,找到Nginx的Pid文件:

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



將以下命令加入啟動腳本

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

/sbin/sysctl -p


為了方便大家閱讀,一下附上筆記附件!

《解決方案》

由於是subversion的開發者版本,所以官方几乎每天都有更新
地址是http://www.linuxfromscratch.org/lfs/view/development/index.html

為了方便大家參考,我將SVN-20090601打包發上來了。
《解決方案》

:lol: 太好了。
《解決方案》

頂一下,辛苦
《解決方案》

即使是LFS編譯成功了,生產環境誰敢用啊

[火星人 ] 利用LFS SVN20090601打造一個強大的WEB伺服器已經有1135次圍觀

http://coctec.com/docs/service/show-post-22100.html