search
HomeOperation and MaintenanceNginxAnalysis of Tomcat7 Nginx Redis configuration example under CentOS6.5

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

Note: Since the redis configuration is strict on jar packages and tomcat versions, please be sure to use tomcat7 and the ones provided in this article jar package.

Download address:

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

tomcat: tomcat1 localhost:8080

tomcat2 localhost:9080

nginx: localhost:1210

#redis: localhost:6379

1. tomcat Installation and configuration

1. In the server.xml file, modify the port of tomcat2. A total of 3 modifications are required, namely 8080, 8005 and 8009, which are modified to 9080, 9005 and 9008 respectively.

After configuring this step, enter http://localhost:8080 and http://localhost:9080 in the browser to see the tomcat homepage.

2. nginx configuration to achieve load balancing.

2.1 Install pcre. Because the rewrite module of nginx requires pcre support, the pcre library needs to be installed.

2.1.1. Obtain the pcre compilation and installation package. The latest version can be obtained at http://www.pcre.org/

2.1.2. Unzip pcre-xx. tar.gz package.

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

2.1.4. make

2.1.5. make install

2.2 Install nginx. Since the nginx we want does not exist 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 content, then save and exit.

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

2.2.2. Check whether the yum source is configured properly 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 task is to configure the nginx.conf file and use the rpm -qc nginx command to query the location of the configuration file.

CentOS6.5下Tomcat7 Nginx Redis配置实例分析

2.2.5 Check whether the configuration file is correct and restart nginx.

nginx -t
service nginx restart 此处也可用如下命令: nginx -s reload

2.3 Verify the load balancing configuration

2.3.1 Modify the tomcat1 and tomcat2 homepage files respectively, obtain the login session id value, and add the h1 tag in the red box in the figure below

CentOS6.5下Tomcat7 Nginx Redis配置实例分析

2.3.2 Enter: localhost:1210 in the browser and check whether the configuration is successful. You can see that you have jumped to the tomcat page and the configuration is successful.

CentOS6.5下Tomcat7 Nginx Redis配置实例分析

#3. redis configuration, tomcat shared session.

3.1 Download and install redis3

3.1.1 Go to the redis official website to download redis3, the steps are omitted.

3.1.2 Unzip the file

tar -xvf redis-3.0.2.tar.gz

3.1.3 Compile and install.

cd redis-3.0.2
make
make install
./utils/install_server.sh # 配置redis随机启动

3.1.4 Starting and shutting down redis.

service redis_6379 start #6379 is the default port number of redis. After modification according to requirements, the service name will change

service redis_6379 stop

service redis_6379 restart

3.2 Configure tomcat to share the redis-based session mechanism.

3.2.1 Copy the following three jar packages to tomcat's lib directory respectively:

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 tomcat's conf directory, in the node Add the following content:

<valve classname="com.radiadesign.catalina.session.redissessionhandlervalve" /> 
<manager classname="com.radiadesign.catalina.session.redissessionmanager" 
host="localhost" 
port="6379" 
database="0" 
maxinactiveinterval="60" />

3.3 Restart tomcat, enter localhost:1210 in the browser, and find that the sessions of tomcat1 and tomcat2 have been shared.

CentOS6.5下Tomcat7 Nginx Redis配置实例分析CentOS6.5下Tomcat7 Nginx Redis配置实例分析

The above is the detailed content of Analysis of Tomcat7 Nginx Redis configuration example under CentOS6.5. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
NGINX vs. Apache: Performance, Scalability, and EfficiencyNGINX vs. Apache: Performance, Scalability, and EfficiencyApr 19, 2025 am 12:05 AM

NGINX and Apache are both powerful web servers, each with unique advantages and disadvantages in terms of performance, scalability and efficiency. 1) NGINX performs well when handling static content and reverse proxying, suitable for high concurrency scenarios. 2) Apache performs better when processing dynamic content and is suitable for projects that require rich module support. The selection of a server should be decided based on project requirements and scenarios.

The Ultimate Showdown: NGINX vs. ApacheThe Ultimate Showdown: NGINX vs. ApacheApr 18, 2025 am 12:02 AM

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX in Action: Examples and Real-World ApplicationsNGINX in Action: Examples and Real-World ApplicationsApr 17, 2025 am 12:18 AM

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINX Unit: Supporting Different Programming LanguagesNGINX Unit: Supporting Different Programming LanguagesApr 16, 2025 am 12:15 AM

NGINXUnit supports multiple programming languages ​​and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

Choosing Between NGINX and Apache: The Right Fit for Your NeedsChoosing Between NGINX and Apache: The Right Fit for Your NeedsApr 15, 2025 am 12:04 AM

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

How to start nginxHow to start nginxApr 14, 2025 pm 01:06 PM

Question: How to start Nginx? Answer: Install Nginx Startup Nginx Verification Nginx Is Nginx Started Explore other startup options Automatically start Nginx

How to check whether nginx is startedHow to check whether nginx is startedApr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to close nginxHow to close nginxApr 14, 2025 pm 01:00 PM

To shut down the Nginx service, follow these steps: Determine the installation type: Red Hat/CentOS (systemctl status nginx) or Debian/Ubuntu (service nginx status) Stop the service: Red Hat/CentOS (systemctl stop nginx) or Debian/Ubuntu (service nginx stop) Disable automatic startup (optional): Red Hat/CentOS (systemctl disabled nginx) or Debian/Ubuntu (syst

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment