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

How to build Redis3.2.8 stand-alone distributed Cluster by CentOS6.5

2025-04-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces CentOS6.5 how to build a Redis3.2.8 stand-alone distributed cluster, which has a certain reference value. Interested friends can refer to it. I hope you will learn a lot after reading this article. Let's take a look at it.

Recently, a set of Redis3.0 pseudo-distributed cluster has been built on the server, and a problem has been found, that is, the scripting ability of Shell and the importance of operation and maintenance tools need to be improved.

Cluster environment installation

1. Install Redis

$cd / usr/local # installation directory $wget http://download.redis.io/releases/redis-3.2.8.tar.gz$ tar xzf redis-3.2.8.tar.gz$ mv redis-3.2.8/ redis$ cd redis$ make$ make install

Note: make install is missing from the official command, so redis-server can only be used under the src directory of redis.

two。 Install Ruby&rubygems

$yum install ruby ruby-devel rubygems

3. Create a cluster environment

Directories required to create a cluster [at least 6, 3 master,3, slave, formula 6n]

$mkdir-p / usr/local/redis/cluster/16001/$ mkdir-p / usr/local/redis/cluster/16002/$ mkdir-p / usr/local/redis/cluster/16003/$ mkdir-p / usr/local/redis/cluster/16004/$ mkdir-p / usr/local/redis/cluster/16005/$ mkdir-p / usr/local/redis/cluster/16006/

Copy redis.conf to each node

$cp / usr/local/redis/redis.conf / usr/local/redis/cluster/16001/redis.conf$ cp / usr/local/redis/redis.conf / usr/local/redis/cluster/16002/redis.conf$ cp / usr/local/redis/redis.conf / usr/local/redis/cluster/16003/redis.conf$ cp / usr/local/redis/redis.conf / usr/local/redis/cluster/16004/redis.conf$ cp / usr/local/redis/redis.conf / usr/local/redis/cluster / 16005Universe redis.conf$ cp / usr/local/redis/redis.conf / usr/local/redis/cluster/16006/redis.conf

Then modify the redis.conf under each node, the main changes are as follows

Port daemonize yescluster-enabled yescluster-config-file nodes.confcluster-node-timeout 5000logfile "redis-server.log" appendonly yes

4. Remote access

① remote access configuration

If you want remote access, you need to modify the bind in redis.conf

The default is 127.0.0.1 loopback address. If you want to access it remotely, you need to change it to a local area network address or 0.0.0.0. Of course, you can also use a dual address mode. For example, my local area network address is 192.168.12.213. In addition, the ip on the server is generally fixed, so you can modify it as follows

$bind 192.168.12.213 127.0.0.1 # recommended $bind 0.0.0.0 # not recommended

For more information, please refer to Redis to open a remote login connection.

two。 Open firewall port

$service iptables status # View firewall status $iptables-I INPUT-p tcp-- dport 16001-j ACCEPT$ iptables-I INPUT-p tcp-- dport 16002-j ACCEPT$ iptables-I INPUT-p tcp-- dport 16003-j ACCEPT$ iptables-I INPUT-p tcp-- dport 16004-j ACCEPT$ iptables-I INPUT-p tcp-- dport 16005-j ACCEPT$ iptables-I INPUT-p tcp-- dport 16006-j ACCEPT

④ telnet links

Telnet 192.168.12.213 16001

5. Start the Redis instance

# launch each of these six redis instances (at this time, the nodes are all running in Redis Cluster mode, but the cluster is not automatically built, because they are still in the state of "I don't know you, you don't belong to me", and each of them is an isolated Redis node, or a cluster containing only one node)

$cd / usr/local/redis/cluster/16001 & & redis-server redis.conf > redis-server.log 2 > & 1 & $cd / usr/local/redis/cluster/16002 & & redis-server redis.conf > redis-server.log 2 > & 1 & $cd / usr/local/redis/cluster/16003 & & redis-server redis.conf > redis-server.log 2 > & 1 & $cd / usr/local/redis/cluster/16004 & & redis-server redis.conf > redis-server.log 2 > & 1 & $cd / usr/local/redis/cluster/16005 & & redis-server redis.conf > redis-server.log 2 > & 1 & $cd / usr/local/redis/cluster/16006 & & redis-server redis.conf > redis-server.log 2 > & 1 &

The 2 > & 1 in the command indicates that the standard error stream is input to the standard output stream, that is, it is input to the redis-server.log of each node. As for the last & indicating whether to start in the background, redis-server itself starts in the background on linux, so this & can be left out.

Of course, we can listen for changes in each redis-server.log through the tail command

Tail-f / usr/local/redis/cluster/16002/redis-server.log

After all the above redis is started, we can detect it with any of the following commands

$netstat-lntp | grep 'redis*'$ ps-e | grep' redis*'$ lsof-I 4 TCP$ hping-- scan 16001-16006-S 192.168.12.213$ nmap-sS 192.168.12.213-p 1600-16007

Create a cluster

1. Install the redis gem plug-in

We need to install gem tools that support redis, or we will report an error

$gem install redis-- version 3.0.0

Note: if gem install redis-version 3.0.0 fails, you need to modify the source of gem

Gem sources-- remove https://rubygems.org/gem sources-a https://ruby.taobao.org/

two。 Create a cluster

Let the above instances communicate with each other (1 means that each master is assigned a salve)

$/ usr/local/redis/src/redis-trib.rb create-- replicas 1\ 127.0.0.1 16001\ 127.0.0.1 VR 16002\ 127.0.0.1 16003\ 127.0.0.1 16004\ 127.0.0.1Freight 16005\ 127.0.0.1

3. View cluster information

After the cluster has been created, you can use the following command to view the relevant information:

# View the current status of the cluster $redis-cli-c-p 1600 close one of the nodes $redis-cli-p 16001 shutdown# print cluster information $redis-cli cluster info# lists all the nodes (node) currently known in the cluster, as well as the related information of these nodes. $redis-cli cluster nodes

Output information:

127.0.0.1 master 16002 master-01439345771781 2 connected 5461-10922127.0.0.1 master-01439345772286 3 connected 10923-16383127.0.0.1Vera 16001 myself,master-001 connected 0-5460127.0.1Vue 16004 slave 2566ea486fc30c911aafaf1b71130fd24a38dba9 01439345772791 4 connected127.0.0.1:16005 slave edea1e50bd224c6895b1904bce79e83fa07d6017 01439345772286 5 connected127.0.0.1:16006 slave ab06e033698627ce0ecd4c8c645585a1ae70cc84 01439345771276 6 connected

From the above information, you can clearly see which are master nodes and slave nodes.

4. Save cluster information

Save the node configuration file to the hard disk

$redis-cli cluster saveconfig

Connect the port (you can use other ports to test 16001-> 16006)

$redis-cli-c-p 16001 $127.0.0.1 get key001 16001 > set key001 v001 $127.0.0.1 VR 16001

Election port detection

If you are careful, you will find that after we have created the cluster, we have started some new ports

With the following command

Netstat-lntp | grep 'redis'

You will find the following ports, which are used for election and active / standby switching.

26001 26002 26003 26004 26005 26006

Thank you for reading this article carefully. I hope the article "how to build a Redis3.2.8 stand-alone distributed cluster in CentOS6.5" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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