|
今日搭建httpd版本为:httpd-2.2.17.tar.gz 所用linux服务器为 :CentOs6.5
搭建准备
rpm -e httpd --nodeps && rpm -q httpd
2.卸载rpm方式安装的httpd包,及所属依赖关系。
rpm -e httpd httpd-manual webalizer subversion mod_python mod_ssl mod_perl system-config-httpd php php-cli php-ldap php-common mysql dovecot --nodeps (需要的情况下使用0-0)
3.将软件包,放入linux中 (本人习惯在root下)
开始搭建过程
tar -zxf httpd-2.2.17.tar.gz && cd httpd-2.2.17
2.配置
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
3.安装
make && make install
4.查看是否安装成功
ls /usr/local/httpd
优化路径
ln -s /usr/local/httpd/bin/* /usr/local/bin
查看是否优化成功
ls -l /usr/local/bin/httpd /usr/local/bin/apachectl
查看程序版本
httpd -v
添加http服务
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
编辑httpd
vim /etc/init.d/httpd
添加
1 #!/bin/sh
2 #chkconfig: 35 85 21
3 #description:apache httpd server
chkconfig --add httpd
chkconfig --list httpd
httpd 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭
基本配置
vim /usr/local/httpd/conf/httpd.conf
97 #ServerName www.benet.com
httpd -t
我遇到的错误:
(如果更改主机名为 benet, vim /etc/hosts 添加127.0.0.1 benet)
如果启动httpd报错
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName httpd not running, trying to start
解决问题的方法
vim /usr/local/httpd/conf/httpd.conf
98行 加入一句 ServerName localhost:80
service httpd restart
netstat -anpt | grep httpd
网页文档
vim /usr/local/httpd/htdocs/index.html
httpd的主配文件
vim /usr/local/httpd/conf/httpd.conf
主配文件(全局配置)
安装位置
29 ServerRoot "/usr/local/httpd"
监听端口
40 Listen 80
运行用户 组
65 User daemon
66 Group daemon
管理员的邮箱
88 ServerAdmin you@example.com
默认的主页文件
104 DocumentRoot "/usr/local/httpd/htdocs"
默认主页
165 <IfModule dir_module>
166 DirectoryIndex index.html (可修改 可添加)
167 </IfModule>
错误日志文件
186 ErrorLog "logs/error_log"
日志级别
193 LogLevel warn(警告)
常见日志
215 CustomLog "logs/access_log" common
包含另一个配置文件
397 #Include conf/extra/httpd-default.conf
查看web站点访问情况
tail -f /usr/local/httpd/logs/access_log
4.进程模式process 和 线程模式(thread)
进程是指在系统中正在进行的一个应用程序
线程是进程的一个实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位.线程自己基本上不拥有系统资源,只拥有一点在运行中必不可少的资源(如程序计数器,一组寄存器和栈),一个线程可以创建和撤销另一个线程;
如何调优:(进程模式 )
#<IfModule mpm_prefork_module>
StartServers 5 启动apache时候启动进程数量
MinSpareServers 不能大大 5 最小空闲(备用)进程 如当前空闲子进程数少于MinSpareServers 那么Apache将以最大每秒一个的速度产生新子进程
MaxSpareServers 10 最大空闲(备用)进程 如果当前有超过MaxSpareServers数量的空闲子进程,那么父进程将杀死多余的子进程。
ServerLimit 150 服务器允许配置的进程数上限
MaxClients 150 最大进程数
MaxRequestsPerChild 0
然后 使用ab 命令进行压测 ab -n 1000 -c 1000 httpd://localhost/ )-n 请求次数 -c 客户端数
区域配置项
114 <Directory /> /目录的开始
115 Options FollowSymLinks 允许使用符号链接
116 AllowOverride None 不允许隐含控制文件中的覆盖配置
117 Order deny,allow 访问控制策略的应用顺序
118 Deny from all 禁止任何人访问此区域
119 </Directory> /目录的结束
httpd.conf
KeepAlive On 打开持续性连接 即一个连接可以发送多个请求
MaxKeepAliveRequest 500 与KeepAlive有关,每一个持续性连接的最大请求数量 500
KeepAliveTimeout 持续性连接超时时间 一般不能设置太大,设置15秒差不多,太长系统等待时间太长影响服务器性能
httpd -l 看到prefork.c 即为进程模式
进程process 与线程(thread)
进程是指在系统中正在进行的一个应用程序
线程是进程的一个实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位.线程自己基本上不拥有系统资源,只拥有一点在运行中必不可少的资源(如程序计数器,一组寄存器和栈),一个线程可以创建和撤销另一个线程;
一 进程与线程区别与联系
(1) 划分尺度:线程更小,所以多线程程序并发性更高;
(2) 资源分配:进程是资源分配的基本单位,同一进程内多个线程共享其资源;
(3) 地址空间:进程拥有独立的地址空间,同一进程内多个线程共享其资源;
(4) 处理器调度:线程是处理器调度的基本单位;
(5) 执行:每个线程都有一个程序运行的入口,顺序执行序列和程序的出口,但线程不能单独执行,必须组成进程,一个进程至少有一个主线程。简而言之,一个程序至少有一个进程,一个进程至少有一个线程.
总结
线程
(1) 轻量级的进程
(2)进程有独立的地址空间,线程没有
(3) 线程不能独立存在,线程有进程创建
(4) 相对连说,线程消耗的cpu和内存 小于进程,但是进程更稳定
如何调优:(进程模式 )(prefork 预创建模式 预先派生模式)
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
#<IfModule mpm_prefork_module>
StartServers 5 启动apache时候启动进程数量
MinSpareServers 不能大大 5 最小空闲(备用)进程 如当前空闲子进程数少于MinSpareServers 那么Apache将以最大每秒一个的速度产生新子进程
MaxSpareServers 10 最大空闲(备用)进程 如果当前有超过MaxSpareServers数量的空闲子进程,那么父进程将杀死多余的子进程。
ServerLimit 150 服务器允许配置的进程数上限
MaxClients 150 最大进程数
MaxRequestsPerChild 0
空闲子进程是指没有正在处理请求的子进程。
调优:(为修改该文件,然后 使用ab 命令进行压测 ab -n 1000 -c 1000 httpd://localhost/ )-n 请求次数 -c 客户端数
这时候,会看见:
[iyunv@localhost extra]# ab -n 1000 -c 1000 http://localhost/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
apr_socket_recv: Connection reset by peer (104)
调优,在每一行后面加上0
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
StartServers 50
MinSpareServers 50
MaxSpareServers 100
ServerLimit 1500
MaxClients 1500
MaxRequestsPerChild 0
</IfModule>
测试 就有结果了
ab -n 1000 -c 1000 http://localhost/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: Apache/2.2.17
Server Hostname: localhost
Server Port: 80
Document Path: /
Document Length: 44 bytes
Concurrency Level: 1000
Time taken for tests: 3.161 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 294000 bytes
HTML transferred: 44000 bytes
Requests per second: 316.38 [#/sec] (mean)
Time per request: 3160.770 [ms] (mean)
Time per request: 3.161 [ms] (mean, across all concurrent requests)
Transfer rate: 90.84 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 65 41.5 54 133
Processing: 40 654 572.4 620 3028
Waiting: 40 653 572.3 619 3028
Total: 41 719 602.2 662 3161
Percentage of the requests served within a certain time (ms)
50% 662
66% 737
75% 1506
80% 1516
90% 1541
95% 1553
98% 1562
99% 1564
100% 3161 (longest request)
|
|