Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1436936
  • 博文数量: 463
  • 博客积分: 10540
  • 博客等级: 上将
  • 技术积分: 5450
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-12 08:30
文章分类

全部博文(463)

文章存档

2014年(2)

2012年(14)

2011年(42)

2010年(18)

2009年(78)

2008年(35)

2007年(182)

2006年(92)

我的朋友

分类: LINUX

2009-04-29 22:42:31

建立一个带宽、线程可控的下载型WEB网站

一、前言

这种配置的WEB网站初步实现了IP线程和线程流量的管理,用的linux版本是RedHat AS 4.2。

二、所需要的软件及其版本

httpd-2.0.54.tar.gz
mysql-4.1.18.tar.gz
php-4.4.2.tar.gz
ZendOptimizer-2.6.2-linux-glibc21-i386.tar.gz
mod-cband-0.9.7.3.tgz   限制Apache的并发连接数以及控制Apache的带宽

三、安装配置Mysql

#  cd  /tmp
#   wget  
#  tar  zxvf    mysql-4.1.18.tar.gz
#  cd  mysql-4.1.18
#  ./configure --prefix=/usr/local/mysql --sysconfdir=/etc --localstatedir=/var/lib/mysql
#  prefix=/usr/local/mysql   mysql安装的目标目录
#  sysconfdir=/etc   my.ini配置文件的路径
#  localstatedir=/var/lib/mysql  数据库存放的路径

#  make
#  make  install
安装完以后要初始化数据库,当然你是升级的话不用做这步;
#  /usr/local/mysql/bin/mysql_install_db
建立 mysql 用户;
#  /usr/sbin/useradd -M -o -r -d /var/lib/mysql -s /bin/bash -c "MySQL Server" -u 27 mysql
设置权限;
#  chown -R mysql:mysql /var/lib/mysql
#  chmod 750 /var/lib/mysql
#  chown -R mysql:mysql /usr/local/mysql
#  chmod -R 750 /usr/local/mysql
做完上面的步骤,然后把编译目录的一个脚本复制过去;
#  cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#  chmod 755 /etc/rc.d/init.d/mysqld
#  /sbin/chkconfig --add mysqld
#  /sbin/chkconfig mysqld on    设置使 mysql 每次启动都能自动运行。
好了,至此mysql安装完毕,可以起动mysql服务
/etc/rc.d/init.d/mysqld start
下面这步比较关键;


#  ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
#  ln -s /usr/local/mysql/include/mysql /usr/include/mysql
可以不做这步,大可以在编译其他软件的时候自定义myslq的库文件路径,但最好还是把库文件链接到默认的位置,这样在编译类似PHP,Vpopmail等软件时可以不用指定mysql的库文件地址。

四、安装配置Apache

#  cd   /tmp
#  wget  
#  tar  zxvf    httpd-2.0.54.tar.gz
#  cd  httpd-2.0.54
#  ./configure --prefix=/usr/local/apache --enable-module=so --enable-speling --enable-rewrite  --enable-forward
#  so模块用来提供 DSO 支持的 apache 核心模块,rewrite是地址重写的模块,如果不需要可以不编译。
--enable-so 选项:让 Apache 可以支持DSO模式,注意,我们在这里采用的是 Apache2.0 的语法。如果你的Apache 是1.3版本,应改为--enable-module=so
--enable-mods-shared=most选项:告诉编译器将所有标准模块都编译为DSO模块。你要是用的是 Apache1.3, 改为--enable-shared=max就可以。
--enable-rewrite选项:支持地址重写功能,使用1.3版本的朋友请将它改为--enable-module=rewrite

======================== 方式 2 =============================
./configure --prefix=/usr/local/apache --enable-module=so --enable-mods-shared=most --enable-rewrite  --enable-forward
==========================================================

#  make
#  make  install
#  cp  /usr/local/apache/bin/apachectl    /etc/rc.d/init.d/httpd
#  /etc/rc.d/init.d/httpd  start

五、安装配置 PHP

#  cd  /tmp
#  wget  
#  tar  zxvf    php-4.4.2.tar.gz
#  cd  php-4.4.2
#  ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs
说明:
--with-apxs2=/usr/local/apache/bin/apxs 是Apache2的语法
--with-apxs=/usr/local/apache/bin/apxs 是Apache1.3的语法
#  make
#  make  install
#  cp  php.ini-dist  /usr/local/php/lib/php.ini
#  vi  /usr/local/apache/conf/httpd.conf



AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
下添加:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

重新启动 Apache 服务;
#  /etc/rc.d/init.d/httpd  restart

六、安装配置mod-cband

#  cd  /tmp
#  wget  
#  tar  zxvf    mod-cband-0.9.7.3.tgz
#  cd  mod-cband-0.9.7.3
#  PATH=/usr/local/apache/bin:$PATH
#  ./configure
#  make
#  make  install

在屏幕下方看到下列文字段 :

Libraries have been installed in:
  /usr/local/apache/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
  - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
    during execution
  - add LIBDIR to the `LD_RUN_PATH' environment variable
    during linking
  - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
  - have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/local/apache/modules/mod_cband.so
[activating module `cband' in /usr/local/apache/conf/httpd.conf]

如果有,则说明安装成功。


#  mkdir  /usr/local/apache/htdocs/
#  mkdir  /usr/local/apache/logs/
#  vi  /usr/local/apache/conf/httpd.conf

在配置文件的最下方添加以下内容:

NameVirtualHost 12.34.56.78    ( 主机 IP 地址 )

       ServerName :80
       ServerAdmin admin@test.net.cn
       DocumentRoot "/usr/local/apache/htdocs/ "
       DirectoryIndex test.php
       ErrorLog logs//error_log
       CustomLog logs//access_log  common


       SetHandler  cband-status


       SetHandler  cband-status-me

RewriteEngine  on
RewriteOptions  inherit
# limit speed of this vhost to 500kb/s, 10 request/s, 30 open connections
       CbandSpeed  500kb/s    10  30
# in addition every remote host connecting to this vhost
# will be limited to 100kb/s, 5 request/s, 2 open connections
       CbandRemoteSpeed  100kb/s    5  2
       CbandPeriod  3S


#  /etc/rc.d/init.d/httpd  stop
#  /etc/rc.d/init.d/httpd  start

七、安装配置ZendOptimizer

说明:Zend Optimizer V2.5.5以上版本,就可以支持PHP5
#  cd  /tmp
#  wget  http://download.discuz.net/ZendOptimizer-2.6.2-linux-glibc21-i386.tar.gz
#  tar  zxvf    ZendOptimizer-2.6.2-linux-glibc21-i386.tar.gz
#  cd  ZendOptimizer-2.6.2-linux-glibc21-i386
#  ./install.sh

出现终端图形化安装界面,一路回车,其中有两处需要指定路径的,检查缺省是否与你的机器实现路径相符,不同则改之。如Specify the Apache bin directory,变更下方路径为你的Apache的bin目录:/usr/local/apache/bin。之后,又是一路回车至最后提示安装成功并重启apache。
Zend的安装目录一般为/usr/local/Zend/。

测试

编辑test.php文件在/usr/local/apache/htdocs/目录下,内容为:
Phpinfo()
?>

在浏览器地址栏中输入,回车。在不滚动的屏幕下方Zend Engine2图标左侧是否看到下列文字段 :

This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies
with Zend Extension Manager v1.0.4, Copyright (c) 2003-2004, by Zend Technologies
with Zend Optimizer v2.6.2, Copyright (c) 1998-2004, by Zend Technologies

如果有,则说明安装成功,此时在滚动屏幕可以看到有Zend Optimizer参数表格。
如果没有上方文字的后面两行,则说明安装有问题。最有可以的是Zend Optimizer没有找到你的php.ini文件。在上述文字段上方表格找到Configuration File (php.ini) Path后面的具体路径,将你的php.ini


复制过去,然后重启Apache,一般可以解决。

阅读(1089) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~