脚本安装httpd
下载软件包
[root@sb src]# ls
apr-1.6.5.tar.bz2 apr-util-1.6.1.tar.bz2 debug httpd-2.4.54.tar.bz2 kernels
[root@sb ~]# vim hehe.sh
#!/bin/bash
# 安装yum源和epel源
cd /etc/yum.repos.d/
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
# 安装工具包
dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ --allowerasing
# 安装apr
cd /usr/src/
tar -xjf apr-1.6.5.tar.bz2
cd apr-1.6.5/
sed -i '/$RM "$cfgfile"/d' configure
# 编译安装apr
./configure --prefix=/usr/local/apr &> /dev/null
make &> /dev/null
make install &> /dev/null
# 安装apr-util
cd /usr/src/
tar -xjf apr-util-1.6.1.tar.bz2
cd apr-util-1.6.1/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make &> /dev/null
make install &> /dev/null
# 安装httpd
cd /usr/src/
tar -xjf httpd-2.4.54.tar.bz2
cd httpd-2.4.54/
./configure --prefix=/usr/local/apache \
--sysconfdir=/etc/httpd24 \
--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 &> /dev/null
make install &> /dev/null
# 配置环境变量
cd /root
echo 'export PATH=/usr/local/apache/bin/:$PATH' > /etc/profile.d/httpd.sh
source /etc/profile.d/httpd.sh
# 编写systemctl配置文件
cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=mysqld server daemon
After=network.target sshd-keygen.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
#/usr/local/apache/bin/apachectl start
# 配置防火墙
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
[root@sb ~]# chmod +x hehe.sh
[root@sb ~]# ./hehe.sh
浏览器访问