Apache负载均衡服务器安装及配置

Posted 陌灬城

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Apache负载均衡服务器安装及配置相关的知识,希望对你有一定的参考价值。

1    Apache简介

  Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一.它快速,可靠并且可通过简单的API扩展,将Perl/Python等解释器编译到服务器中。关于更多Apache的介绍,可以参考百科http://baike.baidu.com/view/28283.htm或官网http://www.apache.org/ 或 http://httpd.apache.org/的介绍

 

2    Apache软件及相关软件下载

2.1  Apache软件下载

2.2  APR and APR-Util包下载

·        APR 1.4.8, released June 21, 2013

·        APR-util 1.5.2, released April 4, 2013

·        APR-iconv 1.2.1, released November 26, 2007

2.3  PCRE包下载

·        https://sourceforge.net/projects/pcre/files/pcre/

2.4  Apache安装要求

将上面的安装包上传到linux中的root/kerry这个临时目录.

 

3    Apache安装

3.1  安装包gcc或gcc-c++

[root@getlnx05 pcre-8.33]# yum list gcc-c++

Loaded plugins: product-id, security,subscription-manager

Updating Red Hat repositories.

Available Packages

gcc-c++.x86_64                                                           4.1.2-51.el5                                                               rhel-debuginfo

[root@getlnx05 pcre-8.33]# yum list gcc

Loaded plugins: product-id, security,subscription-manager

Updating Red Hat repositories.

Installed Packages

gcc.x86_64                                                                   4.1.2-51.el5                                                                   installed

[root@getlnx05 pcre-8.33]# rpm -q gcc

gcc-4.1.2-51.el5

从上面可见gcc包已经安装,缺少gcc-c++包,那么接下来安装包gcc-c++,如果此处不安装该包,后面安装过程中会报错

[root@getlnx05 pcre-8.33]#yum install gcc-c++

3.2  安装包gcc或gcc-c++

[root@getlnx05 kerry]# ls apr*

apr-1.4.8.tar.gz  apr-util-1.5.2.tar.gz

[root@getlnx05 kerry]#

[root@getlnx05 kerry]# tar -zxfapr-1.4.8.tar.gz

[root@getlnx05 kerry]# cd apr-1.4.8

[root@getlnx05 apr-1.4.8]# ls

新建目录/usr/local/apr,用作安装目录:

[root@getlnx05 apr-1.4.8]# mkdir/usr/local/apr

[root@getlnx05 apr-1.4.8]# ./configure--prefix=/usr/local/apr

[root@getlnx05 apr-1.4.8]# make

[root@getlnx05 apr-1.4.8]# make install

安装完成后,可以验证一下

[ root@getlnx05 apr]# ls -lrt

total 32

drwxr-xr-x 3 root root 4096 Aug 15 06:57include

drwxr-xr-x 3 root root 4096 Aug 15 06:57 lib

drwxr-xr-x 2 root root 4096 Aug 15 06:57build-1

drwxr-xr-x 2 root root 4096 Aug 15 06:57 bin

[root@getlnx05 kerry]# mkdir/usr/local/apr-util

[root@getlnx05 kerry]# tar -zxfapr-util-1.5.2.tar.gz

[root@getlnx05 kerry]# cd apr-util-1.5.2

[root@getlnx05apr-util-1.5.2]# ./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr/bin/apr-1-config

[root@getlnx05 apr-util-1.5.2]# make

[root@getlnx05 apr-util-1.5.2]# make install

3.3  安装包PRCE

[root@getlnx05 kerry]# unzip pcre-8.33.zip

[root@getlnx05 kerry]# cd pcre-8.33

[root@getlnx05 kerry]#mkdir /usr/local/pcre

[root@getlnx05 pcre-8.33]# ./configure --prefix=/usr/local/apr-util/--with-apr=/usr/local/apr

[root@getlnx05 pcre-8.33]# make

[root@getlnx05 pcre-8.33]# make install

3.4  安装Apache Http Server

[root@getlnx05 kerry]# tar zxvfhttpd-2.4.6.tar.gz

[root@getlnx05  kerry]#cd httpd-2.4.6

[root@getlnx05 httpd-2.4.6]# ./configure--prefix=/usr/local/apache --with-pcre=/usr/local/pcre--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

[root@getlnx05 httpd-2.4.6]#make

[root@getlnx05 httpd-2.4.6]#make install

3.5  启动Apache服务

[root@getlnx05 httpd-2.4.6]#  /usr/local/apache/bin/apachectlstart

用浏览器访问http://localhost时提示Itworks!

 

4    Apache安装常见问题

4.1  缺少gcc-c++导致安装apr-util通不过

[root@getlnx05 kerry]# unzip pcre-8.33.zip

[root@getlnx05 kerry]# cd pcre-8.33

[root@getlnx05 pcre-8.33]# ./configure--prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config

一般出现这个错误是因为没有安装包gcc-c++,可以通过如下命令检查,

[root@getlnx05 pcre-8.33]# yum list gcc-c++

Loaded plugins: product-id, security,subscription-manager

Updating Red Hat repositories.

Available Packages

gcc-c++.x86_64                                                              4.1.2-51.el5                                                               rhel-debuginfo

[root@getlnx05 pcre-8.33]# yum list gcc

Loaded plugins: product-id, security,subscription-manager

Updating Red Hat repositories.

Installed Packages

gcc.x86_64                                                                   4.1.2-51.el5                                                                   installed

[root@getlnx05 pcre-8.33]# rpm -q gcc

gcc-4.1.2-51.el5

[root@getlnx05 pcre-8.33]# rpm -q gcc-c++

4.2  checking forAPR-util..configure:error:the –with-apr-util parameter is incorrect

[root@getlnx05 httpd-2.4.6]#  ./configure--prefix=/usr/local/apache  --with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util

checking for chosen layout... Apache

checking for working mkdir -p... yes

checking for grep that handles long lines and-e... /bin/grep

checking for egrep... /bin/grep -E

checking build system type... x86_64-unknown-linux-gnu

checking host system type...x86_64-unknown-linux-gnu

checking target system type...x86_64-unknown-linux-gnu

configure:

configure: Configuring Apache Portable Runtimelibrary...

configure:

checking for APR... yes

  setting CC to "gcc"

  setting CPP to "gcc -E"

  setting CFLAGS to " -g -O2-pthread"

  setting CPPFLAGS to " -DLINUX-D_REENTRANT -D_GNU_SOURCE"

  setting LDFLAGS to " "

configure:

configure: Configuring Apache Portable RuntimeUtility library...

configure:

checking for APR-util... configure: error: the--with-apr-util parameter is incorrect. It must specify an install prefix, abuild directory, or an apu-config file.

[root@getlnx05 httpd-2.4.6]#

一般是由于APR-util没有安装成功,可以通过验证该目录是否为空来判断,因为你有时候执行了make,忘了执行make isntall命令有可能导致这个错误。

[root@getlnx05 apr]# cd /usr/local/apr-util

[root@getlnx05 apr-util]# ls

4.3  没有指定PCRE参数

[root@getlnx05 httpd-2.4.6]#  ./configure--prefix=/usr/local/apache  --with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util

checking for chosen layout... Apache

checking for working mkdir -p... yes

checking for grep that handles long lines and-e... /bin/grep

checking for egrep... /bin/grep -E

checking build system type...x86_64-unknown-linux-gnu

checking host system type...x86_64-unknown-linux-gnu

checking target system type...x86_64-unknown-linux-gnu

configure:

configure: Configuring Apache Portable Runtimelibrary...

configure:

checking for APR... yes

  setting CC to "gcc"

  setting CPP to "gcc -E"

  setting CFLAGS to " -g -O2-pthread"

  setting CPPFLAGS to " -DLINUX-D_REENTRANT -D_GNU_SOURCE"

  setting LDFLAGS to " "

configure:

configure: Configuring Apache Portable RuntimeUtility library...

configure:

checking for APR-util... yes

checking for gcc... gcc

checking whether the C compiler works... yes

checking for C compiler default output filename... a.out

checking for suffix of executables...

checking whether we are cross compiling... no

checking for suffix of object files... o

checking whether we are using the GNU Ccompiler... yes

checking whether gcc accepts -g... yes

checking for gcc option to accept ISO C89...none needed

checking how to run the C preprocessor... gcc-E

checking for gcc option to accept ISO C99...-std=gnu99

checking for pcre-config... false

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

[root@getlnx05 httpd-2.4.6]#

4.4  安装前忘记了先安装APR相关包

[root@getlnx05 httpd-2.4.6]#  ./configure--prefix=/usr/local/appache/

checking for chosen layout... Apache

checking for working mkdir -p... yes

checking for grep that handles long lines and-e... /bin/grep

checking for egrep... /bin/grep -E

checking build system type...x86_64-unknown-linux-gnu

checking host system type...x86_64-unknown-linux-gnu

checking target system type...x86_64-unknown-linux-gnu

configure:

configure: Configuring Apache Portable Runtimelibrary...

configure:

checking for APR... no

configure: error: APR not found.  Pleaseread the documentation.

[root@getlnx05 httpd-2.4.6]#

4.5  启动服务时报错

[root@getlnx05 httpd-2.4.6]# /usr/local/apache/bin/apachectl start

AH00558: httpd: Could not reliably determinethe server's fully qualified domain name, using getlnx05.gfg1.esquel.com. Setthe 'ServerName' directive globally to suppress this message

[root@getlnx05 conf]# cd/usr/local/apache/conf/

[root@getlnx05 conf]# ls

extra  httpd.conf  magic mime.types  original

[root@getlnx05 conf]# vi httpd.conf

ServerAdmin you@example.com

#

# ServerName gives the name and port that theserver uses to identify itself.

# This can often be determined automatically,but we recommend you specify

# it explicitly to prevent problems duringstartup.

#

# If your host doesn't have a registered DNSname, enter its IP address here.

#

#ServerName www.example.com:80

ServerName 192.168.9.122:80

#

# Deny access to the entirety of your server'sfilesystem. You must

# explicitly permit access to web contentdirectories in other

# <Directory> blocks below.

#

"httpd.conf" 502L, 18179C written

[root@getlnx05 conf]#/usr/local/apache/bin/apachectl restart

httpd not running, trying to start

[root@getlnx05 conf]#/usr/local/apache/bin/apachectl start

httpd (pid 7797) already running

[root@getlnx05 conf]# chkconfig iptables off

[root@getlnx05 conf]# chkconfig iptables off

[root@getlnx05 conf]#/usr/local/apache/bin/apachectl restart

[root@getlnx05 conf]#/usr/local/apache/bin/apachectl restart

[root@getlnx05 conf]#

 

5    Apache对Weblogic服务器负载均衡配置

5.1  在Apache中添加Weblogic配置文件

将mod_wl_24.so拷贝到apache中的目录modules下 #注意 mod_wl_24.so 文件要和使用的weblogic版本匹配 我这里使用的64位的

mod-wl_24.so对应的是Apache2.4的版本

5.2  修改httpd.conf配置文件

配置文件在/apache/conf/下

在httpd.conf中找到配置

LoadModuleproxy_module modules/mod_proxy.so

LoadModuleproxy_http_module modules/mod_proxy_http.so   # 两个文件 去掉前面的#

在httpd.conf最下面一行新增

LoadModule weblogic_modulemodules/mod_wl_24.so  #注意 mod_wl_24.so 文件要和使用的weblogic版本匹配 我这里使用的64位的

<IfModulemod_weblogic.c> 

MatchExpression *.*

</IfModule>

5.3  重启apache服务

[root@getlnx05 httpd-2.4.6]# /usr/local/apache/bin/apachectl stop

[root@getlnx05 httpd-2.4.6]# /usr/local/apache/bin/apachectl start

http://192.168.0.35/testApp/index.jsp 这里会按指定好的规则 负载均衡的分发到 上面配置的3个节点上面


以上是关于Apache负载均衡服务器安装及配置的主要内容,如果未能解决你的问题,请参考以下文章

Apache web服务软件安装启动负载均衡反向代理配置

lvs负载均衡NAT模式

Apache服务器反向代理,负载均衡,热备份

个人技能总结7--Apache服务器反向代理,负载均衡,热备份+Tomcat配置

Tomcat安装配置优化及负载均衡详解

使用LVS负载均衡搭建web群集的原理及安装配置详解