• 压力测试以及编译安装httpd2.4


                        压力测试以及编译安装httpd2.4

                                          作者:尹正杰

    版权声明:原创作品,谢绝转载!否则将追究法律责任。

    一.使用 deflate_module模块压缩页面优化传输速度
      我们的httpd软件自带的有一个mod_deflate模块,它可以实现调用gzip这样的工具来实现对文本数据压缩的。二进制的格式的文件一般不压缩,因为压缩空间比例并不大,反而会浪费服务器的CPU时间周期,吃力不讨好。使用mod_deflate模块压缩页面优化传输速度,节省带宽等。
     
    [root@yinzhengjie ~]# httpd -M |grep deflate_module
    deflate_module (shared) ------>检查该模块是否被加载了,如果加载了就可以直接进行配置。
    Syntax OK
    [root@yinzhengjie ~]#
    [root@yinzhengjie ~]# more /etc/httpd/conf.d/deflate.conf ----->具体配置可以按照这个文件来整。我都已经做了注释了
    #启用DEFLATE过滤器来实现输出内容过滤并完成文件压缩的,需要我们明确定义的。
    SetOutputFilter DEFLATE
     
    #Restrict compression to these MIME types
    #纯文本格式;
    AddOutputFilterByType DEFLATE text/plain
     
    #超文本格式;
    AddOutputFilterByType DEFLATE text/html
     
    #扩展的超文本和合并的xml格式;
    AddOutputFilterByType DEFLATE application/xhtml+xml
    #文本类型的xml格式的;
     
    AddOutputFilterByType DEFLATE text/xml
    #application类型的xml格式;
     
    AddOutputFilterByType DEFLATE application/xml
    #application类型的x-js格式;
     
    AddOutputFilterByType DEFLATE application/x-javascript
    #文本类型的js格式;
     
    AddOutputFilterByType DEFLATE text/javascript
    #文本类型的css格式;
    AddOutputFilterByType DEFLATE text/css
     
    # Level of compression (Highest 9 - Lowest 1)默认为6
    DeflateCompressionLevel 9
     
    # Netscape 4.x has some problems.
    BrowserMatch ^Mozilla/4 gzip-only-text/html #用BrowserMatch关键字进行正则匹配浏览器客户端支持压缩的版本号;
     
    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4.0[678] no-gzip #用BrowserMatch关键字进行正则匹配浏览器客户端不支持压缩的版本号;
     
    # MSIE masquerades as Netscape, but it is fine
    BrowserMatch MSI[E] !no-gzip !gzip-only-text/html
    [root@yinzhengjie ~]#
    [root@yinzhengjie ~]# httpd -t
    Syntax OK ------>重新加载服务之前,一定要检查配置文件的语法是否OK啊!
    [root@yinzhengjie ~]#
    [root@yinzhengjie ~]# service httpd restart
    Stopping httpd: [ OK ]
    Starting httpd: [ OK ]
    [root@yinzhengjie ~]#
     
     
     
    二.httpd自带的命令行工具
      事实上,在我们安装完Apache之后,它默认就会给我们安装上很多命令行工具,这个是httpd自带的工具。
    1>.apachectl ( Apache HTTP服务控制工具)
    [root@yinzhengjie ~]# file `which apachectl`
    /usr/sbin/apachectl: POSIX shell script text executable -----这是一个脚本程序
    [root@yinzhengjie ~]#
    [root@yinzhengjie ~]# apachectl stop
    [root@yinzhengjie ~]# ss -tnl | grep 80
    [root@yinzhengjie ~]# ss -tnl | grep 443
    [root@yinzhengjie ~]#
    [root@yinzhengjie ~]# apachectl start
    [root@yinzhengjie ~]# ss -tnl | grep 80
    LISTEN 0 128 :::80 :::*
    [root@yinzhengjie ~]# ss -tnl | grep 443
    LISTEN 0 128 :::443 :::*
    [root@yinzhengjie ~]#
     
    2>.ab(Apache HTTP服务器性能测试基准工具;)
      我这里测试是在本机测试的,效果是相当的好,实际生产环境中建议要跨主机测试,还有就是测试的时候不能光等测试结果,在进行压力测试的同时还要手动去打开这个网页,观察网页是否能够正常打开,如果不能正常打开就不是压力测试了,而成了崩溃测试啦,哈哈~尽管你满足了以上两点,ab的测试也并不准确,因为我们这里只是测试一个页面,而在生产实际环境中,我们打开的页面也不止一个哟。我们这里主要介绍ab的用法。ab只是可以用来做参考,不能真正用来作为实际生产环境中服务器可以承载的压力,除了ab的测试压力工具还有很多,比如http_load,webbench,seige等等,这些模拟测试工具都不精确。新环境上线之前,我们可以用tcp_copy来进行压力测试,它的可靠性会强一些。
     1 [root@yinzhengjie ~]# ab -c 100 -n 50000 http://www.yinzhengjie.org.cn/index.html             ----->注意, -c 模拟的并发数,-n 模拟的总请求数, 一般并发数应该小于等于请求数。
     2 This is ApacheBench, Version 2.3 <$Revision: 655654 $>
     3 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
     4 Licensed to The Apache Software Foundation, http://www.apache.org/
     5 
     6 Benchmarking www.yinzhengjie.org.cn (be patient)
     7 Completed 5000 requests    ----->告诉我们测试以及完成了5000个请求,下面一次是执行进度。
     8 Completed 10000 requests
     9 Completed 15000 requests
    10 Completed 20000 requests
    11 Completed 25000 requests
    12 Completed 30000 requests
    13 Completed 35000 requests
    14 Completed 40000 requests
    15 Completed 45000 requests
    16 Completed 50000 requests
    17 Finished 50000 requests        ------->这就说明任务完成了。
    18 
    19 
    20 Server Software:        Apache/2.2.15            ----->服务器程序及版本;
    21 Server Hostname:        www.yinzhengjie.org.cn    ----->服务器的主机名;
    22 Server Port:            80                        ------>访问服务器的端口;
    23 
    24 Document Path:          /index.html                ------->请求资源的路径;
    25 Document Length:        7152 bytes                ------->请求资源的大小;
    26 
    27 Concurrency Level:      100                    -------->并发级别为100个;
    28 Time taken for tests:   9.013 seconds            --------->测试所经历的市场;
    29 Complete requests:      50000                    --------->完成的请求个数;
    30 Failed requests:        0                        --------->失败的请求个数;
    31 Write errors:           0                        ---------->发送的失败个数;
    32 Total transferred:      372761652 bytes            ---------->一共传输的355M,默认单位为字节;
    33 HTML transferred:       358043424 bytes            ---------->所传输的HTML大小为341M,上面的值包括请求首部等,因此上面的值会大于该值,该项只只包含文档实体本身;
    34 Requests per second:    5547.74 [#/sec] (mean)    ----------->每秒钟完成的请求数;
    35 Time per request:       18.025 [ms] (mean)        ----------->表示总的并发数需要的时间;
    36 Time per request:       0.180 [ms] (mean, across all concurrent requests)    ------>表示单个请求所需的时间。总的并发数是100,就用总的时间除以100就会得到这个数字;
    37 Transfer rate:          40390.33 [Kbytes/sec] received    -------->每秒钟传输的字节数;
    38 
    39 Connection Times (ms)    ----->处理时间,单位是毫秒。
    40               min  mean[+/-sd] median   max
    41 Connect:        0    4   4.1      2      47        ---->连接时间
    42 Processing:     2   14   4.1     14      58        ----->处理进程(请求)总的时间
    43 Waiting:        0   12   3.6     13      49        ----->处理请求的等待的时间
    44 Total:          3   18   4.4     16      68            ------>整体花费的时间
    45 
    46 Percentage of the requests served within a certain time (ms)
    47   50%     16    ------>表示完成50%的请求需要的时间是16ms,就是做一个评估。
    48   66%     18
    49   75%     19
    50   80%     19
    51   90%     20
    52   95%     26
    53   98%     33
    54   99%     37
    55  100%     68 (longest request)        ------>表示完成100%的请求需要的时间为68ms;
    56 You have new mail in /var/spool/mail/root
    57 [root@yinzhengjie ~]# 
    3>.apxs (Apache 扩展工具,用于编译第三方模块或是开发第三方模块时会用到它;)
    4>.configure( 配置源代码)
    5>.dbmmanage(为基本认证创建和更新DBM格式的用户认证文件)
    6>.htcacheclean(清理磁盘缓存)
    7>.htdigest(为摘要认证创建和更新用户认证文件。)
    8>.htdbm(操作 DBM 密码数据库。)
    9>.htpasswd(为基本认证创建和更新用户认证文件。)
    10>.httxt2dbm(为 RewriteMap 创建 dbm 文件。)
    11>.logresolve(将 Apache 日志文件中的 IP 地址解析到主机名称。)
    12>.rotatelogs(不关闭 Apache 而切换日志文件。用于日志滚动的工具。)
    13>. suexec(执行外部程序前切换用户。)
     
    三.资源限定
      我们知道客户端和服务器端在进行通信时,双方都要建立套接字文件,而且每一个连接通常都需要四个元素,客户单ip和端口,服务器端ip和端口。如果某一个客户端想服务端发起请求时,如果它的请求量很大久意味着打开的套接字文件就会很多。那么想象一下这个套接字文件到底可以打开多少个呢?作为一个服务器来讲,每一个用户(或每一个进程)所能够打开的文件数是有限定的。不然的话对于整个系统资源可能每一个用户(或每一个进程)占用的过多。我们可以用ulimit命令来查看。它是一个内建命令。
      对要求并发性程度非常高的应用程序来讲,资源限定一个是进程数的限定,一个是打开文件句柄的限定是我们将来要考虑的通用的概念。资源限定分为软限制(可以超出的限制,但仅能超出一定时长)和硬限制(绝对不能超出的限制)
      ulimit:只能修改软限制
        -n [N]:显示或软限制能打开的最大的文件句柄数
        -u [N]:所能够打开的最大进程数
     1 [root@yinzhengjie ~]# ulimit -n
     2 1024
     3 [root@yinzhengjie ~]# 
     4 [root@yinzhengjie ~]# ulimit -n 65535        ----->临时修改文件的打开数为65535
     5 [root@yinzhengjie ~]# ulimit -n
     6 65535
     7 [root@yinzhengjie ~]# 
     8 [root@yinzhengjie ~]# ulimit -u
     9 7669
    10 [root@yinzhengjie ~]# 
    11 [root@yinzhengjie ~]# ulimit -u 30000        ------->临时修改进程打开的数为30000
    12 [root@yinzhengjie ~]# ulimit -u
    13 30000
    14 [root@yinzhengjie ~]# 
    15 [root@yinzhengjie ~]# tail -3 /etc/security/limits.conf     ------>修改配置文件可以永久修改但是但是不能立即生效。需要重启操作系统才好使,和关闭selinux机制很像。
    16 #Add by yinzhengjie
    17 apache          hard    nofile          65535
    18 apache          hard    nproc           30000
    19 [root@yinzhengjie ~]# 
     
    四.httpd2.4新特性
      它依赖于更高版本的apr(apr全称 apache portable runtime,运行时移植)和arp-util。apr是一个移植工具,是一个让Apache可以跨平台的工具,它是一个底层库。有了这个apr以后,你在windows装饰apr,在Linux也安装上apr,那么我们的Apache的代码既可以在windows上跑又可以在Linux上跑。对于httpd2.4它需要apr-1.4以上版本。
      apr和arp-util软件包的下载地址:http://mirror.bit.edu.cn/apache/apr/
      httpd软件包的下载地址:http://mirror.bit.edu.cn/apache/httpd/
      httpd2.4的特点有以下几点:
        1>.MPM支持在运行时装载
          --enable-mpms-shared=all --with-mpm=event 启用默认的event
        2>. 支持event
        3>.异步读写
        4>.在每模块及每目录上指定日志级别
        5>.每请求配置:<If> <Elseif>
        6>.增强版的表达式分析器
        7>.毫秒级的keepalive timeout
        8>.支持主机名的虚拟主机不在需要NameVirtualHost指令
        9>.支持使用自定义变量
      httpd2.4新增一些模块:
        1>.mod_proxy_fcgi(基于fcgi模块去连接PHP的);
        2>.mod_ratelimit(用作速率限定);
        3>.mod_request(对请求方法限定的);
        4>.mod_remoteip(对远端ip做限定的)等等;
      对于基于IP的访问做了修改,不在使用order,allow,deny这些机制;而是统一使用require进行。
     
    五.编译安装httpd2.4
    1.将之间的yum安装打入冷宫;
    1 [root@yinzhengjie httpd]# service httpd stop
    2 Stopping httpd: [  OK  ]
    3 [root@yinzhengjie httpd]# chkconfig httpd off
    4 [root@yinzhengjie ~]# lsof -i :80
    5 [root@yinzhengjie ~]# netstat -untalp | grep 80
    6 [root@yinzhengjie ~]# 
    2.安装环境
    1 [root@yinzhengjie ~]# cat /etc/redhat-release 
    2 CentOS release 6.6 (Final)
    3 [root@yinzhengjie ~]# 
    4 [root@yinzhengjie ~]# uname -r
    5 2.6.32-504.el6.x86_64
    6 [root@yinzhengjie ~]# 
    7 [root@yinzhengjie ~]# uname -m
    8 x86_64
    9 [root@yinzhengjie ~]# 
    3.解决依赖环境-安装pcre-devel软件包,该包用来支持httpd的正则表达式。
     1 [root@yinzhengjie ~]# rpm -qi pcre
     2 Name        : pcre                         Relocations: (not relocatable)
     3 Version     : 7.8                               Vendor: CentOS
     4 Release     : 6.el6                         Build Date: Fri 07 Sep 2012 04:03:41 AM PDT
     5 Install Date: Fri 13 Oct 2017 01:13:49 PM PDT      Build Host: c6b8.bsys.dev.centos.org
     6 Group       : System Environment/Libraries   Source RPM: pcre-7.8-6.el6.src.rpm
     7 Size        : 526268                           License: BSD
     8 Signature   : RSA/SHA1, Fri 07 Sep 2012 06:12:35 AM PDT, Key ID 0946fca2c105b9de
     9 Packager    : CentOS BuildSystem <http://bugs.centos.org>
    10 URL         : http://www.pcre.org/
    11 Summary     : Perl-compatible regular expression library
    12 Description :
    13 Perl-compatible regular expression library.        ------>Perl兼容的正则表达式库,Apache和Nginx都依赖于CGI,而CGI又通常是以Perl为基准的。
    14 PCRE has its own native API, but a set of "wrapper" functions that are based on
    15 the POSIX API are also supplied in the library libpcreposix. Note that this
    16 just provides a POSIX calling interface to PCRE: the regular expressions
    17 themselves still follow Perl syntax and semantics. The header file
    18 for the POSIX-style functions is called pcreposix.h.
    19 [root@yinzhengjie ~]# 
    20 [root@yinzhengjie ~]# yum -y install pcre-devel
    4.解决依赖环境-安装apr软件包,我们这里通过源码安装
     1 [root@yinzhengjie httpd]# pwd
     2 /yinzhengjie/httpd
     3 [root@yinzhengjie httpd]# ll
     4 total 7672
     5 -rw-r--r--. 1 root root  853363 Oct 24 08:05 apr-1.6.2.tar.bz2
     6 -rw-r--r--. 1 root root  428595 Oct 24 08:06 apr-util-1.6.1.tar.bz2
     7 -rw-r--r--. 1 root root 6567926 Oct 24 08:08 httpd-2.4.29.tar.bz2
     8 [root@yinzhengjie httpd]# tar xf apr-1.6.2.tar.bz2 
     9 [root@yinzhengjie httpd]# cd apr-1.6.2
    10 [root@yinzhengjie apr-1.6.2]#  ./configure --prefix=/yinzhengjie/apr        ---->编译时需要指定安装路径,你可以自定义。
    11 [root@yinzhengjie apr-1.6.2]# make -j 4 && make install        ----->开始安装
    12 [root@yinzhengjie apr-1.6.2]# ls /yinzhengjie/apr/        -----检查是否安装成功
    13 bin  build-1  include  lib
    14 [root@yinzhengjie apr-1.6.2]# 
     
    5.解决依赖环境-安装apr-util,它是apr的工具,我们也通过源码的方式安装
    1 [root@yinzhengjie apr-util-1.6.1]# yum -y install expat-devel    ----这个包是安装apr-util时所依赖的。
    2 [root@yinzhengjie apr-1.6.2]# cd ..
    3 [root@yinzhengjie httpd]# tar xf apr-util-1.6.1.tar.bz2 
    4 [root@yinzhengjie httpd]# cd apr-util-1.6.1
    5 [root@yinzhengjie apr-util-1.6.1]# ./configure --prefix=/yinzhengjie/apr-util --with-apr=/yinzhengjie/apr/        ------>因为apr-util是apr的工具,因此我们需要告诉它apr的安装路径
    6 [root@yinzhengjie apr-util-1.6.1]# make -j 4 && make install
    6.httpd的编译安装
     1 [root@yinzhengjie ~]# wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz        --->如果你的OpenSSL太老了可能会导致没法配置httpd的步骤,我们可以直接安装一下新版本的OpenSSL即可,然后在安装的时候指定安装的路径
     2 [root@yinzhengjie ~]# tar xf openssl-1.0.2l.tar.gz
     3 [root@yinzhengjie ~]# cd openssl-1.0.2l
     4 [root@yinzhengjie ~]# ./config --prefix=/usr/local/openssl    ----配置OpenSSL的安装路径
     5 [root@yinzhengjie ~]# make -j 4                          ---->编译OpenSSL(最多允许4个编译命令同时执行)
     6 [root@yinzhengjie ~]# make install                        ---->开始安装
     7 [root@yinzhengjie ~]# mkdir /yinzhengjie/etc
     8 [root@yinzhengjie ~]# cd /yinzhengjie/httpd/
     9 [root@yinzhengjie httpd]# tar xf httpd-2.4.29.tar.bz2 
    10 [root@yinzhengjie httpd]# cd httpd-2.4.29
    11 [root@yinzhengjie httpd-2.4.29]# ./configure --prefix=/yinzhengjie/apache --sysconfdir=/yinzhengjie/etc/http24 --enable-so --enable-ssl=/usr/local/openssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/yinzhengjie/apr --with-apr-util=/yinzhengjie/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-event
    12 [root@yinzhengjie httpd-2.4.29]# make -j 4 && make install
    13 [root@yinzhengjie httpd-2.4.29]# cd
    14 [root@yinzhengjie ~]# cd /yinzhengjie/apache/            ---->检查是否安装成功。
    15 [root@yinzhengjie apache]# ll
    16 total 52
    17 drwxr-xr-x.  2 root root  4096 Oct 24 09:31 bin            ---->可以使用的工具,基本上都是可执行脚本
    18 drwxr-xr-x.  2 root root  4096 Oct 24 09:31 build            ----->编译时的一些工具;
    19 drwxr-xr-x.  2 root root  4096 Oct 24 09:31 cgi-bin            ------>存放CGI执行脚本的目录;
    20 drwxr-xr-x.  3 root root  4096 Oct 24 09:31 error            ------->存放错误页面的目录;
    21 drwxr-xr-x.  2 root root  4096 Oct 17 11:53 htdocs            ------>存放网页的目录;
    22 drwxr-xr-x.  3 root root  4096 Oct 24 09:31 icons            ------->存放一些二进制文件的目录;
    23 drwxr-xr-x.  2 root root  4096 Oct 24 09:31 include            ------->存放头部文件的目录;
    24 drwxr-xr-x.  2 root root  4096 Oct 24 09:31 logs            -------->存放日志的目录;
    25 drwxr-xr-x.  4 root root  4096 Oct 24 09:31 man            -------->存放帮助文档目录;
    26 drwxr-xr-x. 14 root root 12288 Oct 17 11:53 manual        -------->存放手册的目录;
    27 drwxr-xr-x.  2 root root  4096 Oct 24 09:31 modules        -------->存放模块的目录;
    28 You have new mail in /var/spool/mail/root
    29 [root@yinzhengjie apache]# 
     
    httpd安装参数说明:
      --prefix=/yinzhengjie/apache --->配置指定的安装路径,以后要是不用了直接删除即可;
      --sysconfdir=/yinzhengjie/etc/http24 ---->配置指定配置文件的存放处;
      --enable-so ----->配置支持基于DSO方式动态加载模块;
      --enable-ssl=/usr/local/openssl ------>配置支持https协议;
      --enable-cgi ------>配置支持CGI机制
      --enable-rewrite ------>配置支持URL重新机制;
      --with-zlib ------>配置zlib(它是网络上发送数据报文通用压缩库的API)库,你可以理解是支持压缩功能;
      --with-pcre ------>配置支持prel(支持正则);
      --with-apr=/yinzhengjie/apr ------>配置支持apr,如果不跟路径就会去默认的位置找,因为我们是自定义安装的就得写明路径;
      --with-apr-util=/yinzhengjie/apr-util/ ----->配置apr-util;
      --enable-modules=most ------>配置大多数常用的模块;
      --enable-mpms-shared=all ------>配置所有的mpm模块都编译进来;
      --with-event ------->配置指定使用event模式,当然你也可以选择worker模式或者prefork模式均可,由于event是该版本的新特性,因此我们就用新的来测试一下吧。
     
    六.安装httpd后续配置
      1 1.导出头文件(有人易于它二次开发需要导出,或是后期编译PHP可能也会用到)
      2 [root@yinzhengjie ~]# ln -sv /yinzhengjie/apache/include /usr/include/httpd
      3 `/usr/include/httpd' -> `/yinzhengjie/apache/include'
      4 [root@yinzhengjie ~]#
      5 2.导出库文件(由于没有库,我们这里了解一下该命令即可)
      6 [root@yinzhengjie ~]# vim /etc/ld.so.conf.d/http.conf
      7 [root@yinzhengjie ~]# ldconfig -p        ------>查看当前系统已经缓存的库文件列表
      8 3.导出man手册
      9 [root@yinzhengjie ~]# more /etc/man.config  | grep yinzhengjie    ----->可以在man路径里面帮助文档路径
     10 MANPATH /yinzhengjie/apache/man
     11 [root@yinzhengjie ~]# 
     12 [root@yinzhengjie ~]# man -M /yinzhengjie/apache/man httpd    ----->指定目录获取man帮助信息
     13 4.添加程序的path环境
     14 [root@yinzhengjie ~]# more /etc/profile.d/httpd.sh 
     15 export PATH=/yinzhengjie/apache/bin:$PATH
     16 [root@yinzhengjie ~]# 
     17 [root@yinzhengjie ~]# . /etc/profile.d/httpd.sh             ----->重新加载一下该配置文件
     18 [root@yinzhengjie ~]# 
     19 [root@yinzhengjie ~]# httpd -V    ---->查看Apache当前的版本
     20 Server version: Apache/2.4.29 (Unix)
     21 Server built:   Oct 24 2017 09:30:02
     22 Server's Module Magic Number: 20120211:68
     23 Server loaded:  APR 1.6.2, APR-UTIL 1.6.1
     24 Compiled using: APR 1.6.2, APR-UTIL 1.6.1
     25 Architecture:   64-bit
     26 Server MPM:     event
     27   threaded:     yes (fixed thread count)
     28     forked:     yes (variable process count)
     29 Server compiled with....
     30  -D APR_HAS_SENDFILE
     31  -D APR_HAS_MMAP
     32  -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
     33  -D APR_USE_SYSVSEM_SERIALIZE
     34  -D APR_USE_PTHREAD_SERIALIZE
     35  -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
     36  -D APR_HAS_OTHER_CHILD
     37  -D AP_HAVE_RELIABLE_PIPED_LOGS
     38  -D DYNAMIC_MODULE_LIMIT=256
     39  -D HTTPD_ROOT="/yinzhengjie/apache"
     40  -D SUEXEC_BIN="/yinzhengjie/apache/bin/suexec"
     41  -D DEFAULT_PIDLOG="logs/httpd.pid"
     42  -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
     43  -D DEFAULT_ERRORLOG="logs/error_log"
     44  -D AP_TYPES_CONFIG_FILE="/yinzhengjie/etc/http24/mime.types"
     45  -D SERVER_CONFIG_FILE="/yinzhengjie/etc/http24/httpd.conf"
     46 [root@yinzhengjie ~]# 
     47 5.启动新版的Apache。
     48 [root@yinzhengjie ~]# apachectl start
     49 [root@yinzhengjie ~]# lsof -i :80
     50 COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
     51 httpd   69937   root    4u  IPv6 110433      0t0  TCP *:http (LISTEN)
     52 httpd   69938 daemon    4u  IPv6 110433      0t0  TCP *:http (LISTEN)
     53 httpd   69939 daemon    4u  IPv6 110433      0t0  TCP *:http (LISTEN)
     54 httpd   69940 daemon    4u  IPv6 110433      0t0  TCP *:http (LISTEN)
     55 You have new mail in /var/spool/mail/root
     56 [root@yinzhengjie ~]# 
     57 [root@yinzhengjie ~]# 
     58 [root@yinzhengjie ~]# curl http://www.yinzhengjie.org.cn    ---->验证服务是否启动成功。
     59 <html><body><h1>It works!</h1></body></html>
     60 [root@yinzhengjie ~]# 
     61 
     62 6.查看配置文件的目录;
     63 [root@yinzhengjie ~]# cd /yinzhengjie/etc/http24/    
     64 [root@yinzhengjie http24]# ll
     65 total 104
     66 drwxr-xr-x. 2 root root  4096 Oct 24 09:31 extra            ------>是httpd.conf主配置的补充文件目录;
     67 -rw-r--r--. 1 root root 18811 Oct 24 09:31 httpd.conf
     68 -rw-r--r--. 1 root root 13077 Oct 24 09:31 magic
     69 -rw-r--r--. 1 root root 60847 Oct 24 09:31 mime.types
     70 drwxr-xr-x. 3 root root  4096 Oct 24 09:31 original
     71 [root@yinzhengjie http24]# 
     72 [root@yinzhengjie http24]# cp httpd.conf{,bak}        ----->备份配置文件
     73 [root@yinzhengjie http24]# grep mpm_event_module httpd.conf
     74 LoadModule mpm_event_module modules/mod_mpm_event.so
     75 [root@yinzhengjie http24]#     
     76 [root@yinzhengjie ~]# ll /yinzhengjie/etc/http24/extra/
     77 total 68
     78 -rw-r--r--. 1 root root  2883 Oct 24 09:31 httpd-autoindex.conf
     79 -rw-r--r--. 1 root root  1822 Oct 24 09:31 httpd-dav.conf
     80 -rw-r--r--. 1 root root  2942 Oct 24 09:31 httpd-default.conf
     81 -rw-r--r--. 1 root root  1119 Oct 24 09:31 httpd-info.conf
     82 -rw-r--r--. 1 root root  5078 Oct 24 09:31 httpd-languages.conf
     83 -rw-r--r--. 1 root root  1397 Oct 24 09:31 httpd-manual.conf    ------>配置手册是否启动;
     84 -rw-r--r--. 1 root root  4444 Oct 24 09:31 httpd-mpm.conf    ------>配置httpd的工作模式文件;
     85 -rw-r--r--. 1 root root  2225 Oct 24 09:31 httpd-multilang-errordoc.conf
     86 -rw-r--r--. 1 root root 13379 Oct 24 09:31 httpd-ssl.conf        ------->配置https的文件;
     87 -rw-r--r--. 1 root root   694 Oct 24 09:31 httpd-userdir.conf
     88 -rw-r--r--. 1 root root  1469 Oct 24 09:31 httpd-vhosts.conf    -------->配置虚拟主机的文件;
     89 -rw-r--r--. 1 root root  3161 Oct 24 09:31 proxy-html.conf
     90 [root@yinzhengjie ~]#     
     91 
     92 7.自定义启动脚本
     93 其实也不用自定义,直接把之前较低版本的脚本拿来改一下路径即可。
     94 [root@yinzhengjie ~]# cd /etc/init.d/
     95 [root@yinzhengjie init.d]# cp httpd httpd24 
     96 [root@yinzhengjie init.d]# more httpd24 | grep httpd=
     97 httpd=/yinzhengjie/apache/bin/httpd    ----->指定httpd服务存放处
     98 [root@yinzhengjie init.d]# more httpd24 | grep apachectl=
     99 apachectl=/yinzhengjie/apache/bin/apachectl            ----->指定该命令的位置
    100 [root@yinzhengjie init.d]# 
    101 [root@yinzhengjie init.d]# more httpd24 | grep pidfile= | grep -v LANG
    102 pidfile=${PIDFILE-/yinzhengjie/apache/logs/httpd.pid}        ------>指定进程存放pid的文件
    103 [root@yinzhengjie init.d]# 
    104 [root@yinzhengjie ~]# chkconfig --add httpd24
    105 [root@yinzhengjie ~]# chkconfig httpd24 on        ------>让其开启开机自启即可;
    106 [root@yinzhengjie ~]# chkconfig httpd24 --list
    107 httpd24         0:off   1:off   2:on    3:on    4:on    5:on    6:off
    108 [root@yinzhengjie ~]# 
    109 [root@yinzhengjie ~]# service httpd24 restart
    110 Stopping httpd: [  OK  ]
    111 Starting httpd: [  OK  ]
    112 [root@yinzhengjie ~]# 
     
     
     
     
     
  • 相关阅读:
    大数据离线分析平台 JavaSDK数据收集引擎编写
    大数据离线分析平台 需求分析(三)
    大数据离线分析平台 需求分析(二)
    大数据离线分析平台 需求分析(一)
    Hive 严格模式与非严格模式
    MapReduce案例:统计共同好友+订单表多表合并+求每个订单中最贵的商品
    Hadoop 目录分析及存储机制
    zookeeper 启动显示started,jps查看进程却没有,解决方法
    Azkaban介绍+安装部署+实战案例
    Flume 高可用配置案例+load balance负载均衡+ 案例:日志的采集及汇总
  • 原文地址:https://www.cnblogs.com/yinzhengjie/p/7795397.html
Copyright © 2020-2023  润新知