当前位置:   article > 正文

shell_一键部署Apache脚本_shell自动化部署apache脚本

shell自动化部署apache脚本

一.一键部署Apache

1.将安装Apache所需软件包传到/opt目录下

在这里插入图片描述

#!/bin/bash
read -p "输入域名www.xxx.com:" a
systemctl stop firewalld
systemctl disable firewalld
setenforce 0

yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl


cd /opt/
tar zxvf apr-1.6.2.tar.gz
tar zxvf apr-util-1.6.0.tar.gz
tar jxvf httpd-2.4.29.tar.bz2

mv apr-1.6.2 /opt/httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util

cd /opt/httpd-2.4.29/
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi

make && make install

ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/

echo '[Unit]
Description=The Apache HTTP Server      
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/httpd/logs/httpd.pid
ExecStart=/usr/local/bin/apachectl $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target' > /lib/systemd/system/httpd.service
systemctl start httpd.service

cp /etc/httpd.conf{,.bak}
c=`ifconfig | awk 'NR==2{print $2}'`
sed -i "51c Listen $c:80" /etc/httpd.conf.bak
sed -i '52 s/^/#/' /etc/httpd.conf.bak
sed -i '197d' /etc/httpd.conf.bak
sed -i "196a ServerName $a:80" /etc/httpd.conf.bak
cat /etc/httpd.conf.bak > /etc/httpd.conf

httpd -t
cat /usr/local/httpd/htdocs/index.html
systemctl start httpd.service
systemctl restart httpd.service

echo "$c $a" >> /etc/hosts
netstat -anpt | grep 80

if [ $? -eq 0 ];then 
	echo "Apache服务已启动"
else 
	echo 启动失败
	exit 1
fi

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60

在这里插入图片描述在这里插入图片描述

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/503499
推荐阅读
相关标签
  

闽ICP备14008679号