成都创新互联网站制作重庆分公司

apache服务自动化安装_shell脚本-创新互联

项目背景:在局域网内,取某一台主机当作服务器,并且开启ftp服务,提供apr、apr-utils、pcre、httpd软件下载

成都创新互联专业为企业提供都兰网站建设、都兰做网站、都兰网站设计、都兰网站制作等企业网站建设、网页设计与制作、都兰企业网站模板建站服务,十年都兰做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

运行环境:redhat 6.4

#!/bin/bash
#自动化安装apache
yum list &>/dev/null
if [[ "$?" != "0" ]];then
   if [ -e /dev/sr0 ];then
      mount /dev/sr0 /mnt
   elif [ -e /dev/cdrom ];then
      mount /dev/cdrom /mnt
   else
      echo "未检测到光盘,请插入光盘"
      exit 10
   fi
   #搭建yum源
   cd /etc/yum.repos.d
   sed -i "s/^/#/g" *.repo
cat << EOF >>*.repo
[local]
name=local
baseurl=file:///mnt
enabled=1
gpgcheck=0
EOF
   yum list &>/dev/null
   if [ $? -eq 0 ];then
      echo "yum源搭建成功"
   else
      echo "yum源搭建失败,系统退出"
      exit 20
   fi
fi

ruanjian=(gcc gcc-c++ lynx)
echo "${ruanjian[@]}"
for i in ${ruanjian[@]}
do
   yum remove $i -y &>/dev/null
   if [ $? -eq 0 ];then
      yum install $i -y &>/dev/null
      if [ $? -eq 0 ];then
         continue
      else
         echo "$i install error,program exit"
         exit 30
      fi
   else
      echo "$i remove error"
      exit 40
   fi
done

#下载源码包
yum install expect -y &>/dev/null
ping -c 3 10.0.0.254 &>/dev/null
if [ $? -eq 0 ];then
   yum install lftp -y &>/dev/null
   mkdir /root/soft
   cd /root/soft
/usr/bin/expect <set timeout 20
spawn lftp 10.0.0.254
expect {
   "*" { send "mget soft/lamp/httpd-2.4.20.tar.bz2 soft/lamp/apr-1.5.2.tar.gz soft/lamp/apr-util-1.5.4.tar.gz soft/lamp/pcre-8.36.tar.gz\n"}
}
expect {
   "*" { send "exit\n"}
}
expect eof
EOF
   if [ $? -eq 0 ];then
      echo "源码包下载成功"
   else
      echo "源码包下载失败,程序退出"
      exit 50
   fi
else
   echo "与服务器网络不通,程序退出"
   exit 60
fi

cd /root/soft

tar -xf httpd-2.4.20.tar.bz2
cp -ar httpd-2.4.20 httpd

tar -xf apr-1.5.2.tar.gz
cp -ar apr-1.5.2 apr

tar -xf apr-util-1.5.4.tar.gz
cp -ar apr-util-1.5.4 apr-util

tar -xf pcre-8.36.tar.gz
cp -ar pcre-8.36 pcre

cd ./pcre
pwd
./configure --prefix=/usr/local/pcre --enable-utf8 --enable-jit &>./pcre.txt
if [ $? -eq 0 ];then
      yum install make -y &>/dev/null
      make &>./pcre.txt && make install &>./pcre.txt
       if [ $? -eq 0 ];then
               echo "pcre安装成功"
       else
               echo "pcre安装失败,程序退出"
               exit 70
       fi
else
       echo "pcre配置失败,程序退出"
       exit 80
fi
cd ..

cd ./httpd/srclib
pwd
cp -r ../../apr .
cp -r ../../apr-util .
cd ..
./configure --prefix=/usr/local/httpd --enable-cache --enable-cache-disk --enable-cache-socache --enable-so --enable-modules=all --enable-mods-shared=all --enable-echo --enable-data --enable-include --enable-sed --enable-proxy --enable-proxy-connect --enable-proxy-http --enable-proxy-fcgi --enable-proxy-scgi --enable-proxy-ajp --enable-proxy-balancer --enable-info --enable-rewrite  --with-pcre=/usr/local/pcre --enable-mpms-shared=all --enable-userdir &>./httpd.txt
if [ $? -eq 0 ];then
       make &>./httpd.txt && make install &>./httpd.txt
       if [ $? -eq 0 ];then
               echo "apache安装成功"
       else
               echo "apache安装失败,程序退出"
               exit 80
       fi
else
       echo "apache配置失败,程序退出"
       exit 90
fi

#编辑配置文件,开启apache服务
cd /usr/local/httpd/conf
pwd
ip="`ifconfig eth0|grep "inet addr:"|awk -F ":" '{print $2}'|awk '{print $1}' `"
sed -i "/ServerName www.example.com:80/a ServerName $ip" httpd.conf
sed -i "/^#Include conf\/extra\/httpd-mpm.conf/a Include conf/extra/httpd-mpm.conf" httpd.conf
sed -i "/^#Include conf\/extra\/httpd-default.conf/a Include conf/extra/httpd-default.conf" httpd.conf

#验证apache服务是哦否开启成功
#cd /usr/local/httpd/bin
#./apachectl start
#lsof -i:80 -n
#if [ $? -eq 0 ];then
#   echo "apache服务开启成功"
#else
#   echo "apache服务开启失败,开始查看错误日志"
#   tail ../logs/error_log
#fi

#将httpd服务加入到service管理
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
sed -i "9a #    chkconfig: - 85 15" /etc/init.d/httpd
chkconfig --add httpd
service httpd start
lsof -i:80 -n &>/dev/null
if [ $? -eq 0 ];then
   echo "apache服务开启成功"
else
   echo "apache服务开启失败,开始查看错误日志"
   tail ../logs/error_log
fi

我的测试结果会报错,说mod_slotmem_shm这个模块没有开启,可以编辑httpd.conf文件,开启这个模块,可以成功开启apache服务

具体错误如下:

[Sun Aug 28 13:40:01.931826 2016] [proxy_balancer:emerg] [pid 74484:tid 140584019928832] AH01177: Failed to lookup provider 'shm' for 'slotmem': is mod_slotmem_shm loaded??
[Sun Aug 28 13:40:01.932096 2016] [:emerg] [pid 74484:tid 140584019928832] AH00020: Configuration Failed, exiting

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


新闻标题:apache服务自动化安装_shell脚本-创新互联
当前路径:http://cxhlcq.cn/article/dsphdi.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部