zoukankan      html  css  js  c++  java
  • 编译安装httpd

    编译安装httpd

    实验准备:

        httpd包:httpd-2.4.41.tar.gz
        apr依赖包:apr-1.7.0.tar.bz2、apr-util-1.6.1.tar.bz2
    

    开始编译:

    • 下载相关依赖包
    [root@centos7 ~]$yum -y install gcc make pcre-devel openssl-devel expat-devel
    
    • 解压包
    [root@centos7 src]$ll
    total 10324
    -rw-r--r-- 1 root root  872238 May 14  2019 apr-1.7.0.tar.bz2
    -rw-r--r-- 1 root root  428595 May 14  2019 apr-util-1.6.1.tar.bz2
    -rw-r--r-- 1 root root 9267917 Oct  8 15:10 httpd-2.4.41.tar.gz
    
    [root@centos7 src]$tar xvf apr-1.7.0.tar.bz2 
    [root@centos7 src]$tar xvf apr-util-1.6.1.tar.bz2 
    [root@centos7 src]$tar xvf httpd-2.4.41.tar.gz 
    
    [root@centos7 src]$ll
    total 10336
    drwxr-xr-x 27 1001 1001    4096 Apr  2  2019 apr-1.7.0
    -rw-r--r--  1 root root  872238 May 14  2019 apr-1.7.0.tar.bz2
    drwxr-xr-x 20 1001 1001    4096 Oct 18  2017 apr-util-1.6.1
    -rw-r--r--  1 root root  428595 May 14  2019 apr-util-1.6.1.tar.bz2
    drwxr-sr-x 11 root   40    4096 Aug  9 21:36 httpd-2.4.41
    -rw-r--r--  1 root root 9267917 Oct  8 15:10 httpd-2.4.41.tar.gz
    
    • 三个目录合并编译
    [root@centos7 src]$mv apr-1.7.0 httpd-2.4.41/srclib/apr
    [root@centos7 src]$mv apr-util-1.6.1 httpd-2.4.41/srclib/apr-util
    
    [root@centos7 src]$ll httpd-2.4.41/srclib/
    total 12
    drwxr-xr-x 27 1001 1001 4096 Dec 10 20:26 apr
    drwxr-xr-x 20 1001 1001 4096 Oct 18  2017 apr-util
    -rw-r--r--  1 root   40  121 Feb 11  2005 Makefile.in
    
    • 进入目录开始编译
    [root@centos7 src]$cd httpd-2.4.41/   # 进入到这个目录里
    
    [root@centos7 httpd-2.4.41]$./configure     # 指定编译安装
    --prefix=/app/httpd24 
    --enable-so 
    --enable-ssl 
    --enable-cgi 
    --enable-rewrite 
    --with-zlib 
    --with-pcre 
    --with-included-apr 
    --enable-modules=most 
    --enable-mpms-shared=all 
    --with-mpm=prefork
    
    [root@centos7 ~]$make && make install   # 编译完成之后执行
    
    • 添加PATH变量
    [root@centos7 httpd-2.4.41]$echo 'PATH=/app/httpd24/bin:$PATH' > /etc/profile.d/httpd24.sh
    [root@centos7 httpd-2.4.41]$. /etc/profile.d/httpd24.sh
    
    • 启动服务
    [root@centos7 ~]$apachectl start
    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::c970:4699:c2c3:ec08%eth0. Set the 'ServerName' directive globally to suppress this message
    [root@centos7 ~]$ss -ntl
    State       Recv-Q Send-Q  Local Address:Port                 Peer Address:Port              
    LISTEN      0      128                 *:22                              *:*                  
    LISTEN      0      100         127.0.0.1:25                              *:*                  
    LISTEN      0      128                :::80                             :::*                  
    LISTEN      0      128                :::22                             :::*                  
    LISTEN      0      100               ::1:25                             :::*                 
    
    • 创建服务用户
    [root@centos7 ~]$useradd -s /sbin/nologin -r apache
    
    • 更改为开机启动
    [root@centos7 ~]$vim /etc/rc.d/rc.local   # 在这个配置文件里加上这一行就可以了
    /app/httpd24/bin/apachectl start
    
    [root@centos7 ~]$ll /etc/rc.d/rc.local
    -rw-r--r-- 1 root root 506 Dec 10 20:47 /etc/rc.d/rc.local
    [root@centos7 ~]$chmod +x /etc/rc.d/rc.local  # 添加执行权限
    [root@centos7 ~]$ll /etc/rc.d/rc.local 
    -rwxr-xr-x 1 root root 506 Dec 10 20:47 /etc/rc.d/rc.local
    
    • 指定运行httpd的用户
    [root@centos7 ~]$vim /app/httpd24/conf/httpd.conf 
    # User/Group: The name (or #number) of the user/group to run httpd as.
    # It is usually good practice to create a dedicated user and group for
    # running httpd, as with most system services.
    #
    User apache    # 修改这两行
    Group apache
    
    
    • 配置帮助
    [root@centos7 ~]$vim /etc/man_db.conf 
    MANDATORY_MANPATH                       /app/httpd24/man
    
    • 重启服务 (这个提示是没有绑定SeeverName)
    [root@centos7 ~]$apachectl restart
    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::c970:4699:c2c3:ec08%eth0. Set the 'ServerName' directive globally to suppress this message
    
    • 指定服务器名
    # If your host doesn't have a registered DNS name, enter its IP address here.
    #
    ServerName localhost:80   # 找到这一行原来这一行是注释掉的取消注释并在后面加上自己想要的名字,注意:这里不是域名可以按自己意愿设置。
    
    • 重启服务
    [root@centos7 ~]$apachectl restart
    [root@centos7 ~]$apachectl restart
    [root@centos7 ~]$apachectl restart  # 不在出现那个提示
    
    • 创建service unit文件(使这个服务受system监控)
    # centos7以上版本适用
    [root@centos7 ~]$vim /usr/lib/systemd/system/httpd.service
    [Unit]
    Description=The Apache HTTP Server
    After=network.target remote-fs.target nss-lookup.target
    Documentation=man:httpd(8)
    Documentation=man:apachectl(8)
    [Service]
    Type=forking
    #EnvironmentFile=/etc/sysconfig/httpd
    ExecStart=/app/httpd24/bin/httpd $OPTIONS -k start
    ExecReload=/app/httpd24/bin/httpd $OPTIONS -k graceful
    ExecStop=/bin/kill -WINCH {MAINPID}
    KillSignal=SIGCONT
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target
    
    # centos6以前版本启动服务脚本
    #自定义启动脚本(参考httpd-2.2的服务脚本)
    [root@centos6 ~]$cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24
    [root@centos6 ~]$vim /etc/rc.d/init.d/httpd24
    apachectl=/app/httpd24/bin/apachectl
    httpd=${HTTPD-/app/httpd24/bin/httpd}
    pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}
    lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
    
    [root@centos6 ~]$chkconfig –add httpd24
    [root@centos6 ~]$chkconfig –list httpd24
    
    • 使用systemd和service启动服务
    
    [root@centos7 ~]$apachectl stop   # 先使用apachectl停止服务
    [root@centos7 ~]$systemctl start httpd  # 再用systemctl启动服务
    [root@centos7 ~]$ss -ntl                # 查看端口
    State       Recv-Q Send-Q  Local Address:Port                 Peer Address:Port              
    LISTEN      0      128                 *:22                              *:*                  
    LISTEN      0      100         127.0.0.1:25                              *:*                  
    LISTEN      0      128                :::80                             :::*                  
    LISTEN      0      128                :::22                             :::*                  
    LISTEN      0      100               ::1:25                             :::*                
    
    # centos6 启动方法
    [root@centos6 ~]$apachectl stop
    [root@centos6 ~]$service httpd start
    
    • 重新加载服务
    [root@centos7 ~]$systemctl status httpd.service
    ● httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled
       Active: active (running) since Tue 2019-12-10 22:06:02 CST; 10s ago
         Docs: man:httpd(8)
               man:apachectl(8)
      Process: 7629 ExecStop=/bin/kill -WINCH {MAINPID} (code=exited, status=1/FAILURE)   #错误提示
      Process: 7747 ExecStart=/app/httpd24/bin/httpd $OPTIONS -k start (code=exited, status=0/S
     Main PID: 7748 (httpd)
       CGroup: /system.slice/httpd.service
               ├─7748 /app/httpd24/bin/httpd -k start
               ├─7749 /app/httpd24/bin/httpd -k start
               ├─7750 /app/httpd24/bin/httpd -k start
               ├─7751 /app/httpd24/bin/httpd -k start
               ├─7752 /app/httpd24/bin/httpd -k start
               └─7753 /app/httpd24/bin/httpd -k start
    
    Dec 10 22:06:02 centos7 systemd[1]: Starting The Apache HTTP Server...
    Dec 10 22:06:02 centos7 systemd[1]: Started The Apache HTTP Server.
    #如果出现以上情况,关闭服务特别慢,重启服务特别慢
    #重新加载服务配置文件
    [root@centos7 ~]$systemctl restart httpd
    Warning: httpd.service changed on disk. Run 'systemctl daemon-reload' to reload units.
    ^C
    [root@centos7 ~]$systemctl daemon-reload
    
    
    systemctl daemon-reload
    重新加载某个服务的配置文件,如果新安装了一个服务,归属于 systemctl 管理,要是新服务的服务程序配置文件生效,需重新加载
  • 相关阅读:
    objectiveC中的序列化(serialize)与反序列化(deserialize)
    objectiveC 的代码文件组织
    [转载]Multicast Explained in Flash 10.1 P2P
    几种异步操作方式
    objectiveC 的内存管理之自动释放池(autorelease pool)
    用VS2010调试微软开放的部分源码
    浏览器窗口尺寸改变时的图片自动重新定位
    数据结构C#版笔记啥夫曼树(Huffman Tree)与啥夫曼编码(Huffman Encoding)
    objectiveC 的内存管理之实例分析
    objectiveC 的OOP(上)类定义、继承及方法调用
  • 原文地址:https://www.cnblogs.com/www233ii/p/12025158.html
Copyright © 2011-2022 走看看