周玉雙
摘要:LAMP(Linux+Apache+MySQL+PHP)網(wǎng)站架構(gòu)是性能非常穩(wěn)定的Web框架,該框架包括:Linux操作系統(tǒng)、Apache網(wǎng)絡(luò)服務(wù)器、MySQL數(shù)據(jù)庫(kù)、PHP編程語(yǔ)言,所有組成產(chǎn)品均是開(kāi)源軟件。LAMP具有輕量、通用、跨平臺(tái)、高性能、低價(jià)格、資源豐富、快速開(kāi)發(fā)的優(yōu)勢(shì),因此LAMP無(wú)論是性能、質(zhì)量還是價(jià)格都是企業(yè)搭建網(wǎng)站的首選平臺(tái)。
關(guān)鍵詞:Linux;Apache;PHP;Mysql;GD;http
正文
1 安裝Linux系統(tǒng)
1.1 啟動(dòng)字符界面
為了調(diào)試方便,修改linux的啟動(dòng)進(jìn)程,以便直接啟動(dòng)到字符界面下。
#vi inittab
修改:id:5:initdefault:為id:3:initdefault:
1.2 編譯內(nèi)核啟動(dòng)配置文件
# vi /etc/sysctl.conf
編輯/etc/sysctl.conf文件,增加三行:
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
2 設(shè)置Mysql數(shù)據(jù)庫(kù)
2.1 修改數(shù)據(jù)庫(kù)密碼
#mysql –u root –p(進(jìn)入mysql數(shù)據(jù)庫(kù),開(kāi)始密碼為空)
#use mysql
#update user set password=password(yourpassword)where user=root;
#flush privileges;
2.2 修改數(shù)據(jù)庫(kù)最大連接數(shù)
#vi my.cnf
在[Mysqld]中添加
max_connections=20000(設(shè)置mysql數(shù)據(jù)庫(kù)最大連接數(shù),默認(rèn)為100)
#mysqladmin –u root –p variables|grep max_connections
顯示:| max_connections|20000|
2.3 禁止遠(yuǎn)程連接數(shù)據(jù)庫(kù)
在命令行netstat -ant下看到3306端口是打開(kāi)的,為了禁止該功能,啟動(dòng)skip-networking,不監(jiān)聽(tīng)sql的任何TCP/IP的連接,切斷遠(yuǎn)程訪問(wèn)的權(quán)利,保證安全性。
2.4 用戶目錄權(quán)限限制
默認(rèn)的mysql是安裝在/usr/local/mysql,而對(duì)應(yīng)的數(shù)據(jù)庫(kù)文件在/usr/local/mysql/var目錄下,因此,必須保證該目錄不能讓未經(jīng)授權(quán)的用戶訪問(wèn)后把數(shù)據(jù)庫(kù)打包拷貝走了,所以要限制對(duì)該目錄的訪問(wèn)。確保mysqld運(yùn)行時(shí),只使用對(duì)數(shù)據(jù)庫(kù)目錄具有讀或?qū)憴?quán)限的linux用戶來(lái)運(yùn)行。
3 安裝apache和php
3.1 編譯Apache
#./configure --prefix=/usr/local/apache --enable-module=so --enable-module=rewrite --enable-shared=max --enable-module=most
3.2 編譯apache的限制IP并發(fā)數(shù)的模塊
#/usr/local/apache/bin/apxs –c –i –a mod_limitipconn.c
3.3 卸載GD庫(kù)
重新編譯GD庫(kù),編譯時(shí)必須加上相應(yīng)參數(shù)
#./configure –prefix=/usr/local/gd –with-png=/usr/lib –with-jpeg=/usr/lib –with-freetype=/usr/lib –with-xpm=/usr/lib
3.4 編譯php
#./configure --prefix=/usr/local/php --with-mysql --with-apxs=/usr/local/apache/bin/apxs --with-xml --enable-ftp --enable-force-cgi-redirect --enable-trans-sid --enable-track-vars --enable-url-includes --enable-sockets --with-gd=/usr/local/gd --with-zlib-dir=/usr/lib --with-gdbm-dir=/usr/lib
3.5 COPY PHP的配置文件
cp../php4.3.4/php.ini.dist /usr/local/php/lib/php.ini
修改php.ini文件
register_globals = On
3.6 編輯httpd.conf文件
修改DocumentRoot "/yourdir
查找
把#ExtendedStatus On這一行注釋掉,
添加
#this is my new mod
MaxConnPerIP 1(每個(gè)IP用戶的最大連接數(shù))
這里的 / 代表所有目錄
ok!重新啟動(dòng)一下apache服務(wù)器
/usr/local/apache/bin/apachectl restart
4 測(cè)試
寫(xiě)個(gè)php測(cè)試頁(yè)info.php:內(nèi)容如下
<?php
phpinfo();
?>
正常的話,應(yīng)該能看到php的信息了,恭喜你的Apche+Mysql +PHP安裝成功。
如果不正常,有Cannot load /usr/local/apache/libexec/libphp4.so into server等提示,那就是系統(tǒng)的SELINUX沒(méi)有關(guān)閉。
修改/etc/selinux/config文件中的SELINUX="" 為 disabled,然后重啟。
到此,LAMP系統(tǒng)架構(gòu)及性能優(yōu)化全部完成。
參考文獻(xiàn):
[1] Michael D Bauer.Linux Server Security[M].O'Reilly,2005.
[2] Russel Dyer.MySQL in a Nutshell[M].O'Reilly,2005.
[3] Ivan Ristic.Apache Security[M].O'Reilly,2005.
[4] John Coggeshall,ncy Malcolm.PHP Security Collection[M].O' Reilly,2004.
(作者單位:吉化集團(tuán)信息網(wǎng)絡(luò)技術(shù)有限公司)