当前位置:   article > 正文

shell脚本部署apache_666mpm

666mpm

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
  • 1
  • 2
  • 3
  • 4
  • 5

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

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
  • 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
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73

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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/503508?site
推荐阅读
相关标签
  

闽ICP备14008679号