Ali cloud first need to purchase ECS server. I purchased a low profile, OS is Ubuntu18.04.
All operations described herein are based on the operation command after connection to the ECS Putty server.
First, the basic environment ready to install
To run Tomcat, first make sure that there is no install Java. Run the command:
java --version
If the output words below, prove that Java has been installed.
openjdk 11.0.3 2019-04-16
The above prove I installed OpenJDK, if it is Oracle JDK output may be other words.
If not, you can use apt-get install command to install openjdk.
apt-get install default-jdk
Tomcat installation and apache2.
Apache2 installation using the command:
apt-get install apache2
Tomcat is downloaded from the official website apache 8.5.1, unzip directly to the / usr / local directory.
Start Apache and Tomcat, respectively visit as follows:
The following highlights Tomcat and Apache integration.
Although Tomcat also offers WebServer functionality, but generally only used for debugging, and its main function is to deal with Servlet, used as a Servlet container. For the treatment or the Apache Web Httpd this professional WebServer better.
To integrate, we need all the Apache HTTP requests have been screened, the request is forwarded to conform to certain rules Tomcat process. Which required modules are module_jk, responsible for forwarding the work, this module is present in the form of dynamic libraries, loaded only when needed. Apache Tomcat is called with respect to worker, typically using TCP port 8009 and Tomcat AJP communication protocol.
Second, the installation and configuration module_jk
Installation command as follows:
apt-get install libapache2-mod-jk
安装后在/etc/apache2/mods-enabled目录下会多出一个jk.load文件,文件内容就是标准的apache加载模块的LoadModule命令。重启Apache2会自动加载这个模块。
在同一个目录有一个jk.conf文件,它是对mod_jk的相关配置,如下图:
从上面的配置文件我们可以确认,jk_worker的配置文件/etc/libapache2-mod-jk/workers.properties,要将Tomcat作为一个Worker就得修改这个文件。编辑这个文件,会看到一个worker.list,默认是ajp13_worker,如果你不喜欢可以将此名字进行修改,如果不想修改一定要记住,后面的配置会使用。如果修改就得将文件中的所有地方都修改为统一的名字如myworker什么的。如果在替换,在vi的命令模式输入如下的命令即可:
:%s#ajp13_worker#myworker#g
然后回车即完成全文替换。
另外还要修改Tomcat和JDK目录,如下:
然后设置apache2的转发规则,
vi /etc/apache2/sites-available/000-default.conf
在VirtualHost节点的未尾添加转发规则(一条或多条),如下图:
这条规则的意思是把所有的/examples/和/MyWebApp/的请求转交给tomcat处理。
整个配置中涉及和可能修改的文件列表如下:
- /etc/apache2/mods-enabled/jk.load
- /etc/apache2/mods-enabled/jk.conf
- /etc/libapache2-mod-jk/workers.properties
- /etc/apache2/sites-available/000-default.conf
which jk.load / jk.conf is mod_jk load and configuration, it may be modified. workers.properties worker is set to be modified. 000-default.conf forwarding rule must be modified.
Third, set the worker in Tomcat
Modify Engine node. Add worker name, as shown below:
and to determine the 8009 port is listening protocol AJP1.3.
Fourth, functional verification
After the above configuration, you need to restart tomcat and apache2.
systemctl stop apache2
systemctl start apache2
Into the tomcat home directory, and then go to the bin directory. carried out
./shutdown.sh
./startup.sh &
Open your browser and enter http://xxx.xxx.xxx.xxx/examples/
I no longer as input: 8080 can access a tomcat. If I arranged for other applications in tomcat, by forwarding rules apache2 directly it can be visited, as my MyWebApp. As shown below: