apache的安装与配置
安装
01)下载httpd-2.2.27.tar.gz
02)解压:tar xf httpd-2.2.27.tar.gz
然后进入解压的文件查看INSTALL和RAEDME
03)直接make会出错,然后进行编译(也会有问题,这时候yum -y install zlib zlib-devel即可解决),然后进行编译:
./configure --prefix=/application/apache2.2.27 \ 安装路径 --enable-deflate \ 压缩(为了发送给客户端的时候更快一点,但是消耗CPU) --enable-expires \ 过期 --enable-headers \ 提供对http请求头的控制 --enable-modules=most \ 激活大多数模块 --enable-so \ --with-mpm=worker \ 选择work模式(进程下的线程提供服务)还有profork模式(直接用进程提供服务,更安全稳定,但是消耗内存) --enable-rewrite 伪静态
04)make&makeinstall
05)ln -s /application/apache2.2.27/ /application/apache
06)/application/apache/bin/apachectl -t
/application/apache/bin/apachectl start
lsof -i :80
Netstat -ntlup|grep 80
Ps -ef |grep httpd
07)curl 本机ip 如果不能访问进行下面的检查与操作:
/etc/init.d/iptables stop
setenforce 0
然后看看端口起来没
08)查看配置文件
[[email protected] ~]# cd /application/apache [[email protected] apache]# ls bin build cgi-bin conf error htdocs icons include lib logs man manual modules [[email protected] apache]# cd conf/ [[email protected] conf]# ls extra httpd.conf magic mime.types original [[email protected] conf]# grep -i documentroot httpd.conf # DocumentRoot: The directory out of which you will serve your DocumentRoot "/application/apache2.2.27/htdocs" 查看主配文件的存放数据的目录(index.html) # This should be changed to whatever you set DocumentRoot to. # access content that does not live under the DocumentRoot. 去掉注释查看主配文件 [[email protected] conf]# grep -Ev "#|^$" httpd.conf > httpd.conf.ori [[email protected] conf]# cd extra/ [[email protected] extra]# ls httpd-autoindex.conf httpd-info.conf httpd-mpm.conf httpd-userdir.conf httpd-dav.conf httpd-languages.conf httpd-multilang-errordoc.conf httpd-vhosts.conf httpd-default.conf httpd-manual.conf httpd-ssl.conf
深入解析主配文件
[[email protected] conf]# cat httpd.conf.ori ServerRoot "/application/apache2.2.27"软件安装路径,也是服务器的根目录 #监听的端口 Listen 80 <IfModule !mpm_netware_module> <IfModule !mpm_winnt_module> User daemon Group daemon </IfModule> </IfModule> ServerAdmin [email protected] 管理员邮箱 DocumentRoot "/application/apache2.2.27/htdocs"默认站点目录 <Directory /> Options FollowSymLinks AllowOverride None Order deny,allow Deny from all </Directory> <Directory "/application/apache2.2.27/htdocs"> 这个配置只对默认站点生效,如果有虚拟主机,需要复制这一段到主配文件最后,进行配置,对于option里面的indexes(没有首页展示的目录,一般去掉,不对外展示目录结构) Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> <IfModule dir_module>指定访问首页 DirectoryIndex index.html </IfModule> <FilesMatch "^\.ht">文件匹配 Order allow,deny Deny from all Satisfy All </FilesMatch> ErrorLog "logs/error_log"设置错误日志 LogLevel warn 设置日志级别 <IfModule log_config_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common <IfModule logio_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio </IfModule> CustomLog "logs/access_log" common </IfModule> <IfModule alias_module> ScriptAlias /cgi-bin/ "/application/apache2.2.27/cgi-bin/" </IfModule> <IfModule cgid_module> </IfModule> <Directory "/application/apache2.2.27/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory> DefaultType text/plain <IfModule mime_module> TypesConfig conf/mime.types AddType application/x-compress .Z AddType application/x-gzip .gz .tgz </IfModule> Include conf/extra/httpd-mpm.conf Include conf/extra/httpd-vhosts.conf <IfModule ssl_module> SSLRandomSeed startup builtin SSLRandomSeed connect builtin </IfModule>
01)建立目录配置apache基于域名虚拟主机
[[email protected] var]# mkdir -p /var/html/{www,blog,bbs} [[email protected] var]# touch /var/html/{www,blog,bbs}/index.html [[email protected] var]# for name in www blog bbs;do echo "http://$name.my.org" > /var/html/$name/index.html;done [[email protected] html]# cat bbs/index.html http://bbs.my.org [[email protected] html]# cat blog/index.html http://blog.my.org [[email protected] html]# cat www/index.html http://www.my.org
02)在http-vhosts.conf里面配置
[[email protected] conf]# ls extra httpd.conf httpd.conf.ori magic mime.types original [[email protected] conf]# cd extra/ [[email protected] extra]# ls httpd-autoindex.conf httpd-info.conf httpd-mpm.conf httpd-userdir.conf httpd-dav.conf httpd-languages.conf httpd-multilang-errordoc.conf httpd-vhosts.conf httpd-default.conf httpd-manual.conf httpd-ssl.conf httpd-vhosts-name.conf [[email protected] extra]# cat httpd-vhosts.conf # # Virtual Hosts # NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/var/html/www" ServerName www.my.org ServerAlias my.org ErrorLog "logs/www-error_log" CustomLog "logs/www-access_log" common </VirtualHost> <VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/var/html/blog" ServerName blog.my.org ErrorLog "logs/blog-error_log" CustomLog "logs/blog-access_log" common </VirtualHost> <VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/var/html/bbs" ServerName bbs.my.org ErrorLog "logs/bbs-error_log" CustomLog "|/usr/local/sbin/cronolog /app/logs/access_bbs_%Y%m%d.log" combined </VirtualHost> [[email protected] extra]#
03)在主配文件中打开虚拟主机
Include conf/extra/httpd-mpm.conf Include conf/extra/httpd-vhosts.conf
04)检查语法和发布
/application/apache/bin/apachectl -t /application/apache/bin/apachectl graceful 注:做以上操作的时候可能会有延迟和报错(fully qualified domian name FQDN),解决如下: [[email protected] ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 httpd ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 [[email protected] ~]# [[email protected] conf]# vim httpd.conf #ServerName www.example.com:80 ServerName 127.0.0.1:80
05)当访问的时候会报403错误,因为没有dns解析,所以可以进行本地解析
06)之后还是不能访问,因为没有配置虚拟主机访问站点
解决:在主配文件最后加
<Directory "/var/html"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory>
07)到此就可以访问了
08)基于IP的虚机主机、基于不同端口的虚拟主机
配置apache轮询日志
01)安装轮询软件
tar zxvf cronolog-1.6.2.tar.gz cd cronolog-1.6.2 ./configure make&make install pwd
02)建立日志目录
mkdir -p /app/logs
03)在子配文件中配置
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/var/html/bbs" ServerName bbs.my.org ErrorLog "logs/bbs-error_log" CustomLog "|/usr/local/sbin/cronolog /app/logs/access_bbs_%Y%m%d.log" combined </VirtualHost>
04)检查语法和发布
/application/apache/bin/apachectl -t /application/apache/bin/apachectl graceful
05)此时访问网站就会生成日志
06)其他日志轮询工具rotatelog
07)不记录图片的日志
在主配文件中
<FilesMatch "\.(css|js|gif|jpg|ico|swf)"> SetEvn IMAG 1 </FilesMatch> |
在虚拟主机配置文件http-vhosts.conf的日志配置中
CustomLog "|/usr/local/sbin/cronolog /app/logs/access_bbs_%Y%m%d.log" combined evn=!IMAG |
08)RS服务器不记录负载均衡健康检查日志
在http-vhosts.conf中
SetEvnIf Request_URI “^/check\.txt$” dontlog CustomLog "|/usr/local/sbin/cronolog /app/logs/access_bbs_%Y%m%d.log" combined evn=!dontlog |
09)通过脚本分析日志
统计访问IP
awk ‘{print $1}‘ access_bbs_20170608.log |sort |uniq -c |sort -rn -k1|head -10
awk ‘{++S[$1]} END {for (key in S) print S[key],key}‘ access_bbs_20170608.log | sort -rn -k1|head -10
010)安装PHP
=================php===================== 5.3=====> ============================= ./configure --prefix=/application/php5.3.27 --with-apxs2=/application/apache/bin/apxs --with-mysql=/application/mysql --with-xmlrpc --with-openssl --with-zlib --with-freetype-dir --with-gd --with-jpeg-dir --with-png-dir --with-iconv=/usr/local/libiconv --enable-short-tags --enable-sockets --enable-zend-multibyte --enable-soap --enable-mbstring --enable-static --enable-gd-native-ttf --with-curl --with-xsl --enable-ftp --with-libxml-dir ==========php========== 安装准备 yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y tar zxf libiconv-1.14.tar.gz cd libiconv-1.14 ./configure --prefix=/usr/local/libiconv make make install cd ../