脚本一键安装apache

使用脚本安装apache

[root@node3 apache]# tree
.
├── apache.sh
└── soft
    ├── apr-1.7.0.tar.gz
    ├── apr-util-1.6.1.tar.gz
    └── httpd-2.4.48.tar.gz

apr包下载链接: https://dlcdn.apache.org/apr/apr-1.7.0.tar.gz.
apr-util包下载链接: https://dlcdn.apache.org/apr/apr-util-1.6.1.tar.gz.
httpd包下载链接: https://dlcdn.apache.org/httpd/httpd-2.4.48.tar.gz.

编写脚本

#!/bin/bash

user=apache
apr_version=1.7.0
apr_util_version=1.6.1
httpd_version=2.4.48
httpd_dir=/usr/local/httpd

id $user &>/dev/null
if [ $? -ne 0 ];then
        useradd -r -M -s /sbin/nologin $user
fi

yum groups mark install "Development Tools" -y
yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make wget

rm -rf /usr/src/{apr* httpd*}
tar xf soft/apr-${apr_version}.tar.gz -C /usr/src
tar xf soft/apr-util-${apr_util_version}.tar.gz -C /usr/src
tar xf soft/httpd-${httpd_version}.tar.gz -C /usr/src

#安装apr包
        echo "下载安装apr包"
cd /usr/src/apr-${apr_version}
sed -i '/$RM "$cfgfile"/d' configure
if [ ! -d  /usr/local/apr ];then
    ./configure --prefix=/usr/local/apr  && make && make install
fi

#安装apr-util包
        echo "下载安装apr-util包"
cd /usr/src/apr-util-${apr_util_version}
if [ ! -d /usr/local/apr-util ];then
    ./configure  --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install
fi

#安装httpd包
        echo "下载安装httpd包"
cd /usr/src/httpd-${httpd_version}
if [ ! -d ${httpd_dir} ];then
    ./configure --prefix=${httpd_dir} \
        --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 && make install
fi

sed -i 's/#ServerName www.example.com:80/ServerName www.example.com:80/g' /usr/local/httpd/conf/httpd.conf
echo 'export PATH=/usr/local/httpd/bin:$PATH' > /etc/profile.d/httpd.sh

cat > /usr/lib/systemd/system/httpd.service  << EOF
[Unit]
Description=The Apache http server
After=network.targe

[Service]
Type=forking
ExecStart=/usr/local/httpd/bin/apachectl start
ExecStop=/usr/local/httpd/bin/apachectl stop
ExecReload=/usr/local/httpd/bin/apachectl restart

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable --now httpd

查看端口

[root@node3 apache]# ss -antl
State        Recv-Q       Send-Q              Local Address:Port               Peer Address:Port               
LISTEN       0            128                             *:80                            *:*  
上一篇:7.编写一个22选5的彩票选号程序。每次选出不同的五组号码,并输出到控制台中


下一篇:大数据之路week04--day06(I/O流阶段一 之异常)