手动编译安装和自动化脚本编译安装httpd-2.4.46

手动编译安装httpd-2.4.46:

#环境准备:
关闭selinux和防火墙
#安装相关包:
[root@centos8 ~]#yum -y install make gcc apr-devel apr-util-devel pcre-devel redhat-rpm-config openssl-devel bzip2
#下载并解压缩包:
[root@centos8 ~]#cd /usr/local/src
[root@centos8 src]#tar xvf httpd-2.4.43.tar.bz2
#配置:
[root@centos8 httpd-2.4.46]#cd httpd-2.4.43
[root@centos8 httpd-2.4.46]#./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd --enable-ssl
#编译并安装:
[root@centos8 httpd-2.4.46]#make -j 4
[root@centos8 httpd-2.4.46]#make intsall
#配置环境:
[root@centos8 httpd-2.4.46]# echo "PATH=/apps/httpd/bin:$PATH" > /etc/profile.d/httpd.sh
[root@centos8 httpd-2.4.46]# . /etc/profile.d/httpd.sh
[root@centos8 httpd-2.4.46]# sed -i 's/It works!/Welcome to my web!/' /apps/httpd/htdocs/index.html
#运行:
[root@centos8 httpd-2.4.46]# apachectl start
#指定用户apache运行
[root@centos8 httpd-2.4.46]#cd
[root@centos8 ~]#useradd -r -u 48 -s /sbin/nologin -d /var/www -c Apache apache
[root@centos8 ~]#vim /etc/httpd/httpd.conf
user apache
group apache
#配置生效和验证:
[root@centos8 ~]#apachectl restart
#用浏览器打开页面验证

脚本自动化实现编译安装httpd-2.4.46:

#!/bin/bash
DIR1=/usr/local/src
PACKAGE=httpd-2.4.46.tar.bz2
DIR2=httpd-2.4.46
DIR3=/apps/httpd
DIR4=/etc/httpd
echo -e "\e[1;$[RANDOM%7+31]mStarting compile install httpd-2.4.46\e[0m"
sleep 3
yum -y install make gcc apr-devel apr-util-devel pcre-devel redhat-rpm-config openssl-devel bzip2
cd $DIR1 
wget https://downloads.apache.org/httpd/httpd-2.4.46.tar.bz2
tar xvf $PACKAGE
cd $DIR2 
./configure --prefix="$DIR3" --sysconfdir="$DIR4" --enable-ssl
make -j 4 && make install
echo "PATH=${DIR3}/bin:$PATH" > /etc/profile.d/httpd.sh
. /etc/profile.d/httpd.sh
sed -i 's/It works!/Welcome to my web!/' /apps/httpd/htdocs/index.html
apachectl start &> /dev/null
cd
useradd -r -u 48 -s /sbin/nologin -d /var/www -c Apache apache
sed -i 's/User daemon/User apache/' /etc/httpd/httpd.conf 
sed -i 's/Group daemon/Group apache/' /etc/httpd/httpd.conf
apachectl restart &> /dev/null
echo -e "\e[1;$[RANDOM%7+31]mCompile install httpd-2.4.46 finished.\e[0m"
echo -e "\e[1;$[RANDOM%7+31]mPlease input ip access the web.\e[0m"

你可能感兴趣的:(Linux运维,linux)