SHELL编程开发实战Apache虚拟主机

Posted Linux运维学习

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SHELL编程开发实战Apache虚拟主机相关的知识,希望对你有一定的参考价值。

SHELL编程开发实战Apache虚拟主机

1)手工方式源码编译Apache最新版本;

2)编译过程中遇到各种故障查找解决方案;

3)基于SHELL编程开发Apache源码编译脚本;

4)Apache源码编译脚本进行调优和实战;

5)基于SHELL编程开发Apache虚拟主机门户网站;

1、纯手工打造源码编译Apache软件实战(思路分析)

1)Apache一款基于HTTP协议WEB服务器软件,可以发布WEB网页,静态网页,浏览器基于HTTP协议实现访问;

2)Apache软件安装方式两种:源代码编译安装,二进制软件方式安装;

3)Apache源代码软件方式四个必备的步骤:官网下载及解压,预编译、编译、安装;

4)官网下载Apache源码软件包;

5)./configure,检测操作系统是否存在软件包安装依赖环境、依赖库文件、检测系统是否存在GCC编译环境,最终会生成makefile文件;

6)make,基于make工具读取makefile,通过GCC编译器将源代码文件编译生成二进制文件,类似Ant工具需要读取build.xml文件,maven工具需要读取pom.xml文件;

7)make install,将make产生的二进制文件安装|拷贝至指定的安装目录:/usr/local/soft_name/

8)启动Apache服务:/usr/local/apache2/bin/apachectl start;

2、纯手工打造源码编译Apache软件实战(实战v1

1)官网下载Apache源码版本2.4.x

wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.33.tar.bz2

2)解压源码软件httpd-2.4.x

tar -jxf  httpd-2.4.33.tar.bz2

 

3)预编译Apache软件;

./configure  --prefix=/usr/local/apache2/  --enable-so  --enable-rewrite  --enable-proxy  --enable-ssl  ---enable-info

报错信息一如下:

configure: error: unrecognized option: `---enable-info'

Try `./configure --help' for more information

解决方法:根据错误提升,报编译参数未知,发现多了一个-横岗,改成--enable-info即可;

 

报错信息二如下:

checking for APR-util... yes

checking for gcc... gcc

checking whether the C compiler works... no

configure: error: in `/data/sh/20180330/httpd-2.4.33':

configure: error: C compiler cannot create executables

See `config.log' for more details

解决方法:软件编译时,需要用到GCC环境,提前要准备好GCC编译环境,执行命令解决:yum install gcc gcc-c++ glibc -y

报错信息三如下:

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

解决方法:yum install pcre pcre-devel -y

报错信息四如下:

configure: WARNING: OpenSSL version is too old no

checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures

解决方法:yum install openssl openssl-devel -y

 

4)基于Make工具编译软件;

Make编译报错信息如下:

mod_proxy_balancer.c:25:24: fatal error: apr_escape.h: No such file or directory#include "apr_escape.h"

`/data/sh/20180330/httpd-2.4.33/modules/proxy'

make[2]: *** [shared-build-recursive] Error 1

解决方法:

跳过该错误,后期指定该模块,一般安装不成功,推荐解决该问题;

或者编译参数可以去掉该模块,禁止该模块,添加--disable-proxy

更换软件版本,考虑到操作系统和软件兼容性问题;

 

5)基于make install安装软件;

6)启动Apache软件服务:

 

 

3、基于SHELL编程开发Apache源码安装脚本(实战v1

#!/bin/bash

#201833015:24:44

#auto install apache soft

#by author www.jfedu.net

########################

yum install -y gcc gcc-c++ glibc perl per-devel pcre pcre-devel

yum install -y zlib zlib-devel openssl openssl-devel make wget

wget -c http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.33.tar.bz2

tar -jxf httpd-2.4.33.tar.bz2

cd httpd-2.4.33

./configure  --prefix=/usr/local/apache2/  --enable-so  --enable-rewrite  --disable-proxy  --enable-ssl

  ---enable-info

make -j4

make -j4 install

/usr/local/apache2/bin/apachectl start

ps -ef|grep httpd

netstat -tnlp|grep 80

4、基于SHELL编程开发Apache源码安装脚本(实战v2

#!/bin/bash

#201833015:24:44

#auto install apache soft

#by author www.jfedu.net

########################

APACHE_VER="2.4.33"

APACHE_SOFT="httpd-${APACHE_VER}.tar.bz2"

APACHE_URL="http://mirrors.hust.edu.cn/apache/httpd"

APACHE_ARG="--enable-so  --enable-rewrite  --disable-proxy  --enable-ssl --enable-info"

APACHE_DIR="/usr/local/apache2"

APACHE_YUM="yum install -y"

APACHE_SRC=`echo $APACHE_SOFT|sed 's/.tar.*//g'`

$APACHE_YUM gcc gcc-c++ glibc perl per-devel pcre pcre-devel

$APACHE_YUM zlib zlib-devel openssl openssl-devel make wget

wget -c  $APACHE_URL/$APACHE_SOFT

tar -jxf $APACHE_SOFT

cd  $APACHE_SRC

./configure  --prefix=$APACHE_DIR/  $APACHE_ARG

make -j4

make -j4 install

$APACHE_DIR/bin/apachectl start

ps -ef|grep httpd

netstat -tnlp|grep 80

5、基于SHELL编程开发Apache源码安装脚本(实战v3

#!/bin/bash

#201833015:24:44

#auto install apache soft

#by author www.jfedu.net

########################

APACHE_VER="$1"

APACHE_SOFT="httpd-${APACHE_VER}.tar.bz2"

APACHE_URL="http://mirrors.hust.edu.cn/apache/httpd"

APACHE_ARG="--enable-so  --enable-rewrite  --disable-proxy  --enable-ssl --enable-info"

APACHE_DIR="/usr/local/apache2"

APACHE_YUM="yum install -y"

APACHE_SRC=`echo $APACHE_SOFT|sed 's/.tar.*//g'`

if [ $# -eq 0 ];then

        echo -e "\033[32m----------------------\033[0m"

        echo -e "\033[32mUsage:{/bin/bash $0 2.4.29|2.4.33|help}\033[0m"

        exit 0

fi

if [ $1 == "help" ];then

        echo -e "\033[32m----------------------\033[0m"

        echo -e "\033[32mUsage:{/bin/bash $0 2.4.29|2.4.33|help}\033[0m"

        exit 0

fi

$APACHE_YUM gcc gcc-c++ glibc perl perl-devel pcre pcre-devel

$APACHE_YUM zlib zlib-devel openssl openssl-devel make wget

wget -c  $APACHE_URL/$APACHE_SOFT

tar -jxf $APACHE_SOFT

cd  $APACHE_SRC

./configure  --prefix=$APACHE_DIR/  $APACHE_ARG

make -j4

make -j4 install

$APACHE_DIR/bin/apachectl start

ps -ef|grep httpd

netstat -tnlp|grep 80


本节教学视频请加Q:1753938973获取




点击左下角阅读全文进入直播课堂在线学习

周一至周五上午10:30~11:30

下午14:30~16:30


以上是关于SHELL编程开发实战Apache虚拟主机的主要内容,如果未能解决你的问题,请参考以下文章

Shell脚本编程实战

《shell编程实战》第3章shell变量基础(上)

Shell编程实战

Shell编程实战

Apache Kafka 编程实战-java客户端开发例子(入门教程轻松学)

Apache Kafka 编程实战-java客户端开发例子(入门教程轻松学)