#!/bin/bash
#function:Source code compile and install Apache
#author:signal
#filname:Install_Apache.sh
#date:2018-03-16
#version:1.0
echo -e “Follow the prompts:\n\t1:Check if Apache is installed\n\t2:Download Apache source package\n\t3:Compile and install\n\t”
cpu=`lscpu | sed -n ‘4p’ | awk ‘{print $2}’`
dir=$PWD
dir1=”/data/httpd”
dir2=”/etc/httpd24″
Chenk(){
rpm -q httpd &>/dev/null
if [ $? -eq 0 ];then
echo “Apache is already installed”
else
echo “Apache is not installed,please continue,Re-execute the script 2”
fi
}
Download(){
echo “============================================================”
dir=$PWD
[ ! -d $dir/httpd_tmp ] && mkdir -p ${dir}/httpd_tmp
cd ${dir}/httpd_tmp && wget http://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.29.tar.gz &>/dev/null
[ $? -eq 0 ] && echo “Apache is Download” || echo “download failed,please check your network,Downloading”
cd ${dir}/httpd_tmp && tar xf http* && rm -f *.tar.gz && echo “Decompression succeeded”
}
Cinstall(){
#/usr/bin/yum -y groupinstall “development tools” && yum -y install apr-devel apr-util-devel pcre-devel &>/dev/null
#if [ $? -eq 0 ];then
# echo “Compiled dependencies and related tools have been installed successfully”
#fi
echo “============================================================”
[ ! -d $dir1 ] && mkdir -p $dir1
[ ! -d $dir2 ] && mkdir -p $dir2
#cd ${dir}/httpd_tmp/ && rm -f *.tar.gz
cd ${dir}/httpd_tmp/http*
./configure –prefix=/data/httpd –sysconfdir=/etc/httpd24 &>${dir}/fail.txt
if [ $? -eq 0 ];then
echo “configure successfully”
else
echo “configure failed”
exit 1
fi
make -j $cpu &>${dir}/failmake.txt
if [ $? -eq 0 ];then
echo “make successfully”
else
echo “make failed”
exit 1
fi
make install &>${dir}/failaaa.txt
if [ $? -eq 0 ];then
echo “mkae install successfully”
echo “PATH=${dir1}/bin:$PATH” > /etc/profile.d/httpd24.sh
source /etc/profile.d/httpd24.sh
else
echo “make install failed”
exit 1
fi
}
read -p “Please input your number: 1)Check install Apache 2)download apache 3) Compile and install apache ” num
case $num in
1)
Chenk
;;
2)
Download
;;
3)
Cinstall
;;
*)
echo “Please enter again”
;;
esac
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/92563