编译安装apache
[root@localhost ~]# cat httpd.sh
#!/bin/bash
route=/usr/local
path=/usr/src
#安装开发环境
yum -y groups mark install "Development Tools"
yum -y install openssl-devel pcre-devel expat-devel libtool wget make
#下载源码包
cd $path
wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
wget https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz
#解压
cd $path
tar xf apr-1.7.0.tar.gz
tar xf apr-util-1.6.1.tar.gz
tar xf httpd-2.4.54.tar.gz
#创建用户和组
id apache
if [ $? -ne 0 ];then
useradd -r -M -s /sbin/nologin apache
fi
#编译apr-1.7.0
cd $path/apr-1.7.0
if [ ! -d apr-1.7.0 ];then
sed -i '/$RM "$cfgfile"/d' apr-1.7.0/configure
./configure --prefix=$route/apr &&\
make && make install
fi
#编译apr-util-1.6.1
cd $path/apr-util-1.6.1
if [ ! -d apr-util-1.6.1 ];then
./configure --prefix=$route/apr-util --with-apr=$route/apr &&\
make && make install
fi
#编译httpd-2.4.54
cd $path/httpd-2.4.54
if [ ! -d httpd-2.4.54 ];then
./configure --prefix=$route/apache \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=$route/apr \
--with-apr-util=$route/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork &&\
make && make install
fi
#设置环境变量
echo 'export PATH=$route/apache/bin:\$PATH' > /etc/profile.d/apache.sh
sed -i "/#ServerName/s/#//" $route/apache/conf/httpd.conf
#映射
ln -s $route/apache/include/ /usr/include/apache
#配置man文档
echo "MANDATORY_MANPATH $route/apache/man" >> /etc/man_db.conf
#配置service文件
cat > /usr/lib/systemd/system/httpd.service << EOF
[Unit]
Description=httpd server daemon
After=network.target sshd-keygen.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
systemctl start httpd
systemctl status httpd
#防火墙关闭
systemctl disable --now firewalld
setenforce 0
sed -i '/^SELINUX/s/enforcing/disabled/' /etc/selinux/config
优化
(恢复最小化快照,布置好yum源,关闭防火墙)
[root@localhost apache]# ls
config.sh files install.sh
[root@localhost apache]# ls files/
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.54.tar.gz
[root@localhost apache]# cat install.sh
#!/bin/bash
if [ $UID -ne 0 ];then
echo "Please execute this script with root user."
exit
fi
install_dir=/usr/local/apache
#安装依赖包
echo -e "\033[32minstalling package for depend\033[0m\033[5;32m...\033[0m"
yum -y install wget make openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
id apache &> /dev/null
if [ $? -ne 0 ];then
useradd -r -M -s /sbin/nologin apache
fi
#解压软件包
rm -rf /usr/src/*
tar xf files/apr-1.7.0.tar.gz -C /usr/src/
tar xf files/apr-util-1.6.1.tar.gz -C /usr/src/
tar xf files/httpd-2.4.54.tar.gz -C /usr/src/
cd /usr/src/apr-1.7.0
if [ ! -d /usr/local/apr ];then
sed -i '/$RM "$cfgfile"/d' /usr/src/apr-1.7.0/configure
./configure --prefix=/usr/local/apr && \
make && make install
fi
cd ../apr-util-1.6.1
if [ ! -d /usr/local/apr-util ];then
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && \
make && make install
fi
cd ../httpd-2.4.54
if [ ! -d $install_dir ];then
./configure --prefix=$install_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
echo "export PATH=$install_dir/bin:\$PATH" > /etc/profile.