歡迎您光臨本站 註冊首頁

1、下載centos 5

我是下載的DVD版本,大家也可以下載伺服器CD安裝版本,其實都差不多。大家可以到這兒下載,速度很快的。

http://ftp.iasi.roedu.net/mirror ... .0-i386-bin-DVD.iso

當然也可以在windows下用BT或迅雷下載,速度也很不錯的。

下載后當然就刻錄成光碟。我建議你刻錄DVD啦,如果是菜鳥,也可以在圖形界面進行學習,不會這麼抓不住頭腦。

2、(1)安裝CentOS 5

作為伺服器,不安裝不需要的組件,所以在選擇組件的時候,除了選擇FTP SERVER外取消所有組件的選擇。也不要選web伺服器。因為我們後面要手動編譯安裝。

系統約定RPM包和源碼包存放位置

RPM包和源碼包存放位置 /usr/local/src

源碼包編譯安裝位置(prefix) /usr/local/xxx

腳本以及維護程序存放位置 /usr/local/sbin

MySQL 資料庫位置 /var/lib/mysql

Apache 網站根目錄 /home/www

Apache 虛擬主機日誌根目錄 /data/logs/www

yum RPM包信息文件 /etc/yum.list

3、系統環境部署及調整

(1). 檢查系統是否正常

# more /var/log/messages //檢查有無系統內核級錯誤信息

# demesg //檢查硬體設備是否有錯誤信息

# ifconfig //檢查網卡設置是否正確

# ping www.163.com // 檢查網路是否正常

(2). 關閉不需要的服務

# export LANG='en_US' //設置語言

# setup //選擇啟動的服務

進入system service 選項。

以space 鍵選定所需服務。

以下僅列出需要啟動的服務,未列出的服務一律關閉:

crond

irqbalance 僅當伺服器CPU為S.M.P架構或支持雙核心、HT技術時,才需開啟,否則關閉。

microcode_ctl

network

vsftpd

sshd

syslog

(3)、修改/etc/yum.repos.d/CentOS-Base.repo,將鏡象站點地址改為在中國的鏡象站點地址。不然我們通過yum安裝軟體速度會極慢。修改如下:

# CentOS-Base.repo

#

# This file uses a new mirrorlist system developed by Lance Davis for CentOS.

# The mirror system uses the connecting IP address of the client and the

# update status of each mirror to pick mirrors that are updated to and

# geographically close to the client. You should use this for CentOS updates

# unless you are manually picking other mirrors.

#

# If the mirrorlist= does not work for you, as a fall back you can try the

# remarked out baseurl= line instead.

#

#

[base]

name=CentOS-$releasever - Base

baseurl=http://mirror.be10.com/centos/$releasever/os/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

protect=1

#released updates

[updates]

name=CentOS-$releasever - Updates

baseurl=http://mirror.be10.com/centos/$releasever/updates/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

protect=1

#packages used/produced in the build but not released

[addons]

name=CentOS-$releasever - Addons

baseurl=http://mirror.be10.com/centos/$releasever/addons/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

protect=0

#additional packages that may be useful

[extras]

name=CentOS-$releasever - Extras

baseurl=http://mirror.be10.com/centos/$releasever/extras/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

protect=0

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$releasever - Plus

baseurl=http://mirror.be10.com/centos/$releasever/centosplus/$basearch/

gpgcheck=1

enabled=0

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

protect=1

#contrib - packages by Centos Users

[contrib]

name=CentOS-$releasever - Contrib

baseurl=http://mirror.be10.com/centos/$releasever/contrib/$basearch/

gpgcheck=1

enabled=0

protect=0

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#packages in testing

[testing]

name=CentOS-5 - Testing

baseurl=http://mirror.be10.com/centos/5/testing/i386/

gpgcheck=1

enabled=0

protect=0

保存。

(2)更新系統,我們使用yum,

然後執行:

# yum upgrade

建議更新所有列出的程序,rhel 5.X的穩定性還要繼續努力呢。

(4)、定時校正伺服器時間

# yum install ntp

# crontab -e

0 23 * * * root /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1

以上命令設置好后存檔。您的機器將在每天的23:00根據中國國家授時中心的NTP伺服器時間自動校準時間。

(5). 對TCP/IP網路參數進行調整,加強抗SYN Flood能力

# echo 'net.ipv4.tcp_syncookies = 1' >> /etc/sysctl.conf //將net.ipv4.tcp_syncookies = 1寫入sysctl.conf 文件

# sysctl -p //查看

(6)、FTP伺服器的配置

vi /etc/vsftpd/vsftpd.conf

把anonymous_enable=YES註釋掉不允許匿名登錄。

把chroot_list_enable=YES

chroot_list_file=/etc/vsftpd.chroot_list

前的註釋去掉。

把ftpd_banner=*前的註釋去掉。後面改成你的歡迎信息(這樣設置可以避免顯示ftp伺服器的版本信息)

然後保存,service vsftpd start就可以了。

這時應當添加用戶,因為root默認不能通過FTP方式登錄。

# adduser username

# passwd userpassword

這樣對於我們上傳一些文件到系統中很方便。

4. 重新啟動系統

# init 6

5. 使用 yum 程序安裝所需開發包(以下為標準的 RPM 包名稱)

# yum install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel

#這裡我們將編譯GD所必須的一些小軟體比如libpng,libtiff,freetype,libjpeg,等先用RPM的方式一併安裝好,避免手動編譯浪費時間,同時也能避免很多錯誤,這幾個小軟體的編譯很麻煩。這幾個小軟體編譯錯誤了,GD當然安裝不了,php5的編譯當然也沒戲了。所以我們抓大放小,對這些小牛鬼蛇神採取快速簡潔的方式進行安裝。並且對伺服器的性能也不能產生什麼影響。

另外libxml2系統已經默認安裝了,所以我們不需要手工編譯了,直接安裝它的開發包就行了。

6. 源碼編譯安裝所需包 (Source)

(1) GD2

# cd /usr/local/src

# wget http://www.boutell.com/gd/http/gd-2.0.34.tar.gz

# tar xzvf gd-2.0.34.tar.gz

# cd gd-2.0.34

# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" ./configure --prefix=/usr/local/gd2 --mandir=/usr/share/man //./configure 配置。

# make //make 是用來編譯的,它從 Makefile 中讀取指令,然後編譯。

# make install //make install 是用來安裝的,它也從 Makefile 中讀取指令,安裝到指定的位置。

(2) Apache 日誌截斷程序

# cd /usr/local/src

# wget http://cronolog.org/download/cronolog-1.6.2.tar.gz

# tar xzvf cronolog-1.6.2.tar.gz

# cd cronolog-1.6.2

# ./configure --prefix=/usr/local/cronolog

# make

# make install

7、編譯mysql 5.0.46

mysql 5.0.46是企業版本,貌似雙數版本都是企業版本了。個人覺得代碼質量要比社區版本要好一些。大家可以下載,免費使用。並不需要向mysql公司交錢。

cd /usr/local/src

# wget http://mirror.provenscaling.com/ ... mysql-5.0.46.tar.gz

# tar xzvf mysql-5.0.46.tar.gz

# cd mysql-5.0.46

修改mysql 客戶端最大連接數, 默認的只有100,遠遠達不到我們的要求。

# vi sql/mysqld.cc

搜索找到下面一行:

{"max_connections", OPT_MAX_CONNECTIONS,

"The number of simultaneous clients allowed.", (gptr*) &max_connections,

(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 100, 1, 16384, 0, 1,

0},

將其中的100改為1500, 當然小點也可以,根據你的需要來,不建議改的太大。

{"max_connections", OPT_MAX_CONNECTIONS,

"The number of simultaneous clients allowed.", (gptr*) &max_connections,

(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 1500, 1, 16384, 0, 1,

0},

保存。

# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" ./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --with-comment=Source --with-server-suffix=-enterprise-gpl --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all --with-pthread --enable-static --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-innodb --without-ndb-debug --without-isam

配置成功會提示:

MySQL has a Web site at http://www.mysql.com/ which carries details on the

latest release, upcoming features, and other information to make your

work or play with MySQL more productive. There you can also find

information about mailing lists for MySQL discussion.

Remember to check the platform specific part of the reference manual for

hints about installing MySQL on your platform. Also have a look at the

files in the Docs directory.

Thank you for choosing MySQL!

// 注意 ,CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" 這個環境參數只針對intel P4 晶元,如果你的CPU是AMD的,注意不能使用。請查看相應的編譯優化參數。否則程序會無法編譯,即使編譯成功也無法運行,嘿嘿。

關於其他CPU的優化請看我的BLOG的一篇轉貼:

http://www.cnprint.org/bbs/blogs/1/blog43.html

# make

編譯的時間可能會比較長,畢竟優化的比較厲害。

# make install

編譯安裝完成後執行後續操作:

# useradd mysql //添加 mysql 用戶

# cd /usr/local/mysql

# bin/mysql_install_db --user=mysql

# chown -R root:mysql . //設置許可權,注意後面有一個 "."

# chown -R mysql /var/lib/mysql //設置 mysql 目錄許可權

# chgrp -R mysql . //注意後面有一個 "."

# cp share/mysql/my-medium.cnf /etc/my.cnf

# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld //開機自動啟動 mysql。

# chmod 755 /etc/rc.d/init.d/mysqld

# chkconfig --add mysqld

# /etc/rc.d/init.d/mysqld start //啟動 MySQL

# bin/mysqladmin -u root password "password_for_root"

# service mysqld stop //關閉 MySQL

8. 編譯安裝 Apache

# cd /usr/local/src

# wget http://www.ip97.com/apache.org/httpd/httpd-2.2.6.tar.gz

# tar zxvf httpd-2.2.6.tar.gz

# cd httpd-2.2.6

依次安裝apr和apr-util

# cd srclib/apr

# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" ./configure --prefix=/usr/local/apr --enable-threads --enable-other-child --enable-static

# make && make install

# cd ../apr-util

# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ --with-mysql=/usr/local/mysql

# make && make install

cd /usr/local/src/httpd-2.2.6

# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" ./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --with-mysql=/usr/local/mysql --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-static-support --enable-static-htpasswd --enable-static-htdigest --enable-static-rotatelogs --enable-static-logresolve --enable-static-htdbm --enable-static-ab --enable-static-checkgid --disable-cgid --disable-cgi --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-ssl --with-ssl=/usr/include/openssl

# make

# make install

# echo '/usr/local/apache2/bin/apachectl start ' >> /etc/rc.local //將 apachectl 的調用加入到你的系統啟動文件中。

註解:

./configure //配置源代碼樹

--prefix=/usr/local/apache2 //體系無關文件的頂級安裝目錄PREFIX ,也就Apache的安裝目錄。

--enable-module=so //打開 so 模塊,so 模塊是用來提 DSO 支持的 apache 核心模塊

--enable-mods-shared=all //編譯全部的模板,對於不需要我們可以在httpd.conf去掉。

--enable-cache //支持緩存

--enable-file-cache //支持文件緩存

--enable-mem-cache //支持記憶緩存

--enable-disk-cache //支持磁碟緩存

--enable-static-support //支持靜態連接(默認為動態連接)

--enable-static-htpasswd //使用靜態連接編譯 htpasswd - 管理用於基本認證的用戶文件

--enable-static-htdigest //使用靜態連接編譯 htdigest - 管理用於摘要認證的用戶文件

--enable-static-rotatelogs //使用靜態連接編譯 rotatelogs - 滾動 Apache 日誌的管道日誌程序

--enable-static-logresolve //使用靜態連接編譯 logresolve - 解析 Apache 日誌中的IP地址為主機名

--enable-static-htdbm //使用靜態連接編譯 htdbm - 操作 DBM 密碼資料庫

--enable-static-ab //使用靜態連接編譯 ab - Apache HTTP 伺服器性能測試工具

--enable-static-checkgid //使用靜態連接編譯 checkgid

--disable-cgid //禁止用一個外部 CGI 守護進程執行CGI腳本

--disable-cgi //禁止編譯 CGI 版本的 PHP

--enable-ssl // 編譯 ssl模塊。

我們不再使用worker模式編譯apache,worker模式和php貌似有一些不協調不穩定之處。所以使用了默認的perfork模式。

將apache設置成開機自啟動:

在/etc/rc.d/rc.local文件中加入一行

/usr/local/apache2/bin/apachectl start

這樣每次重新啟動系統以後,apache也會隨系統一起啟動.

或者

# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd

然後 vi /etc/rc.d/init.d/httpd 添加(#!/bin/sh下面)

# chkconfig: 2345 10 90

# description: Activates/Deactivates Apache Web Server

最後,運行chkconfig把Apache添加到系統的啟動服務組裡面:

# chkconfig --add httpd

# chkconfig httpd on

9、編譯php 5.2.5-devel。

php 5.2.4有點小BUG,無法在centos 5上正常編譯,官方已經在php5.2.5中修復了。所以我們使用php 5.2.5進行編譯。

Suhosin是php增強型安全補丁,可以編譯到靜態內核中,也可以編譯成php動態擴展。我個人強烈你建議安裝成靜態內核。Suhosin已經進入freebsd和gentoo的ports。下面的以下先說靜態安裝步驟。當然你也可以在安裝php后將它編譯成php的動態擴展。

# cd /usr/local/src

# wget http://cn.php.net/get/php-5.2.5.tar.gz/from/this/mirror

wget http://www.hardened-php.net/suho ... .5-0.9.6.2.patch.gz

# tar zxvf php-5.2.5.tar.gz

# gunzip suhosin-patch-5.2.1-0.9.6.2.patch.gz

# cd php-5.2.5

# CHOST="i686-pc-linux-gnu" CFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -msse2 -mmmx -Wall -W -mfpmath=sse -funroll-loops -mcpu=pentium4 -march=pentium4 -pipe -fomit-frame-pointer" ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-pear=/usr/share/php --with-zlib-dir --with-bz2 --with-libxml-dir=/usr --with-gd=/usr/local/gd2 --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf=shared,/usr --enable-mbstring --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/etc --with-iconv --disable-ipv6 --enable-static --enable-maintainer-zts --enable-zend-multibyte --enable-inline-optimization --enable-zend-multibyte --enable-sockets --enable-soap --with-openssl

配置成功會提示:

+--------------------------------------------------------------------+

| License: |

| This software is subject to the PHP License, available in this |

| distribution in the file LICENSE. By continuing this installation |

| process, you are bound by the terms of this license agreement. |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point. |

+--------------------------------------------------------------------+

Thank you for using PHP.

# make

# make install

# cp php.ini-recommended /etc/php.ini

在這裡也順便說一下將suhosin安裝成為php的動態擴展的方法。畢竟網上根本不見它的中文安裝教程。

雖然我個人不推薦這種方式。

wget http://www.hardened-php.net/suhosin/_media/suhosin-0.9.16.tgz

tar zxvf suhosin-0.9.16.tgz

cd suhosin-0.9.16

./configure --with-php-config=/usr/local/php/bin/php-config

make

make install

會提示編譯的模塊存在的目錄,記住它。

Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/

然後在php.ini中增加一行下列語句。

extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/suhosin.so

10 、整合apache 與php

# vi /usr/local/apache2/conf/httpd.conf

在最後一行加上:

AddType application/x-httpd-php .php

查找:(設置 WEB 默認文件)

DirectoryIndex index.html

替換為:

DirectoryIndex index.php index.html index.htm //在 WEB 目錄不到默認文件,httpd 就會執行 /var/www/error/noindex.html

找到這一段:

# AllowOverride controls what directives may be placed in .htaccess files.

# It can be "All", "None", or any combination of the keywords:

# Options FileInfo AuthConfig Limit

#

AllowOverride none

更改為AllowOverride all

允許apache rewrite

# 監聽443埠,支持https連接

取消註釋 httpd.conf 中的 Include conf/extra/httpd-ssl.conf

保存httpd.conf,退出。

# /usr/local/apache2/bin/apachectl restart //重啟 Apache

這時會出現錯誤:

/usr/local/apache2/bin/apachectl start

httpd: Syntax error on line 107 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

不急,我們慢慢解決。

先重啟下機器:

reboot

這個Permission denied問題,在centos 5下面一般是Selinux引起的,作為生產用伺服器,我建議你千萬別草率地關掉Selinux一了百了。就像家裡的防盜網,阻礙了你的貓自由進出窗戶,你不能為了貓方便,就把防盜網簡單拆除是同樣的道理。我看見網上許多人建議把Selinux簡單關閉來解決這個問題,很不以為然。

我們可以這樣操作:

# audit2allow -d

allow initrc_t usr_t:file execmod;

allow mount_t default_t:file execute;

# cd /etc/selinux/targeted/modules/

# audit2allow -M local -d

屏幕產生如下提示:

產生類型強制文件:local.te

正在編譯策略

checkmodule -M -m -o local.mod local.te

semodule_package -o local.pp -m local.mod

********************重要 ***********************

為了在內核中載入這個新創建的策略軟體包,

您需要執行

semodule -i local.pp

我們運行

# semodule -i local.pp

這樣就讓Selinux載入了新的規則。

更詳細的內容請看我在BLOG上的轉貼:

http://www.cnprint.org/bbs/blogs/1/blog48.html

reboot

哈哈,apache不會再報錯了吧?

這樣我保留了selinux的功能,同時apache也能正常運行。

11. 查看確認 L.A.M.P 環境信息

vi /usr/local/apache2/htdocs/phpinfo.php

新增加下面一行,並保存。

# chmod 755 /usr/local/apache2/htdocs/phpinfo.php

用瀏覽器打開 http://127.0.0.1/phpinfo.php

# echo ' ' > /usr/local/apache2/htdocs/testdb.php

# chmod 755 /usr/local/apache2/htdocs/testdb.php

# service mysqld start

用瀏覽器打開 http://127.0.0.1/testdb.php

檢查 phpinfo 中的各項信息是否正確。

12、設置SSL並創建自己的CA

# cd /usr/share/ssl/misc

# ./CA -newca

屏幕上出現如下的提示:CA certificate filename (or enter to create)

這是要求輸入要創建的CA的證書文件名, 可以直接回車或輸入證書文件名。

Making CA certificate ...

Generating a 1024 bit RSA private key

.........++++++

................................++++++

writing new private key to './demoCA/private/./cakey.pem'

Enter PEM pass phrase:

Verifying password - Enter PEM pass phrase:-

此時要求輸入和驗證CA的私鑰口令、國家代碼(中國是CN)、省份、城市或地區、組織或企業名稱、部門名稱、CA的名稱或伺服器的主機名稱、管理員電子郵件地址。

至此,在當前目錄下生成了demoCA的目錄,CA的證書就在該目錄下,文件名為cacert.pem

生成伺服器的證書請求

# ./CA -newreq

屏幕上出現如下的提示:

Generating a 1024 bit RSA private key

.....................................................++++++

.....++++++

writing new private key to 'newreq.pem'

Enter PEM pass phrase:

Verifying password - Enter PEM pass phrase:

此時要求輸入和驗證伺服器的私鑰口令、國家代碼(中國是CN)、省份、城市或地區、組織或企業名稱、部門名稱、CA的名稱或伺服器的主機名稱、管理員電子郵件地址。

Please enter the following 'extra' attributes

to be sent with your certificaterequest

A challenge password []:

An optional company name []:

.Request (and private key) is in newreq.pem

這是要求輸入伺服器的相關信息。

此時,在當前目錄下生成了一個名為newreq.pem的文件,包含了要生成伺服器數字證書的請求。

簽署證書

# ./CA -sign

屏幕上出現如下的提示:

Using configuration from /usr/share/ssl/openssl.cnf

Enter PEM pass phrase:

此時一樣需要輸入CA的私鑰口令、國家代碼(中國是CN)、省份、城市或地區、組織或企業名稱、部門名稱、CA的名稱或伺服器的主機名稱、管理員電子郵件地址。

Certificate is to be certified until Nov 19 13:46:19 2002 GMT (365 days)

Sign the certificate? [y/n]:y

這時顯示證書請求文件中的各項信息,並詢問是否要簽署證書,回答y,進行簽署。

1 out of 1 certificate requests certified, commit? [y/n]y

回答y,會顯示已經簽署的證書的信息,並在當前目錄下生成伺服器的證書文件newcert.pem。

# mkdir /usr/local/apache2/conf/ssl.crt/

# mkdir /usr/local/apache2/conf/ssl.key/

# cp newcert.pem /usr/local/apache2/conf/ssl.crt/server.pem

# cp newreq.pem /usr/local/apache2/conf/ssl.key/server.pem

更改伺服器的證書文件的相關配置

# vi /usr/local/apache2/conf/extra/httpd-ssl.conf

查找並修改

# Server Certificate:

# Point SSLCertificateFile at a PEM encoded certificate. If

# the certificate is encrypted, then you will be prompted for a

# pass phrase. Note that a kill -HUP will prompt again. Keep

# in mind that if you have both an RSA and a DSA certificate you

# can configure both in parallel (to also allow the use of DSA

# ciphers, etc.)

SSLCertificateFile /usr/local/apache2/conf/ssl.crt/server.pem

#SSLCertificateFile /usr/local/apache2/conf/server-dsa.crt

# Server Private Key:

# If the key is not combined with the certificate, use this

# directive to point at the key file. Keep in mind that if

# you've both a RSA and a DSA private key you can configure

# both in parallel (to also allow the use of DSA ciphers, etc.)

SSLCertificateKeyFile /usr/local/apache2/conf/ssl.key/server.pem

#SSLCertificateKeyFile /usr/local/apache2/conf/server-dsa.key

示例文件

在SSL的根目錄中生成一個index.html,它是如下所示:

<html>

這是SSL示例!

</html>

測試

假如Web伺服器的DNS名稱是www.cnprint.org.

在瀏覽器的URL地址欄里輸入 http://www.cnprint.org/,瀏覽器便會顯示APACHE安裝時確省的Test Page.

在瀏覽器的URL地址欄里輸入 https://www.cnprint.org/,注意:是 https 而不是http !

瀏覽器會提示站點已經採用了SSL進行數據的加密傳輸.由於我們的CA證書不是瀏覽器預設的信任的根證書,所以,瀏覽器會說無法確認伺服器的證書可信。暫時不管,一直NEXT,最後,瀏覽器會顯示:這是SSL示例!

可以把CA的證書放在非SSL的站點上,讓瀏覽器下載並安裝CA證書,並將其設置成可信任的根證書,便可解決上面的問題.8 解除HTTPD起動時的口令輸入。

由於安全的原因,Web伺服器的私鑰是口令加密了的,每次重新起動HTTPD或Linux時,都會要求輸入Web伺服器的私鑰的口令。

如果要解除HTTPD起動時的口令輸入,可以這樣:

# cd /usr/local/apache2/conf/ssl.key/

# cp server.pem server.pem.org

# openssl rsa -in server.pem.org -out server.pem

# chmod 400 server.pem

另外在網上看到一個方法,我沒有試。有興趣的可以試下。

創建SSL密碼自動應答文件,否則每次Apache啟動的時候,都會要求你輸入SSL的密碼.

創建 /usr/local/apache2/conf/ssl.key/sendsslpwd ,內容如下.

#!/bin/bash

SSLpasswd="YOUR PASSPHRASE"

echo $SSLpasswd

chmod 755 /usr/local/apache2/conf/ssl.key/sendsslpwd

此時,Web伺服器的私鑰已經沒有口令加密,一定要確保server.pem文件除root外,任何用戶均無權讀取它。

13、安裝 Zend Optimizer

# cd /usr/local/src

# wget http://downloads.zend.com/optimi ... glibc21-i386.tar.gz

# tar xzvf ZendOptimizer-3.3.0-linux-glibc21-i386.tar.gz

# ./ZendOptimizer-3.3.0-linux-glibc21-i386/install.sh

按照它的提示一步步進行就行了。

總之一句話。如果你的伺服器環境不需要ZendOptimizer,那麼能不安就不安裝這個。避免和eaccelerator衝突。

14、安裝eaccelerator // eaccelerator是php的加速軟體,使用后php的執行效率會有較大幅度的提升。目前eaccelerator 0.9.5.2已經和ZendOptimizer-3.3.0能夠基本上兼容啦。不過我個人覺得,ZendOptimizer-3.3.0沒有加速的功能,反而使php運行變慢,只是起到了運行zend加密文件的作用而已。閑話不多說了,大家有興趣的,可以去google下。

# cd /usr/local/src

# wget http://bart.eaccelerator.net/sou ... tor-0.9.5.2.tar.bz2

# tar -jxvf eaccelerator-0.9.5.2.tar.bz2

# cd eaccelerator-0.9.5.2

export PHP_PREFIX="/usr/local/php"

$PHP_PREFIX/bin/phpize //指定一下php的目錄

# ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config // 設置

# make & make install

編譯安裝后我們會看到屏幕提示的eaccelerator.so所在的目錄,比如我得到的是/usr/local/php/lib/php/extensions/no-debug-zts-20060613/eaccelerator.so,記住這個路徑,待會要用到。

修改php.ini(安裝完zend之後,php.ini存放於/usr/local/Zend/etc)

在文件最後,zend之前,注意,這部分內容務必放在zend之前,不然可能會出現不可預期的伺服器問題。添加下列信息:

[eaccelerator]

extension="/usr/local/php/lib/php/extensions/no-debug-zts-20060613/eaccelerator.so"

eaccelerator.shm_size="32"

eaccelerator.cache_dir="/tmp/eaccelerator"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="0"

eaccelerator.shm_prune_period="0"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"

解釋:

zend_extension 是安裝完程序自動指示給我們的

eaccelerator.shm_size="32" 緩存大小單位MB

eaccelerator.cache_dir="/tmp/eaccelerator" 緩存路徑

# mkdir /tmp/eaccelerator // 建立目錄

# chmod 0777 /tmp/eaccelerator // 修改目錄屬性

最後重新啟動apachectl

重啟apache,phpinfo顯示:

This program makes use of the Zend Scripting Language Engine:

Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies

with eAccelerator v0.9.5.2, Copyright (c) 2004-2006 eAccelerator, by eAccelerator

with Zend Extension Manager v1.0.11, Copyright (c) 2003-2006, by Zend Technologies

with Zend Optimizer v3.3.0, Copyright (c) 1998-2006, by Zend Technologies

也會有eAccelerator的具體信息。

15、安裝phpmyadmin,管理mysql資料庫

# cd /usr/local/apache2/htdocs/

# wget http://nchc.dl.sourceforge.net/s ... s-utf-8-only.tar.gz

# tar zxvf phpMyAdmin-2.11.1-all-languages-utf-8-only.tar.gz

# mv phpMyAdmin-2.11.1-all-languages-utf-8-only phpmyadmin

# cd phpmyadmin/libraries

修改配置文件

# vi config.default.php

找到這幾行進行修改:

$cfg['Servers'][$i]['auth_type'] = 'http'; // Authentication method (valid choices: config, http, HTTP, signon or cookie)

$cfg['Servers'][$i]['user'] = 'root'; // MySQL user

$cfg['Servers'][$i]['password'] = 'PASSWORD'; // MySQL password (only needed

經過這幾個步驟,我們一個比較安全的LAMP伺服器就環境基本建立成功啦。感覺上也不是很難,是吧?

[火星人 ] centos 5.0 編譯安裝apache 2.2.6+php5.2.5+mysql5.0.46+Zend Optimizer 3.3.0+eacc已經有794次圍觀

http://coctec.com/docs/linux/show-post-202183.html