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 and use Redis Cluster in CentOS 7. 0

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

CentOS 7.0in how to build and use Redis cluster, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

Install Redis

Download, extract, compile:

$cd / usr/local/ $wget http://download.redis.io/releases/redis-3.2.6.tar.gz $tar xzf redis-3.2.6.tar.gz $cd redis-3.2.6$ make

Create a Redis node

First create the redis_cluster directory on the 192.168.1.8 machine under the / usr/local/redis-3.2.6 directory

$mkdir / usr/local/redis-3.2.6/redis_cluster

Under the redis_cluster directory, create directories named 7000, 7001, 7002, and copy redis.conf to these three directories

$mkdir 7000 7001 7002$ cp / usr/local/redis-3.2.6/redis.conf / usr/local/redis-3.2.6/redis_cluster/7000$ cp / usr/local/redis-3.2.6/redis.conf / usr/local/redis-3.2.6/redis_cluster/7001$ cp / usr/local/redis-3.2.6/redis.conf / usr/local/redis-3.2.6/redis_cluster/7002

Modify the three configuration files respectively, and modify the following

Port 7000 / / Port 7000Magol 7002J7003 bind Native ip / / default ip is 127.0.0.1, which needs to be changed to an ip accessible to other node machines, otherwise the corresponding port cannot be accessed when creating a cluster Unable to create cluster daemonize yes / / redis background run pidfile / var/run/redis_7000.pid / / pidfile file corresponding to 7000Magneto 7001j7002 cluster-enabled yes / / start the cluster, and remove the cluster-config-file nodes_7000.conf / / cluster configuration from note # Configuration file * initiates automatic generation of 7000Magne 7001d7002 cluster-node-timeout 15000 / / request timeout. Default is 15 seconds. You can set the appendonly yes / / aof log to enable, and open it if necessary. It will record a log for each write operation.

Then repeat the above three steps on the other two machines (192.168.1.9, 192.168.1.10), just change the directory to 7003, 7004, 7005, 7006, 7007, 7008 and modify the corresponding configuration files according to this rule.

Start each node

# # * * execute $/ usr/local/redis-3.2.6/src/redis-server / usr/local/redis-3.2.6/redis_cluster/7000/redis.conf $/ usr/local/redis-3.2.6/src/redis-server / usr/local/redis-3.2.6/redis_cluster/7001/redis.conf $/ usr/local/redis-3.2.6/src/redis-server / usr/local/redis-3 on the machine .2.6 / redis_cluster/7002/redis.conf # # execute $/ usr/local/redis-3.2.6/src/redis-server / usr/local/redis-3.2.6/redis_cluster/7003/redis.conf $/ usr/local/redis-3.2.6/src/redis-server / usr/local/redis-3.2.6/redis_cluster/7004/redis.conf $/ usr/local/redis-3.2.6 on the second machine / src/redis-server / usr/local/redis-3.2.6/redis_cluster/7005/redis.conf # # execute $/ usr/local/redis-3.2.6/src/redis-server / usr/local/redis-3.2.6/redis_cluster/7006/redis.conf $/ usr/local/redis-3.2.6/src/redis-server / usr/local/redis-3.2.6/redis_cluster/7007/redis on the third machine. Conf $/ usr/local/redis-3.2.6/src/redis-server / usr/local/redis-3.2.6/redis_cluster/7008/redis.conf

Check the startup status of each Redis

# # * $ps-ef | whether grep redis / / redis starts successfully $netstat-tnlp | grep redis / / listens to the redis port

Note: make sure that each node is not misconfigured and starts up

Turn off the firewall

$firewall-cmd-- state # # View firewall status running

Running indicates that the firewall is on.

$systemctl stop firewalld # # turn off firewall $firewall-cmd-- state not running

Note: CentOS 7 shutting down the firewall is different from CentOS 6

Install Ruby

$yum-y install ruby ruby-devel rubygems rpm-build $gem install redis

Note: Ruby needs to be installed to run redis-trib.rb when creating a cluster

Create a cluster

Redis officially provides redis-trib.rb, which is located in the src directory of the unzipped directory.

$/ usr/local/redis-3.2.6/src/redis-trib.rb create-- replicas 1 192.168.1.8Viru 7000 192.168.1.8RV 7002 192.168.1.8Rd 7002 192.168.1.9Rd 7006 192.168.1.9Rd 7004 192.168.1.9005 7005 192.168.1.10VOV 7006 192.168.1.10Vol 7007 192.168.1.10Rd 7008

Among them, the first three ip:port are the nodes of * machines, the middle three are the second machines, and * three are the third machines

Enter yes, and then the following appears, indicating that the installation was successful

Cluster verification

Connect 7000 nodes of the cluster on * machines and 7004 nodes on the other. The connection method is as follows:

# # add the parameter-C to connect to the cluster, because redis.conf changed bind to ip address, so the-h parameter cannot be omitted. The-p parameter is port number $/ usr/local/redis-3.2.6/src/redis-cli-h 192.168.1.8-c-p 7000.

Execute the command on the 7004 node:

192.168.1.8vv7000 > get name

Then check the content where key is name on ports 7000 and 7007 of the other two sets

192.168.1.8vv7000 > get name

192.168.1.10 7007 > get name

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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