Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Case study and implementation of installing Tomcat based on centos 7

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

The following brings you the case study and implementation of installing Tomcat based on centos 7, hoping to bring some help to you in practical application. Load balancing involves more things, there are not many theories, and there are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.

1. Case analysis 1. Case overview

In general, a Tomcat site may have a single point of failure and unable to cope with too many complex and diverse customer requests, so it can not be used in the production environment alone, so it is necessary to use load balancing to solve these problems.

Nginx is a very excellent http CVM software, which can support responses of up to 50000 concurrent connections, has strong static resource processing capacity, runs stably, and consumes very low memory, CPU and other system resources. At present, many large websites use Nginx server as the reverse proxy and load balancer of the back-end website program to improve the load concurrency ability of the whole site.

Start the preparatory work and set up the following environment. In order to simplify, the shared storage server will not be deployed. The environment is as follows:

The image can be extracted from my network disk: https://pan.baidu.com/s/1YAtbAVRg7wejN3XRl28J1g

Extraction code: 2f7f

Case implementation 1. Deploy the first Tomcat server [root@centos02 ~] # java-version openjdk version "1.8.0x131" OpenJDK Runtime Environment (build 1.8.0_131-b12) OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode) [root@centos02 ~] # systemctl stop firewalld [root@centos02] # systemctl disable firewalld [root@centos02 ~] # mount / dev/cdrom / mnt/ mount: / dev/sr0 write protection [root@centos02 ~] # rm-rf / etc/yum.repos.d/CentOS-* [root@centos02 ~] # tar zxvf / mnt/apache-tomcat-7.0.54.tar.gz-C / usr/src/ [root@centos02 ~] # mv / usr/src/apache-tomcat-7.0.54/ / usr/local/tomcat will be mounted read-only [root@centos02 ~] # / usr/local/tomcat/bin/startup.sh

The client configuration and the IP address of the same network segment of the server test whether the access to tomcat is normal or not http://192.168.100.20:8080

2 、 Tomcat publishes Web site [root@centos02 ~] # mkdir / var/www [root@centos02 ~] # vim / var/www/index.jsp test01 [root@centos02 ~] # vim / usr/local/tomcat/conf/server.xml 126 127 [root@centos02] # / usr/local/tomcat/bin/shutdown.sh [root@centos02 ~ ] # / usr/local/tomcat/bin/startup.sh

When the client visits http://192.168.100.20:8080, it will find that the content of the home page of the website has become the content written by us.

At this point, the Tomcat of 192.168.100.20 has been configured, and the configuration of another Tomcat server 192.168.100.30 is exactly the same as that of 192.168.100.20. You can configure the above configuration on the 192.168.100.30 server once (I am lazy and convenient to copy it directly). However, in order to see the effect of load balancing during the test, we can see that each visit to the server is not the same, so the home page content settings of the two tomcat servers need to be called different content. In the actual production environment, the two Tomcat must use the same shared storage server. No matter which server provides services to users, the pages they receive must be the same.

3 、 Deploy the second tomcat server [root@centos03 ~] # mkdir / var/www [root@centos02 ~] # scp / var/www/index.jsp root@192.168.100.30:/var/www/ The authenticity of host '192.168.100.30 (192.168.100.30)' can't be established.ECDSA key fingerprint is SHA256:PUueT9fU9QbsyNB5NC5hbSXzaWxxQavBxXmfoknXl4I.ECDSA key fingerprint is MD5:6d:f7:95:0e:51:1a:d8:9e:7b B6:3f:58:51:51:4b:3b.Are you sure you want to continue connecting (yes/no)? Yes root@192.168.100.30's password: index.jsp 100% 240 59.3KB/s 00:00 [root@centos03 ~] # cd / var/www/ [root@centos03 www] # ls index.jsp [root@centos02 ~] # scp-r / usr/local/tomcat/ root@192.168.100.30:/usr/local/tomcatroot@ 192.168.100.30s password: [root@centos03 ~] # cd / usr/local/tomcat/ [root@centos03 tomcat] # lsbin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work [root@centos03 ~] # vim / var/www/index.jsp test02 [root@centos03 ~] # / usr/local/tomcat/bin/startup.sh

The client accesses the second tomcat server http://192.168.100.30:8080

4. Deploy Nginx server [root@centos01 ~] # groupadd nginx [root@centos01 ~] # useradd-M-s / sbin/nologin-g nginx nginx [root@centos01 ~] # mount / dev/cdrom / mnt/ mount: / dev/sr0 write protection [root@centos01 ~] # rm-rf / etc/yum.repos.d/CentOS-* [root@centos01 ~] # yum-y install pcre-devel zlib-devel openssl-devel [root@centos01 ~] # mount / dev/cdrom / mnt/ mount: / dev/sr0 write protection will be mounted read-only [root@centos01 ~] # tar zxvf / mnt/nginx-1.6.0.tar.gz-C / usr/src/ [root@centos01 ~] # cd / usr/src/nginx-1.6.0/ [root@centos01 nginx-1.6.0] #. / configure-- prefix=/usr/local/nginx-- user=nginx-- group=nginx-- with-http_stub_status_module-- with-http_gzip_static_module-- with-file will be mounted read-only -aio-- with-http_ssl_module-- with-http_flv_module [root@centos01 nginx-1.6.0] # make & & make install [root@centos01 ~] # ln-s / usr/local/nginx/sbin/* / usr/local/sbin/ [root@centos01 ~] # vim / usr/local/nginx/conf/nginx.conf 34 upstream tomcat_server {35 server 192.168.100.20 Fran 8080 weight=1 36 server 192.168.100.30 weight=1; 37} 38 server {39 listen 80; 40 server_name www.benet.com; 41 charset utf-8; 42 location / {43 root html; 44 proxy_pass http://tomcat_server; 45 index index.html index.htm 46} [root@centos01 ~] # nginx-t nginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful [root@centos01 ~] # nginx [root@centos01 ~] # netstat-anptu | grep nginx tcp 0 0. 0. 0. 0. Deploy DNS [root@centos01 ~] # umount / mnt/ [root@centos01 ~] # mount / dev/cdrom / mnt/ mount: / dev/sr0 write protection [root@centos01 ~] # yum-y install bind bind-chroot bind-utils [root@centos01 ~] # echo "> / etc/named.conf [root@centos01 ~] # vim / etc/named.conf options {listen-on port 53 {any will be mounted read-only }; directory "/ var/named";}; zone benet.com IN {type master; file "benet.com.zone";}; [root@centos01 ~] # named-checkconf-z / etc/named.conf [root@centos01 ~] # vim / var/named/benet.com.zone $TTL 86400 @ SOA benet.com. Root.benet.com. (2019113001 1H 15M 1W 1D) @ NS centos01.benet.com.centos01 A 192.168.100.10www A 192.168.100.10 [root@centos01 ~] # named-checkzone benet.com/ var/named/benet.com.zone zone benet.com/IN: loaded serial 2019113001OK [root@centos01 ~] # chmod + x / var/named/benet.com.zone [root@centos01 ~] # chown named:named / var/named/benet.com.zone [root@centos01 ~] # systemctl start named [root@centos01 ~] # systemctl enable named

The client adds a DNS address

Client accesses www.benet.com for the first time

Refresh the page and you will see the following home page on your second visit:

After reading the above case study and implementation of installing Tomcat based on centos 7, if there is anything else you need to know, you can find what you are interested in in the industry information or find our professional and technical engineer to answer, the technical engineer has more than ten years of experience in the industry. Official website link www.yisu.com

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report