Detailed explanation of Linux installation using tomcat

01-Install Tomcat

# 0. Download tomcat

http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.46/bin/apache-tomcat-8.5.46.tar.gz

# 1. Upload to the Linux system through tools

# 2. Unzip into the /usr directory

[root@localhost ~]# tar -zxvf apache-tomcat-8.5.46.tar.gz -C /usr/
-C is used to specify the location of decompression

# 3. View the decompressed content

[root@localhost apache-tomcat-8.5.46]# ls -l
Total usage 124
drwxr-x---. 2 root root 4096 Oct 13 12:27 bin
-rw-r-----. 1 root root 19318 9月 17 02:19 BUILDING.txt
2 root root 238 Sep 17 02:19 conf
-rw-r-----. 1 root root 5407 Sep 17 02:19 CONTRIBUTING.md
drwxr-x---. 2 root root 4096 Oct 13 12:27 lib
-rw-r-----. 1 root root 57011 Sep 17 02:19 LICENSE
drwxr-x---. 2 root root 6 Sep 17 02:17 logs
-rw-r-----. 1 root root 1726 Sep 17 02:19 NOTICE
-rw-r-----. 1 root root 3255 Sep 17 02:19 README.md
-rw-r-----. 1 root root 7139 Mar 9 17 02:19 RELEASE-NOTES
-rw-r-----. 1 root root 16262 9月 17 02:19 RUNNING.txt
drwxr-x---. 2 root root 30 Oct 13 12:27 temp
drwxr-x---. 7 root root 81 Sep 17 02:17 webapps
drwxr-x---. 2 root root 6 9月 17 02:17 work

# 4. Start tomcat

[root@localhost apache-tomcat-8.5.46]# ./bin/startup.sh

# 5. Turn off the network firewall

systemctl stop firewalld Turn off the network firewall
systemctl disable firewalld turn off boot self-start (permanently closed)

# 6. Access tomcat in windows

http://10.15.0.8:8080/

# 7. Display tomcat real-time console information

Enter the logs directory of tomcat and use the tail -f catalina.out command to view the console information in real time

# 8. Close tomcat

Use ./shutdown.sh under the bin directory of tomcat
Note: You cannot end the process with shutdown.sh, you can first query the process of tomcat and then kill the process.

02-Tomcat load balancing cluster

# 0. Prepare multiple tomcats

tar -zxvf apache-tomcat-8.5.46.tar.gz #Decompress a new tomcat installation package
mv apache-tomcat-8.5.46 tomcat1 #Change the name to tomcat1
cp -r tomcat1/ tomcat2 #copy a copy
cp -r tomcat1/ tomcat3 #copy a copy

# 1. At this time, there are three servers in the current directory, as follows:

[root@localhost ~]# ls -l
Total usage 12248
-rwxrwxrwx. 1 root root 11623939 10月13 12:25 apache-tomcat-8.5.46.tar.gz
drwxr-xr-x. 9 root root 220 10月 14 21:28 tomcat1
drwxr-xr-x. 9 root root 220 10月 14 21:38 tomcat2
drwxr-xr-x. 9 root root 220 10月 14 21:38 tomcat3

# 2. Modify the tomcat1 port number: (pseudo-distributed)

vim tomcat1/conf/server.xml, command to modify the following content:
a.<Server port="8001" shutdown="SHUTDOWN"> --- close the port
b.<Connector port="8888" protocol="HTTP/1.1" ---http protocol port
connectionTimeout="20000"
redirectPort="8443" />
c.<Connector port="10010" protocol="AJP/1.3" redirectPort="8443" /> ---AJP protocol port

# 3. Modify the tomcat2 port number: (pseudo-distributed)

vim tomcat2/conf/server.xml, command to modify the following content:
a.<Server port="8002" shutdown="SHUTDOWN">
b.<Connector port="8889" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
c.<Connector port="10011" protocol="AJP/1.3" redirectPort="8443" />

# 4. Modify the tomcat3 port number: (pseudo-distributed)

vim tomcat2/conf/server.xml, command to modify the following content:
a.<Server port="8003" shutdown="SHUTDOWN">
b.<Connector port="8890" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
c.<Connector port="10012" protocol="AJP/1.3" redirectPort="8443" />

# 5. Start multiple tomcats:

tomcat1/bin/startup.sh
tomcat2/bin/startup.sh
tomcat3/bin/startup.sh

# 6. Check whether tomcat starts successfully

ps -aux|grep tomcat

# 7. Visit tomcat separately in windows, and you can see the home page means the startup is successful:

http://10.15.0.8:8888/
http://10.15.0.8:8889/
http://10.15.0.8:8890/
Note: This step must turn off the network firewall

# 8. Configure multiple tomcats into the nginx configuration file:

1). Enter the sbin directory of nginx and turn off the nginx service
./nginx -s stop
2). Enter the conf directory, and edit the nginx.conf file
vi nginx.conf
3). Add the following configuration to the server label:
upstream tomcat-servers {
server 192.168.80.130:8090;
server 192.168.80.130:8091;
server 192.168.80.130:8092;
}
4). Comment out the following configuration in the configuration file (in the server configuration)
        location / {
            root   html;
            index  index.html index.htm;
        }
5). Replace location / in the configuration file with the following configuration:
location / {
proxy_pass http://tomcat-servers;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
}

# 9. Enter the nginx installation directory sbin directory to start nginx

./nginx -c /usr/nginx/conf/nginx.conf

# 10. Visit nginx and see one of the tomcat screens:

http://10.15.0.8/

03-MSM configuration

Memcached Session Manager is based on the session sharing of memcache cache. That is, using cacheDB to access session information, the application server accepts new requests and saves the session information in the cache DB. When the application server fails, the scheduler will traverse to find available nodes and distribute requests. When the application server finds that the session is not in the local memory, it will search in the cacheDB, and if it is found, it will be copied to the local machine, so as to achieve session sharing and high availability.

# 0. Prepare a memcache service

# 1. Install memcached

yum install -y memcached

# 2. Start memcached

memcached -p 11211 -vvv -u root

# 3. Put the jar package integrated with memcache into the lib directory installed by tomcat

cp *.jar tomcat1/lib
cp *.jar tomcat2/lib
cp *.jar tomcat3/lib

# 4. Configure context.xml in the conf directory in the tomcat directory (all tomcats need to be configured)

<Context>
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:10.15.0.8:11211"
sticky="false"
sessionBackupAsync="false"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>

# 5. Put in the test project for testing

Continually updated!

Guess you like

Origin blog.csdn.net/weixin_51689532/article/details/130685837