shell脚本源码部署apache
编写脚本
[root@100 ~]# vim apache.sh
#!/bin/bash
# 配置yum源
echo "配置yum源中"
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*
echo "yum源配置完成"
# 清理缓存
echo "清理缓存中"
yum clean all &>/dev/null
yum makecache &>/dev/null
echo "清理完成"
# 安装环境
yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ vim bzip2 wget make --allowerasing
echo "环境安装完成"
# 部署apr
echo "部署apr中"
cd /usr/src
tar -jxf apr-1.6.5.tar.bz2
cd apr-1.6.5
sed -i '/$RM "$cfgfile"/d' configure
./configure --prefix=/usr/local/apr &>/dev/null
make &>/dev/null
make install &>/dev/null
echo "apr部署完成"
# 部署apr-util
echo "部署apr-util中"
cd /usr/src
tar -jxf apr-util-1.6.1.tar.bz2
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &>/dev/null
make &>/dev/null
make install &>/dev/null
echo "apr-util部署完成"
# 部署httpd
echo "部署httpd中"
cd /usr/src
tar -jxf httpd-2.4.54.tar.bz2
cd httpd-2.4.54
./configure --prefix=/usr/local/apache \
--sysconfdir=/etc/http24 \
--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 &>/dev/null
make &>/dev/null
make install &>/dev/null
echo "httpd部署完成"
# 配置服务
cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=apache 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 start httpd
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
运行脚本
[root@100 ~]# chmod +x apache.sh
[root@100 ~]# ./apache.sh
配置yum源中
yum源配置完成
清理缓存中
清理完成
环境安装完成
部署apr中
apr部署完成
部署apr-util中
apr-util部署完成
部署httpd中
httpd部署完成
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 0.0.0.100. Set the 'ServerName' directive globally to suppress this message
success
success
[root@100 ~]# systemctl status httpd
Active: active (exited) since Fri 2022-09-16 20:31:39 CST; 2min 3s ago
[root@100 ~]# ss -antl |grep 80
LISTEN 0 128 *:80 *:*