设为首页 收藏本站
查看: 976|回复: 0

[经验分享] RHEL6.4 apache搭建WEB网站,安装日志分析工具awstats

[复制链接]

尚未签到

发表于 2018-11-22 13:54:15 | 显示全部楼层 |阅读模式
  实验需求:
  搭建一个HTTP服务器,可通过域名www.jinjianjun.com访问,部署Awstats统计Http访问日志。
  

  一、搭建DNS(host与DNS任选一个即可)
  1)host文件
  192.168.100.1www.jinjianjun.com    www
  2)构建DNS(tarena.com)服务器
  1、安装软件包
  [root@http-server ~]# yum -y install bind bind-chroot
  2、修改主配置文件
  [root@http-server named]# vim /etc/named.conf   
  ...
  11         listen-on port 53 { 192.168.100.1; };  //本地IP
  ...
  17         allow-query     { any; };          //开放给任何人查询
  ……
  42 zone "jinjianjun.com" IN {               
  43         type master;
  44         file "jinjianjun.com.zone";            
  45 };
  46
  47 zone "100.168.192.in-addr.arpa" IN {
  48         type master;
  49         file "192.168.100.zone";
  50 };
  

  [root@http-server ~]# named-checkconf /etc/named.conf
  

3、修改数据库文件
  

[root@http-server ~]# cd /var/named/
  

[root@http-server named]# cp -p named.localhost jinjianjun.com.zone    //让named对配置文件有读取权限
  


  

[root@http-server named]# cat jinjianjun.com.zone         
  $TTL  1D
  @         IN SOA      jinjianjun.com. root.jinjianjun.com. (
                              20140141701; serial
                              1D; refresh
                              1H; retry
                              1W; expire
                              3H ); minimum
            NS        dns.jinjianjun.com.
  dns       A         192.168.100.1
  www       A         192.168.100.1
  

  [root@http-server named]# cp -p jinjianjun.com.zone 192.168.100.zone
  [root@http-server named]# cat 192.168.100.zone
  $TTL   1D
  @         IN SOA    jinjianjun.com.  root.jinjianjun.com. (
                              2014041701; serial
                              1D; refresh
                              1H; retry
                              1W; expire
                              3H ); minimum
            NS       dns.jinjianjun.com.
  1         PTR      www.jinjianjun.com.
  1         PTR      dns.jinjianjun.com.
  4、启动服务
  [root@http-server named]#service named start
  [root@http-server named]#chkconfig named on
  

  5.测试DNS解析
  [root@http-server named]# nslookup www.jinjianjun.com 192.168.100.1   //测试正向解析
  Server:192.168.100.1
  Address:192.168.100.1#53
  

  Name:www.jinjianjun.com
  Address: 192.168.100.1
  

  [root@http-server named]# nslookup 192.168.100.1 192.168.100.1     //测试反向解析
  Server:192.168.100.1
  Address:192.168.100.1#53
  

  1.100.168.192.in-addr.arpaname = www.jinjianjun.com.
  1.100.168.192.in-addr.arpaname = dns.jinjianjun.com.
  

  

  二、搭建http服务
  1、安装软件包
  [root@http-server ~]# rpm -q httpd
  httpd-2.2.15-26.el6.x86_64
  

  2、修改主配置文件
  [root@http-server ~]# vim /etc/httpd/conf/httpd.conf
  ……
  76 KeepAlive On              //建议开启此选项
  ...
  276 ServerName www.jinjianjun.com:80
  

  3.制作测试主页
  [root@http-server ~]# cat /var/www/html/index.html
  Test Page!!!
  

  

  4、启动服务
  [root@http-server ~]# service httpd start
  [root@http-server ~]# chkconfig httpd on
  

  

  5.测试:
  [root@http-server ~]# vim /etc/resolv.conf        //指向DNS服务器
  nameserver 192.168.100.1                          
  [root@http-server ~]# elinks -dump http://www.jinjianjun.com  //也可使用浏览器测试
                                    Test Page!!!
  

  

  三.部署Awstats统计Http访问日志
  1.安装软件
  [root@http-server Desktop]# tar zxvf awstats-7.1.tar.gz -C /usr/local/
  [root@http-server Desktop]# cd /usr/local/
  [root@http-server local]# mv awstats-7.1/ awstats
  [root@http-server Desktop]# cd /usr/local/awstats/tools/
  

  2、为站点建立配置文件
  [root@http-server tools]# ./awstats_configure.pl
  

  ----- AWStats awstats_configure 1.0 (build 1.9) (c) Laurent Destailleur -----
  This tool will help you to configure AWStats to analyze statistics for
  one web server. You can try to use it to let it do all that is possible
  in AWStats setup, however following the step by step manual setup
  documentation (docs/index.html) is often a better idea. Above all if:
  - You are not an administrator user,
  - You want to analyze downloaded log files without web server,
  - You want to analyze mail or ftp log files instead of web log files,
  - You need to analyze load balanced servers log files,
  - You want to 'understand' all possible ways to use AWStats...
  Read the AWStats documentation (docs/index.html).
  

  -----> Running OS detected: Linux, BSD or Unix
  

  -----> 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):
  > /etc/httpd/conf/httpd.conf             //web配置路径
  

  -----> Check and complete web server config file '/etc/httpd/conf/httpd.conf'
    Add 'Alias /awstatsclasses "/usr/local/awstats/wwwroot/classes/"'
    Add 'Alias /awstatscss "/usr/local/awstats/wwwroot/css/"'
    Add 'Alias /awstatsicons "/usr/local/awstats/wwwroot/icon/"'
    Add 'ScriptAlias /awstats/ "/usr/local/awstats/wwwroot/cgi-bin/"'
    Add '' directive
    AWStats directives added to Apache config file.
  

  -----> Update model config file '/usr/local/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                  //同意创建新的站点配置
  

  -----> 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.jinjianjun.com                                         //指定网站名称
  

  -----> 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):          //回车,接受默认配置文件
  >
  

  -----> Create config file '/etc/awstats/awstats.www.jinjianjun.com.conf'
   Config file /etc/awstats/awstats.www.jinjianjun.com.conf created.
  

  -----> Restart Web server with '/sbin/service httpd restart'
  Stopping httpd:                                            [  OK  ]
  Starting httpd:                                            [  OK  ]
  

  -----> 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:
  /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.jinjianjun.com
  Or if you have several config files and prefer having only one command:
  /usr/local/awstats/tools/awstats_updateall.pl now
  Press ENTER to continue...                                            //回车
  

  

  A SIMPLE config file has been created: /etc/awstats/awstats.www.jinjianjun.com.conf
  You should have a look inside to check and change manually main parameters.
  You can then manually update your statistics for 'www.jinjianjun.com' with command:
  > perl awstats.pl -update -config=www.jinjianjun.com
  You can also read your statistics for 'www.jinjianjun.com' with URL:
  > http://localhost/awstats/awstats.pl?config=www.jinjianjun.com
  

  Press ENTER to finish...                                               //回车,完成
  

  [root@http-server tools]# ls /etc/awstats/awstats.www.jinjianjun.com.conf
  /etc/awstats/awstats.www.jinjianjun.com.conf        //为站点www.jinjianjun.com新建的统计配置文件                                
  

  

  3、指定统计的目标日志文件
  [root@http-server tools]# vim /etc/awstats/awstats.www.jinjianjun.com.conf
  51 LogFile="/var/log/httpd/access_log"
  [root@http-server tools]# mkdir /var/lib/awstats        //根据配置文件建立数据目录
  

  4.将日志文件导入Awstats
  [root@http-server tools]# ./awstats_updateall.pl now   //手动导入
  [root@http-server tools]# crontab -e                   //使用计划任务每5分钟导入一次
  */5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now
  [root@http-server tools]# service crond restart
  [root@http-server tools]# chkconfig crond on
  

  5.浏览器测试
  http://www.jinjianjun.com/awstats/awstats.pl?config=www.jinjianjun.com
  

  6.给awstats设置访问权限
  [root@http-server tools]# vim /etc/httpd/conf/httpd.conf
  ……
  1029                        //在最后添加对此文件访问权限
  1030     AuthType Basic
  1031     AuthName "awstat access"
  1032     AuthUserFile "/etc/httpd/.authusers"
  1033     Require valid-user
  1034
  

  [root@http-server tools]# htpasswd -c /etc/httpd/.authusers awuser  //创建登录账号和密码
  New password:
  Re-type new password:
  Adding password for user awuser
  

  [root@http-server tools]# service httpd restart         //重启服务
  

  7.验证
  http://www.jinjianjun.com/awstats/awstats.pl?config=www.jinjianjun.com //出现登录窗口
  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-638306-1-1.html 上篇帖子: failed to execute goal org apache maven plugins maven surefire plugin 2.7 1 test 下篇帖子: 利用Apache+Subversion搭建Linux版本控制系统
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表