脚本编译安装httpd
没有演技全是精髓
#/bin/bash
#列出httpd版本号
echo '有以下可以选择的版本号:
1.2.4.54
2.2.4.53
'
#设置执行权限
if [ $UID -ne 0 ];then
echo "请以管理员用户进行执行"
exit
fi
#定义版本号
apache_version=2.4.54
#定义变量
install_dir=/usr/local/apache
#选择要安装的httpd版本号
read -p "输入你想要下载版本号的序号:"
#定义files下的主页目录名称
homepage=502
#创建用户
id apache &> /dev/null
if [ $? -ne 0 ];then
useradd -r -M -s /sbin/nologin apache
else
echo "用户已存在"
fi
#安装依赖包
dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ wget make vim --allowerasing
#解压源码包
rm -rf /usr/src/*
tar xf files/apr-1.7.0.tar.gz -C /usr/src
tar xf files/apr-util-1.6.1.tar.gz -C /usr/src
tar xf files/httpd-$apache_version.tar.gz -C /usr/src/
if [ ! -d /usr/src/$homepage ];then
mkdir /usr/src/$homepage
cp files/$homepage/* /usr/src/$homepage/
fi
#编译安装apr
cd /usr/src/apr-1.7.0
if [ ! -d /usr/local/apr ];then
sed -i '/$RM "$cfgfile"/d' configure
./configure --prefix=/usr/local/apr && \
make && make install
else
ls /usr/local
echo "apr 编译安装完成"
fi
#编译安装apr-util
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
else
ls /usr/local/
echo "apr-util 编译安装完成"
fi
#编译安装httpd
cd ../httpd-$apache_version/
if [ ! -d ${install_dir} ];then
./configure --prefix=${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
else
ls ${install_dir}
echo "httpd 编译安装完成"
fi
#设置环境变量,man文档,头文件
echo "export PATH=${install_dir}/bin:\$PATH" > /etc/profile.d/apache.sh
ln -s ${install_dir}/include /usr/include/apache &> /dev/null
grep 'apache' /etc/man_db.conf &> /dev/null
if [ $? -ne 0 ];then
sed -i "22a MANDATORY_MANPATH ${install_dir}/man" /etc/man_db.conf
fi
#将其加入systemd服务里面
cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=httpd server daemon
After=network.target
[Service]
Type=forking
ExecStart=${install_dir}/bin/apachectl start
ExecStop=${install_dir}/bin/apachectl stop
ExecReload=/bin/kill -HUP \$MAINPID
[Install]
WantedBy=multi-user.target
EOF
#放行端口
firewall-cmd --add-rich-rule 'rule family=ipv4 source address=0.0.0.0/0 port port=80 protocol=tcp accept' --permanent
firewall-cmd --reload
#加载文件并设置开机自启
systemctl daemon-reload
systemctl enable --now httpd
#查看端口
ss -antl
#拷贝头文件到网站目录
ls /usr/local/apache/htdocs/$homepage
if [ ! -d /usr/local/apache/htdocs/$homepage ];then
rm -f /usr/local/apache/htdocs/* && \
cp /usr/src/$homepage/* /usr/local/apache/htdocs/
#重启httpd服务
systemctl restart httpd
echo "httpd已完成部署,并设置了502主页"
ss -antl
ip a
fi
exit
整个包下载(含脚本,所需文件,自定义网站文件):https://www.aliyundrive.com/s/ySkkGsCp6bw
标签:脚本,httpd,编译,--,apr,usr,install,local From: https://www.cnblogs.com/soap-bubble/p/16705999.html