shell脚本一键部署httpd服务
根据自己需求将下载好的服务压缩包放到/httpd/files
目录下,如果版本与我脚本版本不同只需要把脚本里的版本号改成你需要的版本号就行
此脚本可以重复执行也不会报错
项目目录
[root@localhost ]# cd /httpd
[root@localhost httpd]# tree
.
├── install.sh
└── files
├── apr-1.7.0.tar.gz
├── apr-util-1.6.1.tar.gz
├── httpd-2.4.54.tar.gz
install.sh脚本内容
#!/bin/bash
apache_version=2.4.54
apache_install_dir=/usr/local/apache
if [ $UID -ne 0];then
ehco"请使用管理员用户执行此脚本"
fi
id apache &> /dev/bull
if [ $? -ne 0];then
useradd -rMs /sbin/nologiin apache
exit
fi
yum -y install wget vim make openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
rm -rf /tmp/*
tar xf files/apr-1.7.0.tar.gz -C /tmp
tar xf files/apr-util-1.6.1.tar.gz -C /tmp
tar xf files/httpd-2.4.54.tar.gz -C /tmp
sed -i '/$RM "$cfgfile"/d' /tmp/apr-1.7.0/configure
cd /tmp/apr-1.7.0
if [ ! -d /usr/local/apr ];then
./configure --prefix=/usr/local/apr && \
make && make install
fi
cd ../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 ../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=$apache_install_dir/bin:\$PATH" > /etc/profile.d/httpd.sh
ln -s $apache_install_dir/include /usr/include/httpd &>/dev/null
grep 'apache' /etc/man_db.conf &>/dev/null
if [ $? -ne 0];then
sed -i "22a MANDATORY_MANPATH $apache_install_dir/man" /etc/man_db.conf
fi
cat > /usr/lib/systemd/system/httpd.service << EOF
[Unit]
Description=web server daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP \$MAINPID
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now httpd.service
ss -antl