Setup of redis standalone and cluster Environments

Source: Internet
Author: User
Tags redis cli redis cluster install redis
1. Install the standalone version of redis. 1. You can download it from the official website. Of course, you can also use the compressed package provided by the course.
# yum install gcc# wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz# tar -xzvf tcl8.6.1-src.tar.gz# cd  /usr/local/tcl8.6.1/unix/# ./configure  # make && make install
2XX use redis-3.2.8.tar.gz (stable version)
# tar -zxvf redis-3.2.8.tar.gz# cd /usr/local/redis-3.2.8# make# make test# make install

3. redis production environment startup solution (1) There is a redis_init_script script under the redis utils directory
(2) copy the redis_init_script script to the/etc/init. d directory in Linux and rename redis_init_script to redis_6379. 6379 is the port number we want this redis instance to listen.
(3) modify the redisport of row 6th of the redis_6379 script and set it to the same port number (6379 by default)
(4) create two directories:/etc/redis (storing redis configuration files) and/var/redis/6379 (storing redis persistent files)
(5) modify the redis configuration file (redis. conf under the root directory by default), copy it to the/etc/redis directory, and change the name to 6379. conf.
(6) modify some configuration in redis. conf to the production environment.

Daemonize yes # Let redis run pidfile/var/run/redis_62.16.pid with the daemon process # Set the redis PID File Location port 6379 # Set the redis listening port number DIR/var/redis/6379 # storage location of persistent files

(7) Start redis and run CD/etc/init. d, chmod 777 redis_6379,./redis_6379 start

(8) check whether the redis process is started, PS-Ef | grep redis

(9) Let redis follow the system to start automatically

Add two lines of comment at the top of the redis_6379 script

# Chkconfig: 2345 90 10

# Description: redis is a persistent key-value Database

Chkconfig redis_6379 on

4. Use redis CLI
Redis-cli shutdown # connect to port 6379 of the Local Machine to stop the redis process redis-cli-H 127.0.0.1-P 6379 shutdown # specify the IP address and port number to be connected redis-cli Ping # Ping redis Port, redis-cli # Enter interactive command line set K1 v1get K1
Ii. redis cluster (read/write splitting + high availability + Multi-master) 1. Important configurations of redis Cluster

Cluster-enabled <yes/no>

Cluster-config-file <FILENAME>: This specifies a file for redis instances in cluster mode to save the cluster status, including information about other machines in the cluster, for example, if the node goes online and has lower limits, and Failover is not maintained, you can specify a file for it so that redis can maintain it on its own.

Cluster-node-Timeout <milliseconds>, slave will not provide services when it goes down

2. Start 6 redis instances on three machines

(1) Deploy directories on the eshop-cache03

/Etc/redis (storing redis configuration files );

/Var/redis/6379 (store redis persistent files)

(2) Compile the configuration file

Redis cluster requires at least three masters to form a highly available and robust distributed cluster. Each master is recommended to at least one slave, three masters, and three slave, minimum requirements

In the official environment, we recommend that you build at least three machines on six machines.

Ensure that each master is not on the same machine as its own slave. If it is 6, it would be better that one master and one slave will die.

3. Set up the redis cluster of six redis instances on one machine
# mkdir -p /etc/redis-cluster# mkdir -p /var/log/redis# mkdir -p /var/redis/7001

. Conf configuration file:

port 7001cluster-enabled yescluster-config-file /etc/redis-cluster/node-7001.confcluster-node-timeout 15000daemonize    yes                            pidfile        /var/run/redis_7001.pid                         dir         /var/redis/7001        logfile /var/log/redis/7001.logbind 192.168.31.187        appendonly yes

Start with at least three master nodes. Add a Server Load balancer node to each master node. Select six nodes and start six instances.

Put the above configuration files under/etc/redis, respectively: 7001. conf, 7002. conf, 7003. conf, 7004. conf, 7005. conf, 7006. conf

(3) Prepare the startup script for the production environment

Put six startup scripts under/etc/init. d: redis_7001, redis_7002, redis_7003, redis_7004, redis_7005, redis_7006

In each STARTUP script, the corresponding port number is modified.

(4) start six redis instances on three machines respectively

Delete the slaveof in each configuration file

3. Create a cluster
# yum install -y ruby# yum install -y rubygems
# gem install redis

3.1 When executing gem install redis
Error: Error installing redis:
Redis requires Ruby version> = 2.2.2.
This is because the default Ruby version of Linux is too low.

    # sudo yum install curl    # curl -L get.rvm.io | bash -s stable    # source /usr/local/rvm/scripts/rvm    # rvm list known    # rvm install 2.5.1    # rvm use 2.5.1    # rvm use 2.5.1 --default

3.2: [curl: (35) SSL Connect Error
Solution: Upgrade the network security service.
 

# yum update nss 
# cp /usr/local/redis-3.2.8/src/redis-trib.rb /usr/local/bin

# redis-trib.rb create --replicas 1 192.168.51.118:7001 192.168.51.118:7002 192.168.51.119:7003 192.168.51.119:7004 192.168.51.120:7005 192.168.51.120:7006
>>> Creating cluster
[ERR] Sorry, can‘t connect to node 192.168.51.119:7003

This error occurs because of the firewall. The method to disable the firewall is as follows:

3.3 permanent effect

Enable: chkconfig iptables on

Close: chkconfig iptables off

3.4. It takes effect immediately and becomes invalid after restart

Enable: Service iptables start

Disable: Service iptables stop


-- Replicas: Each master has several slave

6 machines, 3 master and 3 slave, try to make the master and slave not on one machine

>>> Creating cluster>>> Performing hash slots allocation on 6 nodes...Using 3 masters:192.168.51.118:7001192.168.51.119:7003192.168.51.120:7005Adding replica 192.168.51.119:7004 to 192.168.51.118:7001Adding replica 192.168.51.118:7002 to 192.168.51.119:7003Adding replica 192.168.51.120:7006 to 192.168.51.120:7005M: c929af23011ce7e6888721845d1d300196c3046f 192.168.51.118:7001   slots:0-5460 (5461 slots) masterS: 60643541639fa838a23708027dfd8f05084fa0bb 192.168.51.118:7002   replicates c330af95e5053ead51943d17b7ede77ff26e357cM: c330af95e5053ead51943d17b7ede77ff26e357c 192.168.51.119:7003   slots:5461-10922 (5462 slots) masterS: bde24d208a5c42771348bbedb2351f0b7ef9c06a 192.168.51.119:7004   replicates c929af23011ce7e6888721845d1d300196c3046fM: 422632826b23edf928d213e980ea0680b1a15ac0 192.168.51.120:7005   slots:10923-16383 (5461 slots) masterS: 1e242b9cd55bd702dd386ed3d74916ad6fb78a10 192.168.51.120:7006   replicates 422632826b23edf928d213e980ea0680b1a15ac0Can I set the above configuration? (type ‘yes‘ to accept): yes

Redis-trib.rb check 192.168.31.187: 7001

4. read/write splitting + high availability + multiple masters

Read/write Splitting: Each master has an slave
High Availability: Master is down, and slave is automatically switched over
Multi-MASTER: supports larger data volumes for horizontal resizing

Setup of redis standalone and cluster Environments

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.