Home  >  Article  >  Backend Development  >  centos65 load balancing nginx session shared redis

centos65 load balancing nginx session shared redis

WBOY
WBOYOriginal
2016-08-08 09:22:03897browse

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
Port: 8005->9005Port: 8080->9080
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


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:
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