mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
translated
This commit is contained in:
parent
4a14483874
commit
ce65089aad
@ -1,140 +0,0 @@
|
||||
translating---geekpi
|
||||
|
||||
How To Integrate Apache2 With Tomcat 7 Using mod_jk Connector
|
||||
================================================================================
|
||||
Apache is the most popular available web server. A web server is used basically to accept requests from clients and send responses to those requests. It gets an URL, translates it to a filename (for static requests), and sends that file back over the internet from the local disk, or it translates it to a program name, executes it, and then sends the output of that program back over the internet to the requesting party. If the web server was not able to process and complete the request, it instead returns an error message.
|
||||
|
||||
In this article we will list the features of Apache, and how we can integrate it with Tomcat8 and Tomcat7 using the mod_jk connector.
|
||||
|
||||
### Features of Apache ###
|
||||
|
||||
As we said Apache is the most popular available web server. The reasons behind its popularity are the following features:
|
||||
|
||||
- It is free tool that you can download and install it easily.
|
||||
- It is open source web server so you can easily see the code, adjust it, optimize it, and fix errors and security holes. New features and modules can be also added.
|
||||
- It can be used for small websites of one or two pages, or huge websites of hundreds and thousands of pages, serving millions of regular visitors each month. It can serve both static and dynamic content.
|
||||
- Improved caching modules (mod_cache, mod_disk_cache, mod_mem_cache).
|
||||
- Apache 2 supports the Internet protocol IPv6.
|
||||
|
||||
### Tomcat directory ###
|
||||
|
||||
${tomcat_home} is the root directory of tomcat. Your Tomcat installation should have the following subdirectories:
|
||||
|
||||
- ${tomcat_home}\conf – Where you can place various configuration files
|
||||
- ${tomcat_home}\webapps – Containing example applications
|
||||
- ${tomcat_home}\bin – Where you place web server plugins
|
||||
|
||||
### Mod_jk module ###
|
||||
|
||||
The mod_jk can be obtained in two formats: binary and source. Depending on the platform you are running your web server on, a binary version of mod_jk may be available. It is recommended to use the binary version if it is available.
|
||||
|
||||
The mod_jk module was developed and tested on:
|
||||
|
||||
- Linux, FreeBSD, AIX, HP-UX, MacOS X, Solaris and should work on major Unix’s platforms supporting Apache 1.3 and/or 2.x
|
||||
- 0-i386 SP4/SP5/SP6a (should be able to work with other service packs), Win2K and WinXP and Win98
|
||||
- Cygwin (until you have an apache server and autoconf/automake support tools)
|
||||
- Netware
|
||||
- i5/OS V5R4 (System I) with Apache HTTP Server 2.0.58. Be sure to have the latest Apache PTF installed.
|
||||
- Tomcat 3.2 to Tomcat 8.
|
||||
|
||||
The mod_jk requires two entities:
|
||||
|
||||
- **mod_jk.xxx** – The Apache HTTP Server module, depending on your operating system, it will be mod_jk.so, mod_jk.nlm or MOD_JK.SRVPGM.
|
||||
- **workers.properties** – A file that describes the host and used ports by the workers (Tomcat processes). A sample workers.properties can be found under the conf directory in the source download.
|
||||
|
||||
Also as with other Apache HTTP Server modules, mod_jk should be first installed on the modules directory of your Apache webserver: /usr/lib/apache and you should update your **httpd.conf** file.
|
||||
|
||||
### Installation ###
|
||||
|
||||
It is required to have a non-root user system with the “sudo” privileges before starting the installation. Now we will start our installation, so we will install Apache2 and Tomcat using the following command:
|
||||
|
||||
sudo apt-get install apache2
|
||||
|
||||
sudo apt-get install tomcat7
|
||||
|
||||
sudo apt-get install tomcat7-admin
|
||||
|
||||
And now we will create a test application for Tomcat using the following commands:
|
||||
|
||||
cd /var/lib/tomcat7/webapps
|
||||
sudo mkdir tomcat-demo
|
||||
sudo mkdir tomcat-demo/goodmoring
|
||||
sudo vim tomcat-demo/helloworld/index.jsp
|
||||
|
||||
And paste the following code:
|
||||
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Good Morning</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<H1>Good Morning</H1>
|
||||
Today is: <%= new java.util.Date().toString() %>
|
||||
</BODY>
|
||||
</HTML>
|
||||
|
||||
Everything is okay, good now we will install and configure the mod_jk using the following command:
|
||||
|
||||
sudo apt-get install libapache2-mod-jk
|
||||
|
||||
We have to start by enabling the redirect port 8443 on Tomcat using the following command:
|
||||
|
||||
sudo vim /etc/tomcat7/server.xml
|
||||
|
||||
And we will uncomment the following line:
|
||||
|
||||
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
|
||||
|
||||
After that, we will create our workers.properties file for Apache using the following command:
|
||||
|
||||
sudo vim /etc/apache2/workers.properties
|
||||
|
||||
Paste the following text:
|
||||
|
||||
# Define 1 real worker using ajp13
|
||||
worker.list=worker
|
||||
# Set properties for worker (ajp13)
|
||||
worker.worker.type=ajp13
|
||||
worker.worker.host=localhost
|
||||
worker.worker.port=8009
|
||||
|
||||
Now we will use the following command to let Apache use this worker:
|
||||
|
||||
sudo vim /etc/apache2/mods-available/jk.conf
|
||||
|
||||
And we will change the JkWorkersFile property to the following one;
|
||||
|
||||
/etc/apache2/workers.properties
|
||||
|
||||
Finally to configure the URL Apache should pass through the Tomcat
|
||||
|
||||
sudo vim /etc/apache2/sites-enabled/000-default
|
||||
|
||||
And we will add the following line in the configurtation file:
|
||||
|
||||
<VirtualHost *:80>
|
||||
.......................................
|
||||
.......................................
|
||||
JkMount /tomcat-demo* worker1
|
||||
</VirtualHost *:80>
|
||||
|
||||
You can now restart the servers using the following commands to check their functionality:
|
||||
|
||||
sudo /etc/init.d/tomcat7 restart
|
||||
sudo /etc/init.d/apache2 restart
|
||||
|
||||
### Conclusion ###
|
||||
|
||||
In this article we showed you how to configure and install Apache2 and Tomcat 7 using the mod_jk connector.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.unixmen.com/integrate-apache2-tomcat-7-using-mod_jk-connector/
|
||||
|
||||
作者:[anismaj][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.unixmen.com/author/anis/
|
@ -0,0 +1,138 @@
|
||||
如何用mod_jk连接器来集成Apache2和Tomcat 7
|
||||
================================================================================
|
||||
Apache是最流行的web服务器。通常用来接收客户端的请求并响应。它得到一个URL并将它翻译成一个文件名(或者静态请求),并将文件从本地磁盘中通过因特网返回,或者将它翻译成程序名执行它,接着将输出返回给请求方。如果web服务器不能处理和完成请求,它会返回一个错误信息。
|
||||
|
||||
在本篇中,我们会列出Apache的特性以及我们该如何用mod_jk连接器来集成Tomcat7和Tomcat8.
|
||||
|
||||
### Apache的特性 ###
|
||||
|
||||
如我们所说Apache是最流行的web服务器。下面是流行背后的原因:
|
||||
|
||||
- 它是自由工具,你可以很简单地下载和安装
|
||||
- 它开放源码因此你可以查看源码,调整它,优化它,并且修复错误和安全漏洞。也可以增加新的功能和模块。
|
||||
- 它可以用在只有一两个页面的小网站,或者是有成千上万个页面的大网站,每月处理上百万的常规访问者的请求。它可以同时处理静态和动态内容。
|
||||
- 提高的缓存模块(mod_cache、 mod_disk_cache、 mod_mem_cache)。
|
||||
- Apache 2 支持 IPv6.
|
||||
|
||||
### Tomcat 目录 ###
|
||||
|
||||
${tomcat_home} 是tomcat的根目录。你的tomcat安装应该有下面的子目录:
|
||||
|
||||
- ${tomcat_home}\conf – 存放不同配置文件的地方
|
||||
- ${tomcat_home}\webapps – 包含示例程序
|
||||
- ${tomcat_home}\bin – 存放插件的地方
|
||||
|
||||
### Mod_jk 模块 ###
|
||||
|
||||
mod_jk有两种可接受的方式:二进制或者源码。取决于你运行的web服务器的平台,二进制版本的mod_jk也许可以找到。如果有二进制版本的话建议使用这个。
|
||||
|
||||
mod_jk模块在这些平台上开发及测试过:
|
||||
|
||||
- Linux、 FreeBSD、 AIX、 HP-UX、 MacOS X、 Solaris ,应该在主流的Unix平台上都支持Apache 1.3 和/或者 2.x。
|
||||
- 0-i386 SP4/SP5/SP6a (应该可以于其他的服务包一起工作), Win2K and WinXP and Win98
|
||||
- Cygwin (需要你有apache服务器及autoconf/automake支持工具)
|
||||
- Netware
|
||||
- i5/OS V5R4 (System I) 中的 Apache HTTP Server 2.0.58。 确保已经安装了Apache PTF
|
||||
- Tomcat 3.2 到 Tomcat 8.
|
||||
|
||||
The mod_jk 需要两个组件:
|
||||
|
||||
- **mod_jk.xxx** – Apache HTTP服务器模块,取决于你的操作系统,它可能是mod_jk.so、mod_jk.nlm或者MOD_JK.SRVPGM。
|
||||
- **workers.properties** - 描述主机以及处理器使用的端口(Tomcat进程)。在下载的源码内可以在conf目录下找到workers.properties文件。
|
||||
|
||||
和Apache HTTP服务器其他的模块一样,mod_jk应该安装在你的Apache服务器下的模块目录下:/usr/lib/apache,你应该更新你的**httpd.conf**文件。
|
||||
|
||||
### 安装 ###
|
||||
|
||||
它需要非root用户在安装钱使用“sudo”特权。现在我们开始安装,我们将使用下面的命令来安装Apache2和Tomcat:
|
||||
|
||||
sudo apt-get install apache2
|
||||
|
||||
sudo apt-get install tomcat7
|
||||
|
||||
sudo apt-get install tomcat7-admin
|
||||
|
||||
下面在我们将会使用下面的命令来创建一个测试程序:
|
||||
|
||||
cd /var/lib/tomcat7/webapps
|
||||
sudo mkdir tomcat-demo
|
||||
sudo mkdir tomcat-demo/goodmoring
|
||||
sudo vim tomcat-demo/helloworld/index.jsp
|
||||
|
||||
粘贴下面的代码:
|
||||
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Good Morning</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<H1>Good Morning</H1>
|
||||
Today is: <%= new java.util.Date().toString() %>
|
||||
</BODY>
|
||||
</HTML>
|
||||
|
||||
一切完毕后,我们将使用下面的命令安装和配置mod_jk:
|
||||
|
||||
sudo apt-get install libapache2-mod-jk
|
||||
|
||||
我们将使用下面的命令启用Tomcat的8443转发端口:
|
||||
|
||||
sudo vim /etc/tomcat7/server.xml
|
||||
|
||||
我们将解除下面的注释行:
|
||||
|
||||
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
|
||||
|
||||
之后,我们将用下面的命令位Apache创建workers.properties文件:
|
||||
|
||||
sudo vim /etc/apache2/workers.properties
|
||||
|
||||
粘贴下面的行:
|
||||
|
||||
# Define 1 real worker using ajp13
|
||||
worker.list=worker
|
||||
# Set properties for worker (ajp13)
|
||||
worker.worker.type=ajp13
|
||||
worker.worker.host=localhost
|
||||
worker.worker.port=8009
|
||||
|
||||
现在我们将使用下面的命令来让Apache使用这个worker:
|
||||
|
||||
sudo vim /etc/apache2/mods-available/jk.conf
|
||||
|
||||
我们将JkWorkersFile属性成下面这行:
|
||||
|
||||
/etc/apache2/workers.properties
|
||||
|
||||
最后配置Apache交给Tomcat处理的URL
|
||||
|
||||
sudo vim /etc/apache2/sites-enabled/000-default
|
||||
|
||||
我们将在配置文件中下面的行:
|
||||
|
||||
<VirtualHost *:80>
|
||||
.......................................
|
||||
.......................................
|
||||
JkMount /tomcat-demo* worker1
|
||||
</VirtualHost *:80>
|
||||
|
||||
现在用下面的命令重启服务来检查它们的功能:
|
||||
|
||||
sudo /etc/init.d/tomcat7 restart
|
||||
sudo /etc/init.d/apache2 restart
|
||||
|
||||
### 总结 ###
|
||||
|
||||
在本篇中我们展示了你该如何使用mod_jk连接器配置和安装Apache2以及Tomcat7。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.unixmen.com/integrate-apache2-tomcat-7-using-mod_jk-connector/
|
||||
|
||||
作者:[anismaj][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.unixmen.com/author/anis/
|
Loading…
Reference in New Issue
Block a user