鸦鸦 发表于 2019-1-30 08:58:05

搭建web服务与awstats日志分析系统部署

  一.搭建web服务
  1. 使用母盘链接克隆虚拟机并修改ip等基本参数:
  克隆虚拟机,命名为web服务器,修改如下:
  ip a ##查看MAC地址
  # vi /etc/sysconfig/network-scripts/ifcfg-eth0 ##确保MAC地址与eth1一致
  DEVICE=eth0
  HWADDR=**************
  TYPE=Ethernet
  ONBOOT=yes
  NM_CONTROLLED=no
  BOOTPROTO=static
  IPADDR=192.168.100.150
  NETMASK=255.255.255.0
  GATEWAY=192.168.100.100
  DNS1=192.168.100.100
  :wq
http://s3.运维网.com/wyfs02/M01/86/52/wKioL1e77zOiImgMAAAKuQMMaWU097.jpg
http://s3.运维网.com/wyfs02/M02/86/52/wKioL1e77zTCM0b_AAA-CRHI7cY886.png
http://s3.运维网.com/wyfs02/M02/86/52/wKiom1e77zSA5HehAAAMUOx3yKE009.jpg
  # vim /etc/udev/rules.d/70-persistent-net.rules ##删除eth0行,并将eth1改为eth0
  # cat /etc/sysconfig/network ##设置主机的FQDN
  NETWORKING=yes
  HOSTNAME=www.linuxfan.cn
  :wq
  # reboot
  登录到192.168.100.100上添加主机的dns解析:
  # vim /var/named/chroot/var/named/linuxfan.cn.zone
  www IN A 192.168.100.150
  :wq
  # vim /var/named/chroot/var/named/192.168.100.arpa
  150 IN PTR www.linuxfan.cn.
  :wq
  /etc/init.d/named restart
  # nslookup
  > server 192.168.100.100
  Default server: 192.168.100.100
  Address: 192.168.100.100#53
  > www.linuxfan.cn
  Server: 192.168.100.100
  Address: 192.168.100.100#53
  Name: www.linuxfan.cn
  Address: 192.168.100.150
  > exit
http://s3.运维网.com/wyfs02/M00/86/52/wKioL1e77zWAO1koAAAicq9DOT0192.jpg
http://s3.运维网.com/wyfs02/M02/86/52/wKiom1e77zbj9gChAAAdr6p2nas231.png
http://s3.运维网.com/wyfs02/M00/86/52/wKiom1e77zagN4GVAAAK3_pNsn0656.jpg
http://s3.运维网.com/wyfs02/M02/86/52/wKioL1e77zezJrOYAAAK5s7oZCs506.png
http://s3.运维网.com/wyfs02/M00/86/52/wKioL1e77zegho_kAAAJdCU2ers744.jpg
http://s3.运维网.com/wyfs02/M01/86/52/wKioL1e77zjDAyBoAAANszf_4IA212.png
http://s3.运维网.com/wyfs02/M02/86/52/wKiom1e77zmS7JkGAAAMCvRutOc220.jpg
http://s3.运维网.com/wyfs02/M00/86/52/wKiom1e77znjTCx7AABKv01tjys231.png
  2. 下载软件并安装:登录192.168.100.100
  1)下载httpd
  # lftp ftp.linuxfan.cn
  lftp ftp.linuxfan.cn:~> cd tools/
  lftp ftp.linuxfan.cn:/tools> get httpd-2.2.17.tar.gz
  6597991 bytes transferred
  lftp ftp.linuxfan.cn:/tools> bye
  # ls httpd-2.2.17.tar.gz
  httpd-2.2.17.tar.gz
http://s3.运维网.com/wyfs02/M00/86/52/wKioL1e77zrgMk9wAAAUCg9Sm1o637.jpg
http://s3.运维网.com/wyfs02/M01/86/52/wKioL1e77zrThUVNAAAaNOY-s5I400.png
  2)解压并安装:
  mount /dev/cdrom /mnt
  yum -y install openssl-devel ##安装openssl-devel提供https的支持
  # tar zxvf httpd-2.2.17.tar.gz -C /usr/src/
  # cd /usr/src/httpd-2.2.17/
  # ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-cgi --enable-ssl && make &&make install
  # echo $? ##返回0为成功
  0
  # ls /usr/local/httpd/ ##安装成功
  bin cgi-bin error icons lib man modules
  build conf htdocs include logs manual
http://s3.运维网.com/wyfs02/M02/86/52/wKioL1e77zvhKaxfAAAPpzidx1k215.png
http://s3.运维网.com/wyfs02/M02/86/52/wKioL1e77zyQDGE2AAAJiiSvvWM663.jpg
http://s3.运维网.com/wyfs02/M01/86/52/wKiom1e77zzj-z7KAAALqhSetPI140.jpg
http://s3.运维网.com/wyfs02/M00/86/52/wKioL1e77z2SO4-mAAARdpPTexk884.png
http://s3.运维网.com/wyfs02/M02/86/53/wKiom1e77z6R5VysAAASI_jKCBg507.jpg
  3. 安装后优化和调整:
  # ln -s /usr/local/httpd/bin/* /usr/local/bin/ ##优化执行命令的路径
  # cp bin/apachectl /etc/init.d/httpd
  # vim /etc/init.d/httpd ##在开始位置修改bash和添加chkconfig和description;修改第82行实现执行命令时友好提示
  #!/bin/bash ##声明shell为bash
  # chkconfig: 35 85 15 ##在3和5运行级别开机启动,开机启动顺序为85,关机关闭顺序为15
  # description: A Scripts for apache httpd deamon!
  $HTTPD -k $ARGV &&echo "httpd is $ARGV complete." ##第82行
  :wq
  # ls -l /etc/init.d/httpd ##确认文件有执行权限,如果没有使用命令“chmod +x /etc/init.d/httpd”授权
  -rwxr-xr-x 1 root root 3496 1月 1 02:59 /etc/init.d/httpd
  # chkconfig --add httpd
  # chkconfig --list httpd
  httpd 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭
http://s3.运维网.com/wyfs02/M02/86/53/wKiom1e77z6R4s76AAAJAIXX22s699.jpg
http://s3.运维网.com/wyfs02/M02/86/52/wKioL1e77z-ABRl5AAAVoxNFtpc446.pnghttp://s3.运维网.com/wyfs02/M00/86/52/wKioL1e77z-jA-0GAAAUCMa6lbE041.png
http://s3.运维网.com/wyfs02/M00/86/53/wKiom1e770ChNXqQAAANlcK4Wo0916.png
http://s3.运维网.com/wyfs02/M02/86/52/wKioL1e770DTMpTEAAAMTUJTNf8305.jpg
http://s3.运维网.com/wyfs02/M02/86/52/wKioL1e770HjGpgPAAAOp11BrC0669.png
http://s3.运维网.com/wyfs02/M01/86/53/wKiom1e770HASvPIAAAK897PHNs959.png
http://s3.运维网.com/wyfs02/M01/86/53/wKiom1e770KhHNDRAAANj_PpdNI312.jpg
http://s3.运维网.com/wyfs02/M02/86/53/wKiom1e770KTrv4FAAANx1-6O1Y514.jpg
  4. 修改配置文件并启动服务:
  # vim /usr/local/httpd/conf/httpd.conf
  :set nu ##打印出行号
  88 ServerAdmin admin@linuxfan.cn ##修改管理员的邮箱
  98 ServerName www.linuxfan.cn:80 ##添加网站的FQDN
  :wq
  # /etc/init.d/httpd start ##启动服务
  httpd is start complete.
  # ps aux |grep httpd ##查看进程
  root 73341 0.0 0.5 54808 2520 ? Ss 03:21 0:00 /usr/local/httpd/bin/httpd -k start
  daemon 73342 0.0 0.4 54944 2000 ? S 03:21 0:00 /usr/local/httpd/bin/httpd -k start
  daemon 73343 0.0 0.4 54944 2000 ? S 03:21 0:00 /usr/local/httpd/bin/httpd -k start
  daemon 73344 0.0 0.4 54944 2000 ? S 03:21 0:00 /usr/local/httpd/bin/httpd -k start
  daemon 73345 0.0 0.4 54944 2000 ? S 03:21 0:00 /usr/local/httpd/bin/httpd -k start
  daemon 73346 0.0 0.4 54944 2000 ? S 03:21 0:00 /usr/local/httpd/bin/httpd -k start
  # netstat -utpln |grep httpd ##查看监听
  tcp 0 0 :::80 :::* LISTEN 73341/httpd
http://s3.运维网.com/wyfs02/M00/86/52/wKioL1e770OC5Fj3AAAT9Wn4_pQ425.png
http://s3.运维网.com/wyfs02/M00/86/53/wKiom1e770STdvURAAAQegOwTd4448.png
http://s3.运维网.com/wyfs02/M00/86/53/wKiom1e770Tiug4jAAAKB3XfdCc118.jpg
http://s3.运维网.com/wyfs02/M01/86/53/wKiom1e770WQws-VAAAk8c8Eyts699.png
http://s3.运维网.com/wyfs02/M02/86/53/wKiom1e770bhYXRoAAAbIqSpAsA113.jpg
http://s3.运维网.com/wyfs02/M01/86/53/wKiom1e770bROMrgAAAMOaSfMDU889.jpg
  5. 访问并测试:
  # yum -y install elinks ##在192.168.100.100上进行测试
  # vi /etc/resolv.conf
  ; generated by /sbin/dhclient-script
  nameserver 192.168.100.100 ##添加DNS服务器
  nameserver 192.168.1.1 ##不必修改,此dns服务器为桥接网卡自动获取的dns服务器目的是能上公网
  # elinks --dump http://www.linuxfan.cn ##成功完成实验
  It works!
  windows主机上使用IE或者chrome(谷歌),firefox(火狐)等浏览器访问:
  http://www.linuxfan.cn
http://s3.运维网.com/wyfs02/M02/86/52/wKioL1e770fyfiaHAAAQhdrId2w925.jpg
http://s3.运维网.com/wyfs02/M02/86/53/wKiom1e770jAOLAdAAATkWMgJu4729.png
http://s3.运维网.com/wyfs02/M00/86/53/wKiom1e770jzo2acAAAM3gBgGl0726.jpg
http://s3.运维网.com/wyfs02/M02/86/53/wKiom1e770nBjFg2AAANV337sA4878.jpg
http://s3.运维网.com/wyfs02/M01/86/53/wKiom1e770ryNOysAAAay4wOWS0507.jpg
  二.awstats日志分析系统部署
  1.确认apache已经安装:
  netstat -utpln |grep 80
http://s3.运维网.com/wyfs02/M00/86/52/wKioL1e770rREqpiAAAlInFimPc266.png
  2.下载与解压:
  lftp ftp.linuxfan.cn
  tar zxvf awstats-7.3.tar.gz
  mv awstats-7.3 /usr/local/awstats
http://s3.运维网.com/wyfs02/M01/86/53/wKiom1e770uQQ4QFAAAQNTfETpg661.png
http://s3.运维网.com/wyfs02/M02/86/53/wKiom1e770yzmu3MAAAR6XgthQc205.jpg
http://s3.运维网.com/wyfs02/M02/86/53/wKiom1e770yRJjArAAAdjK2J9yc801.png
http://s3.运维网.com/wyfs02/M02/86/52/wKioL1e7703wF9rZAAAO-9_YNyc999.png
http://s3.运维网.com/wyfs02/M00/86/53/wKiom1e7703wPJS9AAAOhf92zrg266.png
  3.配置awstats:
  cd /usr/local/awstats/tools
  chmod +x ./*
  ./awstats_configure.pl
  #####开始配置###
  a.当提示输入httpd.conf时输入并回车继续:
  /usr/local/httpd/conf/httpd.conf
  b.其他提示输入:y回车继续
  c.当提示配置文件名称时,输入:
  www.linuxfan.cn
  ####配置结束###
http://s3.运维网.com/wyfs02/M01/86/53/wKiom1e7706QQFNCAAAe6WbrOis669.png
http://s3.运维网.com/wyfs02/M02/86/53/wKiom1e7706QOE7OAAAPUKebA88532.png
http://s3.运维网.com/wyfs02/M02/86/53/wKiom1e770-AIY4cAAAgLmHUlzI927.jpg
  4.修改awstats配置文件:
  vim /etc/awstats/awstats.www.linuxfan.cn.conf
  LogFile="/usr/local/httpd/logs/access_log" ##修改第 50 行
  :wq
  mkdir /var/lib/awstats
http://s3.运维网.com/wyfs02/M00/86/53/wKiom1e771CyxVK4AAAKg1l6lyA224.jpg
http://s3.运维网.com/wyfs02/M00/86/52/wKioL1e771DT4tnPAAAMcNc2EeU301.png
http://s3.运维网.com/wyfs02/M01/86/52/wKioL1e771GiY3o6AAARtCi0SaM010.png
  5.设置计划任务并重启服务器:
  echo "*/5 * * * * /usr/local/awstats/tools/awstats_updateall.pl now" >/var/spool/cron/root ##每个5分更新一次
  /usr/local/awstats/tools/awstats_updateall.pl now ##执行首次更新
  /usr/local/httpd/bin/apachectl restart
  netstat -utpln |grep 80
  /etc/init.d/crond restart
  crontab -l
  chkconfig crond on
http://s3.运维网.com/wyfs02/M02/86/52/wKioL1e771HSRkzzAAAPDbaNUyk295.jpg
http://s3.运维网.com/wyfs02/M01/86/53/wKiom1e771KQsp1JAAAdCoEP07A275.jpg
  6. 访问测试:
  http://www.linuxfan.cn/awstats/awstats.pl?config=www.linuxfan.cn
  编写简化页面:
  vim /usr/local/httpd/htdocs/aws.html
  
  
  
  
  
  
  :wq
  访问:
  http://www.linuxfan.cn/aws.html
http://s3.运维网.com/wyfs02/M02/86/53/wKiom1e771OxXtaZAAAs8FdrVE8031.jpg
http://s3.运维网.com/wyfs02/M01/86/52/wKioL1e771TQ5xqaAAAYhJoZzlI210.png
http://s3.运维网.com/wyfs02/M02/86/52/wKioL1e771Tz02AiAAAWCCWHmDE520.jpg
http://s3.运维网.com/wyfs02/M02/86/53/wKiom1e771WxpFuLAAAvvMqrkZo223.jpg



页: [1]
查看完整版本: 搭建web服务与awstats日志分析系统部署