Home  >  Article  >  Operation and Maintenance  >  Tomcat7 Nginx Redis configuration method under CentOS6.5

Tomcat7 Nginx Redis configuration method under CentOS6.5

WBOY
WBOYforward
2023-05-13 21:34:041223browse

1. Installation and configuration of tomcat

1. In the server.xml file, modify the port of tomcat2. A total of 3 modifications need to be made, namely 8080, 8005 and 8009. 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 af16c4db277e0498b5fa9e30613367f1 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 Tomcat7 Nginx Redis configuration method under CentOS6.5. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete