shell腳本部署apache

編譯安裝nginx

首先創(chuàng)建一個(gè)目錄,用來存放腳本

[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

下載apache的包
創(chuàng)建一個(gè)目錄用來存放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

編寫腳本

[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

檢驗(yàn)效果

[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                      :::* 
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容