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
The Advantages of NGINX: Speed, Efficiency, and ControlThe Advantages of NGINX: Speed, Efficiency, and ControlMay 12, 2025 am 12:13 AM

The reason why NGINX is popular is its advantages in speed, efficiency and control. 1) Speed: Adopt asynchronous and non-blocking processing, supports high concurrent connections, and has strong static file service capabilities. 2) Efficiency: Low memory usage and powerful load balancing function. 3) Control: Through flexible configuration file management behavior, modular design facilitates expansion.

NGINX vs. Apache: Community, Support, and ResourcesNGINX vs. Apache: Community, Support, and ResourcesMay 11, 2025 am 12:19 AM

The differences between NGINX and Apache in terms of community, support and resources are as follows: 1. Although the NGINX community is small, it is active and professional, and official support provides advanced features and professional services through NGINXPlus. 2.Apache has a huge and active community, and official support is mainly provided through rich documentation and community resources.

NGINX Unit: An Introduction to the Application ServerNGINX Unit: An Introduction to the Application ServerMay 10, 2025 am 12:17 AM

NGINXUnit is an open source application server that supports a variety of programming languages ​​and frameworks, such as Python, PHP, Java, Go, etc. 1. It supports dynamic configuration and can adjust application configuration without restarting the server. 2.NGINXUnit supports multi-language applications, simplifying the management of multi-language environments. 3. With configuration files, you can easily deploy and manage applications, such as running Python and PHP applications. 4. It also supports advanced configurations such as routing and load balancing to help manage and scale applications.

Using NGINX: Optimizing Website Performance and ReliabilityUsing NGINX: Optimizing Website Performance and ReliabilityMay 09, 2025 am 12:19 AM

NGINX can improve website performance and reliability by: 1. Process static content as a web server; 2. forward requests as a reverse proxy server; 3. allocate requests as a load balancer; 4. Reduce backend pressure as a cache server. NGINX can significantly improve website performance through configuration optimizations such as enabling Gzip compression and adjusting connection pooling.

NGINX's Purpose: Serving Web Content and MoreNGINX's Purpose: Serving Web Content and MoreMay 08, 2025 am 12:07 AM

NGINXserveswebcontentandactsasareverseproxy,loadbalancer,andmore.1)ItefficientlyservesstaticcontentlikeHTMLandimages.2)Itfunctionsasareverseproxyandloadbalancer,distributingtrafficacrossservers.3)NGINXenhancesperformancethroughcaching.4)Itofferssecur

NGINX Unit: Streamlining Application DeploymentNGINX Unit: Streamlining Application DeploymentMay 07, 2025 am 12:08 AM

NGINXUnit simplifies application deployment with dynamic configuration and multilingual support. 1) Dynamic configuration can be modified without restarting the server. 2) Supports multiple programming languages, such as Python, PHP, and Java. 3) Adopt asynchronous non-blocking I/O model to improve high concurrency processing performance.

NGINX's Impact: Web Servers and BeyondNGINX's Impact: Web Servers and BeyondMay 06, 2025 am 12:05 AM

NGINX initially solved the C10K problem and has now developed into an all-rounder who handles load balancing, reverse proxying and API gateways. 1) It is well-known for event-driven and non-blocking architectures and is suitable for high concurrency. 2) NGINX can be used as an HTTP and reverse proxy server, supporting IMAP/POP3. 3) Its working principle is based on event-driven and asynchronous I/O models, improving performance. 4) Basic usage includes configuring virtual hosts and load balancing, and advanced usage involves complex load balancing and caching strategies. 5) Common errors include configuration syntax errors and permission issues, and debugging skills include using nginx-t command and stub_status module. 6) Performance optimization suggestions include adjusting worker parameters, using gzip compression and

Nginx Troubleshooting: Diagnosing and Resolving Common ErrorsNginx Troubleshooting: Diagnosing and Resolving Common ErrorsMay 05, 2025 am 12:09 AM

Diagnosis and solutions for common errors of Nginx include: 1. View log files, 2. Adjust configuration files, 3. Optimize performance. By analyzing logs, adjusting timeout settings and optimizing cache and load balancing, errors such as 404, 502, 504 can be effectively resolved to improve website stability and performance.

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor