Redis cluster mode deployment tutorial in Linux, linuxredis

Source: Internet
Author: User
Tags gnupg gpg redis version wrappers redis cluster install redis redis server

Redis cluster mode deployment tutorial in Linux, linuxredis
1. Redis deployment

The following uses Linux as an example.

1.1 download and compile
$ wget https://download.redis.io/releases/redis-4.0.7.tar.gz$ tar xzf redis-4.0.7.tar.gz$ cd redis-4.0.7$ make

After compilation, the Redis server program redis-server and the client program redis-cli are generated in the src directory.

1.2 start the service

1. Run on the foreground

src/redis-server

By default, this mode is enabled in the foreground mode and uses the default configuration.

2. running in the background

You can modify the daemonize parameter of the redis. conf file to yes and specify the configuration file to start. For example:

vi redis.conf# By default Redis does not run as a daemon. Use 'yes' if you need it.# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.daemonize yes

Specify the configuration file to start.

src/redis-server redis.conf

For example:

# Specify the configuration file background boot [root @ kube-node-1 redis-4.0.7] # src/redis-server redis. conf95778: C 30 Jan 00:44:37. 633 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo95778: C 30 Jan 00:44:37. 634 # Redis version = 4.0.7, bits = 64, commit = 00000000, modified = 0, pid = 95778, just started95778: C 30 Jan 00:44:37. 634 # Configuration loaded # view Redis process [root @ kube-node-1 redis-4.0.7] # ps aux | grep redisroot 95779 0.0 0.0 145268 468? Ssl src/redis-server 127.0.0.1: 6379

More startup parameters are as follows:

[root@kube-node-1 src]# ./redis-server --helpUsage: ./redis-server [/path/to/redis.conf] [options]       ./redis-server - (read config from stdin)       ./redis-server -v or --version       ./redis-server -h or --help       ./redis-server --test-memory 
 
  Examples:       ./redis-server (run the server with default conf)       ./redis-server /etc/redis/6379.conf       ./redis-server --port 7777       ./redis-server --port 7777 --slaveof 127.0.0.1 8888       ./redis-server /etc/myredis.conf --loglevel verboseSentinel mode:       ./redis-server /etc/sentinel.conf --sentinel
 
1.3 client Test
$ src/redis-cliredis> set foo barOKredis> get foo"bar"
2. Redis cluster deployment

To deploy a Redis cluster, you need to install Redis on the machine deployed in each cluster (refer to Redis installation), and then modify the configuration to start the cluster.

2.1 manually deploy the cluster 2.1.1 and set the configuration file and start the instance

Modify the configuration file redis. conf. The minimal configuration file in cluster mode is as follows:

# Optional. daemonize yesport 7000cluster-enabled yescluster-config-file nodes. confcluster-node-timeout 5000 appendonly yes

For more Cluster configuration parameters, refer to the description of the Cluster module in the default configuration file redis. conf.

The minimum cluster mode requires three master instances. Generally, we recommend that you create six instances, namely three master instances and three slave instances. Therefore, we create six directories named after the port number to store the configuration files and other information of the instance.

mkdir cluster-testcd cluster-testmkdir 7000 7001 7002 7003 7004 7005

Create the redis. conf file in the directory of the corresponding port number. For details about the configuration file, refer to the preceding cluster mode configuration. Change the port parameter in each configuration file to the port number of the corresponding directory.

Copy the redis-server binary file to the cluster-test directory and start the redis service by specifying the configuration file. For example:

cd 7000../redis-server ./redis.conf

If it is run in the foreground mode, the following information is output on the console:

[82462] 26 Nov 11:56:55.329 * No cluster configuration found, I'm 97a3a64667477371c4479320d683e4c8db5858b1

Each instance generates a Node ID, similar to 97a3a64667477371c4479320d683e4c8db5858b1, which is used as the unique identifier of the Redis instance in the cluster, rather than using IP and Port. The IP and Port may change and the Node ID will not change.

For the directory structure, see:

cluster-test/├── 7000│   ├── appendonly.aof│   ├── dump.rdb│   ├── nodes.conf│   └── redis.conf├── 7001│   ├── appendonly.aof│   ├── dump.rdb│   ├── nodes.conf│   └── redis.conf├── 7002│   ├── appendonly.aof│   ├── dump.rdb│   ├── nodes.conf│   └── redis.conf├── 7003│   ├── appendonly.aof│   ├── dump.rdb│   ├── nodes.conf│   └── redis.conf├── 7004│   ├── appendonly.aof│   ├── dump.rdb│   ├── nodes.conf│   └── redis.conf├── 7005│   ├── appendonly.aof│   ├── dump.rdb│   ├── nodes.conf│   └── redis.conf├── redis-cli└── redis-server
2.1.2 create a cluster using redis-trib

After all Redis instances run, you also need a redis-trib.rb tool to create the cluster, redis-trib.rb binaries in the src directory under the Redis package home directory, run the tool depends on the Ruby environment and gem, therefore, you must install the SDK in advance.

1. Install Ruby

yum -y install ruby rubygems

View Ruby version information.

[root@kube-node-1 src]# ruby --versionruby 2.0.0p648 (2015-12-16) [x86_64-linux]

Because centos supports Ruby 2.0.0 by default, the following error is reported when executing the gem install redis command.

[root@kube-node-1 src]# gem install redisFetching: redis-4.0.1.gem (100%)ERROR:  Error installing redis:    redis requires Ruby version >= 2.2.2.

The solution is to first install rvm and then upgrade ruby.

2. Install rvm

curl -L get.rvm.io | bash -s stable

If the following error is reported, run the gpg2 -- recv-keys command in the error.

[Root @ kube-node-1 ~] # Curl-L get. rvm. io | bash-s stable % Total % Received % Xferd Average Speed Time Current Dload Upload Total Spent Left Speed100 194 100 194 0 0 335 0 --:--:----:--: --: -- 335100 24090 100 24090 0 0 17421 0 0:00:01 --: -- 44446 Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gzDownloading commit: The signature created by CST at on Monday 10, September 11, 2017. RSA is used. Key number: BF04FF17gpg: the signature cannot be checked: there is no public key Warning, RVM 1.26.0 introduces signed releases and automatic check of signatures when GPG software found. assuming you trust Michal Papis import the mpapis public key (downloading the signatures ). GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.3.tgz'-'https: // github.com/rvm/rvm/releases/download/1.29. 3/1 .29.3.tar.gz. asc '! Try to install GPG v2 and then fetch the public key: gpg2 -- recv-keys available if it fails: command curl-sSL https://rvm.io/mpapis.asc | gpg2 -- import-the key can be compared: https://rvm.io/mpapis.asc https://keybase.io/mpapisNOTE: GPG version 2.1.17 have a bug which cause failures during fetching keys from remote server. please downgrade or upgrade to newer version (if available) or use the second method described above.

Run the gpg2 -- recv-keys command in the error message.

For example:

[Root @ kube-node-1 ~] # Gpg2 -- recv-keys 409b6b1796c275462a1703111084bb82d39dc0e3gpg: Key Ring '/root /. gnupg/secring. gpg' created gpg: Download the key 'd39dc0e3 'from the hkp server keys. gnupg. netgpg:/root /. gnupg/trustdb. gpg: built a trust database gpg: Key D39DC0E3: Public Key "Michal Papis (RVM signing)
 
  
"Gpg imported: no key that is absolutely trusted is found. gpg: Total number of processes: 1gpg: imported: 1 (RSA: 1)
 

Run the command curl-L get. rvm. io | bash-s stable again. For example:

[Root @ kube-node-1 ~] # Curl-L get. rvm. io | bash-s stable % Total % Received % Xferd Average Speed Time Current Dload Upload Total Spent Left Speed100 194 100 194 0 0 310 0 --:--:----:--: --: -- 309100 24090 100 24090 0 0 18230 0 0:00:01 --: -- 103 kDownloading https://github.com/rvm/rvm/archive/1.29.3.tar.gzDownloading signature created by CST on Monday 04, September 11, 2017 0:00:01, using RSA, key number BF04FF17gpg: intact signature, from "Michal Papis (RVM signing)
 
  
"Gpg: that is," Michal Papis
  
   
"Gpg: that is," [jpeg image of size 5015] "gpg: Warning: This key has not been authenticated by a trusted signature! Gpg: there is no evidence that the signature belongs to the holder it claims. Fingerprint of the primary key: 409B 6B17 96C2 7546 2A17 0311 3804 BB82 D39D C0E3 fingerprint of the subkey: 62C9 E5F4 DA30 0D94 AC36 166B E206 C29F BF04 FF17GPG verified '/usr/local/rvm/archives/rvm-1.29.3.tgz 'Creating group' rvm' Installing RVM to/usr/local/rvm/installof ation RVM in/usr/local/rvm/is almost complete: * First you need to add all users that will be using rvm to 'rvm 'group, and logout-login again, anyone using rvm will be operating with 'umask u = rwx, g = rwx, o = rx '. * To start using RVM you need to run 'source/etc/profile. d/rvm. sh 'in all your open shell windows, in rare cases you need to reopen all shell windows.
  
 

The preceding statement indicates that the execution is successful,

source /usr/local/rvm/scripts/rvm

View known ruby versions in the rvm Library

rvm list known

For example:

[root@kube-node-1 ~]# rvm list known# MRI Rubies[ruby-]1.8.6[-p420][ruby-]1.8.7[-head] # security released on head[ruby-]1.9.1[-p431][ruby-]1.9.2[-p330][ruby-]1.9.3[-p551][ruby-]2.0.0[-p648][ruby-]2.1[.10][ruby-]2.2[.7][ruby-]2.3[.4][ruby-]2.4[.1]ruby-head...

3. Upgrade Ruby

# Install rubyrvm install 2.4.0 # use the new version rvm use 2.4.0 # remove the old version rvm remove 2.0.0 # view the current version of ruby -- version

For example:

[root@kube-node-1 ~]# rvm install  2.4.0Searching for binary rubies, this might take some time.Found remote file https://rvm_io.global.ssl.fastly.net/binaries/centos/7/x86_64/ruby-2.4.0.tar.bz2Checking requirements for centos.Installing requirements for centos.Installing required packages: autoconf, automake, bison, bzip2, gcc-c++, libffi-devel, libtool, readline-devel, sqlite-devel, zlib-devel, libyaml-devel, openssl-devel................................Requirements installation successful.ruby-2.4.0 - #configureruby-2.4.0 - #download  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed100 14.0M  100 14.0M    0     0   852k      0  0:00:16  0:00:16 --:--:--  980kNo checksum for downloaded archive, recording checksum in user configuration.ruby-2.4.0 - #validate archiveruby-2.4.0 - #extractruby-2.4.0 - #validate binaryruby-2.4.0 - #setupruby-2.4.0 - #gemset created /usr/local/rvm/gems/ruby-2.4.0@globalruby-2.4.0 - #importing gemset /usr/local/rvm/gemsets/global.gems..............................ruby-2.4.0 - #generating global wrappers........ruby-2.4.0 - #gemset created /usr/local/rvm/gems/ruby-2.4.0ruby-2.4.0 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem listruby-2.4.0 - #generating default wrappers........[root@kube-node-1 ~]# rvm use  2.4.0Using /usr/local/rvm/gems/ruby-2.4.0[root@kube-node-1 ~]# rvm remove 2.0.0ruby-2.0.0-p648 - #already goneUsing /usr/local/rvm/gems/ruby-2.4.0[root@kube-node-1 ~]# ruby --versionruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]

4. Install gem

gem install redis

For example:

[root@kube-node-1 ~]# gem install redisFetching: redis-4.0.1.gem (100%)Successfully installed redis-4.0.1Parsing documentation for redis-4.0.1Installing ri documentation for redis-4.0.1Done installing documentation for redis after 2 seconds1 gem installed

5. Execute the redis-trib.rb command

The above indicates that the installation is successful and you can execute the redis-trib.rb command.

Cd src # execute redis-trib.rb command./redis-trib.rb create -- replicas 1 127.0.0.1: 7000 127.0.0.1: 7001 \> 127.0.0.1: 7002 127.0.0.1: 7003 127.0.0.1: 7004 127.0.0.1: 7005

The create parameter indicates creating a new cluster, and -- replicas 1 indicates creating a slave for each master.

If it is successfully created, the following information is displayed:

[OK] All 16384 slots covered

For example:

[root@kube-node-1 src]# ./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 \> 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005>>> Creating cluster>>> Performing hash slots allocation on 6 nodes...Using 3 masters:127.0.0.1:7000127.0.0.1:7001127.0.0.1:7002Adding replica 127.0.0.1:7004 to 127.0.0.1:7000Adding replica 127.0.0.1:7005 to 127.0.0.1:7001Adding replica 127.0.0.1:7003 to 127.0.0.1:7002>>> Trying to optimize slaves allocation for anti-affinity[WARNING] Some slaves are in the same host as their masterM: d5a834d075fd93eefab877c6ebb86efff680650f 127.0.0.1:7000   slots:0-5460 (5461 slots) masterM: 13d0c397604a0b2644244c37b666fce83f29faa8 127.0.0.1:7001   slots:5461-10922 (5462 slots) masterM: be2718476eba4e56f696e56b75e67df720b7fc24 127.0.0.1:7002   slots:10923-16383 (5461 slots) masterS: 3d02f59b34047486faecc023685379de7b38076c 127.0.0.1:7003   replicates 13d0c397604a0b2644244c37b666fce83f29faa8S: dedf672f0a75faf37407ac4edd5da23bc4651e25 127.0.0.1:7004   replicates be2718476eba4e56f696e56b75e67df720b7fc24S: 99c07119a449a703583019f7699e15afa0e41952 127.0.0.1:7005   replicates d5a834d075fd93eefab877c6ebb86efff680650fCan I set the above configuration? (type 'yes' to accept): yes>>> Nodes configuration updated>>> Assign a different config epoch to each node>>> Sending CLUSTER MEET messages to join the clusterWaiting for the cluster to join....>>> Performing Cluster Check (using node 127.0.0.1:7000)M: d5a834d075fd93eefab877c6ebb86efff680650f 127.0.0.1:7000   slots:0-5460 (5461 slots) master   1 additional replica(s)M: be2718476eba4e56f696e56b75e67df720b7fc24 127.0.0.1:7002   slots:10923-16383 (5461 slots) master   1 additional replica(s)M: 13d0c397604a0b2644244c37b666fce83f29faa8 127.0.0.1:7001   slots:5461-10922 (5462 slots) master   1 additional replica(s)S: 3d02f59b34047486faecc023685379de7b38076c 127.0.0.1:7003   slots: (0 slots) slave   replicates 13d0c397604a0b2644244c37b666fce83f29faa8S: 99c07119a449a703583019f7699e15afa0e41952 127.0.0.1:7005   slots: (0 slots) slave   replicates d5a834d075fd93eefab877c6ebb86efff680650fS: dedf672f0a75faf37407ac4edd5da23bc4651e25 127.0.0.1:7004   slots: (0 slots) slave   replicates be2718476eba4e56f696e56b75e67df720b7fc24[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.
2.1.3 deployment result Verification

Use the redis-cli client to access an instance and perform the set and get tests.

$ redis-cli -c -p 7000redis 127.0.0.1:7000> set foo bar-> Redirected to slot [12182] located at 127.0.0.1:7002OKredis 127.0.0.1:7002> set hello world-> Redirected to slot [866] located at 127.0.0.1:7000OKredis 127.0.0.1:7000> get foo-> Redirected to slot [12182] located at 127.0.0.1:7002"bar"redis 127.0.0.1:7000> get hello-> Redirected to slot [866] located at 127.0.0.1:7000"world"

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.