Recently, the project is going to be online. Due to manpower problems and related knowledge of various researches on operation and maintenance, I just finished the redis cluster deployment and talked with everyone.

First, Redis installation

* The following are executed in Linux, ubuntu16.04

1. Download the stable version

sudo wget http://download.redis.io/redis-stable.tar.gz
Copy the code

2. Unzip

sudo tar -zxvf redis-stable.tar.gz
Copy the code

3. Install a GCC editor if you don’t have one

sudo apt-get install gcc
Copy the code

4. Edit and install

CD redis-stable make make install PREFIX= Installation directoryCopy the code

5. Redis configuration

CD Step 4 Installation directory /bin cp redis-stable directory /redis.conf./ # Redis-stable directory /redis.conf. Bind IP address: 127.0.0.1 port 6379 daemonize yes: RequirePass/masterAuth/requirePass Masterauth password requirepass password (must be consistent) appendonly yes cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 15000Copy the code

6. Service

If you want to start multiple services on one machine, you can copy multiple reids.conf files and change the name of the log file. You can also copy multiple bin folders and change the name of the log file./redis-server redis.confCopy the code

Second, Redis cluster

Currently, there are two Redis clustering solutions:

1. Twemproxy

This is the solution introduced by Twitter. Simply speaking, it is to add a proxy on the upper layer to be responsible for distribution. It belongs to the client cluster solution, which is adopted by most users at present.

LVS, Twemproxy, Keepalived, and Redis master-slave mode are used, which feels too troublesome. Moreover, there is no online node capacity expansion, and the company’s economic capacity is limited, so it cannot reserve enough nodes at the beginning. Later, after finding the official Redis Cluster solution, it gave up Twemproxy.

2. Redis Cluster

After Redis3.0, the official launch of the server side cluster solution

Advantages:

(1) Official solution (2) Online horizontal expansion (one drawback of Twemproxy is that it does not support online node expansion) (3) direct client connection, less system bottleneck (4) no central architecture (5) support for data shardingCopy the code

According to the requirements, the final solution is redis Cluster + master-slave mode

Here is the configuration

1. Install ruby

Sudo apt-get install Ruby sudo apt-get install rubygems sudo gem install redisCopy the code

2. If you want to set a password, modify some configurations

Execute gem Environment to find the INSTALLATION DIRECTORY

+/gems/redis-xxx/lib/redis/ vim client.rb password => "password" # change password to specified passwordCopy the code

3. There is another way to set your password

Do not set the password at the beginning of redis, after the cluster, through the config command redis service one by one to modify the configuration

Configset masterauth password configset requirePass password config rewriteCopy the code

4. Configure the cluster

CD redis installation directory cp redis-stable directory/SRC /redis-trib.rb././redis-trib.rb create --replicas 1 192.168.1.222:6379 192.168.1.223:6379 192.168.1.224:6379 192.168.1.225:6379192.168.1.226:6379 192.168.1.227:6379 # 1 said from replicas, this case SanZhu re-understandingCopy the code

You can check the status of each node by:

. / redis - trib. Rb check 192.168.1.222:6379Copy the code

Third, Redis performance monitoring

Redis – CLI itself provides the monitor function, which is powerful. However, monitor consumes a lot of performance. Therefore, it should only be enabled for debugging for a short time, and cannot be used as a long-term performance monitoring solution

Redis-monitor is selected here, which supports clustering, is written in Python and has web terminal

1. Install the Python environment (Redis-monitor is python2.7 based)

Sudo apt-get install python2.7 python2.7-devCopy the code

2. Install build dependencies – Some PIP installations require the libssl and libevent build environments

sudo apt-get install build-essential libssl-dev libevent-dev libjpeg-devlibxml2-dev libxslt-dev
Copy the code

3. Install the PIP package management tool

sudo apt-get install python-pip
Copy the code

4. Download the redis – monitor

git clone https://github.com/LittlePeng/redis-monitor.git
Copy the code

5. Install dependencies

cd redis-monitor
pip install -r requirements.txt
Copy the code

6. Start the service in background mode

CD redis-monitor/ SRC pythonredis_monitor_daemon.py # web, port:8888 127.0.0.1:8888 / index. HTMLCopy the code