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

Analysis of Tomcat7 Nginx Redis configuration example under CentOS6.5

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "case analysis of Tomcat7 Nginx Redis configuration under CentOS6.5". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn "Tomcat7 Nginx Redis configuration example Analysis under CentOS6.5"!

All configurations are done on one machine, and the deployment topology information is as follows:

Note: because the redis configuration is strict with the jar package and the tomcat version, be sure to use the tomcat7 and the jar package provided in this article.

Download address:

Http://pan.baidu.com/s/1bo67ky

Tomcat: tomcat1 localhost:8080

Tomcat2 localhost:9080

Nginx: localhost:1210

Redis: localhost:6379

1. Installation and configuration of tomcat

1. In the server.xml file, modifying the port of tomcat2 requires a total of three modifications, which are 8080, 8005, and 8009, respectively, to 9080, 9005, and 9008, respectively.

After configuring this step, type http://localhost:8080 and http://localhost:9080 in the browser to see the home page of tomcat.

2. Configure nginx to achieve load balancing.

2.1Install pcre. Because the rewrite module of nginx requires pcre support, you need to install the pcrelibrary.

2.1.1. Get the pcre compilation and installation package, and you can get the latest version on http://www.pcre.org/

2.1.2. Extract the pcre-xx.tar.gz package.

2.1.3. Enter the unzipped directory and execute. / configure.

2.1.4. Make

2.1.5. Make install

2.2 install nginx. Since we don't have the nginx we want in the yum source, we need to create a yum source. The steps are as follows:

2.2.1. Vim / etc/yum.repos.d/nginx.repo

Enter the following and save the exit.

[nginx] name=nginx repobaseurl= http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=1

2.2.2. Check whether the yum source is configured, and execute the following command. If there is a result, the configuration is successful.

Yum list | grep nginx

2.2.3. Install nginx.

Yum-y install nginx

2.2.4. Configure nginx. Achieve load balancing. The main purpose is to configure the nginx.conf file and use the rpm-qc nginx command to query the location of the configuration file.

2.2.5 check that the configuration file is correct and restart nginx.

The nginx-tservice nginx restart command is also available here: nginx-s reload

2.3 verify the load balancing configuration

2.3.1 modify the tomcat1 and tomcat2 home page files respectively to obtain the login session id value and add the H1 tag of the red box in the following figure

2.3.2 enter: localhost:1210 in the browser to check whether the configuration is successful. As you can see, you have jumped to the tomcat page and the configuration is successful.

3. Redis configuration. Tomcat shares session.

3.1 download and install redis3

3.1.1 go to the official website of redis to download redis3, the steps are outlined.

3.1.2 extract the file

Tar-xvf redis-3.0.2.tar.gz

3.1.3 compile and install.

Cd redis-3.0.2makemake install./utils/install_server.sh # configure redis to start randomly

3.1.4 startup and shutdown of redis.

Service redis_6379 start # 6379 is the default port number of Redis. When modified according to the requirements, the service name will change.

Service redis_6379 stop

Service redis_6379 restart

Configure the redis-based session mechanism for tomcat sharing.

3.2.1 copy the following three jar packages to the lib directory of tomcat:

Commons-pool-1.3.jar jedis-2.0.0.jar tomcat-redis-session-manager-1.2-tomcat-7-java-7.jar

3.22 modify the context.xml file in the conf directory of tomcat and add the following to the node:

Restart tomcat, type localhost:1210 in the browser, and find that the session of tomcat1 and tomcat2 has been shared.

At this point, I believe you have a deeper understanding of the "Tomcat7 Nginx Redis configuration example analysis under CentOS6.5". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Internet Technology

Wechat

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

12
Report