简介:
在Internet 网络环境中,Web服务无疑是最为主流的应用系统,有了WEB站点,企业可以充分展示自己的产品,公司,宣传自己的企业形象,提供各种网上交流,业务平台等。
Apache起源:源于 A Patchy Server(基于原有web服务程序的代码进行修改(补丁)后形成的服务器程序),最新的名称为 “Apache HTTP Server” ,软件名称 httpd
1995年,发布1.0 由 Apache Group 管理及维护
1999年,在Apache Group基础上成立Apache 软件基金会(Apache Software Foundation,ASF) 由 ASF 管理及维护
Apache 软件基金会软件:
Apache
Tomcat
Hadoop
官方站点:http://httpd.apache.org/
各种Web软件的市场份额统计:http://news.netcraft.com/
安装方式一:简单,快速,适用于实验环境
[[email protected] ~]# yum -y install httpd
安装方式二:稳定,功能全,适用于生产环境
安装前卸载rpm格式的软件包
[[email protected] ~]# rpm -q httpd
httpd-2.2.15-39.el6.x86_64
[[email protected] ~]# rpm -e httpd --nodeps
[[email protected] ~]# rpm -q httpd
package httpd is not installed
解压软代码软件,配置,编译,安装
[[email protected] ~]# tar xf httpd-2.2.31.tar.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/httpd-2.2.31/
[[email protected] httpd-2.2.31]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi && make && make install
--prefix=/usr/local/httpd 指定服务程序安装目录
--enable-so 启用动态加载模块功能
--enable-rewrite 启用网页重写
--enable-charset-lite 启动字符集支持
--enable-cgi 启用CGI脚本支持
[[email protected] httpd-2.2.31]# ls /usr/local/httpd/
bin build cgi-bin conf error htdocs icons include logs man manual modules
bin 存放执行程序
cgi-bin 存放CGI程序
conf 存放配置文件
htdocs 存放网页文件,例如:html php 等
lib 存放执行程序关联库文件
logs 存放日志文件
man 存放帮助手册文件
modules 存放模块
优化执行路径,使用软链接(将执行程序链接到其他目录下)或者修改默认搜索路径:
[[email protected] httpd-2.2.31]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
[[email protected] httpd-2.2.31]# ls -l /usr/local/bin/httpd /usr/local/bin/apachectl
lrwxrwxrwx 1 root root 30 8月 11 22:52 /usr/local/bin/apachectl -> /usr/local/httpd/bin/apachectl
lrwxrwxrwx 1 root root 26 8月 11 22:52 /usr/local/bin/httpd -> /usr/local/httpd/bin/httpd
查询httpd 服务程序信息
[[email protected] httpd-2.2.31]# httpd -v
Server version: Apache/2.4.16 (Unix)
Server built: Aug 11 2015 22:42:13
[[email protected] httpd-2.2.31]# httpd -l
Compiled in modules:
core.c
mod_so.c
http_core.c
worker.c
添加httpd系统服务
[[email protected] httpd-2.2.31]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[[email protected] httpd-2.2.31]# vi /etc/init.d/httpd
#!/bin/sh
#chkconfig:35 80 20
#description:APACHE HTTPD SERVER
定义服务启动顺序与关闭顺序及描述信息
[[email protected] httpd-2.2.31]# chmod +x /etc/init.d/httpd
[[email protected] httpd-2.2.31]# chkconfig --add httpd
[[email protected] httpd-2.2.31]# chkconfig --list httpd
httpd 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭
[[email protected] httpd-2.2.31]# service httpd start
服务启动问题1:
AH00557: httpd: apr_sockaddr_info_get() failed for RHEL6-Server1
AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1. Set the ‘ServerName‘ directive globally to suppress this message
[[email protected] ~]# vim +98 /usr/local/httpd/conf/httpd.conf
将#注释去掉,更改为:
ServerName www.example.com:80
重新启动apache
[[email protected] ~]# service httpd stop
[[email protected] ~]# service httpd start
[[email protected] ~]# netstat -anpt |grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 86307/httpd
服务启动问题2:
/usr/local/apache/bin/httpd: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
有很多so模块在/usr/local/lib目录下,所以在/etc/ld.so.conf中加入/usr/local/lib这一行
[[email protected] ~]# vi /etc/ld.so.conf
/usr/local/lib
[[email protected] ~]# /sbin/ldconfig -v
现在您已经将 Apach安装在 /usr/local/apache。本安装支持可装载模块
和标准的 MPM prefork。之后,可以使用如下命令启动 Apache 服务器:
[[email protected] ~]# /usr/local/httpd/bin/apachectl start
WEB站点部署:
[[email protected] ~]# apachectl -t
Syntax OK
[[email protected] ~]# cat /usr/local/httpd/htdocs/index.html
<html><body><h1>It works!</h1></body></html>
[[email protected] ~]# service httpd stop; service httpd start
浏览器:http://192.168.200.211
[[email protected] ~]# tail -f /usr/local/httpd/logs/access_log
192.168.200.1 - - [11/Aug/2015:23:06:12 +0800] "GET / HTTP/1.1" 200 45
192.168.200.1 - - [11/Aug/2015:23:06:12 +0800] "GET /favicon.ico HTTP/1.1" 404 209
全局配置参数:作用于整个web服务
ServerRoot: 服务目录,在httpd.conf中配置文件时,如果使用的相对路径,则认为是在服务根目录下
ServerAdmin: 管理员邮箱
User: 运行服务的用户身份 daemon
Group: 运行服务的组身份 daemon
ServerName: 网站服务器的域名
DocumentRoot: 网页文档的根目录
Listen: 监听的IP地址、端口号TCP 80
PidFile: 保存httpd进程PID号的文件
DirectoryIndex: 默认的索引页文件
ErrorLog: 错误日志文件的位置
CustomLog: 访问日志文件的位置
LogLevel: 记录日志的级别,默认为warn(警告)
Timeout: 网络连接超时,默认为300秒
KeepAlive: 是否保持连接,可选On或Off
MaxKeepAliveRequests: 每次连接最多请求文件数
KeepAliveTimeout: 保持连接状态时的超时时间
Include: 需要包含进来的其他配置文件
CharsetDefault: 设置默认的字符集编码
区域配置项:
<Directory /> 定义/ 区域的开始
Options FollowSymLinks 允许使用符号链接
AllowOverride None 不允许隐含控制文件中覆盖配置
Order deny,allow 定义访问控制应用顺序
Deny from all 禁止任何人访问
</Directory> 定义/ 区域的结束
网站访问情况统计:部署AWSTATS分析系统
下载地址:
http://mirrors.cnnic.cn/apache//httpd/httpd-2.2.31.tar.gz
http://jaist.dl.sourceforge.net/project/awstats/AWStats/7.3/awstats-7.3.zip
AWSTATS 通过 Perl 通过语言编写的一款开源日志分析系统,可以分析apache samba vsftpd IIS等日志,支持同时分析多个WEB站点,以网站名称来区分不同的站点
[[email protected] ~]# unzip awstats-7.3.zip
[[email protected] ~]# mv awstats-7.3 /usr/local/awstats
[[email protected] ~]# cd /usr/local/awstats/tools/
[[email protected] tools]# chmod +x awstats_configure.pl
[[email protected] tools]# ./awstats_configure.pl
输入站点主配置文件位置:
/usr/local/httpd/conf/httpd.conf
将日志类型更改为,combined
y
确认创建站点配置文件
y
指定目标网站名称
www.crushlinux.com
按照缺省,接受设置
回车
回车
回车
修改站点配置文件
[[email protected] tools]# vim /etc/awstats/awstats.www.crushlinux.com.conf
51 LogFile="/usr/local/httpd/logs/access_log"
[[email protected] ~]# mkdir /var/lib/awstats
执行日志分析,并设置计划任务
[[email protected] ~]# cd /usr/local/awstats/tools/
[[email protected] tools]# chmod +x awstats_updateall.pl
[[email protected] tools]# ./awstats_updateall.pl now
Running ‘"/usr/local/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=www.crushlinux.com -configdir="/etc/awstats"‘ to update config www.crushlinux.com
Create/Update database for config "/etc/awstats/awstats.www.crushlinux.com.conf" by AWStats version 7.3 (build 20140126)
From data in log file "/usr/local/httpd/logs/access_log"...
Phase 1 : First bypass old records, searching new record...
Searching new records from beginning of log file...
Jumped lines in file: 0
Parsed lines in file: 4
Found 0 dropped records,
Found 0 comments,
Found 0 blank records,
Found 4 corrupted records,
Found 0 old records,
Found 0 new qualified records.
[[email protected] tools]# crontab -e
*/1 * * * * /usr/local/awstats/tools/awstats_updateall.pl now
[[email protected] tools]# service crond restart
[[email protected] tools]# chkconfig --level 35 crond on
浏览器:http://192.168.200.211/awstats/awstats.pl?config=www.crushlinux.com
[[email protected] tools]# vi /usr/local/httpd/htdocs/awb.html
<html>
<head>
<meta http-equiv=refresh content="0;
http://192.168.200.211/awstats/awstats.pl?config=www.crushlinux.com">
</head>
<body></body>
</html>
[[email protected] tools]# /etc/init.d/httpd stop
[[email protected] tools]# /etc/init.d/httpd start