shell脚本部署apache

1. 编译安装apache

首先创建一个目录,用来存放脚本

[root@minion01 ~]# mkdir /script
[root@minion01 ~]# cd /script/
[root@minion01 script]# touch apache.sh
[root@minion01 script]# chmod +x apache.sh
[root@minion01 script]# vim apache.sh

2. 下载apache的包

创建一个目录用来存放apache的安装包

[root@minion01 script]# mkdir packages
[root@minion01 script]# cd packages/
[root@minion01 packages]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.7.0.tar.gz

[root@minion01 packages]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
[root@minion01 packages]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.51.tar.gz

3. 编写脚本

[root@localhost script]# cat apache.sh 
#!/bin/bash
route=/usr/local
path=/usr/src
yum -y install epel-release wget make openssl openssl-devel pcre pcre-devel gcc gcc-c++ zlib-devel expat-devel zlib expat epel-release

id apache
if [ $? -ne 0 ];then
	useradd -r -M -s /sbin/nologin apache
fi

echo "解压依赖包"

if [ ! -d $path/apr-1.7.0 ];then
	tar xf packages/apr-1.7.0.tar.gz -C $path
fi

if [ ! -d $path/apr-util-1.6.1 ];then
	tar xf packages/apr-util-1.6.1.tar.gz -C $path
fi

if [ ! -d $path/httpd-2.4.51 ];then
	tar xf packages/httpd-2.4.51.tar.gz -C $path
fi

cd $path/apr-1.7.0
if [ ! -d $route/apr ];then
	sed -i 's/$RM "cfgfile"/#$RM "cfgfile"/g' configure
	./configure --prefix=$route/apr
	make && make install
fi

cd $path/apr-util-1.6.1
if [ ! -d $route/apr-util ];then
	./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
	make && make install
fi

cd $path/httpd-2.4.51
if [ ! -d $route/httpd-2.4.51 ];then
	./configure --prefix=/usr/local/apache \
		--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 -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
fi
echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh

cat > /usr/lib/systemd/system/httpd.service << EOF
[Unit]
Description=httpd server daemon
After=network.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

5. 检验效果

[root@localhost script]# systemctl status httpd.service 
● httpd.service - httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2021-11-05 18:16:49 CST; 4min 21s ago
  Process: 34128 ExecStart=/usr/local/apache/bin/apachectl start (code=exited, status=0/SUCCESS)


[root@localhost script]# ss -anlt | grep 80
LISTEN     0      128         :::80                      :::* 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值