編譯安裝nginx
首先創(chuàng)建一個(gè)目錄比庄,用來(lái)存放腳本
[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è)目錄用來(lái)存放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
編寫(xiě)腳本
[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 :::*