Linux + Apache + MySQL + PHP (LAMP) 架设详解啰!
1. 查找可以使用:
[root@test root]# rpm -qa | grep gcc libgcc1-3.2-1mdk gcc-cpp-3.2-1mdk gcc-3.2-1mdk gcc-c++-3.2-1mdk 2. 移除 MySQL
可以使用:
|
0. 查找是否已经有
mysql 的帐号:
[root@test root]# grep mysql /etc/passwd # 如果没有 mysql 出现的话,那么请创建一个名为 mysql 的帐号! # 这个是要给 MySQL 的 Process 使用的!为了安全性,请务必创建! # 如果之前已经创建过了,那么底下这一步建置的工作就可以跳过, # 直接到 1. 解压缩与创建链接 去安装啰! [root@test root]# groupadd -g 315 mysql # 因为我刚好没有 315 这个 GID ,而 mysql 是系统使用的帐号,我希望他在 500 以内, # 因此就选择 315 做为 mysql 的 gid 啰!你当然可以变更这个数字, # 使用小于 500 的 GID 做为系统的帐号之用只是惯用的习惯而已啦! ^_^ [root@test root]# useradd -u 315 -g mysql -d /usr/local/mysql/data -M mysql # 我使用 315 做为 mysql 这个帐号(与群组同名!)的 UID 啦! # 并且创建他的家目录在 /usr/local/mysql/data 里面! 1. 解压缩与创建链接: [root@test root]# cd /usr/local <==因为已经是 binary 的套件,不用 make ! [root@test local]# tar -zxvf /root/mysql-3.23.57-pc-linux-i686.tar.gz ...(消息略过).... # 最后会产生一个目录: mysql-3.23.57-pc-linux-i686 [root@test local]# ln -s mysql-3.23.57-pc-linux-i686 mysql # 通常习惯将 MySQL 安装在 /usr/local/mysql 当中!但为了未来升级版本的确认, # 官方网站上面建议使用链接的方式来进行 MySQL 的使用! 3. 文件权限修正: [root@test local]# mkdir -p /var/lib/mysql [root@test local]# chown -R mysql:mysql /var/lib/mysql [root@test local]# chown -R root:mysql /usr/local/mysql-3.23* [root@test local]# chown -R mysql:mysql /usr/local/mysql/data # 修改成较为安全,且数据库所属人为 mysql 喔!特别留意啦! 4. 创建数据库: [root@test local]# cd mysql [root@test mysql]# ./scripts/mysql_install_db [root@test mysql]# chown -R mysql:mysql /var/lib/mysql [root@test mysql]# chown -R mysql:mysql /usr/local/mysql/data # 这个步骤会在 /usr/local/mysql/data 里面创建好 MySQL 的数据库! # 由于 /usr/local/mysql/data 是 MySQL 的数据库目录,所以很重要喔!请多加备份! # 不过,在新版的 3.23.57 这个版本当中,数据库竟然移到 /var/lib/mysql 去了! # 还真是有点奇怪呐!另外,根据诸多网友的回报,发现在创建数据库之后, # 还需要重新设置一下数据库的所属群组与拥有者喔! 5. 启动测试: [root@test mysql]# /usr/local/mysql/bin/safe_mysqld --user=mysql & Starting mysqld daemon with databases from /usr/local/mysql/data # 注意:这个时候 mysql 会创建一个 socket file 在 /var/lib/mysql/mysql.sock 喔! # 未来我们在使用 MySQL 的各种指令功能时,都需要使用到这个 socket file, # 但是 MySQL 偏偏缺省的 socket file 是在 /tmp 底下,怎么办?!真讨厌, # 我们可以通过这个简单的动作来欺骗我们的 MySQL 喔! [root@test mysql]# ln -s /var/lib/mysql/mysql.sock /tmp/ # 如果还是找不到 mysql.sock 时,请使用 find / -name mysql.sock # 来找出这个文件的绝对路径吧! [root@test mysql]# netstat -tl | grep mysql tcp 0 0 *:mysql *:* LISTEN [root@test mysql]# ps -aux | grep mysql mysql 6394 0.0 1.5 10528 992 pts/3 S 16:16 0:00 /usr/local/mysql/ mysql 6395 0.0 1.5 10528 992 pts/3 S 16:16 0:00 /usr/local/mysql/ mysql 6396 0.0 1.5 10528 992 pts/3 S 16:16 0:00 /usr/local/mysql/ root 6422 0.0 1.1 2408 732 pts/3 S 16:20 0:00 grep mysql # 呵呵!这样就应该是搞定了! MySQL 已经在监听要求啰!而且所有人为 mysql ! 6. 开机后立即启动! [root@test mysql]# vi /etc/rc.d/rc.local # 将底下这一行加入这个文件的最后面一行喔! cd /usr/local/mysql; /usr/local/mysql/bin/safe_mysqld --user=mysql & # 这样一来,每次开机就可以自动的启动 MySQL 啰! # 注:由于很多网友回复之问题中发现,如果没有加上 cd /usr/local/mysql 时, # 会导致无法自动于开机的时候启动,因此,请大家记得加上这个动作呢! 7. 高端设置内容: # 由于我们 MySQL 放置的地点在 /usr/local/mysql 内,这个目录并不在 PATH 当中! # 且 man page 亦不在 MANPATH 里面,所以,我们要手动的帮他加入啰! [root@test mysql]# vi /etc/profile # 大约在 33 行的地方,而且每个 distribution 设置的地方都不太相同! # 请找到 export PATH ... 那一行,以 Mandrake 9.0 来说,大概在 33 行左右, # 新加入一行: PATH="$PATH":/usr/local/mysql/bin export PATH ....(略).... [root@test mysql]# vi /etc/man.config( 有的 distribution 为 /etc/man.conf ) # 可以在这个文件的任何地方加入底下这一行: MANPATH /usr/local/mysql/man # 就可以具有 man page 的能力了! 8. 创建 MySQL 的 root 帐号密码! [root@test mysql]# /usr/local/mysql/bin/mysqladmin -u root password 'your.password' # 请创建密码!为了安全起见!否则你的 MySQL 数据库,将缺省所有人都可以登录喔! # 注意,如果运行上面的指令时,竟然出现如下的错误: ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111) # 这表示 mysql 找不到 mysql.sock 这个文件!我们上面不是提到 mysql.sock 的 # 绝对路径吗?假设是 /var/lib/mysql/mysql.sock 好了,那么我们可以: [root@test mysql]# /usr/local/mysql/bin/mysqladmin -u root \ > -S /var/lib/mysql/mysql.sock password 'your.passwd' # 当然也可以进行文件的链接阿! ln -s /var/lib/mysql/mysql.sock /tmp [root@test mysql]# /usr/local/mysql/bin/mysql -u root -p \ > [-S /var/lib/mysql/mysql.sock] # 后面 [] 的内容不一定需要!且 [] 不要打! Enter password: <==这里输入你刚刚创建的那个密码喔! Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 to server version: 3.23.57 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> exit
# 这样就是可以确认已经可以连接到你的
MySQL 数据库了!请特别留意,有的朋友没有移除
|
0. 解压缩:
[root@test root]# cd /usr/local/src [root@test src]# tar -zxvf /root/php-4.3.3.tar.gz # .....(消息略).... # 最后会产生一个 /usr/local/src/php-4.3.3 的目录 1. 搜索设置内容: [root@test src]# cd php-4.3.3 [root@test php-4.3.3]# ./configure --prefix=/usr/local/php4 \ >--with-apxs2=/usr/local/apache2/bin/apxs \ >--with-mysql=/usr/local/mysql \ >--with-config-file-path=/usr/local/php4 # 上面请特别注意到: --prefix=/安装的路径:这个项目在设置未来你的 Apache 安装在那个目录当中?! --with-apxs2 :这个则是 Apache2 专用的选项喔!请针对您的主机情况设置! --with-mysql :这个则是针对 MySQL 啦!当然啦,就写我刚刚搞定的咚咚! --with-config-file-path:这个又是什么?呵呵!是 php 的设置档 php.ini 放置的目录啦! # 其他的额外项目请使用 ./configure --help 来察看吧! 2. 开始编译与安装: [root test php-4.3.3]# make; make install # 如果没有错误的话,那么在 /usr/local/php4 这个目录当中就已经将你的 php 安装好了! 3. 转存 PHP 基本组态文件: [root@test php-4.3.3]# cp php.ini-dist /usr/local/php4/php.ini # 这个路径与你刚刚在 ./configure 当中那个 --with-config-file-path 设置有关! 4. 启动 Apache 当中的 PHP 选项: [root@test php-4.3.3]# vi /usr/local/apache2/conf/httpd.conf # 找到底下两行: LoadModule php4_module modules/libphp4.so <==大约在 231 行处 AddType application/x-httpd-php .php <==这一行可以在 847 行处自行增加! 5. 重新启动 Apache : [root@test php-4.3.3]# /usr/local/apache2/bin/apachectl stop [root@test php-4.3.3]# /usr/local/apache2/bin/apachectl start 6. 测试 PHP 是否是正常工作的: [root@test php-4.3.3]# cd /usr/local/apache2/htdocs [root@test htdocs]# vi test.php <?php phpinfo( ); ?> # 以我的测试主机为例,我的测试主机 IP 为 192.168.1.2 ,所以随便以一部可以连接的PC, # 在网址列输入 http://192.168.1.2/test.php # 或者直接在本机的 X-Window 上面输入 https://#/test.php 亦可! |
[root@test
root]# cd /usr/local/apache2/conf
[root@test root]# vi httpd.conf ServerRoot "/usr/local/apache2"
PidFile logs/httpd.pid
Timeout 300
KeepAlive On
MaxKeepAliveRequests
100
KeepAliveTimeout
15
<IfModule
prefork.c>
Listen 80
User nobody
ServerAdmin
root@localhost
#ServerName
new.host.name:80
UseCanonicalName
Off
AddDefaultCharset
ISO-8859-1
HostnameLookups
Off
|
[root@test
root]# cd /usr/local/apache2/conf
[root@test root]# vi httpd.conf DocumentRoot
"/usr/local/apache2/htdocs"
<Directory
/>
<Directory
"/usr/local/apache2/htdocs">
UserDir public_html
DirectoryIndex
index.html index.html.var
Alias /icons/
"/usr/local/apache2/icons/"
Alias /manual
"/usr/local/apache2/manual"
ScriptAlias
/cgi-bin/ "/usr/local/apache2/cgi-bin/"
|
[root@test
root]# cd /usr/local/apache2/conf
[root@test root]# vi httpd.conf LoadModule php4_module
modules/libphp4.so
ErrorLog logs/error_log
|
[root@test
root]# /etc/rc.d/init.d/httpd start
(启动)
[root@test root]# /etc/rc.d/init.d/httpd stop (关闭) |
[root@test
root]# /usr/local/apache2/bin/apachectl start
(启动)
[root@test root]# /usr/local/apache2/bin/apachectl stop (关闭) |
[root@test
root]# netstat -tuln | grep ':80'
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN |
[root@test
root]# vi /var/log/httpd/error_log
[Thu Dec 26 20:16:53 2002] [notice] Apache/2.0.43 (Unix) PHP/4.2.3 configured -- resuming normal operations |
[root@test
root]# ll /etc/httpd/conf.d/*.conf
-rw-r--r-- 1 root root 814 Feb 10 2003 /etc/httpd/conf.d/perl.conf -rw-r--r-- 1 root root 459 Jun 30 04:35 /etc/httpd/conf.d/php.conf -rw-r--r-- 1 root root 1276 Feb 20 2003 /etc/httpd/conf.d/python.conf -rw-r--r-- 1 root root 11140 Jul 31 23:40 /etc/httpd/conf.d/ssl.conf |
[root@test
root]# cd /etc/httpd/conf.d
[root@test conf.d]# mv ssl.conf ssl.conf.bak [root@test conf.d]# /etc/rc.d/init.d/httpd restart |
[test@test
test]$ cd
# 回到自己的家目录
[test@test test]$ mkdir public_html [test@test test]$ chmod 755 public_html [test@test test]$ chmod 755 /home/test # 在你的用户端家目录中创建了一个 public_html 的目录, # 并将此目录的权限改成可以让其他人观看,注意喔, apache # 缺省是 public_html ,但是如果你在 httpd.conf 这个文件中 # 改变了目录名称,则必须作适当的修正喔! |
[root@test
root]# cd /usr/local/apache2/htdocs
[root@test htdocs]# ln -s /home/test/public_html test |
[root@test
root]# vi /usr/local/apache2/conf/httpd.conf
Alias /test/ "/home/test/public_html/" <Directory "/home/test/public_html"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> [root@test root]#
/usr/local/apache2/bin/apachectl
stop
|
[root@test
root]# vi /usr/local/apache2/conf/httpd.conf
方法一:
# 再加入底下几行:
方法二:
[root@test root]#
/usr/local/apache2/bin/apachectl
stop
|
[root@test
root]# vi /usr/local/apache2/conf/httpd.conf
# 先确认在 httpd.conf
当中,底下这一行已经将注解拿掉了!
# 再加入底下这一行:
[root@test root]#
/usr/local/apache2/bin/apachectl
stop
|
[root@test
root]# vi /usr/local/apache2/conf/httpd.conf
# 大概在 880
行左右,可以找到下面这一行:
[root@test root]#
/usr/local/apache2/bin/apachectl
stop
|
[root@test
root]# vi /usr/local/apache2/htdocs/missing.html
<html> <center> Missing HTML Web Page<br><br> I can't find any web page for you, <br> Please contact with me root@localhost, <br> or press <a href="http://192.168.1.2/manual/">here</a> to see the manual of Apache 2.xx </center> </html> |
[root @test
root]# vi /usr/local/apache2/conf/httpd.conf
# 额外再添加几行吧! <Directory "/home/test/public_html/cgi"> Options ExecCGI SetHandler cgi-script order allow,deny deny from 192.168.1.100 deny from testing.idv.tw </Directory> |
[root@test
root]# vi /usr/local/apache2/conf/httpd.conf
# 额外再添加几行吧! <Directory "/home/test/public_html/cgi"> Options ExecCGI SetHandler cgi-script <Limit GET> order allow,deny deny from 192.168.100 allow from all </Limit> <Limit POST> order allow,deny allow from 192.168.1.50 deny from all </Limit> order allow,deny deny from 192.168.1.100 allow from all </Directory> |
[root@test
root]# vi /usr/local/apache2/conf/httpd.conf
# 找到底下这几行,并且将他修改一下: <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from 192.168.1.11 </Location> [root@test root]#
/usr/local/apache2/bin/apachectl
stop
|
Apache Server Status for 192.168.1.2
Server Version: Apache/2.0.43 (Unix) PHP/4.2.3 Server Built: Dec 26 2002 01:59:03 ------------------------------------------------------------------------------ Current Time: Monday, 30-Dec-2002 01:31:28 CST
Scoreboard Key:
PID Key:
31027 in state: W , 31028
in state: _ , 31029 in state: _
------------------------------------------------------------------------------
Apache/2.0.43 Server at 192.168.1.2 Port 80 |
[root@test
root]# mkdir -p /usr/local/apache2/htdocs/protect
[root@test root]# cd /usr/local/apache2/htdocs/protect [root@test root]# echo "This is a protect page" > test.html |
htpasswd
语法: [root@test root]# htpasswd [-c] password_file_name User_name 说明: -c :当后面的 password_file_name 这个密码档不存在时,那么就创建该文件 范例一:
范例二:
[root@test apache2]#
more
apache.passwd
|
[root@test
root]# vi /usr/local/apache2/conf/httpd.conf
在这个文件的设置中,请特别留意设置的地方,不要设置错误地方, 一般而言,新的咚咚可以加在最后面一行开始,比较不会搞错地方! 加入底下这几行: <Directory "/usr/local/apache2/htdocs/protect"> AuthName "Protected Directory" #这个是显示在窗口上面的提示字符 AuthType Basic #这个则是认证的类型!就选Basic即可,Apache的缺省功能 AuthUserFile /usr/local/apache2/apache.passwd #密码档放置的地方啦!完整的目录与文件名 require valid-user #允许的用户,valid-user为任何一个在认证文件当中的帐号皆可 #require user test #若将 # 移除,则表示只有 test 才是可以登录的帐号! </Directory> |
[root@test
root]# /usr/local/apache2/bin/apachectl stop
[root@test root]# /usr/local/apache2/bin/apachectl start |
关于
root 的设置项目:
0. 先确认底下这些信息可以在您的
httpd.conf 里面发现:
1. 创建让每个用户家目录下都能自行设置
AuthConfig 的规则!
关于 一般身份用户 (test 为例) 的设置项目: 0. 以一般身份用户登录,或者使用
su 转换 test 的身份
1. 创建保护目录与网页内容
2. 创建 test
自己的密码档
3. 创建 .htaccess
文件的内容!
|
[root@test
root]# cd /etc/logrotate.d
[root@test logrotate.d]# vi apache # 新加入这几行 /var/log/httpd/access_log /var/log/httpd/error_log { rotate 4 missingok sharedscripts postrotate /bin/kill -HUP `cat /var/log/httpd/httpd.pid 2>/dev/null` 2> /dev/null || true endscript compress } |
logrotate -f /etc/logrotagte.conf呵呵!这样就对啦!那么为什么要加入这个 logrotate 呢?这是因为,未来,如果你的 WWW 服务器越来越大时,那么应该 access_log 文件会『很可怕的大!』例如目前本小站的流量每周可以造成我的注册表长大到 400MB 以上~如果不将他 rotate 的话,哈哈!不出几个星期,我的硬盘就爆了~所以, logrotate 是很重要的喔!
192.168.1.11
- - [27/Dec/2002:00:20:24 +0800] "GET /manual/ HTTP/1.1" 200 7340
来源 IP 日期与时间 动作与网页 动作代码 |
0. 确认一些必须要的绘图相关
RPM 已经安装!
# 因为这个套件需要 gd, zlib 与 png 才行,所以,你需要安装这三个咚咚! # 在 Mandrake 9.0 当中,你所需要的套件在光盘中的名称为: libpng3-devel-1.2.4-3mdk libpng3-1.2.4-3mdk zlib1-1.1.4-3mdk zlib1-devel-1.1.4-3mdk libgd1-1.8.4-6mdk libgd1-devel-1.8.4-6mdk # 至于在 Red Hat 7.2 当中,你要的套件名称为: zlib-1.1.3-25.7 zlib-devel-1.1.3-25.7 libpng-devel-1.0.14-0.7x.3 libpng-1.0.14-0.7x.3 gd-1.8.4-4 gd-devel-1.8.4-4 # 请一定要安装喔!不然肯定无法安装这套软件的! 1. 下载软件:可以直接到官方网站,或者到我们网站上下载:
2. 安装软件,同样的,到
/usr/local/src 下面解压缩喔!
3. 设置档编修:
4. 测试 Run
的结果
[root@test etc]#
vi
/etc/crontab
|
1. 下载软件:可以直接到官方网站,或者到我们网站上下载:
http://vbird.org.cn/download/index.php#awsats # 使用浏览器将网站上面提供的数据拿回去!当然,你也可以直接到官方网站上面去下载最新的版本! # 假设你已经将数据捉回去,并且放置在 /root 这个目录当中了,文件名为: awstats.tar.gz 2. 安装软件:
3. 设置档编修:
4. 修改一下
httpd.conf 的设置内容:
5. 测试 Run
的结果
6. 设置每日运行!
|
至于这个设置嘛!真的是很简单耶!只要几行就搞定了,设置完成之后还会让你偷笑ㄋㄟ~呵呵!看看实例吧!
[root@test root]# cd /usr/local/apache2/conf
[root@test root]# vi httpd.conf
# 在这个文件的最下方加入底下这些字眼!NameVirtualHost * # 设置你的虚拟主机判定的依据!这里是 * 亦即是
# 所有连上这部机器的名称都会被使用来当作虚拟主机的设置之用!<VirtualHost *>
ServerName mdk90.vbird.net
DocumentRoot /home/mdk90
</VirtualHost><VirtualHost *>
ServerName www.mdk90.vbird.net
DocumentRoot /home/www.mdk90
CustomLog /var/log/httpd/www.access_log combined # 特别将注册表额外分离出来
</VirtualHost><VirtualHost *>
ServerName phorum.mdk90.vbird.net
DocumentRoot /home/phorum.mdk90
</VirtualHost>
要注意的是:马上测试看看!呵呵!会发现,咦!我真的有三个主网页了哩!很不错吧!这个作法可以让你的 WWW 网页更有灵活度喔!举个例子来说,前一阵子因为酷学园讨论区(http://phorum.study-area.org) 常常挂点,所以鸟哥就自告奋勇的跟站长说,只要将 phorum.study-area.org 这个 domain name 指向我的主机 IP ,那么也可以直接进入我的讨论区,如此一来,只要修改一下 DNS 即可转换到我的讨论区啦!并且不需要再进行任何额外的设置!对于网页维护的灵活度是真的很有帮助的喔!
- 在虚拟主机的设置上还有很多的可用的功能,不过,最低的限度是需要有 ServerName 及 DocumentRoot 这两个即可!
- 虽然原来我就有 mdk90.vbird.net 这个网域,但是因为设置了虚拟主机之后,自己的原来名称可能会不见去,所以,这里必须将自己的名称也写入才行!
- 上面有发现一个 CustomLog 的设置喔!该设置会让以 www.mkd90.vbird.net 这个网域登录的注册表不再写入原来的 /var/log/httpd/access_log 文件,而是自行写入 /var/log/httpd/www.access_log 这个文件!
需要注意的事项:
虚拟主机并没有什么值得特别注意的地方,只要设置正确,大致上就不会有太大的问题!不过,你可能需要特别注意刚刚我们创建起来的新的注册表喔!为什么呢?我们上面不是提过说,注册表在大型的网站上面成长的幅度是很可观的吗?所以需要进行 logrotate ,但是你刚刚创建的文件并不在原本的 logrotate 文件之内呀!呵呵!这个时候请自行加入 logrotate 个手续喔!否则.....嘿嘿嘿嘿!硬盘空间被用光可不要怪鸟哥喔! ^_^
什么!?客户端竟然也有文本接口的浏览器?!哈哈!当然是有啦!不然这里干嘛要介绍?!那就是鼎鼎大名的 lynx 以及 wget 啰!请注意的是,这两个套件并不一定会在安装的时候就已经安装在你的系统中,所以请先使用 RPM 查找一下他是否存在于你的系统当中,然后才能运行喔!他的用途是: 这两个指令之前已经介绍过了!请自行前往观察一下啰!加油啦!
[root@test
root]# cd /usr/local/src
[root@test src]# tar -zxvf /完整路径/turck-mmcache-2.3.9.tar.gz # 会产生一个名为 turck-mmcache-2.3.9 的目录 [root@test src]# cd turck-mmcache-2.3.9 [root@test turck-mmcache-2.3.9]# phpize # 这个指令是 PHP 套件所提供的!可以建置好你的 mmcache 原代码 [root@test turck-mmcache-2.3.9]# ./configure --enable-mmcache=shared [root@test turck-mmcache-2.3.9]# make && make install # 这个动作会编译一个名为 mmcache.so 的动态函数库模块, # 并且会主动的将他安装在 /usr/lib/php4 这个目录当中! # 这样就安装完毕了!很简单吧! |
1. 设置主动加载动态函数库模块:
[root@test root]# vi /etc/ld.so.conf # 在这个文件内加入底下这一行: /usr/lib/php4 [root@test root]# ldconfig # 上面这两个步骤比较有趣一点,在 ldconfig 这个指令的功能是: # 『加载动态函数库到内存当中做为缓存』之用,至于加载的动态函数库则是 # 根据 /etc/ld.so.conf 这个文件的设置为准!这的动作只要第一次设置时进行 # 即可,未来在开机完成之后,系统会主动的加载动态函数库的! # 另外请注意, ld.so.conf 里面只要写『目录』即可! 2. 修改 php.ini # 请注意,由于每个人的 php.ini 都不相同,例如使用 RPM 安装者,应该是 # /etc/php.ini ,但是我上面的安装设置却是 /usr/local/php4/php.ini # 请依照您的主机来设置喔! [root@test root]# vi /完整路径/php.ini # 在这个文件的最后一行加入底下这几行: ;;;;;;;;;;;; ; MM Cache ; ;;;;;;;;;;;; extension="mmcache.so" mmcache.shm_size="16" mmcache.cache_dir="/tmp/mmcache" mmcache.enable="1" mmcache.optimizer="1" mmcache.check_mtime="1" mmcache.debug="0" mmcache.filter="" ; end of mmcache 3. 创建缓存目录: [root@test root]# mkdir /tmp/mmcache [root@test root]# chmod 0777 /tmp/mmcache 4.重新启动 Apache [root@test root]# /etc/rc.d/init.d/httpd restart # 或 [root@test root]# /usr/local/apache2/bin/apachectl restart |
[root@test
root]# /usr/sbin/ab [-dSk] [-c number] [-n
number] 网页.php
参数说明: -d :不要显示 saved table 的百分比数据;通常不要那个数据,所以会加 -d -k :还记得上面的 KeepAlive 吧!加入 -k 才会以这样的功能测试; -S :不显示长消息,仅显示类似 min/avg/max 的简短易懂消息! -c :同时有多少个『同时连接』的设置(可想成同时连接的 IP ) -n :同一个连接创建几个要求信道!(可想成同一个 IP 要求的几条连接) 更多的消息请自行 man ab 喔! 范例: [root@test root]# /usr/sbin/ab -dSk -c100 -n100 \ > http://vbird.org.cn/home.php This is ApacheBench, Version 1.3d <$Revision: 1.67 $> apache-1.3 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking
linux.vbird.org (be patient).....done
Document Path:
/home.php
Concurrency
Level: 100
Connnection
Times (ms)
|
几个比较知名的网站管理员大概都有这样的困扰,那就是网站常被砍站软件所强力下载,结果造成主机的 CPU loading 过重,最后竟然会导致死掉~唉!真是的~人怕出名猪怕肥呐!先来解释一下什么是砍站吧!所谓的『砍站』,就是以类似多点连接下载的持续性消息传递软件进行网站数据的下载,而且,一激活该软件,该软件就将『整个网站』的内容都给他 download 下来,很厉害吧!没错!是很厉害,但是却也害死人了~怎么说呢?因为这种软件常常会为了加快 download 的速度,所以采用多点连接的方式,也就是会持续不断的向 Server 发出要求封包,而由于这些封包并不见得能够成功的让 Server 把数据传导给 Client 端,常常会无法投递就是啦!这样的结果就是.....造成 Server 要一直不断的回应,又无法正确的回应出去,此外,要求太过频繁,结果主机应接不暇,最后....就当机了...真的是林老师ㄌㄟ~我们这个小站的主机古早以前,就是因为这样的原因,导致服务常常断断续续的,并且,由于 CPU loading 太高,结果让正常连接进来看数据的网友没有足够的资源,因此网页打开的速度就变的很慢~唉~这些砍站的人,也太不道德啦!
由于这种砍站软件真的很麻烦,一不注意马上就又会被砍站而当机,三天两头就要重新开机一次,完全让 Linux 的稳定性无法发挥!真是气死了~后来,我就自行写了一个 scripts 来挡这样的 IP !我的作法是这样的:大致上就是这样吧!这样的一程序需要与 iptables 相互配合,所以,请先查阅一下简易防火墙设置那一篇文章,然后再来下载这支程序吧!这支程序您可以在底下的网址下载喔!
- 由于砍站软件要多点连续下载,因此,同一个 IP 在同一个时间内,会有相当多的连接发生;
- 由于他是重复不断的要求连接,因此刚刚创建的连接在达成下载的目的后,会立刻死掉,而又多生出其他的连接出来,因此,这个时候他的连接情况就变的相当的不正常了!
- 由于某些较旧的砍站软件并不会『欺骗』主机,所以,会在主机的注册表里面记录住 Teleport 的标记!
- 既然如此的话,那么我就让我的主机每分钟去检查两个东西(1)先检查 log file ,如果有发现到相关的 Teleport 字词,就将该 IP 抵挡掉;(2)使用 netstat 来检查同一个 IP 的同时连接,如果该连接超过一个值(例如同时有 12 个连接)的话,那么就将该 IP 抵挡掉!
- 此外,由于上面的方案可能会将 Proxy 的 Client 端也同时抵挡掉,真是可怜啊!这个时候,这支程序就会主动的将(1)的情况的主机抵挡 3 天,至于(2)的情况则抵挡2小时!过了该抵挡的时限后,该 IP 即可又连上我们的主机了!
http://vbird.org.cn/download/index.php#http-netstat.sh详细的安装步骤我已经以中文写在该文件里面了,所以请先查看一下该文件的前面说明部分吧!此外,Study Area 的 netman 大哥也已经开发了一套很棒的防砍站的程序了!在防堵砍站的原理上面是完全相同的,不过写法可能不是很雷同就是了!如果有需要的话,也可以前往 Study-Area 搜索一下啰!http://phorum.study-area.org/viewtopic.php?t=13643
上面这样一路走来,哈哈!终于我们的 LAMP 服务器就已经大致上搞定啦!那么接下来你可以利用这个 WWW 主机帮你做什么事呢?嗄!能作的事情可多啰!目前很多支持 PHP 的架站软件已经被很完整的开发了,例如 PHPNuke 以及鸟哥很喜欢的 phpBB 呢!这些架站软件都是建构在 LAMP 上面的,而既然我们的 LAMP 已经搞定了,那么其他的架站软件的安装就真的是相当的快速呢!底下介绍 phpBB 的安装!你可以到底下的链接去看看喔:上面最后一个是鸟哥前一阵子写的,目前已经有出较新版本的 phpBB2 啰!所以,请记得到官方网站下载最新的 phpBB 来安装喔!毕竟比较新的不但功能比较多,而且臭虫(Bug)也清理的差不多了!另外,由竹猫星球的竹猫三兄弟也有出一本『phpBB 论坛架设宝典』,里面也有提到相当多的有用的架站心得与技巧的说明!有兴趣的可以先到竹猫星球看看其风格与内容,然后再考虑要不要架站吧! ^_^目前我对 phpBB 倒是蛮喜欢的!
- phpBB 官方网站:http://www.phpbb.com/
- phpBB 正体中文网站『竹猫星球』:http://phpbb-tw.net/phpbb/
- 简易 phpBB2 的安装与设置方法:http://vbird.org.cn/apache_packages/
<?
phpinfo( ); ?> |
<?php
phpinfo( ); ?> |
[root@test
root]# /etc/rc.d/init.d/httpd restart
Stopping httpd: [ OK ] Starting httpd: perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = "en", LC_ALL = "en", LANG = "en" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C"). |
[root@test
root]# vi /etc/sysconfig/i18n
LANG="en_US" LANGUAGE="en_US" LC_ALL="en_US"; export LC_ALL SUPPORTED="zh_TW.Big5:zh_TW:zh:en_US.UTF-8:en_US:en" SYSFONT="latarcyrheb-sun16" |