Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Build jeesz distributed architecture-Redis distributed cache installation (single node)

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Installation environment: CentOS 6.6

Redis version: redis-3.0 (because of Redis3.0 's features in clustering and performance improvement, rc version is a candidate for the official version. Please go to the official website to choose the latest version during installation)

User: root

Installation directory: / usr/local/redis

Let's make a detailed record of the Redis installation:

Compile and install the required packages:

# yum install gcc tcl

Reminder: download version 3.0 of Redis (the latest version of redis-3.0.0-rc5.tar.gz, please go to the official website to choose the latest version during installation)

# cd / usr/local/src

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

Reminder: you can download the directory copy through the official website.

Create the installation directory:

# mkdir / usr/local/redis

Decompress:

# tar-zxvf 3.0.0-rc5.tar.gz

# 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

After the installation is complete, you can see that there is a bin directory in the / usr/local/redis directory, and in the bin directory is the command script for redis:

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

Configure redis as a service:

According to the above steps, the startup script for Redis 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 / etc/rc.d/init.d/redis and modify the configuration so that it can 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..."

$EXEC $CONF

Fi

Stop)

If [!-f $PIDFILE]

Then

Echo "$PIDFILE does not exist, process is 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

Take a look at the above redis service script, focus on the attributes marked orange, and prepare for the following changes:

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

# chkconfig: 2345 80 90

Reminder: if you do not add the above, you will be prompted when registering for the service: service redis does not support chkconfig

(2) the REDISPORT port remains unchanged at 6379; (special note: the port name will be related to the following configuration file name)

(3) change EXEC=/usr/local/bin/redis-server to EXEC=/usr/local/redis/bin/redis-server

(4) change CLIEXEC=/usr/local/bin/redis-cli 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 configuration file / 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 making the above preparations, make the following adjustments to the CONF property:

Change CONF= "/ etc/redis/$ {REDISPORT} .conf" to CONF= "/ usr/local/redis/conf/$ {REDISPORT} .conf"

(6) change the command enabled by redis and execute it in the way of running in the background:

The function of $EXEC $CONF & # "&" is to transfer the service to run later.

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..."

$EXEC $CONF &

Fi

Stop)

If [!-f $PIDFILE]

Then

Echo "$PIDFILE does not exist, process is 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

After the above configuration operations are completed, Redis can be registered as a service:

# chkconfig-add redis

Open the corresponding port in the firewall

# vi / etc/sysconfig/iptables

Add:

-An INPUT-m state-- state NEW-m tcp-p tcp-- dport6379-j ACCEPT

Restart the firewall:

# service iptables restart

Modify the redis profile settings:

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

Modify the configuration as follows

Change daemonize no to daemonize yes

Note: if you do not change to yes,pid file will not be generated, start, stop commands will not take effect (dependent on pid file)

Change pidfile / var/run/redis.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 effective:

# source / etc/profile

Currently, you can directly use redis commands such as redis-cli:

# redis-cli

Turn off the Redis service

# service redis stop

Reminder: by default, Redis enables security authentication, and you can specify one through the requirepass of / usr/local/redis/conf/6379.conf

Verify password

Friends who are willing to know the framework technology or source code directly add QQ (2042849237)

More details of the source code reference source: click to open the website source source

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report