CENTOS4.4 final系統下配置

CENTOS4.4 final系統下配置
 apache2.2.4+mysql5.0.37+php5.1.4+subversion1.4.3+memcache+ZendOptimizer3.0+phpMyAdmin2.10.1
 
    配置這些東西花了2周的時間,經常是這個配好了那個又不行了,那個好了這個又不行了,或者是好象都行了,重啓以後又不行了,中間基本上能遇到的問題全遇到啦,希望能對大家有所幫助,當然這個文章最先也是我從網上拿來的,我不過加了一些可能遇到的錯誤說明,並更改了一些我認爲不正確的地方(下面一些軟件版本號可能寫得有誤,因爲是引用別人的,懶得改啦)。
 
 

第一步:安裝CentOS4.4手動分區,作爲服務器,特別爲服務用途分了一個區,具體一個根目錄“/”,一個“/server”,一個是交換分區。
不安裝不需要的組件,所以在選擇組件的時候,除了選擇FTP SERVER外取消所有組件的選擇。如果是32位機器的話應該是679M,64位機器爲719M。
關閉所有不需要的服務,安裝完成後登陸。輸入SETUP命令,最後只剩下啓動以下幾個服務(具體的請參考自己需要啓動):crond,iptables,irqbalance(多處理器適用),network,sshd,syslog,vsftpd,xinetd
確定以後重啓,就可以利用SSH和FTP服務進行遠程管理了。當然你要知道機器的IP,如果是DHCP的話,可以輸入命令ifconfig進行查看,如果是固定IP,那就直接登陸了。

第二步:安裝服務前的準備:
下載httpd-2.2.2.tar.gz:
下載mysql-5.0.22.tar.gz:
下載php-5.1.4.tar.gz:
下載zendoptimizer-3.0.tar.gz:<[url=http://downloads.zend.com/optimizer/3.0.0/]http://downloads.zend.com/optimizer/3.0.0/[/url]>
下載libxml2-2.6.26.tar.gz:
下載zlib-1.2.3.tar.gz:
下載jpegsrc.v6b.tar.gz:
下載libpng-1.2.10.tar.gz:
下載freetype-2.2.1.tar.gz:
下載gd-2.0.33.tar.gz:
因爲安裝系統的時候是最小安裝,所以編譯服務的時候需要一些軟件支持,具體需要以下RPM包,這些都可以在CentOS安裝盤裏找到:
glibc-kernheaders-2.4-9.1.98.EL.x86_64.rpm(在第二張碟)
glibc-headers-2.3.4-2.19.x86_64.rpm(在第二張碟)
glibc-devel-2.3.4-2.19.x86_64.rpm(在第二張碟)
cpp-3.4.5-2.x86_64.rpm(在第一張碟)
gcc-3.4.5-2.x86_64.rpm(在第二張碟)
libstdc++-devel-3.4.5-2.x86_64.rpm(在第二張碟)
gcc-c++-3.4.5-2.x86_64.rpm(在第三張碟)
flex-2.5.4a-33.x86_64.rpm(在第二張碟)
增加一個用戶,以方便通過FTP上傳文件,命令如下:
useradd biaoest(增加一個名稱爲biaoest的用戶)
passwd biaoest(爲剛剛增加的用戶修改密碼)
上傳文件到biaoest的根目錄/home/biaoest,用軟件上傳的時候注意不要用被動模式,要不感覺會有點慢,把上面需要的文件全部上傳。
第二步:安裝APACHE2.2.2+MYSQL5.0.22+PHP5.1.4+GD2.0.33+ZENDOPTIMIZER3.0
安裝系統的時候特別爲服務相關的軟件準備了一個分區,下面爲分區server的相關分佈:
cd /server(服務根目錄)
mkdir /server/apache2(APACHE2根目錄)
mkdir /server/modlib(相關模塊根目錄)
mkdir /server/modlib/jpeg6(JPEG目錄)
mkdir /server/modlib/png(PNG目錄)
mkdir /server/modlib/gd2(GD目錄)
mkdir /server/modlib/xml2(XML目錄)
mkdir /server/mysql5(MYSQL5根目錄)
mkdir /server/php5(PHP5根目錄)
mkdir /server/php5/zend(ZENDOPTIMIZER3目錄)
mkdir /server/database(MYSQL數據庫目錄)
mkdir /server/webroot(網頁根目錄)
下面的安裝都是假設當前路徑爲剛剛上傳文件路徑/home/biaoest目錄。

安裝GCC編譯器及相關輔助軟件
rpm -Uvh glibc-kernheaders-2.4-9.1.98.EL.x86_64.rpm
rpm -Uvh glibc-headers-2.3.4-2.19.x86_64.rpm
rpm -Uvh glibc-devel-2.3.4-2.19.x86_64.rpm
rpm -Uvh cpp-3.4.5-2.x86_64.rpm
rpm -Uvh gcc-3.4.5-2.x86_64.rpm
rpm -Uvh libstdc++-devel-3.4.5-2.x86_64.rpm
rpm -Uvh gcc-c++-3.4.5-2.x86_64.rpm
####################################################
如果沒有安裝上面軟件,可能出現的錯誤提示:
checking for gcc... no
checking for cc... no
checking for cc... no
checking for cl... no
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
####################################################
rpm -Uvh flex-2.5.4a-33.x86_64.rpm
####################################################
如果沒有安裝上面軟件,可能出現的錯誤提示:
checking lex output file root... ./configure: line 3246: lex: command not found
configure: error: cannot find output from lex; giving up
####################################################

 

安裝MYSQL5.0.22到指定目錄/server/mysql5,數據保存在/server/database

mkdir /server/mysql5
mkdir /server/database
groupadd mysql
useradd -g mysql mysql
cd /home/biaoest
tar -zxvf mysql-5.0.22.tar.gz
cd mysql-5.0.22
./configure --prefix=/server/mysql5 --sysconfdir=/etc --localstatedir=/server/database --with-charset=gbk
或者
./configure --prefix=/server/mysql5 --sysconfdir=/etc --localstatedir=/server/database --with-extra-charsets=gb2312,gbk
#####################################
如果不加 --with-extra-charsets則編譯後的mysql5不識別gbk字符集。extra-charsets用來分別加入多個字符集。
個別情況下采用此選項安裝後,用mysql在本地無法連接數據庫,提示錯誤如下:
mysql: Character set 'gbk' is not a compiled character set and is not specified in the '/app/mysql/share/mysql/charsets/Index.xml' file
可以用以下命令:
#mysql -u root -p --default-character-set=latin1
即可以連接,出現此問題的原因暫時不明。不過這不影響正常使用。

用RPM包安裝的mysql 5.0.16,可以直接在/etc/my.cnf 中設置default-character-set=gbk
則不會有此問題
用RPM包安裝後如果字符集要設爲gb2312可以兩種方法修改:
1, /etc/my.cnf
[mysqld]
default-character-set=gb2312
2,
  編輯/etc/init.d/mysql,找到這一行:
  /usr/bin/safe_mysqld > /dev/null 2>&1 &
  改成:
  /usr/bin/safe_mysqld --default-character-set=gb2312 > /dev/null 2>&1 &
  好,重新啓動MySQL:
  #/etc/init.d/mysql restart
#####################################
接下來:
make
make install
cp /server/mysql5/share/mysql/my-medium.cnf /etc/my.cnf


修改my.cnf的配置,使用utf8編碼:
vi /etc/my.cnf
找到客戶端配置[client] 在下面添加
default-character-set=utf8
在[mysqld]下加
default-character-set=utf8
init_connect='SET NAMES utf8' #(設定連接mysql數據庫時使用utf8編碼,以讓mysql數據庫爲utf8運行)

set-variable = max_connections=1000


修改/server/database屬性
chown mysql.mysql /server/database

 

建立數據庫
/server/mysql5/bin/mysql_install_db --user=mysql
啓動數據庫
/server/mysql5/bin/mysqld_safe --user=mysql
如果發生啓動錯誤,可以打開日誌看看:/server/database/localhost.localdomain.err
可能的錯誤是因爲權限不足、未運行mysql_install_db等等。


設置開機自動運行(把sh腳本拷到啓動裏面)
cp /server/mysql5/share/mysql/mysql.server /etc/rc.d/init.d/mysqld

 

cd /etc/rc.d/init.d
chkconfig --add mysqld

在啓動mysqld以後,建議修改root的密碼,執行如下2條命令:
/server/mysql5/bin/mysqladmin -u root password 'aa1234'
/server/mysql5/bin/mysqladmin -u root -h localhost.localdomain password 'aa1234'

mysql的登錄:
/server/mysql5/bin/mysql -u root -p
然後輸入密碼aa1234即可進入mysql控制檯(-p必須輸入,否則不讓登錄)。

如果運行mysql出錯,提示mysql: error while loading shared libraries: libmysqlclient.so.15,則執行以下2句命令:

echo /server/mysql5/lib/mysql >>/etc/ld.so.conf   # 或者直接打開/etc/ld.so.conf,添加一行/server/mysql5/lib/mysql
再執行:
/sbin/ldconfig


安裝apache2.2.2

cd /home/biaoest
tar -zxvf httpd-2.2.2.tar.gz
cd httpd-2.2.2
修改默認連接數vi server/mpm/prefork/prefork.c,查找256,把它修改爲2048
./configure --prefix=/server/apache2 --enable-module=so --enable-module=rewrite --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --with-mpm=prefork  --enable-dav 

 --enable-shared=max --enable-module=most --enable-dav  (這一行是爲svn配置的,不加的話會報錯:undefined symbol: dav_xml_get_cdata)

make
make install
啓動apache2
/server/apache2/bin/apachectl start
設置開機自動啓動
從/usr/local/apache/bin/apachectl 到 /etc/rc.d/init.d/httpd 建立一個符號連接:
# ln -s /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
然後在此文件總添加以下幾行(大概在文件頂部,約第二行的地方,如果不加,在運行服務時會報錯:httpd 服務不支持 chkconfig):
# chkconfig: 2345 10 90
# description: Activates/Deactivates Apache Web Server
最後,運行chkconfig把Apache添加到系統的啓動服務組裏面:
# /sbin/chkconfig --del httpd
# /sbin/chkconfig --add httpd

編輯/etc/rc.d/rc.local
把/server/apache2/bin/apachectl start 加入進去

如果你以前的apache沒有刪除,而你又想使用
# /etc/init.d/httpd restart
這樣重起apache的話,那就修改/etc/init.d/httpd這個文件,修改其中的apahce的三個路徑就可以了!!

#################################################
可以選擇使用 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 libxml2
如果yum顯示出錯:Cannot find a valid baseurl for repo
可以這樣初始化一下:
yum -y install flash-plugin
然後再執行升級,升級時會提示y或n.

#這裏我們將編譯GD所必須的一些小軟件比如libpng,libtiff,freetype,libjpeg等先用RPM的方式一併安裝好,避免手動編譯浪費時間,同時也能避免很多錯誤,這幾個小軟件的編譯很麻煩。這幾個小軟件編譯錯誤了,GD當然安裝不了,php5的編譯當然也沒戲了。所以我們抓大放小,對這些小牛鬼蛇神采取快速簡潔的方式進行安裝。並且對服務器的性能也不能產生什麼影響。
如果不使用yum,可以手工按照以下步驟安裝(我建議不要手工安裝,這些東西浪費我了太多太多的時間,因爲版本問題,經常弄不成功):
#################################################


安裝ZLIB2
cd /home/biaoest
tar -zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
#################################################
不要用--prefix自定義安裝目錄,否則可能會影響後面安裝,可能出現的錯誤:
configure: error: zlib not installed
#################################################
#################################################
如果你的機器是64位,並且在安裝png時候出現下面錯誤:
/usr/bin/ld: /usr/local/lib/libz.a(compress.o): relocation R_X86_64_32 can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libz.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
修補辦法(接上面步驟):
vi Makefile
找到 CFLAGS=-O3 -DUSE_MMAP
在後面加入-fPIC,即變成CFLAGS=-O3 -DUSE_MMAP -fPIC
接下面步驟
#################################################
make
make install

安裝JPEG6
#################################################
先建立目錄,否則可能會出現類型下面錯誤:
/usr/bin/install -c cjpeg /server/modlib/jpeg6/bin/cjpeg
/usr/bin/install: cannot create regular file `/server/modlib/jpeg6/bin/cjpeg': No such file or directory
make: *** [install] Error 1
解決辦法:
mkdir /server/modlib
mkdir /server/modlib/jpeg6
mkdir /server/modlib/jpeg6/bin
mkdir /server/modlib/jpeg6/lib
mkdir /server/modlib/jpeg6/include
mkdir /server/modlib/jpeg6/man
mkdir /server/modlib/jpeg6/man/man1
#################################################
cd /home/biaoest
tar -zxvf jpegsrc.v6b.tar.gz
cd jpegsrc.v6b.
./configure --prefix=/server/modlib/jpeg6
#################################################
如果你的機器是64位,並且在安裝gd時候出現下面錯誤:
/usr/bin/ld: /server/modlib/jpeg6//lib/libjpeg.a(compress.o): relocation R_X86_64_32 can not be used when making a shared object; recompile with -fPIC
/server/modlib/jpeg6//lib/libjpeg.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [libgd.la] Error 1
修補辦法(接上面步驟):
vi Makefile
找到 CFLAGS= -O2 -I$(srcdir)
在後面加入-fPIC,即變成CFLAGS= -O2 -I$(srcdir) -fPIC
接下面步驟
#################################################
make
make install-lib
#################################################
特別注意,要不下面會出現錯誤:
configure: error: libjpeg.(a|so) not found.
#################################################
make install

安裝PNG
cd /home/biaoest
tar -zxvf libpng-1.2.10.tar.gz
cd libpng-1.2.10
./configure --prefix=/server/modlib/png
make
################################################
如果出現下面錯誤:
configure: error: zlib not installed
請回到zlib,重新安裝一次,最好先make clean
################################################
make install

安裝freetype
cd /home/biaoest
tar -zxvf freetype-2.2.1.tar.gz
cd freetype-2.2.1
./configure --prefix=/server/modlib/freetype
make
make install

安裝GD
cd /home/biaoest
tar -zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --prefix=/server/modlib/gd2 --with-jpeg=/server/modlib/jpeg6/ --with-png=/server/modlib/png/ --with-zlib --with-freetype=/server/modlib/freetype/
make
#################################################
如果出現下面錯誤:
gd_png.c:825: warning: data definition has no type or storage class
make[2]: *** [gd_png.lo] Error 1
修復方法:
找到CPPFLAGS = -I/server/modlib/freetype/include/freetype2 -I/server/modlib/freetyp
e/include -I/server/modlib/freetype//include  -I/server/modlib/jpeg6//include
原來是少了png的支持了,把它改爲
CPPFLAGS = -I/server/modlib/freetype/include/freetype2 -I/server/modlib/freetyp
e/include -I/server/modlib/png/include  -I/server/modlib/jpeg6/include
#################################################
make install

安裝LIBXML2
mkdir /server/modlib
tar -zxvf libxml2-2.6.26.tar.gz
cd libxml2-2.6.26
./configure

make
make install

安裝PHP5.1.4
cd /home/biaoest
tar -zxvf php-5.1.4.tar.gz
cd php-5.1.4
./configure --prefix=/server/php5 --with-mysql=/server/mysql5 --with-apxs2=/server/apache2/bin/apxs --with-libxml-dir=/server/modlib/xml2 --with-gd=/server/modlib/gd2 --with-jpeg-dir=/server/modlib/jpeg6 --with-zlib --with-png-dir=/server/modlib/png --with-freetype-dir=/server/modlib/freetype --enable-experimental-zts
#################################################
如果出現錯誤:
checking lex output file root... ./configure: line 3246: lex: command not found
configure: error: cannot find output from lex; giving up
修補方法,安裝FLEX:
rpm -Uvh flex-2.5.4a-33.x86_64.rpm

如果不指定--with-mysql,則編譯後啓動apache的httpd服務時裝載libphp時,
可能會因找不到mysqlclient而出錯:"can't load libmysqlclient.so"
如果是這樣,可以加上--with-mysql參數重新編譯php5.
################################################
如果又出現下面錯誤:
configure: error: libjpeg.(a|so) not found.
修補方法:
原來在安裝jpeg的時候,執行了make install,應該執行make install-lib才能生成libjpeg.a文件
################################################
make
make install
複製配置文件到相應的目錄
cp php.ini-dict /server/php5/lib/php.ini
配置/server/apache2/conf/httpd.conf
找到DocumentRoot "/server/apache2/htdocs" ,修改爲DocumentRoot "/server/webroot"
找到<Directory "/server/apache2/htdocs"> ,修改爲<Directory "/server/webroot">
找到DirectoryIndex index.html,增加index.php等等,變成DirectoryIndex index.html index.htm index.php index.phtml index.phps
加載php模塊,去掉註釋“#”,如沒有此行,請加上。
LoadModule php5_module        modules/libphp5.so
加上此兩行
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
set-variable = max_connections=100

安裝ZendOptimizer-3.0.0
cd /home/biaoest
tar -zxvf ZendOptimizer-3.0.0-linux-glibc23-x86_64.tar.gz
cd ZendOptimizer-3.0.0-linux-glibc23-x86_64
./install
然後就按照提示給出相應的路徑即可

安裝MEMCACHED
tar -xzf libevent-1.1a.tar.gz
cd libevent-1.1a
./configure --prefix=/usr
make
make install
cd ..
tar -xzf memcached-1.1.12.tar.gz
cd memcached-1.1.12
./configure --prefix=/usr
make
make install
啓動MEMCHED
/usr/bin/memcached -d -m 128 -p 11211 -u nobody
########################################################################
/usr/bin/memcached: error while loading shared libraries: libevent-1.1a.so.1: cannot open shared object file: No such file or directory
cp /usr/lib/libevent* /usr/lib64/ -R
#########################################################################
安裝memcache PHP模塊
tar vxzf memcache-2.0.4.tgz
cd memcache-2.0.4
/server/php5/bin/phpize
./configure --enable-memcache --with-php-config=/server/php5/bin/php-config --with-zlib-dir
make
make install
安裝完後會有類似這樣的提示:
Installing shared extensions: /server/php5/lib/php/extensions/no-debug-non-zts-20050922/
把這個記住,然後修改php.ini,把
extension_dir = "./"
修改爲
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20050922/"
並添加一行

extension=memcache.so

安裝完畢,該測試了,建立一個專門的web用戶,用於上傳網頁吧。
useradd -d /server/webroot web
passwd web
chown web /server/webroot

 

安裝phpMyAdmin,通過web管理mysql:
tar -zxvf phpMyAdmin-2.10.1-all-languages-utf-8-only.tar.gz


[root@locahost]#  cd /server/webroot/phpMyAdmin-2.10.1-all-languages-utf-8-only
mkdir config
chmod o+rw config
cp config.sample.inc.php config/config.inc.php
chmod o+rw config/config.inc.php
修改apache配置:
vi /server/apache2/conf/httpd.conf
找到<IfModule alias_module>段,在裏面添加一行:
 Alias /phpMyAdmin  //server/webroot/phpMyAdmin-2.10.1-all-languages-utf-8-only
重啓httpd:
 service httpd stop
 service httpd start

然後通過瀏覽器進行web訪問初始化:http://<serverUrl>/phpMyAdmin/scripts/setup.php
配置好各項參數後,點Configuration-->save保存配置。
最後將config/config.inc.php 這個文件拷到phpMyAdmin內的頂級目錄,如果不需要再進行配置,爲了安全,刪除config/config.inc.php 。
配置完成後訪問首頁 :http://<serverUrl>/phpMyAdmin
 如果網頁出現錯誤:#1045 - Access denied for user 'root'@'localhost' (using password:...
 請先重啓mysqld,然後重啓httpd
如果http://<serverUrl>/phpMyAdmin 頁面顯示:
Wrong permissions on configuration file, should not be world writable
這是因爲目錄權限設置不對,只要修改文件屬性就可以了,phpmyadminl要運行在755權限下,
如果你把所有文件chmod  777就錯了。

 

 

最後,
如果要讓apache偵聽多個端口,可以在Listen 80下增加幾行,如:Listen 8888

如果要在apache上運行多個虛擬主機,可以修改httpd.conf,
把 #include extra/httpd-vhosts.conf這一行的#號去掉,

然後修改
extra/httpd-vhosts.conf

vi extra/httpd-vhosts.conf
添加:
<VirtualHost 192.168.0.2:8850>
DocumentRoot /server/webroot/mysite1
ServerName test.com
</VirtualHost>

如果還有虛擬主機,再添加:
<VirtualHost ......>
......
</VirtualHost>

......

 

 

最後安裝tomcat和j2sdk就不說了,這兩個東西相對比較獨立,安裝起來簡單些。


 

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章