Apache与nginx对比优势:
经笔者测试:对于提供纯静态文件HTML页面、图片等服务,Apache确实要比nginx逊色一些,但在结合PHP引擎服务及其它很多方面并不比nginx差,而Apache的稳定性更好,这也是为什么Apache仍然占据WEB服务排名第一的一个原因。
一、安装Apache
(1) 卸载系统默认安装的Apache软件包
操作系统自带的Apache,版本都比较低。更新不及时
(2)下载线上常用的稳定版,这里以2.2系列的版本为例
wKiom1NLsa3ykRDUAAHB1R0ss7s484.jpg
右键选择快捷方式,在Linux系统里面使用wget下载即可。
[iyunv@localhost ~]# wgethttp://mirrors.cnnic.cn/apache//httpd/httpd-2.2.27.tar.gz
--2014-03-13 15:33:19-- http://mirrors.cnnic.cn/apache//httpd/httpd-2.2.27.tar.gz
正在解析主机 mirrors.cnnic.cn... 123.125.244.87
正在连接 mirrors.cnnic.cn|123.125.244.87|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:7519677 (7.2M) [application/x-gzip]
正在保存至: “httpd-2.2.27.tar.gz”
6%[===> ] 515,757 159K/s eta(英国中部时 7%[===> ] 564,717 157K/s eta(英国中部时 8%[====> ] 613,677
………………………………………………………………………………………………………………………………………………………
138K/s eta(英国中部时100%[=============================================================>]7,519,677 139K/s in 52s
2014-03-13 15:34:12 (141 KB/s) - 已保存“httpd-2.2.27.tar.gz”[7519677/7519677])
(3)解压:
(1)tar -zxvf httpd-xx.tar.gz
(2)cd 到解压目录
(3) less README
(4)下载keyts文件进行安全验证:
1)进入http子目录,下载keys文件
2)使用gpg导入keys文件
3)使用gpg --verify httpd-XXX.tar.gz.asc进行验证
(4)./configure --help 查看编译参数选项
[iyunv@localhost httpd-2.2.27]#./configure --prefix=/application/apache2.2.22 --enable-deflate --enable-expires--enable-headers --enable-modules=most --enable-so --with-mpm=worker--enable-rewrite
(5)编译安装
[iyunv@localhost httpd-2.2.27]# echo $?
0
[iyunv@localhost httpd-2.2.27]# make&& make install
./configure后的参数说明
./configure \
--prefix=/application/apache2.2.22 安装路径
--enable-deflate \ 压缩内容编码支持
--enable-expires \ 提供客户端缓存支持
--enable-headers \ HTTP请求头控制
--enable-modules=most \
--enable-so \ 激活Apache服务的DSO支持
--with-mpm=worker \ Apache模式为worker模式(线程处理请求,资源开销比 (prefork小)
--enable-rewrite 激活rewrite功能模块,伪静态,提供URL重写
(6)创建软连接
[iyunv@localhost ~]# ln -s/application/apache2.2.22/ /application/apache
[iyunv@localhost ~]# ll /application/apache
lrwxrwxrwx. 1 root root 26 4月 9 14:55 /application/apache ->/application/apache2.2.22/
安装完成之后创建软连接的意义,根据线上经验总结:
ln -s /application/apache2.22 /application/apache
1)去掉Apache版本号
2)将Apache安装路径通过软连接的方式更改为/application/apache方便人类使用。
3)安装时指定版本号路径便于查看当前分区当前使用的Apache版本、也方便以后升级。
4)人类使用路径/application/apache。
5)当Apache软件升级带新版本号后,删除原来软连接在重新建立新的到/application/apache的软连接即可。
6)程序中如果有引用Apache路径的地方,不需要做任何更改,因为升级后访问路径还是/application/apache。
到此,Apache的安装工作就完成了。
/application/apache/bin/apachectl 直接敲回车,查看有哪些参数可供使用
[iyunv@localhost ~]#/application/apache/bin/apachectl
Usage: /application/apache2.2.22/bin/httpd[-D name] [-d directory] [-f file]
[-C"directive"] [-c "directive"]
[-kstart|restart|graceful|graceful-stop|stop]
[-v] [-V] [-h] [-l] [-L] [-t][-T] [-S]
Options:
-Dname : define a name for usein <IfDefine name> directives
-ddirectory : specify an alternateinitial ServerRoot
-ffile : specify an alternateServerConfigFile
-C"directive" : processdirective before reading config files
-c"directive" : processdirective after reading config files
-elevel : show startup errors oflevel (see LogLevel)
-Efile : log startup errors to file
-v : show versionnumber
-V : show compilesettings
-h : listavailable command line options (this page)
-l : list compiledin modules
-L : listavailable configuration directives
-t-D DUMP_VHOSTS : show parsed settings(currently only vhost settings)
-S : a synonym for-t -D DUMP_VHOSTS
-t-D DUMP_MODULES : show all loaded modules
-M : a synonym for -t -D DUMP_MODULES
-t : run syntaxcheck for config files
-T : start withoutDocumentRoot(s) check
7)/application/apache/bin/apachectl -l 查看编译的内容,默认Apache会编译一些必须的选项
[iyunv@localhost ~]# /application/apache/bin/apachectl -l
Compiled in modules:
core.c
mod_authn_file.c
mod_authn_dbm.c
mod_authn_anon.c
mod_authn_dbd.c
mod_authn_default.c
mod_authz_host.c
mod_authz_groupfile.c
mod_authz_user.c
mod_authz_dbm.c
mod_authz_owner.c
mod_authz_default.c
mod_auth_basic.c
mod_auth_digest.c
mod_dbd.c
mod_dumpio.c
mod_reqtimeout.c
mod_ext_filter.c
mod_include.c
mod_filter.c
mod_substitute.c
mod_deflate.c
mod_log_config.c
mod_logio.c
mod_env.c
mod_expires.c
mod_headers.c
mod_ident.c
mod_setenvif.c
mod_version.c
worker.c
http_core.c
mod_mime.c
mod_dav.c
mod_status.c
mod_autoindex.c
mod_asis.c
mod_info.c
mod_cgid.c
mod_dav_fs.c
mod_vhost_alias.c
mod_negotiation.c
mod_dir.c
mod_imagemap.c
mod_actions.c
mod_speling.c
mod_userdir.c
mod_alias.c
mod_rewrite.c
mod_so.c
(7)检验安装成果:
Code:
[iyunv@localhost ~]#/application/apache/bin/apachectl start
httpd: Could not reliably determine theserver's fully qualified domain name, using localhost.localdomain forServerName(此报错在httpd.conf配置文件里面有详细的解决方法1、在ServerName后面直接填写申请的合法域名 2、填写服务器的ip地址或127.0.0.1本地回环地址)
[iyunv@localhost ~]# netstat -lnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 :::80 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:25 :::* LISTEN
[iyunv@localhost ~]#
[iyunv@localhost ~]# lsof -i tcp:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 26978 root 4u IPv6 61958 0t0 TCP *:http (LISTEN)
httpd 26980 daemon 4u IPv6 61958 0t0 TCP *:http (LISTEN)
httpd 26981 daemon 4u IPv6 61958 0t0 TCP *:http (LISTEN)
httpd 26982 daemon 4u IPv6 61958 0t0 TCP *:http (LISTEN)
[iyunv@localhost ~]# ps -ef |grep http
root 26978 1 0 14:58 ? 00:00:00 /application/apache2.2.22/bin/httpd-k start
daemon 26979 26978 0 14:58 ? 00:00:00/application/apache2.2.22/bin/httpd -k start
daemon 26980 26978 0 14:58 ? 00:00:00/application/apache2.2.22/bin/httpd -k start
daemon 26981 26978 0 14:58 ? 00:00:00/application/apache2.2.22/bin/httpd -k start
daemon 26982 26978 0 14:58 ? 00:00:00/application/apache2.2.22/bin/httpd -k start
root 27067 26941 0 14:59 pts/2 00:00:00 grep http
说明:
Apache安装完成之后,不提供任何服务,需要启动
/application/apache/bin/apachectl start 启动Apache服务
netstat - lnt 查看启动端口
lsof -i tcp:80 使用lsof反查tcp的80端口是不是HTTP服务
ps -ef |grep http 查看HTTP的进程
(8)访问网站页面
wKioL1NLshXBndrHAAFq5BGC6w0785.jpg
wKiom1NLsj6QxrXOAACo8kO7KxE972.jpg
二、网站打不开排查方法:
1、iptables防火墙和selinux是否关闭
/etc/init.d/iptables stop 这是关闭防火墙的命令,如果是生产环境则是允许80端口的访问,而不是关闭防火墙
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
非正式环境可以禁止防火墙开机启动,便于学习调试Apache服务。
chkconfig iptables stop
/etc/init.d/iptables status 查看iptables的当前状态
tail -100/application/apache/logs/error_log
[iyunv@localhost ~]# service iptables stop
iptables:清除防火墙规则:[确定]
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:正在卸载模块:[确定]
[iyunv@localhost ~]# setenforce 0
[iyunv@localhost ~]# getenforce 0
Permissive
三、部署一个简单WEB站点
Apache的默认站点目录,是安装目录下的/application/apache/htdocs这可以从Apache主配置文件/application/apache/conf/httpd.conf中查到,内容如下:
[iyunv@localhost ~]# grep -i DocumentRoot/application/apache/conf/httpd.conf
# DocumentRoot: The directory out of whichyou will serve your
DocumentRoot"/application/apache2.2.22/htdocs"
# This should be changed to whatever youset DocumentRoot to.
# access content that does not live underthe DocumentRoot.
如果想要部署网站服务,只需要把开发好的程序全部放置到/application/apache2.2.22/htdocs下面即可
这里我们进入到/application/apache2.2.22/htdocs下,删除掉Apache默认的首页index.html(原始内容为itworks),然后建立一个index.html,加入一段网页内容并保存
此时在浏览器端输入http://IP地址就应该可以看到网页内容了。
html相关代码如下:
<html><head>
<title>白居易的诗</title>
<bgsound src="秋日的私语.MP3"></bgsound>
</head>
<body background="pb.jpg"text="rgb(255,0,0)">
<p>
<b><font face="华文彩云" color="green"size="7">钱塘湖春行</font> </b>
</p><p>
<font face="华文新魏" color="red" size="6">孤山寺北贾亭西,水面初平云脚低。</font>
<b><font face="华文新魏"color="red" size="6">几处早莺争暖树,谁家新燕啄春泥。</font><b>
<i><font face="华文新魏"color="red" size="6">乱花渐欲迷人眼,浅草才能没马蹄。</font><i>
<u><font face="华文新魏"color="red" size="6">最爱西湖行不足,绿扬荫里白沙堤。</font><u>
</u></u></i></i></b></b></p><p><b><b><i><i><u><u>
<font face="宋体"color="blue" size="4">【说明】此诗为作者任杭州刺史时作。写西湖的山光水色、花草亭树,>加上早莺、新燕生机盎然,旖旎动人。是摹写西湖秋色名篇。</font><b></b></u></u></i></i></b></b></p><b><b><i><i><u><u><b>
</b></u></u></i></i></b></b></body></html>
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com