CentOS7编译安装httpd脚本

1. 编译部署http2.4.46

#!/bin/bash

# 关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld &>/dev/null
setenforce 0 &>/dev/null

# 安装开发工具包
yum groups mark install 'Development Tools' &>/dev/null

# 创建apache用户和组
id apache
if [ $? -ne 0 ];then
    groupadd -r apache
    useradd -r -M -s /sbin/nologin -g apache apache
fi

#安装编译环境
yum -y install gcc make autoconf gcc-c++ glibc glibc-devel pcre pcre-devel expat-devel

#升级openssl,因为httpd2.4.46需要openssl v1.1.1版本
#下载openssl并解压
wget https://www.openssl.org/source/old/1.1.1/openssl-1.1.1h.tar.gz
tar -zxvf openssl-1.1.1h.tar.gz &>/dev/null
#编译安装指定目录/app/openssl下
cd openssl-1.1.1h
./config --prefix=/app/openssl
make && make install
#配置环境
echo "/app/openssl/lib/" >> /etc/ld.so.conf
ldconfig -v
echo 'export PATH=/app/openssl/bin:$PATH' > /etc/profile.d/openssl.sh
source /etc/profile.d/openssl.sh

#升级apr包
#下载apr包并解压
cd ~root
wget https://mirror.dsrg.utoronto.ca/apache//apr/apr-1.7.0.tar.bz2
tar xvf apr-1.7.0.tar.bz2 &>/dev/null
cd apr-1.7.0
sed -i 's/$RM "$cfgfile"/#$RM "$cfgfile"/g' /root/apr-1.7.0/configure
#编译安装
./configure --prefix=/usr/local/apr
make && make install

#升级apr-util
#下载apr-util包并解压
cd ~root
wget https://mirror.dsrg.utoronto.ca/apache//apr/apr-util-1.6.1.tar.bz2
tar xvf apr-util-1.6.1.tar.bz2 &>/dev/null
cd apr-util-1.6.1
#编译安装
./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/
make && make install

#安装httpd
#下载http包并解压
cd ~root
wget https://mirror.its.dal.ca/apache//httpd/httpd-2.4.46.tar.bz2
tar xvf httpd-2.4.46.tar.bz2 &>/dev/null
cd httpd-2.4.46
#编译安装
./configure --prefix=/usr/local/apache --enable-rewrite --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
make && make install

#修改apache配置文件
cd ~root
sed -i 's/#ServerName www.example.com:80/ServerName 127.0.0.1:80/g' /usr/local/apache/conf/httpd.conf
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
sed -i '2 i\#chkconfig: 345 70 70' /etc/rc.d/init.d/httpd
sed -i '3 i\#description: apache' /etc/rc.d/init.d/httpd

#设置开机自启
chmod +x /etc/init.d/httpd
chkconfig --add httpd
chkconfig httpd on

#启动httpd服务
systemctl start httpd
if [ $? -eq 0 ];then
        echo "the httpd is start!!"
fi

2. 查看http端口

[root@localhost ~]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      49922/httpd         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      7398/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      7655/master         
tcp6       0      0 :::22                   :::*                    LISTEN      7398/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      7655/master   

3. 查看http进程

[root@localhost ~]# ps -ef |grep httpd
root      49922      1  0 14:17 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    49923  49922  0 14:17 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    49924  49922  0 14:17 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    49925  49922  0 14:17 ?        00:00:00 /usr/local/apache/bin/httpd -k start
daemon    50032  49922  0 14:19 ?        00:00:00 /usr/local/apache/bin/httpd -k start
root      50064   8588  0 14:26 pts/0    00:00:00 grep --color=auto httpd

4. web方式访问

http://192.168.110.40

[root@localhost ~]# curl localhost

It works!

CentOS7编译安装httpd脚本_第1张图片

你可能感兴趣的:(httpd服务,apache)