Linux使用shell脚本源码部署apache

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              *:*

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值