Installation and use of Redis

Source: Internet
Author: User
Tags download redis redis version redis server

The demo sample recommended by Redis can be referenced in this course, "Dubbo-based Distributed system architecture Combat"

IP : 192.168.4.111

Environment: CentOS 6.6

Redis version: redis-3.0 (due to Redis3.0 's features in clustering and performance improvement, RC version is a candidate version of the official version, and will be released soon)

Installation directory:/usr/local/redis

User: Root

To compile and install the required packages:

# yum Install gcc tcl

Download Redis version 3.0 (currently the latest version of redis-3.0.0-rc5.tar.gz, please choose the most recent edition of the students at the time of installation)

# CD/USR/LOCAL/SRC

# wget https://github.com/antirez/redis/archive/3.0.0-rc5.tar.gz

To create the installation directory:

# Mkdir/usr/local/redis

Extract:

# TAR-ZXVF 3.0.0-rc5.tar.gz

# MV Redis-3.0.0-rc5 redis3.0

# CD redis3.0

Install (using prefix to specify the installation directory):

# Make Prefix=/usr/local/redis Install

After the installation is complete, you can see a bin directory under the/usr/local/redis directory, which is the Redis command script in the bin directory:

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

To configure Redis as a service:

By following the steps above, the Redis startup script is:/usr/local/src/redis3.0/utils/redis_init_script

Copy the startup script to the/etc/rc.d/init.d/directory and name it Redis:

# Cp/usr/local/src/redis3.0/utils/redis_init_script/etc/rc.d/init.d/redis

Edit the/etc/rc.d/init.d/redis, modify the configuration so that it can be registered 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 "$" in

Start

If [-F $PIDFILE]

Then

echo "$PIDFILE exists, process is already running or crashed"

Else

echo "Starting Redis server ..."

$EXEC $CONF

Fi

;;

Stop

if [!-F $PIDFILE]

Then

echo "$PIDFILE does not exist, process was not running"

Else

pid=$ (Cat $PIDFILE)

echo "Stopping ..."

$CLIEXEC-P $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

Look at the Redis service script above and look at several attributes labeled orange to prepare for the following modifications:

(1) Add a line after the first line of the script as follows:

#chkconfig: 2345 80 90

(If you do not add the above, you will be prompted when registering the service: Service Redis does not support Chkconfig)

(2) The Redisport port remains 6379 unchanged; (Note that the port name is related to the following profile name)

(3) Exec=/usr/local/bin/redis-server changed to Exec=/usr/local/redis/bin/redis-server

(4) CLIEXEC=/USR/LOCAL/BIN/REDIS-CLI changed to CLIEXEC=/USR/LOCAL/REDIS/BIN/REDIS-CLI

(5) configuration file settings:

Create a Redis profile directory

# mkdir/usr/local/redis/conf

Copy the Redis profile/usr/local/src/redis3.0/redis.conf to the/usr/local/redis/conf directory and rename it to 6379.conf by port number

# cp/usr/local/src/redis3.0/redis.conf/usr/local/redis/conf/6379.conf

After you have made the above preparations, make the following adjustments to the Conf attribute:

conf= "/etc/redis/${redisport}.conf" changed to conf= "/usr/local/redis/conf/${redisport}.conf"

(6) Change the Redis Open command to run in the background:

$EXEC $CONF & # "&" function is to move the service back to run

The contents of the modified/etc/rc.d/init.d/redis service script are:

#!/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 "$" in

Start

If [-F $PIDFILE]

Then

echo "$PIDFILE exists, process is already running or crashed"

Else

echo "Starting Redis server ..."

$EXEC $CONF &

Fi

;;

Stop

if [!-F $PIDFILE]

Then

echo "$PIDFILE does not exist, process was not running"

Else

pid=$ (Cat $PIDFILE)

echo "Stopping ..."

$CLIEXEC-P $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

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

# chkconfig--add Redis

Open the corresponding port in the firewall

# Vi/etc/sysconfig/iptables

Add to:

-A input-m state--state new-m tcp-p TCP--dport 6379-j ACCEPT

To restart the firewall:

# Service Iptables Restart

To modify Redis configuration file settings:

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

Modify the following configuration

Daemonize no change to > Daemonize Yes

Pidfile/var/run/redis.pid instead of > Pidfile/var/run/redis_6379.pid

Start Redis Service

# service Redis Start

To add Redis to an environment variable:

# Vi/etc/profile

At the end, add the following:

# # Redis Env

Export path= $PATH:/usr/local/redis/bin

To make the configuration effective:

# Source/etc/profile

Redis commands such as REDIS-CLI can now be used directly:

Turn off Redis Services

# Service Redis Stop

By default, Redis turns on secure authentication, and you can specify a verification password through/usr/local/redis/conf/6379.conf's requirepass.

Installation and use of Redis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.