• 编译安装apache2.4


    一、安装需知

    • centos7环境

    • apache有自己独立的接口库,可跨多个操作系统使用。APR:Apache portable Run-time libraries,Apache可移植运行库。

    • httpd安装包下载:官网

    • 编译安装,需要依赖关系

    • 创建apache专用账户

    二、编译操作步骤

    #依赖包下载:
    [root@centos7 ~]#yum -y install gcc make pcre-devel openssl-devel expat-devel
    
    #下载源代码并解压缩:
    [root@centos7 ~]#wget https://downloads.apache.org//apr/apr-1.7.0.tar.bz2
    [root@centos7 ~]#wget https://downloads.apache.org//apr/apr-util-1.6.1.tar.bz2
    [root@centos7 ~]#wget https://downloads.apache.org//httpd/httpd-2.4.46.tar.bz2
    
    [root@centos7 ~]#ls
    httpd-2.4.46.tar.bz2,apr-1.7.0.tar.bz2,apr-util-1.6.1.tar.bz2
    
    [root@centos7 ~]#tar xvf apr-1.7.0.tar.bz2
    [root@centos7 ~]#tar xvf apr-util-1.6.1.tar.bz2
    [root@centos7 ~]#tar xvf httpd-2.4.46.tar.bz2
    
    #将apr和apr-util源码与httpd源码合并,同时编译安装,节约操作步骤
    #注意,要放在httpd目录的srclib目录里,并改名
    mv apr-1.7.0 httpd-2.4.46/srclib/apr
    mv apr-util-1.6.1 httpd-2.4.46/srclib/apr-util
    
    #编译安装
    [root@centos7 ~]#cd /httpd-2.4.43
    [root@centos7 ~]#./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 -j 2 && make install
    

    三、编译后操作

    • Httpd编译过程:/app/httpd24/build/config.nice
    • 自带的服务控制脚本:/app/httpd24/bin/apachectl
    #创建专用账户
    [root@centos7 ~]# useradd -s /sbin/nologin -r apache
    
    #启用账户,需要修改配置文件
    [root@centos7 ~]# vim /app/httpd24/conf/http
    ...
    user apche
    group apache
    ...
    
    #配置帮助文档
    [root@centos7 ~]# vim /etc/man_db.conf
    ...
    MANDATORY_MANPATH /app/httpd24/man
    ...
    
    #配置环境变量,便于快捷启停服务,或者配置service unit文件,用systemctl守护进程控制(推荐),centos7以上支持
    #选一种方式即可,启停的的方式不能混着用,不能用apachectl启动,然后systemctl停
    [root@centos7 ~]# echo 'PATH=/app/httpd24/bin:$PATH' > /etc/profile.d/httpd24.sh
    [root@centos7 ~]# apachectl start | stop
    
    #设置开机启动
    [root@centos7 ~]# echo '/app/httpd24/bin/apachectl start' > /etc/rc.d/rc.local
    [root@centos7 ~]# chmod +x /etc/rc.d/rc.local
    
    -------------------------------------------------------------------------------------------------
    #以上编译安装完成
    
    #下面是推荐配置service unit文件,用systemctl守护进程控制服务,centos7以上支持
    #如果不确定格式,可参考yum安装httpd后的service文件
    [root@centos7 ~]# vim /usr/lib/systemd/system/httpd24.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/apachectl start
    #ExecStart=/app/httpd24/bin/httpd $OPTIONS -k start
    ExecReload=/app/httpd24/bin/apachectl graceful
    #ExecReload=/app/httpd24/bin/httpd $OPTIONS -k graceful
    ExecStop=/app/httpd24/bin/apachectl stop
    KillSignal=SIGCONT
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    

    四、创建启动脚本(CentOS 6 以前版本)

    #自定义启动脚本(参考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
    
  • 相关阅读:
    VMware workstation安装linux(ubuntu)配置详解
    虚拟机的三种网络模式
    虚拟机(VMware Workstation)的使用方法
    零基础学习hadoop到上手工作线路指导(初级篇)
    Hadoop到底能做什么?怎么用hadoop?
    什么是云计算技术
    什么是云计算
    静态数据库迁移
    apache-mysql-php安装与配置
    CentOS6.6下的authpuppy源码安装与配置完全纯净版,内有问题解答
  • 原文地址:https://www.cnblogs.com/jkxm/p/15781912.html
Copyright © 2020-2023  润新知