1. Deploy stand-alone Redis

(1) Download the Redis installation package

Wget HTTP: / / http://download.redis.io/releases/redis-4.0.10.tar.gzCopy the code

(2) Decompress to the specified folder

Tar ZXVF redis-4.0.0.tar. gz mv redis-4.0.10 /usr/local/redis/
Copy the code

(3) Compile and install

cd /usr/local/redis
make
make install
Copy the code

(4) Modify the redis configuration file

vim /usr/local/redis/redis.conf
Copy the code
port 6379
daemonize yes
bind 0.0.0.0
pidfile /var/run/redis_6379.pid
cluster-enabled no
appendonly yes
Copy the code

(5) Start Redis

redis-server /usr/local/redis/redis.conf
Copy the code

2. Deploy the Redis cluster

(1) Create folders

mkdir -p /usr/local/ redis cluster / {9001900 2900 3900 4900 5900 6} / dataCopy the code

(2) modify the/usr/local/redis/redis conf configuration files for cluster pattern, as follows:

port 9001
daemonize yes
bind 0.0.0.0
dir /usr/local/redis-cluster/9001/data/
pidfile /var/run/redis_9001.pid
cluster-enabled yes
cluster-config-file nodes9001.conf
cluster-node-timeout 2000
appendonly yes
Copy the code

(3) Copy the configuration file to the created six ports folder and modify the ports in the configuration file

cd /usr/local/redis-cluster
echo 9001/ 9002/ 9003/ 9004/ 9005/ 9006/ | xargs -n 1 cp -v /usr/local/redis/redis.conf
Copy the code

(4) Start 6 Redis services

redis-server /usr/local/redis-cluster/9001/redis.conf
redis-server /usr/local/redis-cluster/9002/redis.conf
redis-server /usr/local/redis-cluster/9003/redis.conf
redis-server /usr/local/redis-cluster/9004/redis.conf
redis-server /usr/local/redis-cluster/9005/redis.conf
redis-server /usr/local/redis-cluster/9006/redis.conf
Copy the code

(5) Install Ruby. If the prompt requires a version greater than 2.2.2, use RVM to install Ruby

yum install ruby
yum install rubygems
gem install redis 
Copy the code

(6) Start the cluster

/usr/local/redis/ SRC /redis-trib.rb create --replicas 1 Server IP address :9001 Server IP address.42:9002 Server IP address :9003 Server IP address :9004 Server IP address :9005 Server IP address :9006Copy the code

3. Install sentries

(1) Create redis instance and sentinel directory

mkdir -p /usr/local/ redis - sentinel / {8001800, 2800, 3} / data mkdir -p/usr /local/redis-sentinel/sentinel
Copy the code

(2) Modify the configuration file of redis master node 8001

cd /usr/local/redis-sentinel/8001
vim redis.conf
Copy the code
# port
port 8001

# Comment the following to enable remote access
# bind 127.0.0.1

# Redis uses background mode
daemonize yes

# Disable protected mode
protected-mode no

# Change the path to which pidfile points
pidfile "/usr/local/redis-sentinel/redis8001.pid"

# log file
logfile "/usr/local/redis-sentinel/log/redis8001.log"

# database file name
dbfilename "dump.rdb"

# Directory for storing database files
dir "/usr/local/redis-sentinel/8001/data"
Copy the code

(3) Modify the configuration file of secondary redis node 8002, and modify the configuration file of secondary redis node 8003

cd /usr/local/redis-sentinel/8002
vim redis.conf
Copy the code
# port
port 8002

# Comment the following to enable remote access
# bind 127.0.0.1

# Redis uses background mode
daemonize yes

# Disable protected mode
protected-mode no

# Change the path to which pidfile points
pidfile "/usr/local/redis-sentinel/redis8002.pid"

# log file
logfile "/usr/local/redis-sentinel/log/redis8002.log"

# database file name
dbfilename "dump.rdb"

# Directory for storing database files
dir "/usr/local/redis-sentinel/8002/data"

IP and port of the primary nodeSlaveof 127.0.0.1 8001Copy the code

(4) Start the primary and secondary nodes

/usr/local/redis/redis-server /usr/local/redis-sentinel/8001/redis.conf
/usr/local/redis/redis-server /usr/local/redis-sentinel/8002/redis.conf
/usr/local/redis/redis-server /usr/local/redis-sentinel/8003/redis.conf
Copy the code

(5) Modify the configuration file of Sentinel 9001 node. In the same way, add the configuration file of Sentinel 9002 node

cd /usr/local/redis-sentinel/sentinel
vim sentinel_9001.conf
Copy the code
# Add as background run
daemonize yes
We will leave the default port of service 1 unchanged and change it later from 2
port 9001
The primary server IP port is valid only after two sentinel elections are successfulSentinel Monitor MyMaster 127.0.0.1 8001 2Copy the code

(6) Start sentinel node

/usr/local/redis/redis-server /usr/local/redis-sentinel/sentinel/sentinel_9001.conf --sentinel
/usr/local/redis/redis-server /usr/local/redis-sentinel/sentinel/sentinel_9002.conf --sentinel
Copy the code