apache学习一安装

1、基本命令
rpm -qa httpd
rpm -e  包名
rpm -e --nodeps  包名      卸载安装程序不依赖


[root@python ~]# rpm -e httpd-2.4.6-40.el7.centos.4.x86_64
error: Failed dependencies:
        httpd-mmn = 20120211x8664 is needed by (installed) php-5.4.45-56.el7.art.x86_64
        httpd is needed by (installed) zabbix-web-3.0.5-1.el7.noarch
[root@python ~]# rpm -e --nodeps httpd-2.4.6-40.el7.centos.4.x86_64
warning: /etc/httpd/conf/httpd.conf saved as /etc/httpd/conf/httpd.conf.rpmsave
warning: file /etc/httpd/conf.d/welcome.conf: remove failed: No such file or directory
[root@python ~]# rpm -qa httpd
[root@python ~]# 
2、安装相关基础包
yum install –y gcc glibc glibc-common gd gd-devel xinetd openssl-devel zlib zlib-devel ncurses-devel gcc-c++ wget tree vim lsof apr*


3、下载安装包并解压
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.27.tar.gz
wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.31.tar.gz
[root@python soft]# ll
total 7696
-rw-r--r--   1 root root 7583841 Jul 17  2015 httpd-2.2.31.tar.gz
[root@python soft]#tar zxvf httpd-2.2.31.tar.gz 
[root@python soft]# ll
total 7700
drwxr-xr-x  11 wolf wolf    4096 Jul 16  2015 httpd-2.2.31
-rw-r--r--   1 root root 7583841 Jul 17  2015 httpd-2.2.31.tar.gz
4、编译安装
查看INSTALL
[root@python httpd-2.2.31]# cat INSTALL 


  APACHE INSTALLATION OVERVIEW


  Quick Start - Unix
  ------------------


  For complete installation documentation, see [ht]docs/manual/install.html or
  http://httpd.apache.org/docs/2.2/install.html


     $ ./configure --prefix=PREFIX
     $ make
     $ make install
     $ PREFIX/bin/apachectl start


     NOTES: * Replace PREFIX with the filesystem path under which 
              Apache should be installed.  A typical installation
              might use "/usr/local/apache2" for PREFIX (without the
              quotes).


            * If you are a developer who will be linking your code with
              Apache or using a debugger to step through server code,
              ./configure's --with-included-apr option may be advantageous,
              as it removes the possibility of version or compile-option
              mismatches with APR and APR-util code.  (Many OSes now
              include their own version of APR and APR-util.)


            * If you are a developer building Apache directly from
              Subversion, you will need to run ./buildconf before running
              configure. This script bootstraps the build environment and
              requires Python as well as GNU autoconf and libtool. If you
              build Apache from a release tarball, you don't have to run
              buildconf.


            * If you want to build a threaded MPM (for instance worker)
              on  FreeBSD, be aware that threads do not work well with
              Apache on FreeBSD versions before 5.4-RELEASE. If you wish
              to try a threaded Apache on an earlier version of FreeBSD,
              use the --enable-threads parameter to ./configure in
              addition to the --with-mpm parameter.


            * If you are building directly from Subversion on Mac OS X
              (Darwin), make sure to use GNU Libtool 1.4.2 or newer. All
              recent versions of the developer tools on this platform
              include a sufficiently recent version of GNU Libtool (named
              glibtool, but buildconf knows where to find it).


  For a short impression of what possibilities you have, here is a
  typical example which configures Apache for the installation tree
  /sw/pkg/apache with a particular compiler and flags plus the two
  additional modules mod_rewrite and mod_speling for later loading
  through the DSO mechanism:


     $ CC="pgcc" CFLAGS="-O2" \
     ./configure --prefix=/sw/pkg/apache \
     --enable-rewrite=shared \
     --enable-speling=shared 


  The easiest way to find all of the configuration flags for Apache 2.2
  is to run ./configure --help.




  Quick Start - Windows
  ---------------------


  For complete documentation, see manual/platform/windows.html.en or
  http://httpd.apache.org/docs/2.2/platform/windows.html.


  The Apache/Win32 binaries are distributed as Windows Installer packages 
  (.msi) named httpd-2.2.xx-win32-x86-no_ssl.msi for a version without mod_ssl
  and httpd-2.2.xx-win32-x86-openssl-0.9.8x.msi for a version including the
  mod_ssl plus the openssl library and command line utility.  These packages
  may be unpacked without "installing" them by using the msiexec /a option.


  If you have unpacked a source distribution (named httpd-2.2.x-win32-src.zip, 
  without any -x86 notation) you must compile the package yourself, see the links
  mentioned above.  Unless you intended to do this, please look again for the 
  binary package from http://www.apache.org/dist/httpd/binaries/win32/ and
  install the desired .msi package.


  The .msi package configures the httpd.conf file, and installs and starts 
  the Apache2.2 service for you.  It also installs plenty of useful shortcuts
  and the taskbar ApacheMonitor.  We strongly encourage you to use it.




  Postscript
  ----------


  The Apache HTTP Server group cannot field user's installation questions.
  There are many valuable forums to help you get started.  Please refer your
  questions to the appropriate forum, such as the Users Mailing List at
  http://httpd.apache.org/userslist.html or the usenet newsgroups
  comp.infosystems.www.servers.unix or
  comp.infosystems.www.servers.ms-windows.


  Thanks for using the Apache HTTP Server, version 2.2.


                                     The Apache Software Foundation
                                     http://www.apache.org/
[root@python httpd-2.2.31]# 
#常用的配置参数:
--prefix 默认安装在/usr/local/apache 目录下,改参数用于自定义 Apache 的安装目录!
例如:./configure –prefix=/usr/local/apache
--enabled-moudles 用于指定除默认模块以外需要额外安装的 Apache 模块,不同模块之间用空格分隔
--enabled-mods-shared 跟—enabled-moudles 相同, 用于指定需要额外安装的模块在 Apache运行的时候会自动载入


编译参数
./configure \
--prefix=/soft/apache \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-moudles=most \
--enable-so \
--with-mpm=worker \
--enable-rewrite


--prefix=/soft/apache \#安装的目录
--enable-deflate \ #压缩文件文本一般 html/js/css 等内容的站点,使用此参数功能会大大提高传输速度,提示访问者访问体验,在生产环境中,这是 apache 调优的重要选项之一
--enable-expires \ #激活允许通过配置文件控制 http 的“expires”和“cache-control”头内容,即对网站图片,js,css 等内容,提供在客户端浏览器缓存的设置,这是 apache 调优的重要选项之一
--enable-headers \ #提供允许 http 请求头的控制
--enable-moudles=most \ #激活多数模块
--enable-so \ #激活 apache 服务的 DSO 支持,即在以后可以以 DSO 的方式编译安装共享模块,这个模块本身不能以 DSO 方式编译
--with-mpm=worker \ #选择 apache mpm 的模式为 worker 模式,因为 worker 模式原理是更多的使用线程来处理请求,所以可以处理更多的并发请求,而系统资源的开销小于基于进程
的 MPM prefork,如果不指定此参数,默认得到模式是 prefork 进程模式。这是 apache 调优的一
个重要选项之一。
--enable-rewrite #提供基于 URL 规则的重写功能,根据已知 URL 地址,转换其他想
要的 url 地址,如伪静态功能就是这个模块实现的,这是 apache 在生产环节中必用的一个重要功能
可以使用./configure –help 命令来查看以上各个参数的用途
在安装 apache 软件包时,忘记安装以上模块,可以使用 dso 方式编译安装




[root@python httpd-2.2.31]#make
[root@python httpd-2.2.31]#make install
[root@python httpd-2.2.31]# ls
ABOUT_APACHE  BuildBin.dsp   config.log     docs         httpd.mak       LAYOUT        Makefile      modules.lo     README            srclib
acinclude.m4  buildconf      config.nice    emacs-style  httpd.spec      libhttpd.dep  Makefile.in   modules.o      README.platforms  support
Apache.dsw    buildmark.o    config.status  httpd        include         libhttpd.dsp  Makefile.win  NOTICE         README-win32.txt  test
build         CHANGES        configure      httpd.dep    INSTALL         libhttpd.mak  modules       NWGNUmakefile  ROADMAP           VERSIONING
BuildAll.dsp  config.layout  configure.in   httpd.dsp    InstallBin.dsp  LICENSE       modules.c     os             server
[root@python httpd-2.2.31]# cd ..
[root@python soft]# ls
apache  httpd-2.2.31  httpd-2.2.31.tar.gz  IPy-0.83  IPy-0.83.tar.gz  psutil-3.2.2  psutil-3.2.2.tar.gz
[root@python soft]# cd apache/
[root@python apache]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules
[root@python apache]# cd bin
[root@python bin]# ls
ab  apachectl  apxs  checkgid  dbmmanage  envvars  envvars-std  htcacheclean  htdbm  htdigest  htpasswd  httpd  httxt2dbm  logresolve  rotatelogs
[root@python bin]# ./apachectl -t
httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fef5:e8c1 for ServerName
Syntax OK


[root@python bin]# ./apachectl start
httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fef5:e8c1 for ServerName
报错解决
[root@python conf]# vi httpd.conf 
加入一句  ServerName  localhost:80


5、检查启动情况
[root@python conf]# lsof -i :80
COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
httpd   24709   root    4u  IPv6 170846      0t0  TCP *:http (LISTEN)
httpd   24711 daemon    4u  IPv6 170846      0t0  TCP *:http (LISTEN)
httpd   24712 daemon    4u  IPv6 170846      0t0  TCP *:http (LISTEN)
httpd   24713 daemon    4u  IPv6 170846      0t0  TCP *:http (LISTEN)
httpd   24803 daemon    4u  IPv6 170846      0t0  TCP *:http (LISTEN)
[root@python bin]# ps -ef | grep httpd
daemon    24366      1  0 22:21 ?        00:00:00 /soft/apache/bin/httpd -k start
root      24709      1  0 22:27 ?        00:00:00 /soft/apache/bin/httpd -k start
daemon    24962  24709  0 22:30 ?        00:00:00 /soft/apache/bin/httpd -k start
daemon    24963  24709  0 22:30 ?        00:00:00 /soft/apache/bin/httpd -k start
daemon    24964  24709  0 22:30 ?        00:00:00 /soft/apache/bin/httpd -k start
daemon    24965  24709  0 22:30 ?        00:00:00 /soft/apache/bin/httpd -k start
root      25109  14373  0 22:35 pts/1    00:00:00 grep --color=auto httpd
6、测试
[root@python bin]# curl http://192.168.3.40/
<html><body><h1>It works!</h1></body></html>[root@python bin]
# curl -I http://192.168.3.40/
HTTP/1.1 200 OK
Date: Thu, 03 Nov 2016 14:28:03 GMT
Server: Apache/2.2.31 (Unix)
Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT
ETag: "23b3bae-2c-3e9564c23b600"
Accept-Ranges: bytes
Content-Length: 44
Content-Type: text/html


7、常用命令
※apachectl 命令详解-graceful 不中断原有连接,重新启动 Apache 服务器
apachectl(Apache control interface)
参 数:
Linux Note
configtest 检查设置文件中的语法是否正确。用于修改了配置文件后进行测试是否有误。
graceful 重新启动 Apache 服务器,但不会中断原有的连接。用于修改了配置文件后进行重新读取配置文件。
help 显示帮助信息。
restart 重新启动 Apache 服务器。 = httpd -k restart
start 启动 Apache 服务器。
stop 停止 Apache 服务器。


[root@python bin]# ./apachectl help
Usage: /soft/apache/bin/httpd [-D name] [-d directory] [-f file]
                              [-C "directive"] [-c "directive"]
                              [-k start|restart|graceful|graceful-stop|stop]
                              [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S]
Options:
  -D name            : define a name for use in <IfDefine name> directives
  -d directory       : specify an alternate initial ServerRoot
  -f file            : specify an alternate ServerConfigFile
  -C "directive"     : process directive before reading config files
  -c "directive"     : process directive after reading config files
  -e level           : show startup errors of level (see LogLevel)
  -E file            : log startup errors to file
  -v                 : show version number
  -V                 : show compile settings
  -h                 : list available command line options (this page)
  -l                 : list compiled in modules
  -L                 : list available 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 syntax check for config files
  -T                 : start without DocumentRoot(s) check
[root@python bin]# ./apachectl configtest
Syntax OK
[root@python bin]# ./apachectl graceful
[root@python bin]# ./apachectl -t
Syntax OK
[root@python bin]# ./apachectl -l
Compiled in modules:
  core.c
  mod_authn_file.c
  mod_authn_default.c
  mod_authz_host.c
  mod_authz_groupfile.c
  mod_authz_user.c
  mod_authz_default.c
  mod_auth_basic.c
  mod_include.c
  mod_filter.c
  mod_deflate.c
  mod_log_config.c
  mod_env.c
  mod_expires.c
  mod_headers.c
  mod_setenvif.c
  mod_version.c
  worker.c
  http_core.c
  mod_mime.c
  mod_status.c
  mod_autoindex.c
  mod_asis.c
  mod_cgid.c
  mod_negotiation.c
  mod_dir.c
  mod_actions.c
  mod_userdir.c
  mod_alias.c
  mod_rewrite.c
  mod_so.c
  
  [root@python bin]# ./apachectl -M
Loaded Modules:
 core_module (static)
 authn_file_module (static)
 authn_default_module (static)
 authz_host_module (static)
 authz_groupfile_module (static)
 authz_user_module (static)
 authz_default_module (static)
 auth_basic_module (static)
 include_module (static)
 filter_module (static)
 deflate_module (static)
 log_config_module (static)
 env_module (static)
 expires_module (static)
 headers_module (static)
 setenvif_module (static)
 version_module (static)
 mpm_worker_module (static)
 http_module (static)
 mime_module (static)
 status_module (static)
 autoindex_module (static)
 asis_module (static)
 cgid_module (static)
 negotiation_module (static)
 dir_module (static)
 actions_module (static)
 userdir_module (static)
 alias_module (static)
 rewrite_module (static)
 so_module (static)
Syntax OK
8、新增加模块并编译
寻找编译该模块的c文件
[root@python bin]# find  /  -name mod_vhost_alias.c
find: 鈥run/user/42/gvfs鈥 Permission denied
/soft/httpd-2.2.31/modules/mappers/mod_vhost_alias.c
用apxs编译该模块
[root@python mappers]# /soft/apache/bin/apxs -i -a -c  mod_vhost_alias.c 
选项说明:
-c 执行编译操作
-i 安装操作,安装一个或多个动态共享对象到服务器的modules目录
-a 自动增加一个LoadModule行到httpd.conf文件,以激活此模块,若此行存在则启用之
-A 与-a类似,但是它增加的LoadModule行前有井号前缀(#),即不激活此模块
-e 需要执行编辑操作,可与-a和-A选项配合使用,与-i操作类似,修改httpd.conf文件,但并不安装此模块 
/usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic   -DLINUX -D_REENTRANT -D_GNU_SOURCE -pthread -I/soft/apache/include  -I/usr/include/apr-1   -I/usr/include/apr-1   -c -o mod_vhost_alias.lo mod_vhost_alias.c && touch mod_vhost_alias.slo
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -o mod_vhost_alias.la  -rpath /soft/apache/modules -module -avoid-version    mod_vhost_alias.lo
/soft/apache/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' mod_vhost_alias.la /soft/apache/modules
/usr/lib64/apr-1/build/libtool --mode=install cp mod_vhost_alias.la /soft/apache/modules/
libtool: install: cp .libs/mod_vhost_alias.so /soft/apache/modules/mod_vhost_alias.so
libtool: install: cp .libs/mod_vhost_alias.lai /soft/apache/modules/mod_vhost_alias.la
libtool: install: cp .libs/mod_vhost_alias.a /soft/apache/modules/mod_vhost_alias.a
libtool: install: chmod 644 /soft/apache/modules/mod_vhost_alias.a
libtool: install: ranlib /soft/apache/modules/mod_vhost_alias.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/sbin" ldconfig -n /soft/apache/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /soft/apache/modules


If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'


See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /soft/apache/modules/mod_vhost_alias.so
[activating module `vhost_alias' in /soft/apache/conf/httpd.conf]
[root@python mappers]# 
执行以上命令后,apache会自动编译、安装和修改httpd.conf文件,并自动激活该模块。
[root@python bin]# ./apachectl -M
Loaded Modules:
 core_module (static)
 authn_file_module (static)
 authn_default_module (static)
 authz_host_module (static)
 authz_groupfile_module (static)
 authz_user_module (static)
 authz_default_module (static)
 auth_basic_module (static)
 include_module (static)
 filter_module (static)
 deflate_module (static)
 log_config_module (static)
 env_module (static)
 expires_module (static)
 headers_module (static)
 setenvif_module (static)
 version_module (static)
 mpm_worker_module (static)
 http_module (static)
 mime_module (static)
 status_module (static)
 autoindex_module (static)
 asis_module (static)
 cgid_module (static)
 negotiation_module (static)
 dir_module (static)
 actions_module (static)
 userdir_module (static)
 alias_module (static)
 rewrite_module (static)
 so_module (static)
 vhost_alias_module (shared)
Syntax OK
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值