Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1284870
  • 博文数量: 161
  • 博客积分: 10192
  • 博客等级: 上将
  • 技术积分: 2165
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-27 17:09
文章分类

全部博文(161)

文章存档

2012年(2)

2011年(13)

2010年(137)

2009年(5)

2008年(4)

我的朋友

分类: LINUX

2010-07-21 15:11:09

1.
/etc/rc.d/init.d/httpd start
or
service httpd start
or
/usr/sbin/apachectl start

2.RPM安装时自动匹配相关包
#rpm -ivh gcc-2.3.rpm  --aid 

3.
注意:

实际中把 配置文件写到/etc/httpd/conf.d下,不改/etc/httpd/conf里的文件.安全。
需要事先在HTTPD。CONF里指定 加载路径:
# Load config files from the config directory "/etc/httpd/conf.d".
#
Include conf.d/*.conf


4。对一个目录(auth)进行身份认证:部 分内容只让有权限的人看到。
1)编辑/etc/httpd/conf.d/auto_user.conf(这个目录下的配置文件名 字随意,但扩展名必须为.conf才能被加载)

   Options Indexes FollowSymLinks
   AllowOverride AuthConfig---》这句是主要的。
   Order allow,deny
   Allow from all

技巧:上面的文字 可以从HTTPD。CONF里复制过来再修改下即可。
在VI中直接读取另一个文件里的一段进来。
:x !cat /etc/httpd/conf/httpd.conf |grep -A 9 "public_html"

2)创建/www/html/auto/.htaccess
AuthName "please input name and pw"
AuthType Basic
AuthUserFile /var/www/html/auth/.htpasswd
Require user szx gdlc
AuthGroupFile /var/www/html/auth/.htgroup
Require group gdlc-group
3)创建认证用户和认证组。
#htpasswd -c /var/www/html/auth/.htpasswd gdlc
#htpasswd  /var/www/html/auth/.htpasswd szx
#vi /var/www/html/auth/.thgroup
gdlc-group:szx gdlc


 
5。基于用户个人主页的身份验证。
lynx
szx
1) 修改/etc/httpd/conf/httpd.conf

      UserDir disable root
      UserDir public_html


    AllowOverride FileInfo AuthConfig Limit
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
   
        Order allow,deny
        Allow from all
   

   
        Order deny,allow
        Deny from all
   

2)vi /home/szx/public_html/.htaccess
AuthName "please input name and pw"
AuthType Basic
AuthUserFile /home/szx/public_html/.htpasswd
Require user szx
3)htpasswd -c /home/szx/public_html/.htpasswd szx
 chmod +x .htpasswd
4) lynx

6.APACHE虚拟目录
虚拟 目录:类似建立一个WEB目录的快捷方式。
1)#vi /etc/httpd/conf.d/vhost.conf
  Alias "/alias" "/var/www/html/aliastest"
 
   Options Indexes MultiVies
   AllowOverride None
   Order allow,deny
   Allow from all
 

2)
#service httpd restart
3)测试
lynx

7.APACHE虚拟目录访问控制
1)#vi /etc/httpd/conf.d/vhost.conf
  Alias "/alias" "/var/www/html/aliastest"
 
   Options Indexes FollowSymLinks
   AllowOverride AuthConfig
   Order allow,deny
   Allow from 192.168.1.0/24
 

2)
#service httpd restart
3) 测试
lynx


8.压力测试:
ab:
格 式:
/usr/sbin/ab [options] [http[s]://]hostname[:port]/path
参数:
-A: 对服务器提供简单认证确定
-c:连接个数
-k:启用HTTP KeepAlive功能,即在一个HTTP对话中执行多个请求。默认时不启用该功能。
-t:测试所进行的最大秒数。默认没有时间限制。
-X: 对请求使用代理服务器。
-n:在测试会话中所执行的请求个数。 
例子:
Server Software:        Allegro-Software-RomPager/2.10
Server Hostname:        172.16.4.1
Server Port:            80

Document Path:          /index.html
Document Length:        238 bytes

Concurrency Level:      10
Time taken for tests:   20.998051 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Non-2xx responses:      102
Total transferred:      33558 bytes
HTML transferred:       24276 bytes
Requests per second:    4.76 [#/sec] (mean)
Time per request:       2099.805 [ms] (mean)
Time per request:       209.981 [ms] (mean, across all concurrent requests)
Transfer rate:          1.52 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1 1443 2777.3      5    9003
Processing:     6  128 539.4      21    2765
Waiting:        1  117 536.2       8    2740
Total:          8 1572 2889.3     27    9027
                                  |->主要是看这个TOTAL参数
Percentage of the requests served within a certain time (ms)
  50%     27
  66%     37
  75%   3015
  80%   3018
  90%   9004
  95%   9023
  98%   9025
  99%   9027
100%   9027 (longest request)


siege:????

9。基于名字的虚拟主机
1)配 置文件。
#vi /etc/httpd/conf.d/namevhost.conf
namevirtualhost 192.168.1.223

servername vhost1.szx.com
documentroot /www/html/vhost1


servername vhost2.szx.com
documentroot /www/html/vhost2

2)配置DNS服务器。
设置/etc /named.conf
设置/var/named/szx.com.zone
vhost1 IN A 192.168.1.223
vhost2 IN A 192.168.1.223
3)测试
lynx

lynx
实际例子1:

    ServerAdmin fad.163.com
    DocumentRoot /var/www/virtualhost/
    ServerName 
om
    ErrorLog logs/-error_log
    CustomLog logs/-access_log combined

实际例子2:

    ServerAdmin fad.163.com
    DocumentRoot /var/www/virtualhost/bbs.fad.com
    ServerName bbs.fad.com
    ErrorLog logs/bbs.fad.com-error_log
    CustomLog "|/usr/sbin/rotatelogs /var/log//bbs.%Y%m%d.log 86400 480" common  //该行是定制WEB日志,24小时一个文件;前提是系统已经安装 了rotatelogs软件.对以后分析日志很有益.
rotatelogs logfile [ rotationtime [ offset ]] | [ filesizeM ]
选项
logfile 它加上基准名就是日志文件名。如果logfile中包含’%',则它会被视为用于的strftime(3)的格式字串;否则,它会被自动加上以秒为单位 的.nnnnnnnnnn后缀。这两种格式都表示新的日志开始使用的时间。
rotationtime 日志文件回卷的以秒为单位的间隔时间
offset 相对于UTC的时差的分钟数。如果省略,则假定为0,并使用UTC时间。比如,要指定UTC时差为-5小时的地区的当地时间,则此参数应为-300。要指 定UTC时差为8小时的地区的当地时间,则此参数应为480。
filesizeM 指定回卷时以兆字节为单位的后缀字母M的文件大小,而不是指定回卷时间或时差。

       
        Options Indexes Includes
       

    ScriptAlias /cgi-bin/ /var/www/virtualhost/bbs.fad.com/cgi-bin/

10。基于IP的虚拟主机
1) 配置文件。
#vi /etc/httpd/conf.d/ipvhost.conf

serveradmin

documentroot /www/html/vhost3
servername vhost3.szx.com


serveradmin

documentroot /www/html/vhost4
servername vhost4.szx.com

2) 配置DNS服务器。
设置/etc/named.conf
设置/var/named/szx.com.zone
vhost3 IN A 192.168.1.223
vhost4 IN A 192.168.1.224
3)测试
lynx

lynx

11。基于端口的虚拟主机
1) 配置文件。
listen 192.168.1.223:8008
listen 192.168.1.223:8009
#vi /etc/httpd/conf.d/portvhost.conf

serveradmin

documentroot /www/html/vhost5


serveradmin

documentroot /www/html/vhost6

2) 测试
lynx

lynx


12。基于CGI的APACHE服务器配置
1) 修改/etc/httpd/conf/httpd.conf,保证有下面的内容。
LoadModule cgi_module modules/mod_cgi.so ---〉该行必须有
ScriptAlias /cgi-bin "/var/www/cgi-bin/"

  AllowOverride all
  Options Execcgi -Indexes---〉该行必须有
  Order allow,deny
  Ollow from all

Addhandler cgi-script .cgi .pl .sh--〉该行必须有
2)创建CGI网页
#vi /var/www/cgi-bin/test.cgi
  #!/usr/bin/perl
  print "Content-type:text/plain \n\n";
  print "hello szx is here!";
3)赋予 执行权限
chmod +x test.cgi
4)service httpd restart
5)测试:
lynx

13。基于PERL的APACHE服务器配置
1) 修改/etc/httpd/cond.d/perl.conf文件,将下面内容前的#去掉。
Alias /perl /var/www/perl

  SetHander perl-script
  PerlResponseHandler ModPerl::Registry
  PerOptions +ParseHeaders
  Options +ExecCGI

2) 创建PERL网页
mkdir /var/www/perl
vi /var/www/perl/test.pl
  #!/usr/bin/perl
  print "Content-type:text/plain \n\n";
  print "hello szxszx is here!";
3)赋予执行权限
chmod +x test.pl
4)service httpd restart
5)测试:
lynx

14。基于PHP的APACHE服务器配置
默 认情况下PHP安装完毕就已经支持PHP。


15。基于JSP的APACHE服务器配置
JSP 是SUN公司领头的一些公司创建的基于JAVA技术的动态网页技术标准。
APACHE默认不支持JSP程序。TOMCAT(TOM猫)支持 JSP。所以整合APACHE
+TOMCAT,让APACHE运行静态网页,TOMCAT运行动态JSP网页,以达到一定的效果。
-------------
步 骤:
1)安装J2DK软件:JAVA环境软件。
2)安装TOMCAT软件:运行JSP程序。
3)修改TOMCAT参数并启动 TOMCAT服务。
4)安装jakarta-tomcat-connectors-jk2连接器,整合APACHE和JK2。
5)整合 TOMCAT和APACHE
6)架设整合后的虚拟主机
7)测试
备注:APACHE我是RPM安装的。
----------------
1) 安装J2DK软件:JAVA环境软件。
#chmod +x jdk*
#sh jdk*
#ln -sf /usr/java/jdk1.5* /jdk
2)安装TOMCAT软件:运行JSP程序。
#tar zxvf apache-tomcat* -C /usr/local
#ln -sf /usr/local/apache-tomcat* /tomcat
3)修改TOMCAT参数并启动TOMCAT服务。
修改/tomcat/bin/startup.sh和/tomcat /bin/shutdown.sh
加入下面的参数,即环境变量。
export JAVA_HOME=/jdk
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$JAVA_HOME/lib
启动 TOMCAT:
#/tomcat/bin/startup.sh
停止TOMCAT:
#/tomcat/bin/shutdown.sh
测 试:
lynx

备注:
jsp文件放在/tomcat/webapps/ROOT/下面。
4)开始安装 jakarta-tomcat-connectors-jk2
tar xzfv jakarta-tomcat-connectors-* -C /tomcat
cd /tomcat/jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2/
./configure --with-apxs2=/usr/sbin/apxs
make
cd ../build/jk2/apache2/
/apache/bin/apxs -n jk2 -i mod_jk2.so
上条命令是将mod_jk2.so添加到apache2的modules中.
--------------
如 果不成功,可以手工做:
复制mod_jk2.so到/etc/httpd/modules下。
手工添加/etc/httpd/conf /httpd.conf里的LoadModule jk2_module modules/mod_jk2.so。
---------------
5)vi /etc/httpd/conf/httpd.conf
编辑配置文件在其中加入这个模块,保存退出
LoadModule jk2_module modules/mod_jk2.so
然后在这个目录新建一文件workers2.properties
 vi workers2.properties
文件内容如下:
  [channel.socket:172.16.100.239:8009]
  port=8009
  host=172.16.100.239
  [ajp13:172.16.100.239:8009]
  channel=channel.socket:172.16.100.239:8009
  [uri:/*]
  worker=ajp13:172.16.100.239:8009
  [uri:/examples/*]
  worker=ajp13:172.16.100.239:8009
当然以上内容中的172.16.100.239也可改成localhost
接 下来进入tomcat下的conf目录:
 cd /tomcat/conf/
修改server.xml文件
 vi server.xml
找到其中的中的项,我修改后的相关参数如下:
        reloadable="true" crossContext="true"/>
编辑后保存退出.
备注:把内容添加到项的下面的空白 处。
重启Apache和Tomcat后可以查看整合后的效果.
  /tomcat/bin/shutdown.sh
  /tomcat/bin/startup.sh
  /apache/bin/apachectl restart

6).架设整合后的虚拟主机
 vi /apache/conf/httpd.conf
在 httpd.conf文档末尾虚拟主机设置处加入以下内容:
NameVirtualHost *:80

    Documentroot /apache/htdocs


    DocumentRoot /tomcat/webapps/webdav
    ServerName ns1.kk.com


    DocumentRoot /tomcat/webapps/ROOT
    ServerName ns2.kk.com

 vi /tomcat/conf/server.xml
在server.xml文档 的......中间添加两段......< /Host>
内容如下:
             unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
                reloadable="true" crossContext="true"/>
                         directory="logs"  prefix="localhost_log." suffix=".txt"
            timestamp="true"/>
     

             unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
                reloadable="true" crossContext="true"/>
                         directory="logs"  prefix="localhost_log." suffix=".txt"
            timestamp="true"/>
     

重启Apache和Tomcat后可以查看架设的虚 拟主机的效果.
7)测试即可。

15.1 补充:200708sh
1)上传程 序文件到指定目录。
2)apache:
httpd.conf: 虚拟主机设置。
workers.properties:如果有多个TOMCAT运 行,分别设置它们的名字(用到几个就写几个)和它们的参数设置。
例子:
ps=/
worker.list=tomcat1
worker.tomcat1.port=8009
worker.tomcat1.host=127.0.0.1
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=100

3)TOMCAT:
完整复制一个原来用的TOMCAT。如TOMCAT_admin--->TOMCAT_aims
conf/server.xml:
Server port="8005" shutdown="SHUTDOWN" :改shutdown端口
Connector port="8080" :TOMCAT服务端口
Host name="localhost" appBase="/var/www/virtualhost/remo。。"程序文件路径
docBase= 程序文件目录

bin/catalina.sh:
JAVA_HOME=/usr/java/jdk1.5.0_02 JDK路径
CATALINA_HOME=/usr/local/Tomcat_Front :TOMCAT本身路径
JAVA_OPTS='-Xms256m -Xmx512m' 开始和最大JVM
4)重新启动APACHE 和TOMCAT,测试。
5)JAVA程序连接MYSQL的配置文件。
/var/www/virtualhost/remotedir/

 

16.APACHE日志系统:
1.
/var/log/httpd/*
/var/log/messages
/tomcat/logs/
2.
httpd.conf 里关于日志的控制字符:
LoadModule log_config_module modules/mod_log_config.so
ErrorLog logs/error_log
LogLevel warn
LogFormat "%h %l %u ......." combined
LogFormat "%h %l %u ......." common
LogFormat "%{referer}  ......." referer
LogFormat "%{User-agent}  ......." agent
备注:
%h。。。等为APACHE中的宏。combined,common....等为指定日至格式的关键字。

17. APACHE故障诊断:
1。 网络连接
2。网络服务
3。系统故障
排故步骤:
1。检查LINUX系统日志
2。本地连接
3。APACHE 服务设置
4。逐行添加新的命令???

------------END-------------

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