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

[url]http://httpd.apache.org/docs/2.2/install.html[/url]
[url]http://httpd.apache.org/docs/2.2/programs/configure.html[/url]


192.168.1.177--->apache http server 2.2.31
192.168.1.178--->apache-tomcat-7.0.73
192.168.1.179--->apache-tomcat-7.0.73

[color=green]ssh登录192.168.1.177[/color]
# vi /etc/hosts
192.168.1.177 apachehs
# yum install gcc
# yum install -y gcc gcc-c++
# yum -y install zlib-devel
# yum -y install openssl-devel


下面安装apr、apr-util、pcre
# tar -xvf apr-1.5.2.tar.gz
# cd apr-1.5.2
# vi configure
? $RM "$cfgfile"
添加#注释掉这一行

# ./configure --prefix=/usr/local/apr
# make && make install

# cd ..
# tar xvf apr-util-1.5.4.tar.gz
# cd apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-
apr=/usr/local/apr/bin/apr-1-config
# make && make install
# cd ..
# unzip pcre-8.38.zip -d /opt/
# cd pcre-8.38
# vi configure
? $RM "$cfgfile"
添加#注释掉这一行

# ./configure --prefix=/usr/local/pcre
# make && make install


[color=green]下面安装Apache Http Server[/color]
# tar xvf httpd-2.2.32.tar.gz
# cd httpd-2.2.32
# vi configure
? "$ap_cv_void_ptr_lt_long"
if test "$ap_cv_void_ptr_lt_long" [color=red]=[/color] "yes"; then
as_fn_error $? "Size of \"void *\" is less than size of \"long\"" "$LINENO" 5
fi
改成
if test "$ap_cv_void_ptr_lt_long" [color=red]!=[/color] "yes"; then
as_fn_error $? "Size of \"void *\" is less than size of \"long\"" "$LINENO" 5
fi

# ./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

# make
# make install
# cd /usr/local/apache/conf
# ls
extra httpd.conf magic mime.types original


[color=green]下面开始配置Apache Http Server[/color]
# vi httpd.conf

[color=green]找到#Listen 80...一行,在下面添加[/color]
Listen 192.168.1.177:10080
[color=green]找到#ServerName ...一行,在下面添加[/color]
ServerName 192.168.1.177:10080


# vi /etc/httpd/conf/httpd.conf
添加
ServerName 192.168.1.177:10080


# cd /usr/local/apache/bin
# ./httpd -l
Compiled in modules:
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

# ./httpd -t -D DUMP_MODULES
Loaded Modules:
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)
Syntax OK


[color=green]为Apache2.2添加mod_proxy模块:
先找到apache源码中modules/proxy目录并进入,然后使用bin/apxs进行编译安装。这里只是提供了安装扩展模块的方法,在实际安装过程中并没有执行,因为上面的安装过程已经安装了负载均衡的代理模块。[/color]
# cd /usr/local/src/httpd-2.2.31/modules/proxy
# /usr/local/apache/bin/apxs -c -i -a mod_proxy.c proxy_util.c
# /usr/local/apache/bin/apxs -c -i -a mod_proxy_ajp.c ajp*.c
# /usr/local/apache/bin/apxs -c -i -a mod_proxy_balancer.c
# /usr/local/apache/bin/apxs -c -i -a mod_proxy_connect.c
# /usr/local/apache/bin/apxs -c -i -a mod_proxy_http.c
# /usr/local/apache/bin/apxs -c -i -a mod_proxy_ftp.c
# /usr/local/apache/bin/apxs -c -i -a mod_proxy_scgi.c

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

果此指令已存在,则启用之。
apxs会根据源码判断模块的名称,或者(在失败的情况下)根据文件名推测模块名称,可以用-n选项显式地指定模块名称。
安装成功以后将在apache的modules目录下生成[/color][color=red]mod_proxy.so[/color][color=green]文件,并且在[/color][color=red]httpd.conf[/color][color=green]中加入了一行[/color]


[color=green]下面开始配置Apache Http Server[/color]
# [color=red]vi httpd.conf[/color]
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so

[color=green]# Virtual hosts[/color]
Include conf/extra/httpd-vhosts.conf

[color=green]找到#Listen 80...一行,在下面添加[/color]
Listen 192.168.1.177:10080
[color=green]找到#ServerName ...一行,在下面添加[/color]
ServerName 192.168.1.177:10080

[color=green]在文件的最后加上如下几行:[/color]
ProxyRequests Off
<Proxy balancer://clu>
BalancerMember ajp://192.168.1.178:8009 loadfactor=1
BalancerMember ajp://192.168.1.179:8009 loadfactor=1
</Proxy>

# [color=red]vi extra/httpd-vhosts.conf[/color]
<VirtualHost *:10080>
# ServerAdmin shihuan830619@163.com
# DocumentRoot "/home/webserver/apache/docs/dummy-host.example.com"
ServerName 192.168.1.177:10080
# ServerAlias www.shihuan.example.com
ProxyPass / balancer://clu/ stickysession=JSESSIONID nofailover=On
ProxyPassReverse / balancer://clu/
ErrorLog "logs/cluster-error.log"
CustomLog "logs/custer-access.log" common
</VirtualHost>

# [color=red]vi /etc/httpd/conf/httpd.conf[/color]
添加
ServerName 192.168.1.177:10080

# /home/webserver/apache/bin/apachectl -k start
# /home/webserver/apache/bin/apachectl -k stop

----------------------------------------------------------------------------------
[color=green]ssh登录192.168.1.178[/color]
# vi /etc/hosts
192.168.1.178 tomcat1

# rpm -ivh jdk-7u80-linux-x64.rpm
# vi /etc/profile
export JAVA_HOME=/usr/java/jdk1.7.0_80
export PATH=$JAVA_HOME/bin:$PATH

# source /etc/profile
# java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)


# tar xvf apache-tomcat-8.0.32.tar.gz
# cd apache-tomcat-8.0.32/conf
# vi server.xml
关注
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

# cd ../bin
# ./startup.sh
# ./shutdown.sh


----------------------------------------------------------------------------------
[color=green]ssh登录192.168.1.179[/color]
# vi /etc/hosts
192.168.1.179 tomcat2


# rpm -ivh jdk-7u80-linux-x64.rpm
# vi /etc/profile
export JAVA_HOME=/usr/java/jdk1.7.0_80
export PATH=$JAVA_HOME/bin:$PATH

# source /etc/profile
# java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)


# tar xvf apache-tomcat-8.0.32.tar.gz
# cd apache-tomcat-8.0.32/conf
# vi server.xml
关注
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

# cd ../bin
# ./startup.sh
# ./shutdown.sh


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


[color=green]最后启动测试两个tomcat和apacheserver,启动顺序不能错[/color]

[root@[color=red]tomcat1[/color] bin]# ./startup.sh
[root@[color=red]tomcat2[/color] bin]# ./startup.sh
[root@[color=red]apachehs[/color] home]# /home/webserver/apache/bin/apachectl -k start

在浏览器的地址栏里输入 http://192.168.1.177:10080/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值