Linux系统环境
[root@apache01 ~]#cat /etc/redhat-release #==》系统版本
CentOS release 6.7 (Final)
[root@apache01 ~]# uname –r #==》内核版本
2.6.32-573.el6.x86_64
[root@apache01 ~]# uname -m #==》系统架构
x86_64
[root@apache01 ~]# echo $LANG #==》系统字符集
en_US.UTF-8
[root@apache01 ~]#/application/apache/bin/apachectl –v #==》Apache版本
Server version: Apache/2.4.38 (Unix)
Server built: Jun 28 2019 15:39:11
Apache配置文件
提示:/application/apache是Apache程序目录
/application/apache/conf/httpd.conf #==》Apache主配置文件httpd.conf
/application/apache/conf/extra/httpd-vhosts.conf #==》Apache扩展的配置文件
/application/apache/bin/apachectl #==》Apache二进制启动命令
一、Apache功能
1、web服务(http 80)
二、Apache优点
1、配置简单,速度快,性能稳定可靠。
2、apache可做代理服务器、负载均衡、rewrite规则过滤等。
3、支持select模型
三、Apache常用命令
标注:假如nginx安装目录在/application/nginx
1、/application/apache2.4.38/bin/apachectl –t #==》检查Apache配置文件语法
2、/application/apache/bin/apachectl start #==》启动Apache服务
3、/application/apache/bin/apachectl stop #==》停止Apache服务
4、/application/apache2.4.38/bin/apachectl graceful #==》优雅重启Apache服务
5、/application/apache2.4.38/bin/apachectl -h #==》查看帮助
四、Apache安装前准备工作
1、配置yum源(建议使用阿里云yum源mirrors.aliyun.com)
[root@apache01 ~]# yum repolist #==》检查yum源
[root@apache01 ~]#wget –O /etc/yum.repos.d/CentOS-Base.repo [http://mirrors.aliyun.com/repo/Centos-6.repo](http://mirrors.aliyun.com/repo/Centos-6.repo) #==》配置yum源为阿里云
[root@apache01 ~]#wget -O /etc/yum.repos.d/epel.repo [http://mirrors.aliyun.com/repo/epel-6.repo](http://mirrors.aliyun.com/repo/epel-6.repo) #==》配置yum源的epel扩展源为阿里云
2、安装Apache所需的lib库
[root@apache01 ~]# yum -y install zlib expat zlib-devel expat-devel openssl openssl-devel
3、源码安装apr软件包
标注:新版本Apache软件包无法支持低版本的apr软件包,yum无法安装最新版本apr软件包,只能下载原码最新版本手动编译安装
[root@apache01 ~]# mkdir -p /home/oldboy/tools/ #==》创建目录存放nginx软件包
[root@apache01 ~]# cd /home/oldboy/tools/
[root@apache01 tools]# wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz
[root@apache01 tools]# tar xf apr-1.7.0.tar.gz
[root@apache01 tools]# cd apr-1.7.0
[root@apache01 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@apache01 apr-1.7.0]# make
[root@apache01 apr-1.7.0]# make install
4、源码安装apr-util软件包
[root@apache01 ~]#cd /home/oldboy/tools/
[root@apache01 tools]# wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
[root@apache01 tools]# tar xf apr-util-1.6.1.tar.gz
[root@apache01 tools]# cd apr-util-1.6.1
[root@apache01 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr_util --with-apr=/usr/local/apr
[root@apache01 apr-util-1.6.1]# make
[root@apache01 apr-util-1.6.1]#make install
5、源码安装pcre软件包
[root@apache01 ~]#cd /home/oldboy/tools/
[root@apache01 tools]# wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
[root@apache01 tools]# tar xf pcre-8.40.tar.gz
[root@apache01 tools]# cd pcre-8.40
[root@apache01 pcre-8.40]# ./configure --prefix=/usr/local/pcre
[root@apache01 pcre-8.40]# make
[root@apache01 pcre-8.40]# make install
五、源码安装Apache
1、Apache官网下载Apache源码安装包到系统指定目录Apache官网地址http://www.apache.org/
[root@apache01 ~]# cd /home/oldboy/tools/
[root@apache01 tools]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.38.tar.gz
[root@apache01 tools]# tar xf httpd-2.4.38.tar.gz
[root@apache01 tools]# ls
httpd-2.4.38 httpd-2.4.38.tar.gz
[root@apache01 httpd-2.4.38]# ./configure --prefix=/application/apache2.4.38/ --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr_util --with-pcre=/usr/local/pcre/
#==》看到以下内容说明编译成功
Server Version: 2.4.38
Install prefix: /application/apache2.4.38/
C compiler: gcc -std=gnu99
CFLAGS: -g -O2 -pthread
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -E
[root@apache01 httpd-2.4.38]# echo $?
0
[root@apache01 httpd-2.4.38]#make
[root@apache01 httpd-2.4.38]# echo $?
0
[root@apache01 httpd-2.4.38]#make install
[root@apache01 httpd-2.4.38]# echo $?
0
[root@apache01 ~]# ln -s /application/apache2.4.38/ /application/apache
六、启动Apache服务
[root@apache01 ~]# /application/apache/bin/apachectl start #==》启动提示如下错误
AH00557: httpd: apr_sockaddr_info_get() failed for apache01
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
解决办法:
[root@apache01 ~]# vim /application/apache/conf/httpd.conf
# ServerName [www.example.com:80](http://www.example.com:80)
修改成
ServerName localhost:80
[root@apache01 ~]# /application/apache/bin/apachectl -t
Syntax OK
[root@apache01 ~]# /application/apache/bin/apachectl start
[root@apache01 ~]# netstat -tlunp | grep 80
tcp 0 0 :::80 :::* LISTEN 46657/httpd
网友评论