Apache Http Server2.2采用ajp协议配置tomcat7负载均衡 博客分类: 服务器中间件ApacheServerTomcatApacheHttpServer apachetomcat
程序员文章站
2024-03-01 23:22:40
...
http://httpd.apache.org/docs/2.2/install.html
http://httpd.apache.org/docs/2.2/programs/configure.html
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
ssh登录192.168.1.177
[root@apachehs opt]# vi /etc/hosts
192.168.1.177 apachehs
[root@apachehs opt]# yum install gcc
[root@apachehs opt]# yum install -y gcc gcc-c++
[root@apachehs opt]# yum -y install zlib-devel
[root@apachehs opt]# yum -y install openssl-devel
下面安装apr、apr-util、pcre
[root@apachehs opt]# tar -xvf apr-1.5.2.tar.gz
[root@apachehs opt]# cd apr-1.5.2
[root@apachehs apr-1.5.2]# vi configure
? $RM "$cfgfile"
添加#注释掉这一行
[root@apachehs apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@apachehs apr-1.5.2]# make && make install
[root@apachehs apr-1.5.2]# cd ..
[root@apachehs opt]# tar xvf apr-util-1.5.4.tar.gz
[root@apachehs opt]# cd apr-util-1.5.4
[root@apachehs apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-
apr=/usr/local/apr/bin/apr-1-config
[root@apachehs apr-util-1.5.4]# make && make install
[root@apachehs apr-util-1.5.4]# cd ..
[root@apachehs opt]# unzip pcre-8.38.zip -d /opt/
[root@apachehs opt]# cd pcre-8.38
[root@apachehs pcre-8.38]# vi configure
? $RM "$cfgfile"
添加#注释掉这一行
[root@apachehs pcre-8.38]# ./configure --prefix=/usr/local/pcre
[root@apachehs pcre-8.38]# make && make install
下面安装Apache Http Server
[root@apachehs src]# tar xvf httpd-2.2.32.tar.gz
[root@apachehs src]# cd httpd-2.2.32
[root@apachehs httpd-2.2.32]# vi configure
? "$ap_cv_void_ptr_lt_long"
if test "$ap_cv_void_ptr_lt_long" = "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" != "yes"; then
as_fn_error $? "Size of \"void *\" is less than size of \"long\"" "$LINENO" 5
fi
[root@apachehs httpd-2.2.32]# ./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
[root@apachehs httpd-2.2.32]# make
[root@apachehs httpd-2.2.32]# make install
[root@apachehs httpd-2.2.32]# cd /usr/local/apache/conf
[root@apachehs conf]# ls
extra httpd.conf magic mime.types original
下面开始配置Apache Http Server
[root@apachehs local]# vi httpd.conf
找到#Listen 80...一行,在下面添加
Listen 192.168.1.177:10080
找到#ServerName ...一行,在下面添加
ServerName 192.168.1.177:10080
[root@apachehs conf]# vi /etc/httpd/conf/httpd.conf
添加
ServerName 192.168.1.177:10080
[root@apachehs conf]# cd /usr/local/apache/bin
[root@apachehs 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
[root@apachehs bin]# ./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
为Apache2.2添加mod_proxy模块:
先找到apache源码中modules/proxy目录并进入,然后使用bin/apxs进行编译安装。这里只是提供了安装扩展模块的方法,在实际安装过程中并没有执行,因为上面的安装过程已经安装了负载均衡的代理模块。
[root@apachehs ~]# cd /usr/local/src/httpd-2.2.31/modules/proxy
[root@apachehs proxy]# /usr/local/apache/bin/apxs -c -i -a mod_proxy.c proxy_util.c
[root@apachehs proxy]# /usr/local/apache/bin/apxs -c -i -a mod_proxy_ajp.c ajp*.c
[root@apachehs proxy]# /usr/local/apache/bin/apxs -c -i -a mod_proxy_balancer.c
[root@apachehs proxy]# /usr/local/apache/bin/apxs -c -i -a mod_proxy_connect.c
[root@apachehs proxy]# /usr/local/apache/bin/apxs -c -i -a mod_proxy_http.c
[root@apachehs proxy]# /usr/local/apache/bin/apxs -c -i -a mod_proxy_ftp.c
[root@apachehs proxy]# /usr/local/apache/bin/apxs -c -i -a mod_proxy_scgi.c
-c表示进行编译,-i表示将生成的模块安装到apache的modules目录下,-a选项在httpd.conf中增加一条LoadModule指令以载入刚安装的模块,或者如
果此指令已存在,则启用之。
apxs会根据源码判断模块的名称,或者(在失败的情况下)根据文件名推测模块名称,可以用-n选项显式地指定模块名称。
安装成功以后将在apache的modules目录下生成mod_proxy.so文件,并且在httpd.conf中加入了一行
下面开始配置Apache Http Server
[root@apachehs home]# vi httpd.conf
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
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
找到#Listen 80...一行,在下面添加
Listen 192.168.1.177:10080
找到#ServerName ...一行,在下面添加
ServerName 192.168.1.177:10080
在文件的最后加上如下几行:
ProxyRequests Off
<Proxy balancer://clu>
BalancerMember ajp://192.168.1.178:8009 loadfactor=1
BalancerMember ajp://192.168.1.179:8009 loadfactor=1
</Proxy>
[root@apachehs conf]# vi extra/httpd-vhosts.conf
<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>
[root@apachehs conf]# vi /etc/httpd/conf/httpd.conf
添加
ServerName 192.168.1.177:10080
[root@apachehs home]# /home/webserver/apache/bin/apachectl -k start
[root@apachehs home]# /home/webserver/apache/bin/apachectl -k stop
----------------------------------------------------------------------------------
ssh登录192.168.1.178
[root@tomcat1 home]# vi /etc/hosts
192.168.1.178 tomcat1
[root@tomcat1 home]# rpm -ivh jdk-7u80-linux-x64.rpm
[root@tomcat1 home]# vi /etc/profile
export JAVA_HOME=/usr/java/jdk1.7.0_80
export PATH=$JAVA_HOME/bin:$PATH
[root@tomcat1 home]# source /etc/profile
[root@tomcat1 home]# 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)
[root@tomcat1 home]# tar xvf apache-tomcat-8.0.32.tar.gz
[root@tomcat1 home]# cd apache-tomcat-8.0.32/conf
[root@tomcat1 conf]# vi server.xml
关注
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
[root@tomcat1 conf]# cd ../bin
[root@tomcat1 bin]# ./startup.sh
[root@tomcat1 bin]# ./shutdown.sh
----------------------------------------------------------------------------------
ssh登录192.168.1.179
[root@tomcat2 home]# vi /etc/hosts
192.168.1.179 tomcat2
[root@tomcat2 home]# rpm -ivh jdk-7u80-linux-x64.rpm
[root@tomcat2 home]# vi /etc/profile
export JAVA_HOME=/usr/java/jdk1.7.0_80
export PATH=$JAVA_HOME/bin:$PATH
[root@tomcat2 home]# source /etc/profile
[root@tomcat2 home]# 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)
[root@tomcat2 home]# tar xvf apache-tomcat-8.0.32.tar.gz
[root@tomcat2 home]# cd apache-tomcat-8.0.32/conf
[root@tomcat2 conf]# vi server.xml
关注
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
[root@tomcat2 conf]# cd ../bin
[root@tomcat2 bin]# ./startup.sh
[root@tomcat2 bin]# ./shutdown.sh
----------------------------------------------------------------------------------
最后启动测试两个tomcat和apacheserver,启动顺序不能错
[root@tomcat1 bin]# ./startup.sh
[root@tomcat2 bin]# ./startup.sh
[root@apachehs home]# /home/webserver/apache/bin/apachectl -k start
在浏览器的地址栏里输入 http://192.168.1.177:10080/
http://httpd.apache.org/docs/2.2/programs/configure.html
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
ssh登录192.168.1.177
[root@apachehs opt]# vi /etc/hosts
192.168.1.177 apachehs
[root@apachehs opt]# yum install gcc
[root@apachehs opt]# yum install -y gcc gcc-c++
[root@apachehs opt]# yum -y install zlib-devel
[root@apachehs opt]# yum -y install openssl-devel
下面安装apr、apr-util、pcre
[root@apachehs opt]# tar -xvf apr-1.5.2.tar.gz
[root@apachehs opt]# cd apr-1.5.2
[root@apachehs apr-1.5.2]# vi configure
? $RM "$cfgfile"
添加#注释掉这一行
[root@apachehs apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@apachehs apr-1.5.2]# make && make install
[root@apachehs apr-1.5.2]# cd ..
[root@apachehs opt]# tar xvf apr-util-1.5.4.tar.gz
[root@apachehs opt]# cd apr-util-1.5.4
[root@apachehs apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-
apr=/usr/local/apr/bin/apr-1-config
[root@apachehs apr-util-1.5.4]# make && make install
[root@apachehs apr-util-1.5.4]# cd ..
[root@apachehs opt]# unzip pcre-8.38.zip -d /opt/
[root@apachehs opt]# cd pcre-8.38
[root@apachehs pcre-8.38]# vi configure
? $RM "$cfgfile"
添加#注释掉这一行
[root@apachehs pcre-8.38]# ./configure --prefix=/usr/local/pcre
[root@apachehs pcre-8.38]# make && make install
下面安装Apache Http Server
[root@apachehs src]# tar xvf httpd-2.2.32.tar.gz
[root@apachehs src]# cd httpd-2.2.32
[root@apachehs httpd-2.2.32]# vi configure
? "$ap_cv_void_ptr_lt_long"
if test "$ap_cv_void_ptr_lt_long" = "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" != "yes"; then
as_fn_error $? "Size of \"void *\" is less than size of \"long\"" "$LINENO" 5
fi
[root@apachehs httpd-2.2.32]# ./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
[root@apachehs httpd-2.2.32]# make
[root@apachehs httpd-2.2.32]# make install
[root@apachehs httpd-2.2.32]# cd /usr/local/apache/conf
[root@apachehs conf]# ls
extra httpd.conf magic mime.types original
下面开始配置Apache Http Server
[root@apachehs local]# vi httpd.conf
找到#Listen 80...一行,在下面添加
Listen 192.168.1.177:10080
找到#ServerName ...一行,在下面添加
ServerName 192.168.1.177:10080
[root@apachehs conf]# vi /etc/httpd/conf/httpd.conf
添加
ServerName 192.168.1.177:10080
[root@apachehs conf]# cd /usr/local/apache/bin
[root@apachehs 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
[root@apachehs bin]# ./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
为Apache2.2添加mod_proxy模块:
先找到apache源码中modules/proxy目录并进入,然后使用bin/apxs进行编译安装。这里只是提供了安装扩展模块的方法,在实际安装过程中并没有执行,因为上面的安装过程已经安装了负载均衡的代理模块。
[root@apachehs ~]# cd /usr/local/src/httpd-2.2.31/modules/proxy
[root@apachehs proxy]# /usr/local/apache/bin/apxs -c -i -a mod_proxy.c proxy_util.c
[root@apachehs proxy]# /usr/local/apache/bin/apxs -c -i -a mod_proxy_ajp.c ajp*.c
[root@apachehs proxy]# /usr/local/apache/bin/apxs -c -i -a mod_proxy_balancer.c
[root@apachehs proxy]# /usr/local/apache/bin/apxs -c -i -a mod_proxy_connect.c
[root@apachehs proxy]# /usr/local/apache/bin/apxs -c -i -a mod_proxy_http.c
[root@apachehs proxy]# /usr/local/apache/bin/apxs -c -i -a mod_proxy_ftp.c
[root@apachehs proxy]# /usr/local/apache/bin/apxs -c -i -a mod_proxy_scgi.c
-c表示进行编译,-i表示将生成的模块安装到apache的modules目录下,-a选项在httpd.conf中增加一条LoadModule指令以载入刚安装的模块,或者如
果此指令已存在,则启用之。
apxs会根据源码判断模块的名称,或者(在失败的情况下)根据文件名推测模块名称,可以用-n选项显式地指定模块名称。
安装成功以后将在apache的modules目录下生成mod_proxy.so文件,并且在httpd.conf中加入了一行
下面开始配置Apache Http Server
[root@apachehs home]# vi httpd.conf
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
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
找到#Listen 80...一行,在下面添加
Listen 192.168.1.177:10080
找到#ServerName ...一行,在下面添加
ServerName 192.168.1.177:10080
在文件的最后加上如下几行:
ProxyRequests Off
<Proxy balancer://clu>
BalancerMember ajp://192.168.1.178:8009 loadfactor=1
BalancerMember ajp://192.168.1.179:8009 loadfactor=1
</Proxy>
[root@apachehs conf]# vi extra/httpd-vhosts.conf
<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>
[root@apachehs conf]# vi /etc/httpd/conf/httpd.conf
添加
ServerName 192.168.1.177:10080
[root@apachehs home]# /home/webserver/apache/bin/apachectl -k start
[root@apachehs home]# /home/webserver/apache/bin/apachectl -k stop
----------------------------------------------------------------------------------
ssh登录192.168.1.178
[root@tomcat1 home]# vi /etc/hosts
192.168.1.178 tomcat1
[root@tomcat1 home]# rpm -ivh jdk-7u80-linux-x64.rpm
[root@tomcat1 home]# vi /etc/profile
export JAVA_HOME=/usr/java/jdk1.7.0_80
export PATH=$JAVA_HOME/bin:$PATH
[root@tomcat1 home]# source /etc/profile
[root@tomcat1 home]# 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)
[root@tomcat1 home]# tar xvf apache-tomcat-8.0.32.tar.gz
[root@tomcat1 home]# cd apache-tomcat-8.0.32/conf
[root@tomcat1 conf]# vi server.xml
关注
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
[root@tomcat1 conf]# cd ../bin
[root@tomcat1 bin]# ./startup.sh
[root@tomcat1 bin]# ./shutdown.sh
----------------------------------------------------------------------------------
ssh登录192.168.1.179
[root@tomcat2 home]# vi /etc/hosts
192.168.1.179 tomcat2
[root@tomcat2 home]# rpm -ivh jdk-7u80-linux-x64.rpm
[root@tomcat2 home]# vi /etc/profile
export JAVA_HOME=/usr/java/jdk1.7.0_80
export PATH=$JAVA_HOME/bin:$PATH
[root@tomcat2 home]# source /etc/profile
[root@tomcat2 home]# 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)
[root@tomcat2 home]# tar xvf apache-tomcat-8.0.32.tar.gz
[root@tomcat2 home]# cd apache-tomcat-8.0.32/conf
[root@tomcat2 conf]# vi server.xml
关注
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
[root@tomcat2 conf]# cd ../bin
[root@tomcat2 bin]# ./startup.sh
[root@tomcat2 bin]# ./shutdown.sh
----------------------------------------------------------------------------------
最后启动测试两个tomcat和apacheserver,启动顺序不能错
[root@tomcat1 bin]# ./startup.sh
[root@tomcat2 bin]# ./startup.sh
[root@apachehs home]# /home/webserver/apache/bin/apachectl -k start
在浏览器的地址栏里输入 http://192.168.1.177:10080/
上一篇: Android下拉刷新框架实现代码实例
下一篇: .Net 单例模式(Singleton)