脚本安装httpd

//在脚本同一目录创建一个file目录用来存放httpd的三个软件包

#!/bin/bash

apache_version=2.4.54
apache_install_dir=/usr/local/apache
if [ $UID -ne 0 ];then
    echo "你不是管理员用户,请使用管理员用户执行此脚本!"
    exit
fi

id apache &>/dev/null
if [ $? -ne 0 ];then
    useradd -rMs /sbin/nologin apache
fi

echo "安装工具包组"
yum -y groups mark install "Development Tools"
yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make wget vim

rm -rf /tmp/*
tar -xf file/apr-1.6.5.tar.gz  -C /tmp/
tar -xf file/apr-util-1.6.1.tar.gz  -C /tmp/
tar -xf file/httpd-2.4.54.tar.gz -C /tmp/

sed -i '/$RM "$cfgfile"/d' /tmp/apr-1.6.5/configure
cd /tmp/apr-1.6.5
if [ ! -d /usr/local/apr ];then
    ./configure --prefix=/usr/local/apr && make && make install
fi

cd /tmp/apr-util-1.6.1
if [ ! -d /usr/local/apr-util ];then
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install
fi

cd /tmp/httpd-$apache_version
if [ ! -d $apache_install_dir ];then
	./configure --prefix=$apache_install_dir \
	--enable-so \
	--enable-ssl \
	--enable-cgi \
     	--enable-rewrite \
	--with-zlib \
	--with-pcre \
	--with-apr=/usr/local/apr \
        --with-apr-util=/usr/local/apr-util/ \
        --enable-modules=most \
        --enable-mpms-shared=all \
        --with-mpm=prefork && \
	make && make install
fi

echo "export PATH=\$PATH:${apache_install_dir}/bin/" > /etc/profile.d/apache.sh
ln -s ${apache_install_dir}/include /usr/include/httpd &> /dev/null
grep 'apache' /etc/man_db.conf
if [ $? -ne 0 ];then
    sed  -i "22aMANDATORY_MANPATH                       ${apache_install_dir}/man" /etc/man_db.conf
else
    echo 'good'
fi

sed -i '/#ServerName/s/#//g' ${apache_install_dir}/conf/httpd.conf
cat > /usr/lib/systemd/system/httpd.service <<EOF
		[Unit]
		Description=httpd server daemon
		After=network.target

		[Service]
		Type=forking
		ExecStart=${apache_install_dir}/bin/apachectl start
		ExecStop=${apache_install_dir}/bin/apachectl stop
		ExecReload=/bin/kill -HUP \$MAINPID

		[Install]
		WantedBy=multi-user.target
EOF
systemctl daemon-reload
if [ $? -eq 0 ];then
    systemctl enable --now httpd
fi
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

1we11

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值