一键编译安装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

相关推荐

  • centos7 root密码忘记怎么修改

           对于事务繁忙或者容易忘东忘西的朋友说,想要记着一些事情总感觉比登天还要难,特别是像密码之类的。可能要记忆的密码太多,总是不经意间就把密码忘记或者把密码混淆。总之这种站的比例还是有点分量的,例如我刚刚接触Linux时 ,第一把centos7装到电脑上没有多久,就把root密码忘记了,费了好时间,也请教了很多…

    Linux干货 2017-04-03
  • 第五周 N21 总有刁民想害朕

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

    Linux干货 2016-07-16
  • 日志管理

    rsyslogd的相关介绍,journalctl的相关介绍和日志的转储

    2018-02-05
  • iptables基础概念

    iptables基本概念梳理 前言 netfilter/Iptables (其中包括netfilter和Iptables两个组件)组 成了Linux平台下的包过滤防火墙,它与大多数的Linux自带软 件一样,这个防火墙是免费提供的,它可以代替昂贵的企业级 防火墙来解决实际问题与实际方案,完成封包过滤,封包重定 向和网络地址转换等功能。 一、工作原理 数据包从…

    Linux干货 2016-12-19
  • tomcat之-从AT到Cluster

    本文导航 一、    LAMT搭建以及部署应用        1、LAMT部署                   (1)、安装Apache     …

    2017-02-13
  • 逻辑卷管理

    1.相关命令:lsblk、fdisk、gdisk、parted、mkfs、mke2fs、blkid、e2label、findfs、tune2fs、dumpe2fs、fsck、e2fsck、mount、swapon、swapoff、mkisofs、wodim、free、df、du、dd。 2.列出块设备:lsblk    &nbs…

    Linux干货 2016-09-01