Home Backend Development PHP Tutorial centos65 load balancing nginx session shared redis

centos65 load balancing nginx session shared redis

Aug 08, 2016 am 09:22 AM
nbsp quot redis tomcat

1. Install JDK7

1. Query the installed jdk
rpm -qa|grep jdk
2. Uninstall the installed jdk
rpm -e --nodeps *****(Query What comes out...)
3. Upload the installation file jdk-7u79-linux-x64.rpm to /usr/java
cd /usr/java
4. Install
rpm -ivh jdk-7u79-linux -x64.rpm
5. Edit profile and add the following three lines
vim /etc/profile
export JAVA_HOME=/usr/java/jdk1.7.0_79
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre /bin
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
6. Make the configuration take effect immediately
source /etc/profile

2. Install nginx

1. Create a new file
touch /etc/yum.repos.d/nginx.repo
2. Edit the new file
vim /etc/yum.repos. d/nginx.repo
3. Copy the following content into it
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled = 1le4. Make yum -yum -yinstall nginx

5. Start nginx
service nginx start
6. Test nginx
curl 127.0.0.1


II

1. Install tcl support

yum install tcl

2. Install gcc support
yum install -y gcc g++ gcc-c++ make
3. Download redis
wget http://download.redis. io/releases/redis-2.8.16
.tar.gz
4. Unzip tar xzf redis-2.8.16.tar.gz
5. Enter the directory
cd redis-2.8.16
6 .Install
makemake test
make install
7. Edit the redis.conf file and copy it to the etc directory

vim redis.conf
Modify daemonize no to yes
cp redis.conf /etc
8. Since startup
Enter the directory
cd /etc/init.d

Create file
touch redis
Edit file
vim redis
Copy the following content into the file, save and exit
####### ###################chkconfig: 2345 10 90
#description: Start and Stop redis
PATH=/usr/local/bin:/sbin:/usr/ bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis.pid
C/ etc/redis.conf" case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server... "
                       $EXEC $CONF
                                                                                                                                                             ​
stop)
if [ ! -f $PIDFILE ]
Then
echo "$ pidfile does not exist, proces is not running"
else
pid = $ (cat $ pidfile)
echo "stopping ..."
$ redis_cli -P $ Redisport Shutdown
While [-x $ {pidfile }]
Doh Echo "WAITING for Redis to Shutdown ..."
Sleep 1
Done
Echo "Redis Stopped"
fi
;;
RESTART | Force-RELOAD)
$ {0} Stop
$ {0} start
; ;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
######### #####################

9. Modify permissions

chmod +x /etc/init.d/redis

10. Start redis service

service redis start



11. Enter redis-cli for testing


set redis hello,redis+OKget redis
$11

hello,redis

4. nginx configuration

1. Forgot where nginx is installed
where is nginx
2. Cut to the directory
cd /etc/nginx
3. Edit the configuration file
upstream www.test.com {
ip_hash;
server localhost:8080;
server localhost:9080;
}
server {
listen 80;
server_name www.test.com;
charset utf-8;
location / {
proxy_pass http://www .test.com;
          proxy_set_header                                                                                                proxy_send 5. Modify the hosts file

vim /etc/hosts

Add

127.0.0.1 www.test.com


5. Run two tomcat configurations on the same server

1. Modify profile

vim /etc/profileAdd the following content:

CATALINA_BASE=/mnt/apache-tomcat-01

[tomcat1 path]CATALINA_HOME=/mnt/apache-tomcat-01

export CATALINA_BASE CATALINA_HOME
CATALINA_2_BASE=/mnt/apache-tomcat-02

【tomcat2 path】
CATALINA_2_HOME=/mnt/apache-tomcat-02
export CATALINA_2_BASE
TOMCAT _HOME=/mnt/apache-tomcat-01 export TOMCAT_HOME
TOMCAT_2_HOME=/mnt/apache-tomcat-02
export TOMCAT_2_HOME
2. Make the configuration take effectsource /etc/profile
3. Copy two copies of tomcat, one of which No modification is required. The other copy needs to be modified as followsModify
server.xml<Server port="9005" shutdown="SHUTDOWN">
Port: 8005->9005<Connector port="9080 " maxHttpHeaderSize="8192"
Port: 8080->9080
<Connector port="9009" Port: 8009->9009

Modify startup.sh and
shutdown.sh Add the following content
export JAVA_HOME=/usr/java/jdk1.7.0_79export ATH=$PATH:$JAVA_HOME/binexport CLASSPATH=$JAVA_HOME/lib
export CATALINA_HOME=$CATALINA_2_HOMEexport CATALINA_BASE=$CATALINA_2_BASE
6. Session sharing


Add


<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />

<Manager className= in the content. "com.orangefunction.tomcat.redissessions.RedisSessionManager"

host="localhost"


port="6379"

database="0"

maxInactiveInterval="60" />7. Test

Create a project and output the sessionID on the pageRefresh the page, ses sionID remains unchanged, which means The configuration is successful

You can enter the redis-cli console and use keys * to see the sessionID on the page

Note: This article integrates scattered information on the Internet, just to facilitate the help of people in need. If If there is any content that infringes upon yours, please contact me, thank you.

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces centos65 load balancing nginx session shared redis, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution to 0x80242008 error when installing Windows 11 10.0.22000.100 Solution to 0x80242008 error when installing Windows 11 10.0.22000.100 May 08, 2024 pm 03:50 PM

Solution to 0x80242008 error when installing Windows 11 10.0.22000.100

How to deploy multiple projects in tomcat How to deploy multiple projects in tomcat Apr 21, 2024 am 09:33 AM

How to deploy multiple projects in tomcat

Where is the root directory of the tomcat website? Where is the root directory of the tomcat website? Apr 21, 2024 am 09:27 AM

Where is the root directory of the tomcat website?

Analyze PHP function bottlenecks and improve execution efficiency Analyze PHP function bottlenecks and improve execution efficiency Apr 23, 2024 pm 03:42 PM

Analyze PHP function bottlenecks and improve execution efficiency

Golang API caching strategy and optimization Golang API caching strategy and optimization May 07, 2024 pm 02:12 PM

Golang API caching strategy and optimization

Reasons for garbled characters in tomcat Reasons for garbled characters in tomcat Apr 21, 2024 am 10:18 AM

Reasons for garbled characters in tomcat

Caching mechanism and application practice in PHP development Caching mechanism and application practice in PHP development May 09, 2024 pm 01:30 PM

Caching mechanism and application practice in PHP development

How to add a server in eclipse How to add a server in eclipse May 05, 2024 pm 07:27 PM

How to add a server in eclipse

See all articles