一键编译安装httpd服务

一键编译安装httpd服务

背景:

httpd服务是一个常用的web服务,所以很多地方会用到,这里写一个一键编译安装httpd服务的脚本。

环境:

系统:centos6.9和centos7.3(应该所有的6和7的版本都可以使用)

httpd源代码版本:httpd-2.2.34.tar.bz2和httpd-2.4.27.tar.bz2 。下载网址官网:http://httpd.apache.org/

条件:已安装yum工具。

准备编译httpd:

当这两个版本的源代码下载好后,我们先将这两个源代码包放在一个文件夹里,这个文件夹取名为httpd。

 

#install development tools 
#安装开发工具组包,其中-y表示当需要输入y/n时,直接选择y
 1 yum groupinstall -y "development tools" &> /dev/null
#这段代码是获取系统的主要版本号是centos6还是centos7,然后将结果放在releasever这个变量里 
 2 releasever=`cat /etc/centos-release | egrep -o " [0-9]" | cut -d" " -f2`
#在编译安装过程中会提示我们有些工具包没有安装,我们这里提前先安装
 3 yum -y install apr-devel.x86_64 &> /dev/null
 4 yum -y install apr-util-devel.x86_64 &> /dev/null
#pcre这个包是我在centos7上测试安装时提示我缺少的包,所以先判断是不是centos7版本,是就安装上
5 [ $releasever -eq 7 ] yum -y install pcre-devel.x86_64 &> /dev/null

开始编译:

 

#先切换目录到httpd下
 18 cd httpd  
#判断系统主版本号,如果是7则解压2.4版本的httpd源代码,如果是6则解压2.2版本的httpd源代码 
#然后切换目录到对应的解压后的文件夹里
#执行configure文件,--prefix=/app/httpd22或者24是指,编译安装的后的文件放在哪,我们这里将所有的文件都放在了/app/httpd22里
#如果需要将不同的文件放在不同的目录下,则需要自己添加相关参数。
 19 [ $releasever -eq 7 ] && tar -xf httpd-2.4.27.tar.bz2 && cd httpd-2.4.27 && ./configure --prefix=/app/httpd24 && make && make install
 20 [ $releasever -eq 6 ] && tar -xf httpd-2.2.34.tar.bz2 && cd httpd-2.2.34 && ./configure --prefix=/app/httpd22 && make && make install
 21 echo "#####httpd install finished####"
 22 echo "#####start config the PATH ####"
#在/etc/profile.d/目录下写配置文件,将httpd的启动过路径放在PATH变量里
 23 [ $releasever -eq 7 ] && echo 'export PATH=/app/httpd24/bin:$PATH' > /etc/profile.d/httpd.sh
 24 [ $releasever -eq 6 ] && echo 'export PATH=/app/httpd22/bin:$PATH' > /etc/profile.d/httpd.sh
#让配置文件生效 
 25 source /etc/profile || echo "httpd.sh start failed"
#启动httpd服务,如果失败则输出开启失败
26 apachectl start || echo "start httpd failed"
 27 echo "#####start httpd finished"
#注销变量 
28 unset releasever

 

完整代码:

 

  1 #!/bin/bash
  2 #install development tools 
  3 yum groupinstall -y "development tools" &> /dev/null
  4 releasever=`cat /etc/centos-release | egrep -o " [0-9]" | cut -d" " -f2`
  5 yum -y install apr-devel.x86_64 &> /dev/null
  6 yum -y install apr-util-devel.x86_64 &> /dev/null
  7 [ $releasever -eq 7 ] yum -y install pcre-devel.x86_64 &> /dev/null
  8 cd httpd  9 [ $releasever -eq 7 ] && tar -xf httpd-2.4.27.tar.bz2 && cd httpd-2.4.27 && ./configure --prefix=/app/ht    tpd24 && make && make install 10 [ $releasever -eq 6 ] && tar -xf httpd-2.2.34.tar.bz2 && cd httpd-2.2.34 && ./configure --prefix=/app/ht    tpd22 && make && make install
 11 echo "#####httpd install finished####"
 12 echo "#####start config the PATH ####"
 13 [ $releasever -eq 7 ] && echo 'export PATH=/app/httpd24/bin:$PATH' > /etc/profile.d/httpd.sh
 14 [ $releasever -eq 6 ] && echo 'export PATH=/app/httpd22/bin:$PATH' > /etc/profile.d/httpd.sh
 15 source /etc/profile || echo "httpd.sh start failed" 16 apachectl start || echo "start httpd failed"
 17 echo "#####start httpd finished"  18 unset releasever               
 18 unset releasever

安装成功界面:

一键编译安装httpd服务

 

原创文章,作者:657188918,如若转载,请注明出处:http://www.178linux.com/83819

(1)
657188918657188918
上一篇 2017-09-16 09:41
下一篇 2017-09-16 09:47

相关推荐

  • linux文件权限详解

    基本命令 1.cut : cat /etc/passwd | cut -d’:’ -f7| uniq -c| sort -nr 2.authconfig 修改加密方式 –passalgo=sha256 — update 3.scp 上传文件 -r dir ip:path 传目录 file ip:path传文件 …

    Linux干货 2017-04-03
  • 使用lxc搭建虚拟机

        使用lxc可以帮助我们搭建轻量级的虚拟机,这种虚拟机的对资源要求不高,非常适合在硬件条件受限时建立多台虚拟机的情况,有助于我们完成需要多节点参与的实验环境。     下面来演示lxc的搭建过程: 一、确保NetworkManager服务是停止的。 二、将宿主机的网卡模拟为…

    Linux干货 2015-06-17
  • 洞悉find中的德摩根定律和条件权限perm

    1.德摩根定律 (1)初悉德摩根定律儿 在命题逻辑和逻辑代数中,德·摩根定律(或称德·摩根定理)是关于命题逻辑规律的一对法则。 奥古斯塔斯·德·摩根首先发现了在命题逻辑中存在着下面这些关系: 非(A 且 B) = (非 A) 或 (非 B)非(A 或 B)&n…

    Linux干货 2016-08-16
  • Linux 基础知识(六.二)

    1、复制/etc/rc.d/rc.sysinit至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加# [root@server01 tmp]# cp /etc/rc.d/rc.sysinit /tmp/ [root@server01 tmp]# sed -n "s@^[[:space:]]\+@#&@…

    Linux干货 2016-11-14
  • 我的学习宣言,不忘初心

    Dear 马哥: 我相信选择马哥教育是正确的。 我将用洪荒之力的努力来成为一名合格的马帮门徒! 一定不学中国足球。 敬礼 自学生 朱宏

    Linux干货 2016-10-30
  • 马哥教育网络班20期+第5周课程练习

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; [root@localhost ~]# grep '^[[:space:]]\+' /boot/grub/grub.conf 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至…

    系统运维 2016-07-12