脚本安装httpd

脚本安装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 

浏览器访问

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值