Apache Http Server2.2 uses ajp protocol to configure tomcat7 load balancing

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"
add # comment out this line

[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"
Add # to comment out this line

[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


Start configuring Apache Http Server below
[root@apachehs local]# vi httpd.conf

find #Listen 80... line, add
Listen 192.168.1.177:10080 below
to find #ServerName ...one line, add
ServerName 192.168.1.177:10080


[root@apachehs conf]# vi /etc/httpd/conf/httpd.conf
Add
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



Add mod_proxy module for Apache2.2:
first find the modules/proxy directory in the apache source code and enter, then use bin/ apxs to compile and install. This only provides a method for installing the extension module, and it is not executed during the actual installation process, because the above installation process has already installed the load balancing proxy module.

[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 means to compile, -i means to install the generated module to the modules directory of apache, the -a option adds a LoadModule directive to httpd.conf to load the module just installed, or

if this directive already exists, enable it.
    apxs will determine the module name from the source code, or (in the case of failure) infer the module name from the file name, which can be specified explicitly with the -n option.
After the installation is successful, the mod_proxy.so file will be generated in the modules directory of apache , and the following line will be added to httpd.conf to start configuring 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

Find the line #Listen 80... and add
Listen 192.168.1.177 below :10080
Find the #ServerName ... line, add
ServerName 192.168.1.177:10080

and add the following lines at the end of the file:
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 [email protected]
    # 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


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


Finally, start and test two tomcat and apacheserver, the startup sequence can not be wrong

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

Enter http://192.168.1.177:10080/ in the address bar of the browser

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326361049&siteId=291194637