使用脚本安装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 *:*
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。