Redis官网 : http://redis.io independent cache server: IP: xxx.xxx.xxx. XXX installation environment: CentOS 6.6 Redis version: Redis3.0 (because Redis3.0 in cluster &#…

Disclaimer: there are a lot of information about distributed cache Redis on the Internet, you can go to the Internet to find some information to learn.

In addition, JEESZ framework for enterprise large Internet distributed enterprise architecture, distributed cache is essential, so here summarized some of the distributed cache Redis actual combat article as a later JEESZ distributed framework tutorial, hope can also help you, please do not ridicule.

Redis website: http://redis.io

Independent cache server: IP address: XXX.XXX.xxx.xxx

Installation environment: CentOS 6.6

Redis version: Redis-3.0 (due to the features of Redis3.0 in clustering and performance improvement, the RC version is a candidate for the official version, please go to the official website to choose the latest version when installing)

User: root

Installation directory: /usr/local/redis

The following is a detailed record of the Redis installation:

Packages required to compile and install:

yum install gcc tcl

Note: Download Redis 3.0 (redis-3.0.0-rc5.tar.gz, please go to the official website for the latest version)

cd /usr/local/src

wgethttps://github.com/antirez/redis/archive/3.0.0-rc5.tar.gz

Note: this path can be downloaded through the official website to the directory copy

Create an installation directory:

mkdir /usr/local/redis

Extract:

The tar – ZXVF 3.0.0 – rc5. Tar. Gz

The mv redis – 3.0.0 – rc5 redis3.0

CD redis3.0

Install (use PREFIX to specify the installation directory) :

make PREFIX=/usr/local/redis install

/usr/local/redis = /usr/local/redis = /usr/local/redis = /usr/local/redis = /usr/local/redis

redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server

Configuring Redis as a service:

According to the above steps, Redis startup scripts for: / usr/local/SRC/redis3.0 / utils/redis_init_script

Copy the startup script to /etc/rc.d/init.d/ and name it redis

Cp/usr/local/SRC/redis3.0 / utils/redis_init_script/etc/rc. D/init. D/redis

Edit /etc/rc.d/init.d/redis to make it register as a service:

vi /etc/rc.d/init.d/redis

#! /bin/sh

Simple Redis init.d script conceived to work on Linux systems

as it does use of the /proc filesystem.

REDISPORT=6379

EXEC=/usr/local/bin/redis-server

CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid

CONF=”/etc/redis/${REDISPORT}.conf”

case “$1” in

start)

if [ -f $PIDFILE ]

then

echo “$PIDFILE exists, process is already running or crashed”

else

echo “Starting Redis server…”

CONF

fi

;;

stop)

if [ ! -f $PIDFILE ]

then

echo “$PIDFILE does not exist, process is not running”

else

PID=PIDFILE)

echo “Stopping …”

REDISPORT shutdown

while [ -x /proc/${PID} ]

do

echo “Waiting for Redis to shutdown …”

sleep 1

done

echo “Redis stopped”

fi

;;

*)

echo “Please use start or stop as first argument”

;;

esac

Check the above redis service script, pay attention to the attributes marked orange, and prepare the following changes:

(1) Add the following line after the first line of the script:

#chkconfig: 2345 80 90

Note: Service redis does not support chkconfig will be displayed during service registration if the preceding content is not added

(2) REDISPORT port remains unchanged at 6379; (Special note: The port name is related to the configuration file name below)

(3) the EXEC = / usr/local/bin/redis server to EXEC = / usr/local/redis/bin/redis server. –

(4) CLIEXEC = / usr/local/bin/redis – cli to CLIEXEC = / usr/local/redis/bin/redis – cli

(5) Configuration file Settings:

Create the redis profile directory

mkdir /usr/local/redis/conf

Copy the redis configuration file/usr/local/SRC/redis3.0 / redis conf to/usr/local/redis/conf directory and the port number to 6379. Conf

Cp/usr/local/SRC/redis3.0 / redis conf/usr/local/redis/conf / 6379. Conf

After the preceding preparations, modify the CONF attributes as follows:

CONF=”/etc/redis/{REDISPORT}.conf”

(6) Change the command enabled by Redis and execute it in the background:

CONF & # “&” is used to forward the service to later

The content of the modified /etc/rc.d/init.d/redis service script is as follows:

#! /bin/sh

#chkconfig: 2345 80 90

Simple Redis init.d script conceived to work on Linux systems

as it does use of the /proc filesystem.

REDISPORT=6379

EXEC=/usr/local/redis/bin/redis-server

CLIEXEC=/usr/local/redis/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid

CONF=”/usr/local/redis/conf/${REDISPORT}.conf”

case “$1” in

start)

if [ -f $PIDFILE ]

then

echo “$PIDFILE exists, process is already running or crashed”

else

echo “Starting Redis server…”

CONF &

fi

;;

stop)

if [ ! -f $PIDFILE ]

then

echo “$PIDFILE does not exist, process is not running”

else

PID=PIDFILE)

echo “Stopping …”

REDISPORT shutdown

while [ -x /proc/${PID} ]

do

echo “Waiting for Redis to shutdown …”

sleep 1

done

echo “Redis stopped”

fi

;;

*)

echo “Please use start or stop as first argument”

;;

esac

After the above configuration is complete, you can register Redis as a service:

chkconfig –add redis

Open the corresponding port on the firewall

vi /etc/sysconfig/iptables

Add:

-A INPUT -m state –state NEW -m tcp -p tcp –dport 6379 -j ACCEPT

Restart the firewall:

service iptables restart

Modify redis profile Settings:

vi /usr/local/redis/conf/6379.conf

Modify the following configuration:

Daemonize no daemonize yes

Note: If the pid file is not changed to yes, the pid file will not be generated, and the start and stop commands will not take effect (dependent on the PID file).

Pid to pidfile /var/run/redis_6379.pid

Start the Redis service

service redis start

Add Redis to the environment variable:

vi /etc/profile

Add the following at the end:

Redis env

export PATH=$PATH:/usr/local/redis/bin

To make the configuration take effect:

source /etc/profile

You can run redis commands such as redis-cli directly.

redis-cli

Stop the Redis service

service redis stop

Remind: by default, Redis open security certification, can use the/usr/local/Redis/conf / 6379. The requirepass specify a conf

Verify password


Complete project source code welcome to study the relevant technology together, source code access please add :2670716182