Build multiple Tomcat servers in Centos

In order to meet business needs, we need to build multiple Tomcat servers in the same Centos server. Let ’s take a look

1. Install JDK

https://blog.csdn.net/qq_40065776/article/details/101000101

2. Install Tomcat

https://blog.csdn.net/qq_40065776/article/details/101000175

The above two steps are very simple, you can refer to my two blogs, I will not repeat them here

3. Open port 8080, 8081

Refer to my blog: Ctntos7 firewall command study notes

https://blog.csdn.net/qq_40065776/article/details/96313045

We mainly use:

Open 8080, 8081 permanently

firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --zone=public --add-port=8081/tcp --permanent

Restart the firewall

firewall-cmd --reload

If we are using the cloud Ali cloud server, we also need to log Ali cloud official website , enter the console, change the firewall settings, open 8080,80801 port

4. Make a copy of Tomcat

cp ./apache-tomcat-8.5.34/ ./apache-tomcat2-8.5.34/ -r

We must add -r, because the decompressed Tomcat itself is a folder, and there are still folders under this directory

Parameter Description:

-a: This option is usually used when copying a directory. It retains links, file attributes, and copies all contents under the directory. Its role is equal to the dpR parameter combination.
-d: Keep the link when copying. The link mentioned here is equivalent to a shortcut in Windows.
-f: Overwrite the existing target file without giving a prompt.
-i: Contrary to the -f option, a prompt is given before overwriting the target file, asking the user to confirm whether to overwrite, the target file will be overwritten when answering "y".
-p: In addition to copying the contents of the file, the modification time and access rights are also copied to the new file.
-r: If the given source file is a directory file, all subdirectories and files in the directory will be copied at this time.
-l: Do not copy files, just generate link files.

5. Modify the environment variables (this step is not required to configure only one Tomcat)

vim /etc/profile

As shown in the figure:
Environment variable configuration
add the following content at the end of the article:

# tomcat1
export CATALINA_BASE=/usr/local/apache-tomcat-8.5.34
export CATALINA_HOME=/usr/local/apache-tomcat-8.5.34
export TOMCAT_HOME=/usr/local/apache-tomcat-8.5.34

# tomcat2
export CATALINA_2_BASE=/usr/local/apache-tomcat2-8.5.34
export CATALINA_2_HOME=/usr/local/apache-tomcat2-8.5.34
export TOMCAT_2_HOME=/usr/local/apache-tomcat2-8.5.34

Multiple Tomcats and so on

Save and exit:

ESC + CTRL + :
wq 回车

Enable / etc / profile configuration

source /etc/profile

6. Modify the second (or third) Tomcat's /bin/catalina.sh

Add the following content after # OS specific support. $ Var must be set to either true or false.

export CATALINA_BASE=$CATALINA_2_BASE
export CATALINA_HOME=$CATALINA_2_HOME

That is, specify the parameters configured in the environment variables

7. Modify the service port number of the second (or third) /conf/server.xml

A total of three areas need to be modified:
(1)

<Server port="8005" shutdown="SHUTDOWN">

change into:

<Server port="9005" shutdown="SHUTDOWN">

(2)

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

change into:

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

(3)

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

change into:

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

You do n’t have to agree with the port I changed, just use a different port from the first Tomcat

8. Start two Tomcat servers

Start the first one:

./startup.sh

Start the second one:

At this time, using the first startup method can not start normally, execute

chmod +x *.sh

Execute again

sh startup.sh

Successful start

9. Access to the server

We visit in the browser

ip:8080

The first tomcat

ip:8081

The second tomcat
Two Tomcat start pages appeared, proving that we have successfully built multiple Tomcat servers

If you find deficiencies in reading, please leave a message! ! !

Published 100 original articles · praised 321 · 20,000+ views

Guess you like

Origin blog.csdn.net/qq_40065776/article/details/105652328