Integration and lower Ubuntu16.04 Apache tomcat server

1. difference

  Apache is a Web server, supports only static pages, can also be used to store and access files, but can not handle the dynamic web page.

  Tomcat as a standalone web server to run, or may be applied (java) server (used to run a Java application), a Servlet container.

  Because Apache tomcat explain static page than fast and stable, the website can be used as an Apache Web server for static pages on the site to provide services requested; while using Tomcat server as a Servlet / JSP plug-in, dynamic display pages on the site.

 

2. how to integrate

  Integration: all access to go through Apache, Apache after screening, the request is forwarded to comply with certain rules of Tomcat for processing.

  In Apache has a module called module_jk, responsible for forwarding the work done, the module in the form of a dynamic library is loaded only when needed. Apache Tomcat is called at the end worker, module_jk typically communicate through TCP port 8009 AJP protocol used with Tomcat.

 

3. Experience [plan] focus

  (1) if you simply write a background service, and would like to open a image hosting (storage) or similar file storage and access, so you can only use the tomcat, two servers do not need to be strenuous used together. Just need to manage files (pictures) into tomcat's webapps directory, you can get the access path to the corresponding file (picture).

  (2) If you want to use apache 80 and 443 (default is 8443), tomcat 8080 and 443, it would not have tried, 443 will get up conflict. (Source of demand: do not want to take port access, but directly with the domain name, but also had to be https)

  (3) If you encounter an error during installation or boot process, then think about the reason, copying information about the error, search solutions.

 

Step 4. Integration

(1) install the Java environment, the official website to download and install JDK

(2) Installation apache server (httpd installed).

  Download the official website link: http://httpd.apache.org/download.cgi

  Installation Tutorial: https://www.cnblogs.com/chevin/p/10222681.html

  Command in the bin directory: ./httpd -k start

  Access port 80 to see whether the installation was successful.

(3) Installation tomcat server.

  Net official download link: http://tomcat.apache.org/

  Decompression: tar -zxvf XXX.tar.gz

  The name is too long rename: mv original name of the new name (such as tomcat7)

  Move positions: mv tomcat7 path (such as / usr / local)

  XXXX see Tutorial: https://blog.csdn.net/jenyzhang/article/details/70159769 

  Start tomcat: sudo ./bin/startup.sh

  [How to find Java installation path]: update-alternatives --config java (whereis Java sometimes useless)

  [Module] to see the tomcat: to install modules in the catalog to see what is inside the module such as this is: / usr / local / tomcat7 / modules

  [Log]: In the logs inside the installation directory, for example here is: / usr / local / tomcat7 / logs startup logs: catalina.log 

 

(4) Integration

  Tutorials from the source, can be accessed directly: https://www.jianshu.com/p/2547f295b6a2

   [Note]: The following paths involved, please according to their actual installation path.

  [View] port open position: use the command lsof -i: 8080  

 

First, install and configure mod_jk.so

1. Install the mod_jk

# apt-get install libapache2-mod-jk

After the installation, in the / etc / apache2 / mods-enabled will be more jk.load a file, restart apache2, apache automatically load the file to load mod_jk

 

2. Locate the worker profile

# Force jk.conf

Found JkWorkersFile:

JkWorkersFile /etc/libapache2-mod-jk/workers.properties

It explains jk_worker profile for /etc/libapache2-mod-jk/workers.properties, you want to tomcat as a worker would have to modify this file.

 

3. Set the end worker in the Apache

# We /etc/libapache2-mod-jk/workers.properties

(1) Modify worker named mytomcat

. A find worker.list:

worker.list=ajp13_worker

b. Insert the document, all ajp13_worker replaced mytomcat

(2) Set mytomcat operating environment

tomcat and jdk installation directory, in order to be able to operate normally worker

workers.tomcat_home=/usr/share/apache-tomcat-8.5.35

workers.java_home=/usr/share/jdk1.8.0_131

(3) Set forwarding rules (if not, you can create a new one)

we /etc/apache2/sites-available/000-default.conf

Add VirtualHost end of the label: JkMount / examples / * mytomcat

<VirtualHost *:80>

...

JkMount /examples/* mytomcat

</VirtualHost>

Meaning that all / examples / beginning of link requests to mytomcat processing, such as: http://192.168.1.155/examples/index.html

examples of the path is tomcat directory: /usr/share/apache-tomcat-8.5.35/webapps/examples

/ ** Apache configuration to this end, it is necessary to modify the file:

jk.load (mod_jk load settings may be changed)

jk.conf (mod_jk settings may be changed)

workers.properties (worker setting must be changed)

sites-available / 000-default.conf (forwarding rule, must be changed) ** /

 

Second, the worker is provided at an end tomcat

#vi /usr/share/apache-tomcat-8.5.35/conf/server.xml

1. Change the name of worker

Engine modifications label:

<Engine name="Catalina" defaultHost="localhost" jvmRoute="mytomcat">

Such Apache and tomcat can pass port 8009 using a communication protocol AJP1.3

 

2. Check that the listening port is 8009, the agreement is set with the same Apache end (AJP1.3 (apache end to ajp13))

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

 

Third, functional verification

1. restart apache

To the next restart httpd directory: ./httpd -k restart

2. Restart tomcat

Bin directory to perform shutdown.sh

Bin directory to perform startup.sh

3. The browser requests

A request (or a file), respectively, and a file request apache tomcat verify
 
 

Guess you like

Origin www.cnblogs.com/haiyoushenmemingzi/p/11300527.html