Apache安装和使用

Apache的特点:

(1.)开放源代码:

Apache服务程序由全世界的众多开发者共同维护,并且任何人都可以自由使用。

(2.)跨平台应用:

Apache服务器可以运行在绝大多数软硬件平台上,所有unix系统都可以运行,也可以良好地运行在大多数windows平台中

(3.)支持各种web编程语言:

支持perl、php、python、jave等,甚至微软的asp技术也可以在apache服务器中使用

(4.)模块化设计:

为apache服务器带来了良好的扩展性,可以编写标准的模块程序,从而添加apache本身并不具有的其他功能

(4.)运行非常稳定:

可用于构建具有大负载访问量的web站点

(4.)良好的安全性:

具有相对较好的安全性,这是开源软件共有的特性

httpd的程序版本:
httpd 1.3:官方已经停止维护;
httpd 2.0:
httpd 2.2:
httpd 2.4:目前最新稳定版;

httpd的功能特性:
CGI:Common Gateway Interface
虚拟主机:IP,PORT, FQDN
反向代理
负载均衡
路径别名
丰富的用户认证机制
basic
digest
支持第三方模块


安装httpd:
rpm包:CentOS 发行版中直接提供;
编译安装:定制新功能,或其它原因;

CentOS 6:httpd-2.2
程序环境:
配置文件:
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf
服务脚本:
/etc/rc.d/init.d/httpd
脚本配置文件:/etc/sysconfig/httpd
主程序文件:
/usr/sbin/httpd
/usr/sbin/httpd.event
/usr/sbin/httpd.worker
日志文件:
/var/log/httpd:
access_log:访问日志
error_log:错误日志
站点文档:
/var/www/html
模块文件路径:
/usr/lib64/httpd/modules
服务控制和启动:
chkconfig httpd on|off
service {start|stop|restart|status|configtest|reload} httpd


CentOS 7:httpd-2.4
程序环境:
配置文件:
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/.conf
模块相关的配置文件:/etc/httpd/conf.modules.d/
.conf
systemd unit file:
/usr/lib/systemd/system/httpd.service
主程序文件:
/usr/sbin/httpd
httpd-2.4支持MPM的动态切换;
日志文件:
/var/log/httpd:
access_log:访问日志
error_log:错误日志
站点文档:
/var/www/html
模块文件路径:
/usr/lib64/httpd/modules

服务控制:
systemctl enable|disable httpd.service
systemctl {start|stop|restart|status} httpd.service

安装httpd服务器

1.准备工作、安装gcc*、make编译工具,如果rpm方式已安装过httpd,为了避免冲突先将其卸载

rpm  -e httpd --nodeps

2.安装依赖环境

yum install -y apr-* cyrus-sas* expat-* libdb-* openldap-* pcre-* gcc*

3. 解压源码包,配置安装功能

tar xzvf httpd-2.4.25.tar.gz	
./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd  --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

–prefix:指定安装的目录,如/usr/local/httpd
–enable-so:启用动态加载模块支持,使httpd具备进一步扩展功能的能力
–enable-rewrite:启用网页地址重写功能,用于网站优化及目录迁移维护
–enable-charset-lite:启动字符集支持,以便支持使用各种字符集编码的网页
–enable-cgi:启用cgi脚本程序支持,便于扩展网站的应用访问能力
–disable-proxy:禁用proxy模块,make报错添加,不禁用需要安装apr和apr-util

4.编译并编译安装

make && make install

安装成功后,安装目录下子目录的用途和作用
 /usr/local/httpd/bin:存放httpd服务的各种执行程序文件,包括主程序httpd、服务控制工具apachectl等
 /usr/local/httpd/cgi-bin:存放各种cgi程序文件
 /usr/local/httpd/logs:存放httpd服务的日志文件
 /usr/local/httpd/conf:存放httpd服务的各种配置文件,包括主配置文件httpd.conf、增强配置子目录extra等
 /usr/local/httpd/htdocs:存放网页文档、包括默认首页文件index.html等
 /usr/local/httpd/modules:存放httpd服务的各种模块文件

5. 优化执行路径
通过编译安装的httpd服务,程序路径并不在默认的搜索路径中,为了该服务在使用时更加方便,为相关程序添加链接并通过软连接的方式查看Apache的版本

ln -sv  /usr/local/httpd/bin/* /usr/local/bin/
httpd -v 

6. 添加httpd系统服务,通过chkconfig命令添加为系统服务,然后就可以由systemctrl进行管理

cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd	//将Apache的控制脚本复制到/etc/init.d/目录下
sed -i '3c #chkconfig:35 85 21' httpd //服务识别参数
chkconfig --add httpd //将httpd服务加入到开机自启
chkconfig --list httpd //查看到httpd每次运行级别时3,5时,httpd将开启自启

httpd.conf全局配置文件

ServerRoot “/usr/local/httpd” 设置httpd服务器根目录
 
Listen 80 设置服务器监听的端口号,默认80
 
User daemon 设置运行进程用户,默认daemon
 
Group daemon 设置运行进程组,默认daemon
 
ServerAdmin www.itynn.com 设置管理员邮箱地址
 
ServerName www.example.com:80 设置站点的完整主机名(主机名+域名)
 
DocumentRoot “/usr/local/httpd/htdocs” 设置网站的根目录,也就是网页的实际存放目录
 
DirectoryIndex index.html 设置网站默认索引页,多个首页空格隔开
 
ErrorLog “logs/error_log” 错误日志存放路径
 
LogLevel warn 记录日志的级别,默认warn(警告)
 
CustomLog “logs/access_log” common
 
PidFile 设置访问日志路径,使用类型为common(通用格式)
 
AddDefaultCharset 设置网页默认使用字符集编码,如utf-8
 
Include 包含另一个配置文件的内容,便于维护

区域配置文件

<Directory />			//定义根目录区域的开始		
    AllowOverride None		//不允许隐含控制文件中的覆盖配置
    Options FollowSymLinks		//控制选项,允许使用符合连接,能否查看目录列表
    Require all denied			//禁止任何人访问此区域
</Directory>			//定义根区域的结束

部署AWStats日志分析系统根据网站访问情况进行统计
 
 

在httpd服务器的访问日志文件access_log中,记录了大量的客户端访问信息,通过分析这些信息,可以及时了解web站点的访问情况。
那么接下来将介绍安装AWStats日志分析系统,以完成自动化的日志分析与统计工作。
 
 
部署AWStats分析系统
 
 
AWStats是使用Perl语言开发的一款开源日志分析系统,它不仅可用来分析Apache网站服务器的访问日志,也可以用来分析Samba、Vsftpd、IIS等服务的日志信息。结合crond等计划任务服务,可以对不断的增长日志内容定期进行分析。
 
 
AWStats的软件包可以从官方网站进行下载:
AWStats最新下载地址https://jaist.dl.sourceforge.net/project/awstats/AWStats/7.7/awstats-7.7.zip
1.安装AWStats软件包
 
将软件包解压到httpd服务器的/local/目录即可

 tar zxvf awstats-7.7.tar.gz 
  mv awstats-7.7 /usr/local/awstats

 

2.为要统计的站点建立配置文件
 
AWStats系统支持统计多个网站的日志文件,通常以网站名称来区分不同的站点,因此,在执行日志文件分析之前,需要为每个web站点建立站点统计配置文件,借助于AWStats系统提供的awstats_configure.pl脚本可以简化创建过程。
 
  首先切换到awstats/tools目录下,并执行其中的awstats_configure.pl脚本。

cd /usr/local/awstats/tools/
perl awstats_configure.pl   
3. Perl脚本awstats_configure.pl安装过程(以下内容引用AWStats英文使用说明)

(1)
-----> Running OS detected: Linux, BSD or Unix
Warning: AWStats standard directory on Linux OS is ‘/usr/local/awstats’.
If you want to use standard directory, you should first move all content
of AWStats distribution from current directory:
/opt/awstats
to standard directory:
/usr/local/awstats
And then, run configure.pl from this location.
Do you want to continue setup from this NON standard directory [yN] ?

这时选择y回车。

(2)
-----> Check for web server install

Enter full config file path of your Web server.
Example: /etc/httpd/httpd.conf
Example: /usr/local/apache2/conf/httpd.conf
Example: c:\Program files\apache group\apache\conf\httpd.conf
Config file path (‘none’ to skip web server setup):

第一次使用请输入Apache的httpd.conf路径,例如/var/www/conf/httpd.conf
以后如果再使用perl awstats_configure.pl生成配置文件,则可以输入none跳过。

(3)
-----> Check and complete web server config file ‘/opt/sina/apache/conf/httpd.conf’
Warning: You Apache config file contains directives to write ‘common’ log files
This means that some features can’t work (os, browsers and keywords detection).
Do you want me to setup Apache to write ‘combined’ log files [y/N] ?

选择y,将日志记录方式由CustomLog /yourlogpath/yourlogfile common改为更详细的CustomLog /yourlogpath/yourlogfile combined

(4)
-----> Update model config file ‘/opt/awstats/wwwroot/cgi-bin/awstats.model.conf’
File awstats.model.conf updated.

-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ?

创建一个新的配置文件,选择y

(5)
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
>

输入站点名称,例如www.ityunn.com

(6)
-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
>

输入AWStats配置文件存放路径,一般直接回车则使用默认路径/etc/awstats

(7)
-----> Add update process inside a scheduler
Sorry, configure.pl does not support automatic add to cron yet.
You can do it manually by adding the following command to your cron:
/opt/awstats/wwwroot/cgi-bin/awstats.pl -update -config=sina
Or if you have several config files and prefer having only one command:
/opt/awstats/tools/awstats_updateall.pl now
Press ENTER to continue…

按回车键继续

(8)
A SIMPLE config file has been created: /opt/awstats/etc/awstats.sina.conf
You should have a look inside to check and change manually main parameters.
You can then manually update your statistics for ‘sina’ with command:

perl awstats.pl -update -config=sina
You can also read your statistics for ‘sina’ with URL:
http://localhost/awstats/awstats.pl?config=www.ityunn.com

Press ENTER to finish…

按回车键结束

4.修改/etc/awstats/awstats.www.ityunn.com.conf配置
vim  /etc/awstats/awstats.www.ityunn.com.conf 
在/,在之后输入要搜索的内容LogFile="然后按回车键,找到LogFIle="/var/www/logs/access_log"改为要分析的Apache日志路径和文件名 然后在/,在hi后输入DirData="/var/lib/awstats"默认没有创建这个文件,需要自己手动创建。否则等会更新失败(DirData用来指定数据库目录,LogFile用来指定日志路径)

 
5.更新分析报告

 perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.ityunn.com -update 

如果出现以下错误提示,很大可能是Apache的Log文件中存在以前CustomLog /yourlogpath/yourlogfile common生成的日志,删除掉这些行的日志即可:
This means each line in your web server log file need to have “combined log format” like this:
111.22.33.44 - - [10/Jan/2001:02:14:14 +0200] “GET / HTTP/1.1” 200 1234 “http://www.fromserver.com/from.htm” “Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)”

清空日志:# echo -n > /var/www/logs/access_log ;

到这里有关Apache2.4版本源码编译安装以及AWStats日志系统的安装使用,演示完毕了!!!
希望对你有所帮助!!!提前恭祝小年快乐!!!!再见!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值