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

Redis5.0.7 cluster building (the latest version of actual combat!)

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

Share

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

In the experimental environment, two Centos 7 virtual machines are added with three network cards to simulate the real scene of six servers.

Server role IP address Master Node M1192.168.142.130 Master Node M2192.168.142.145 Master Node M3192.168.142.146 Slave Node S1192.168.142.147 S3192.168.142.147 S3192.168.142.148 Experimental step 1: install the Redis# installation and compilation environment [root@localhost ~] # yum install gcc gcc-c++ make-y# remote mount source package [root@localhost ~] # mount.cifs / / 192.168.142.1/redis / mntPassword for root@//192.168.142.1/redis: # decompress the source package [root@localhost ~] # cd / mnt [root@localhost mnt] # tar zxvf redis-5.0.7.tar.gz-C / opt# compile and install [root@localhost mnt] # cd / opt/redis-5.0.7/ [root@localhost redis-5.0.7] # make [root@localhost redis-5.0.7] # make PREFIX=/usr/local/redis/ install# create service command soft link to the system [root@localhost redis-5.0.7] # ln-s / usr/redis/bin/* / usr/local/bin/# cut into the utils directory [root@localhost redis-5.0.7] # cd / opt/redis-5.0.7/utils/# to execute the startup script [root@localhost utils] # / install_server.sh# Enter by default Welcome to the redis service installerThis script will help you easily set up a running redis serverPlease select the redis port for this instance: [6379] Selecting default: 6379Please select the redis config file name [/ etc/redis/6379.conf] Selected default-/ etc/redis/6379.confPlease select the redis log file name [/ var/log/redis_6379.log] Selected default-/ var/log/redis_6379.logPlease select the data directory for this instance [/ var/lib/redis/6379] Selected default- / var/lib/redis/6379Please select the redis executable path [] / usr/local/redis/bin/redis-server# here you need to manually specify the extension directory path / usr/local/redis/bin/redis-server# use process control to start the service [root@localhost utils] # / etc/init.d/redis_6379 startStarting Redis server...# configure the 6379.conf file of redis Append listening address [root@localhost utils] # vim / etc/redis/6379.conf # comment line 70 listening address 127, all addresses # bind 127.0.0.1 # remove line 89 comment off security protection protected-mode no# remove line 93 comment, open port 6379port 637comment remove line 137 comment, start daemonize yes# with independent process to remove line 833 comment, turn on cluster function cluster-enabled yes# to remove line 841 comment Cluster name file settings cluster-config-file nodes-6379.conf# to remove line 847 comments, cluster timeout settings cluster-node-timeout 1500 to remove line 700 comments, start aof persistence appendonly yes# restart service [root@localhost utils] # / etc/init.d/redis_6379 restartStopping... Redis stoppedStarting Redis server... Step 2: install rvm components on the master server # Import key file [root@localhost utils] # gpg-- keyserver hkp://keys.gnupg.net-- recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3# install RVM [root @ localhost utils] # curl-sSL https://get.rvm.io | bash-s stable# implements the environment variable [root@localhost utils] # source / etc/profile.d/rvm.sh# lists the versions that ruby can install [root@localhost utils] # rvm list known# Install version 2.4.1 [root@localhost utils] # rvm install 2.4.Use the rubyruby2.4.1 version [root@localhost utils] # rvm use 2.4.1Using / usr/local/rvm/gems/ruby-2.4.1# to view the current ruby2.4.1 version [root@localhost utils] # ruby- vruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux] # install Redi [root @ localhost utils] # again Step 3 of gem install redis: create a Redis cluster # join all node addresses And add the 6379 port number [root@localhost utils] # redis-cli-- cluster create 192.168.142.130 cluster create 6379 192.168.142.145cluster create 6379 192.168.142.146cluster create 6379 192.168.142.143cluster create 6379 192.168.142.147192.168.142.147cluster create 6379 192.168.142.148cluster create 6379-- cluster-replicas 1 > > Performing hash slots allocation on 6 nodes...Master [0]-> Slots 0-5460Master [1]-> Slots 5461-10922Master [2]-> Slots 10923 -16383Adding replica 192.168.142.147to 192.168.142.145:6379Adding replica 6379 to 192.168.142.130:6379Adding replica 192.168.142.143V 6379 to 192.168.142.146 to 6379M: a27b43ec695099b36a5c79beae70cb0364f27338 192.168.142.130V 6379 slots: [0-5460] (5461 slots) masterM: a27b43ec695099b36a5c79beae70cb0364f27338 192.168.142.145RV 6379 slots: [5461-10922] (5462 slots) masterM: a27b43ec695099b36a5c79beae70cb0364f27338 192.168.142. 146masterS 6379 slots: [10923-16383] (5461 slots) masterS: b6d317c5f192bf84e8f464ffbf6481529cd0708a 192.168.142.143 masterS 6379 replicates a27b43ec695099b36a5c79beae70cb0364f27338S: b6d317c5f192bf84e8f464ffbf6481529cd0708a 192.168.142.147PLV 6379 replicates a27b43ec695099b36a5c79beae70cb0364f27338S: b6d317c5f192bf84e8f464ffbf6481529cd0708a 192.168.142.148Fluor6379 replicates a27b43ec695099b36a5c79beae70cb0364f27338Can 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 192.168.142.130 master 6379) M: a27b43ec695099b36a5c79beae70cb0364f27338 192.168.142.130 master 6379 slots: [0-16383] (16384 slots) master 1 additional replica (s) S: b6d317c5f192bf84e8f464ffbf6481529cd0708a 192.168.142.148 master 6379 slots: (0 slots) slave replicates a27b43ec695099b36a5c79beae70cb0364f27338 [OK] All nodes agree about slots configuration. > Check for Check slots coverage... [OK] All 16384 slots covered. Step 4: verify cluster read and write # redis-cli-h 192.168.142.130-p 6379192.168.142.130 yangjia 6379 > set name yangjiaOK192.168.142.130:6379 > get name "yangjia" # View data information from another node [root@localhost ~] # redis-cli-h 192.379192.168.142.146 set name yangjiaOK192.168.142.130:6379 * 1) "name" 192 .168.142.146: 6379 > get name "yangjia" # cannot view data on slave nodes Prompt to switch the master node server address [root@localhost ~] # redis-cli-h 192.168.142.143-p 6379192.168.142.143keys * 1) "name" 192.168.142.143get name 6379 > get name (error) MOVED 5798 192.168.142.146 get name 6379 in the Redis cluster, the master node server is responsible for writing data, and the slave node server is responsible for backing up the real-time data of the master node server.

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