Apache Http Server2.2采用ajp协议配置tomcat7负载均衡

http://httpd.apache.org/docs/2.2/install.html

http://httpd.apache.org/docs/2.2/programs/configure.html

192.168.1.177--->apachehttpserver2.2.31

192.168.1.178--->apache-tomcat-7.0.73

192.168.1.179--->apache-tomcat-7.0.73

ssh登录192.168.1.177

[root@apachehsopt]#vi/etc/hosts

192.168.1.177apachehs

[root@apachehsopt]#yuminstallgcc

[root@apachehsopt]#yuminstall-ygccgcc-c++

[root@apachehsopt]#yum-yinstallzlib-devel

[root@apachehsopt]#yum-yinstallopenssl-devel

下面安装apr、apr-util、pcre

[root@apachehsopt]#tar-xvfapr-1.5.2.tar.gz

[root@apachehsopt]#cdapr-1.5.2

[[email protected]]#viconfigure

?$RM"$cfgfile"

添加#注释掉这一行

[[email protected]]#./configure--prefix=/usr/local/apr

[[email protected]]#make&&makeinstall

[[email protected]]#cd..

[root@apachehsopt]#tarxvfapr-util-1.5.4.tar.gz

[root@apachehsopt]#cdapr-util-1.5.4

[[email protected]]#./configure--prefix=/usr/local/apr-util--with-

apr=/usr/local/apr/bin/apr-1-config

[[email protected]]#make&&makeinstall

[[email protected]]#cd..

[root@apachehsopt]#unzippcre-8.38.zip-d/opt/

[root@apachehsopt]#cdpcre-8.38

[[email protected]]#viconfigure

?$RM"$cfgfile"

添加#注释掉这一行

[[email protected]]#./configure--prefix=/usr/local/pcre

[[email protected]]#make&&makeinstall

下面安装ApacheHttpServer

[root@apachehssrc]#tarxvfhttpd-2.2.32.tar.gz

[root@apachehssrc]#cdhttpd-2.2.32

[[email protected]]#viconfigure

?"$ap_cv_void_ptr_lt_long"

iftest"$ap_cv_void_ptr_lt_long"="yes";then

as_fn_error$?"Sizeof\"void*\"islessthansizeof\"long\"""$LINENO"5

fi

改成

iftest"$ap_cv_void_ptr_lt_long"!="yes";then

as_fn_error$?"Sizeof\"void*\"islessthansizeof\"long\"""$LINENO"5

fi

[[email protected]]#./configure--prefix=/usr/local/apache--with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util/--with-pcre=/usr/local/pcre--enable-module=so--enable-so--enable-authn-anon=shared--enable-authn-dbm=shared--enable-authz-dbm=shared--enable-auth-digest=shared--enable-cache=shared--enable-cern-meta=shared--enable-charset-lite=shared--enable-dav=shared--enable-dav-fs=shared--enable-dav-lock=shared--enable-deflate=shared--enable-disk-cache=shared--enable-expires=shared--enable-ext-filter=shared--enable-file-cache=shared--enable-headers=shared--enable-info=shared--enable-logio=shared--enable-mem-cache=shared--enable-mime-magic=shared--enable-isapi=shared--enable-proxy=shared--enable-proxy-ajp=shared--enable-proxy-balancer=shared--enable-proxy-connect=shared--enable-proxy-ftp=shared--enable-proxy-http=shared--enable-rewrite=shared--enable-speling=shared--enable-ssl=shared--enable-unique-id=shared--enable-usertrack=shared--enable-vhost-alias=shared--enable-bucketeer=shared--enable-case-filter=shared--enable-case-filter-in=shared--enable-echo=shared--enable-example=shared--enable-optional-fn-export=shared--enable-optional-fn-import=shared--enable-optional-hook-export=shared--enable-optional-hook-import=shared

[[email protected]]#make

[[email protected]]#makeinstall

[[email protected]]#cd/usr/local/apache/conf

[root@apachehsconf]#ls

extrahttpd.confmagicmime.typesoriginal

下面开始配置ApacheHttpServer

[root@apachehslocal]#vihttpd.conf

找到#Listen80...一行,在下面添加

Listen192.168.1.177:10080

找到#ServerName...一行,在下面添加

ServerName192.168.1.177:10080

[root@apachehsconf]#vi/etc/httpd/conf/httpd.conf

添加

ServerName192.168.1.177:10080

[root@apachehsconf]#cd/usr/local/apache/bin

[root@apachehsbin]#./httpd-l

Compiledinmodules:

core.c

mod_authn_file.c

mod_authn_default.c

mod_authz_host.c

mod_authz_groupfile.c

mod_authz_user.c

mod_authz_default.c

mod_auth_basic.c

mod_include.c

mod_filter.c

mod_log_config.c

mod_env.c

mod_setenvif.c

mod_version.c

prefork.c

http_core.c

mod_mime.c

mod_status.c

mod_autoindex.c

mod_asis.c

mod_cgi.c

mod_negotiation.c

mod_dir.c

mod_actions.c

mod_userdir.c

mod_alias.c

mod_so.c

[root@apachehsbin]#./httpd-t-DDUMP_MODULES

LoadedModules:

core_module(static)

authn_file_module(static)

authn_default_module(static)

authz_host_module(static)

authz_groupfile_module(static)

authz_user_module(static)

authz_default_module(static)

auth_basic_module(static)

include_module(static)

filter_module(static)

log_config_module(static)

env_module(static)

setenvif_module(static)

version_module(static)

mpm_prefork_module(static)

http_module(static)

mime_module(static)

status_module(static)

autoindex_module(static)

asis_module(static)

cgi_module(static)

negotiation_module(static)

dir_module(static)

actions_module(static)

userdir_module(static)

alias_module(static)

so_module(static)

SyntaxOK

为Apache2.2添加mod_proxy模块:

先找到apache源码中modules/proxy目录并进入,然后使用bin/apxs进行编译安装。这里只是提供了安装扩展模块的方法,在实际安装过程中并没有执行,因为上面的安装过程已经安装了负载均衡的代理模块。

[root@apachehs~]#cd/usr/local/src/httpd-2.2.31/modules/proxy

[root@apachehsproxy]#/usr/local/apache/bin/apxs-c-i-amod_proxy.cproxy_util.c

[root@apachehsproxy]#/usr/local/apache/bin/apxs-c-i-amod_proxy_ajp.cajp*.c

[root@apachehsproxy]#/usr/local/apache/bin/apxs-c-i-amod_proxy_balancer.c

[root@apachehsproxy]#/usr/local/apache/bin/apxs-c-i-amod_proxy_connect.c

[root@apachehsproxy]#/usr/local/apache/bin/apxs-c-i-amod_proxy_http.c

[root@apachehsproxy]#/usr/local/apache/bin/apxs-c-i-amod_proxy_ftp.c

[root@apachehsproxy]#/usr/local/apache/bin/apxs-c-i-amod_proxy_scgi.c

-c表示进行编译,-i表示将生成的模块安装到apache的modules目录下,-a选项在httpd.conf中增加一条LoadModule指令以载入刚安装的模块,或者如

果此指令已存在,则启用之。

apxs会根据源码判断模块的名称,或者(在失败的情况下)根据文件名推测模块名称,可以用-n选项显式地指定模块名称。

安装成功以后将在apache的modules目录下生成mod_proxy.so文件,并且在httpd.conf中加入了一行

下面开始配置ApacheHttpServer

[root@apachehshome]#vihttpd.conf

LoadModuleproxy_modulemodules/mod_proxy.so

LoadModuleproxy_ajp_modulemodules/mod_proxy_ajp.so

LoadModuleproxy_balancer_modulemodules/mod_proxy_balancer.so

LoadModuleproxy_http_modulemodules/mod_proxy_http.so

#Virtualhosts

Includeconf/extra/httpd-vhosts.conf

找到#Listen80...一行,在下面添加

Listen192.168.1.177:10080

找到#ServerName...一行,在下面添加

ServerName192.168.1.177:10080

在文件的最后加上如下几行:

ProxyRequestsOff

<Proxybalancer://clu>

BalancerMemberajp://192.168.1.178:8009loadfactor=1

BalancerMemberajp://192.168.1.179:8009loadfactor=1

</Proxy>

[root@apachehsconf]#viextra/httpd-vhosts.conf

<VirtualHost*:10080>

#[email protected]

#DocumentRoot"/home/webserver/apache/docs/dummy-host.example.com"

ServerName192.168.1.177:10080

#ServerAliaswww.shihuan.example.com

ProxyPass/balancer://clu/stickysession=JSESSIONIDnofailover=On

ProxyPassReverse/balancer://clu/

ErrorLog"logs/cluster-error.log"

CustomLog"logs/custer-access.log"common

</VirtualHost>

[root@apachehsconf]#vi/etc/httpd/conf/httpd.conf

添加

ServerName192.168.1.177:10080

[root@apachehshome]#/home/webserver/apache/bin/apachectl-kstart

[root@apachehshome]#/home/webserver/apache/bin/apachectl-kstop

----------------------------------------------------------------------------------

ssh登录192.168.1.178

[root@tomcat1home]#vi/etc/hosts

192.168.1.178tomcat1

[root@tomcat1home]#rpm-ivhjdk-7u80-linux-x64.rpm

[root@tomcat1home]#vi/etc/profile

exportJAVA_HOME=/usr/java/jdk1.7.0_80

exportPATH=$JAVA_HOME/bin:$PATH

[root@tomcat1home]#source/etc/profile

[root@tomcat1home]#java-version

javaversion"1.7.0_80"

Java(TM)SERuntimeEnvironment(build1.7.0_80-b15)

JavaHotSpot(TM)64-BitServerVM(build24.80-b11,mixedmode)

[root@tomcat1home]#tarxvfapache-tomcat-8.0.32.tar.gz

[root@tomcat1home]#cdapache-tomcat-8.0.32/conf

[root@tomcat1conf]#viserver.xml

关注

<!--DefineanAJP1.3Connectoronport8009-->

<Connectorport="8009"protocol="AJP/1.3"redirectPort="8443"/>

[root@tomcat1conf]#cd../bin

[root@tomcat1bin]#./startup.sh

[root@tomcat1bin]#./shutdown.sh

----------------------------------------------------------------------------------

ssh登录192.168.1.179

[root@tomcat2home]#vi/etc/hosts

192.168.1.179tomcat2

[root@tomcat2home]#rpm-ivhjdk-7u80-linux-x64.rpm

[root@tomcat2home]#vi/etc/profile

exportJAVA_HOME=/usr/java/jdk1.7.0_80

exportPATH=$JAVA_HOME/bin:$PATH

[root@tomcat2home]#source/etc/profile

[root@tomcat2home]#java-version

javaversion"1.7.0_80"

Java(TM)SERuntimeEnvironment(build1.7.0_80-b15)

JavaHotSpot(TM)64-BitServerVM(build24.80-b11,mixedmode)

[root@tomcat2home]#tarxvfapache-tomcat-8.0.32.tar.gz

[root@tomcat2home]#cdapache-tomcat-8.0.32/conf

[root@tomcat2conf]#viserver.xml

关注

<!--DefineanAJP1.3Connectoronport8009-->

<Connectorport="8009"protocol="AJP/1.3"redirectPort="8443"/>

[root@tomcat2conf]#cd../bin

[root@tomcat2bin]#./startup.sh

[root@tomcat2bin]#./shutdown.sh

----------------------------------------------------------------------------------

最后启动测试两个tomcat和apacheserver,启动顺序不能错

[root@tomcat1bin]#./startup.sh

[root@tomcat2bin]#./startup.sh

[root@apachehshome]#/home/webserver/apache/bin/apachectl-kstart

在浏览器的地址栏里输入http://192.168.1.177:10080/

相关推荐