In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to build a Redis cluster in CentOS7". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to build a Redis cluster in CentOS7" can help you solve the problem.
CentOS 7 sets up Redis5.0.5 cluster (3 machines, 3 master and 3 standby)
Preparatory work
Prepare three centos 7 machines: as shown below (each machine turns off the firewall):
IP master node salve node
192.168.0.166 redis-166:7001 redis-166:7002
192.168.0.167 redis-167:7001 redis-167:7002
192.168.0.168 redis-168:7001 redis-168:7002
Set the / etc/hosts of three machines, each with the following three lines, and save and exit
[root@localhost tools] # vim / etc/hosts
192.168.0.166 redis-166
192.168.0.167 redis-167
192.168.0.168 redis-168
one
two
three
four
Download redis-5.0.5 version from the official website: http://download.redis.io/releases/redis-5.0.5.tar.gz
Upload the downloaded package to the above 3 centos
Start installation
Let's take the 192.168.0.166 machine installation as an example, the other two are just configuration files with different IP
If there is no gcc environment in centos, you need to install gcc first. If there is, just look at the next step.
[root@localhost tools] # yum install-y gcc
one
Extract the redis package to the current directory
[root@localhost tools] # tar-zxvf redis-5.0.5.tar.gz
one
Go to the newly extracted redis directory and start the compilation and installation
[root@localhost tools] # cd redis-5.0.5/
[root@localhost redis-5.0.5] # make & & make PREFIX=/usr/local/redis install
one
two
To check whether the compilation and installation is successful, execute the following command. If the output is 0, the redis installation is successful.
[root@localhost redis-5.0.5] # echo $?
0
one
two
Configure the environment variables and add the following at the end of the / etc/profile file:
[root@localhost tools] # vim / etc/profile
# redis env #
Export REDIS_HOME=/usr/local/redis
Export PATH=$PATH:$REDIS_HOME/bin
one
two
three
four
five
The other 167and 168machines have exactly the same installation of redis as the 166machines above.
Cluster configuration
Let's take the 192.168.0.166 machine installation as an example, the other two are just configuration files with different IP
Create two configuration file directories conf, log directory logs, and data storage directory data for 7001 and 7002, respectively, with the following command:
Mkdir-p / usr/local/redis/redis_cluster/7001/conf/
Mkdir-p / usr/local/redis/redis_cluster/7001/logs/
Mkdir-p / usr/local/redis/redis_cluster/7001/data/
Mkdir-p / usr/local/redis/redis_cluster/7002/conf/
Mkdir-p / usr/local/redis/redis_cluster/7002/logs/
Mkdir-p / usr/local/redis/redis_cluster/7002/data/
one
two
three
four
five
six
seven
Create a configuration file for 7001 and add the following:
Vim / usr/local/redis/redis_cluster/7001/conf/redis.conf
# bind server domain name or IP address
Bind redis-166
# set the port to distinguish the Redis instances in the cluster
Port 7001
# running in the background
Daemonize yes
# pid process file name, named after the port number
Pidfile / var/run/redis-7001.pid
# Log file name, distinguished by the port number as the directory
Logfile / usr/local/redis/redis_cluster/7001/logs/redis.log
# address for storing data files, which is distinguished by the port number as the directory name
Dir / usr/local/redis/redis_cluster/7001/data
# enable cluster
Cluster-enabled yes
# configure the configuration file for each node, also with the port number as the name
Cluster-config-file nodes_7001.conf
# configure the timeout of cluster nodes
Cluster-node-timeout 15000
# start AOF incremental persistence policy
Appendonly yes
# log if there is a change
Appendfsync always
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty
twenty-one
twenty-two
twenty-three
twenty-four
Create a configuration file for 7002 and add the following:
Vim / usr/local/redis/redis_cluster/7002/conf/redis.conf
# bind server domain name or IP address
Bind redis-166
# set the port to distinguish the Redis instances in the cluster
Port 7002
# running in the background
Daemonize yes
# pid process file name, named after the port number
Pidfile / var/run/redis-7002.pid
# Log file name, distinguished by the port number as the directory
Logfile / usr/local/redis/redis_cluster/7002/logs/redis.log
# address for storing data files, which is distinguished by the port number as the directory name
Dir / usr/local/redis/redis_cluster/7002/data
# enable cluster
Cluster-enabled yes
# configure the configuration file for each node, also with the port number as the name
Cluster-config-file nodes_7002.conf
# configure the timeout of cluster nodes
Cluster-node-timeout 15000
# start AOF incremental persistence policy
Appendonly yes
# log if there is a change
Appendfsync always
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty
twenty-one
twenty-two
twenty-three
twenty-four
For the other 167 and 168 machines, the cluster configuration is different from the 166 machine configuration above, only the domain name is different, and the other settings are the same.
Start the cluster
After ensuring that 166167168 of the above are configured, start starting the 166167168 nodes
Redis-server / usr/local/redis/redis_cluster/7001/conf/redis.conf
Redis-server / usr/local/redis/redis_cluster/7002/conf/redis.conf
one
two
Check to see if each node on each machine starts successfully
[root@localhost redis-5.0.5] # ps-ef | grep redis
Root 6460 10 14:14? 00:00:10 / usr/local/redis/bin/redis-server redis-166:7001 [cluster]
Root 6471 10 14:14? 00:00:10 / usr/local/redis/bin/redis-server redis-166:7002 [cluster]
one
two
three
four
[root@localhost redis-5.0.5] # ps-ef | grep redis
Root 6532 10 14:14? 00:00:10 / usr/local/redis/bin/redis-server redis-167:7001 [cluster]
Root 6548 10 14:14? 00:00:10 / usr/local/redis/bin/redis-server redis-167:7002 [cluster]
one
two
three
four
[root@localhost redis-5.0.5] # ps-ef | grep redis
Root 6486 10 14:14? 00:00:10 / usr/local/redis/bin/redis-server redis-168:7001 [cluster]
Root 6498 10 14:14? 00:00:10 / usr/local/redis/bin/redis-server redis-168:7002 [cluster]
one
two
three
four
Use reids-cli to create a Redis cluster (Note: IP must be used here. If you use a domain name like redis-166, an error will be reported. I don't know the exact reason.)
Redis-cli-cluster create 192.168.0.166 cluster-replicas 7001 192.168.0.167 cluster-replicas 7002 192.168.0.168 7002 192.168.0.168 7002 192.168.0.168
one
To check the status of the cluster we just created, the following command: (viewing any node in any of the three clusters is the same, it will bring out all the node information)
[root@localhost redis-5.0.5] # redis-cli-cluster check 192.168.0.167purl 7001
192.168.0.167 7001 (b909c05c …) -> 0 keys | 5462 slots | 1 slaves.
192.168.0.166 virtual 7001 (e136a43b …) -> 0 keys | 5461 slots | 1 slaves.
192.168.0.168 7001 (4bf0b7df …) -> 1 keys | 5461 slots | 1 slaves.
[OK] 1 keys in 3 masters.
0.00 keys per slot on average.
> Performing Cluster Check (using node 192.168.0.167)
M: b909c05ca4c89695fee7b4799050312ed20c989e 192.168.0.167:7001
Slots: [5461-10922] (5462 slots) master
1 additional replica (s)
M: e136a43b8dbfd7612f48fe2c17e33203d5329eed 192.168.0.166:7001
Slots: [0-5460] (5461 slots) master
1 additional replica (s)
M: 4bf0b7df6ce34ad2d3ee87ab500b200f3ae64cee 192.168.0.168:7001
Slots: [10923-16383] (5461 slots) master
1 additional replica (s)
S: 84ada651baf494cbcdbfe26232b0061146260a3d 192.168.0.167:7002
Slots: (0 slots) slave
Replicates e136a43b8dbfd7612f48fe2c17e33203d5329eed
S: 4b9a181365ba49dde3def4d9d562c5a4d4ef657e 192.168.0.166:7002
Slots: (0 slots) slave
Replicates 4bf0b7df6ce34ad2d3ee87ab500b200f3ae64cee
S: 02c3fc75bc6e6d4e070563f2b42a41f2616f66a5 192.168.0.168:7002
Slots: (0 slots) slave
Replicates b909c05ca4c89695fee7b4799050312ed20c989e
[OK] All nodes agree about slots configuration.
> > Check for open slots...
> > Check slots coverage...
[OK] All 16384 slots covered.
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty
twenty-one
twenty-two
twenty-three
twenty-four
twenty-five
twenty-six
twenty-seven
twenty-eight
twenty-nine
thirty
Test whether the cluster is normal:
Any test in the cluster can be done, for example, we can connect the 7002 nodes on 167and add a data.
[root@localhost redis-5.0.5] # redis-cli-c-h 192.168.0.167-p 7002
192.168.0.167virtual 7002 > set key001 helloRredis
-> Redirected to slot [274] located at 192.168.0.166 purl 7001
OK
192.168.0.166 purl 7001 > get key001
"helloRredis"
192.168.0.166purl 7001 >
one
two
three
four
five
six
seven
eight
Then connect 7001 nodes to 167and connect 7001 or 7002 to 168to see if you can query the data.
[root@localhost redis-5.0.5] # redis-cli-c-h 192.168.0.167-p 7001
192.168.0.167purl 7001 > get key001
-> Redirected to slot [274] located at 192.168.0.166 purl 7001
"helloRredis"
192.168.0.166purl 7001 >
one
two
three
four
five
six
[root@localhost redis-5.0.5] # redis-cli-c-h 192.168.0.168-p 7002
192.168.0.168 purl 7002 > get key001
-> Redirected to slot [274] located at 192.168.0.166 purl 7001
"helloRredis"
192.168.0.166purl 7001 >
one
two
three
four
five
six
The above results show that the cluster we built is working properly.
If you need to configure boot self-startup, add the following two lines: (each machine needs to be configured), and save and exit. The cluster will be started automatically when it is turned on later.
[root@localhost redis-5.0.5] # vim / etc/rc.local
/ usr/local/redis/bin/redis-server / usr/local/redis/redis_cluster/7001/conf/redis.conf
/ usr/local/redis/bin/redis-server / usr/local/redis/redis_cluster/7002/conf/redis.conf
one
two
three
four
If it is set above and still cannot boot itself, it is possible that / etc/rc.d/rc.local does not have the execution permission and needs to give an execution permission, as shown below:
[root@localhost redis-5.0.5] # chmod + x / etc/rc.d/rc.local
one
This is the end of the introduction on "how to build a Redis cluster in CentOS7". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.