Apache HTTP server and Tomcat integration learning record

preface

In fact, there are many tutorials on the Internet, but the problem is that it is difficult to find one with high accuracy every time. So make a simple record here to facilitate quick search.

be careful:

Start integration

1、 Download and install Apache HTTP server

Step 1: Download and decompress

Download address: https://www.apachehaus.com/cgi-bin/download.plx

Step 2: configuration file

Open the conf folder and modify the "httpd. Conf" file configuration; Change to your own file placement path

Step 3: installation

Open CMD as an administrator, enter the location of the file bin directory, and enter the following command

# 服务名可以自定义,这里我的是Apache24
httpd -k install -n "Apache24"
# 卸载
httpd -k uninstall -n "Apache24"

At the same time, you can open the Apache monitor program under the same level directory

Step 4: start

# 启动 Apache 服务
httpd.exe -k start -n "Apache24"
# 重启 Apache 服务
httpd.exe -k restart -n "Apache24"
# 停止 Apache 服务
httpd.exe -k stop -n "Apache24"

And check whether the installation is started successfully. If you can successfully access localhost: 80 or the button in the Apache monitor program is lit, the installation is started successfully

2、 Download and install Tomcat

There is no need to repeat here. Just go to the official website to download and decompress

Step 1: Download and decompress

Download address: https://tomcat.apache.org/download-80.cgi

Step 2: enter the bin directory and double-click startup Bat

Note: the individual has not modified the configuration information of the original file, so it is not changed from the original file. The problem may be his own configuration.

3、 Integration - Download JK module

Step 1: Download and decompress

Download address: http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/windows/

Note: Download according to your own requirements and version matching. Here is 1.2 Version 40

Step 2: copy Mod_ jk. so

After decompression, find mod_ jk. So file, and then copy the file to the modules folder under Apache

Step 3: create a new "mod_jk. Conf" file

Step diagram

Enter the following file contents

#加载mod_jk Module     
LoadModule jk_module modules/mod_jk.so         
#指定 workers.properties文件路径     
JkWorkersFile conf/workers.properties       
#指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器      
JkMount /*.do controller
JkMount /*WEB-INF controller
JkMount /*j_spring_security_check controller
JkMount /*.action controller
JkMount /servlet/* controller
JkMount /*.jsp controller
JkMount /*.do controller
JkMount /*.action controller
JkMount /* controller

Step 4: modify httpd Conf file

Go to Apache, find the configuration file, add a piece of code at the end of the file, and introduce mod_ jk. Conf configuration file

Include conf/mod_jk.conf

Step 5: create "workers. Properties"

worker.list =controller,tomcat1,tomcat2   #server 列表
#========tomcat1========    
worker.tomcat1.port=8009       #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.host=localhost  #tomcat的主机地址,如不为本机,请填写ip地址 
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1    #server的加权比重,值越高,分得的请求越多 
#========tomcat2========  
#worker.tomcat2.port=8019
#worker.tomcat2.host=localhost
#worker.tomcat2.type=ajp13
#worker.tomcat2.lbfactor = 1
#========controller,负载均衡控制器========   
worker.controller.type=lb
#指定分担请求的tomcat 
worker.controller.balanced_workers=tomcat1,tomcat2      
#回话是否有粘性,false表示无粘性,同一个回话的请求会到不同的tomcat中处理
worker.controller.sticky_session=false               
#当一个节点蹦了,如果设值为true,那么服务器返回500错误给客户端,如果设值为false,则转发给其他的tomcat,但是会丢失回话信息
worker.controller.sticky_session_force=false        

proposal

Some people on the Internet say that starting Apache first and then starting Tomcat will not cause problems. You can pay attention to this point, although I haven't encountered it personally.

If you encounter problems, you can refer to this blog post https://blog.csdn.net/dongdong9223/article/details/64921439

About the configuration of AJP in Tomcat

<!-- Define a non-SSL/TLS HTTP/1.1 Connector on port 8080 -->
<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

About proxy, proxy_ Blancher and Mod_ Comparison of JK

About Apache integration and Tomcat deployment cluster

Refer to this blog post: Apache integrates Tomcat deployment cluster

last

Although technology is constantly changing, you can learn more if you have time. Arrogance, desire, joy and ambition cannot be satisfied

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>