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

Redis Cluster configuration for NoSQL (practice)

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

Share

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

The experimental environment uses two servers to simulate six servers (adding network cards) IP node master server 192.168.144.144192.168.144.159192.168.144.154 slave server 192.168.144.141192.168.144.155192.168.144.160 add two network cards to the master server and slave server respectively

[root@master ruby-2.4.1] # service network restart / / restart the network card [root@master ruby-2.4.1] # systemctl stop firewalld.service / / close the firewall [root@master ruby-2.4.1] # setenforce 0 [root@slave utils] # service network restart / / restart the network card [root@slave utils] # systemctl stop firewalld.service / / turn off the firewall [root@slave utils] # setenforce 0 Redis [root @ localhost utils] # vim / etc/redis/6379.conf # bind 127.0.0.1 / / listens on line 70 of the comment Listened to all addresses protected-mode no / / Open / close Security port 6379 / / Open Port 6379daemonize yes / / Open as an independent process to start cluster-enabled yes / / enable cluster function cluster-config-file nodes-6379.conf / / Cluster name file settings cluster-node-timeout 15000 / / Cluster timeout setting appendonly yes / / enable aof persistence [root@localhost utils] # / etc/init.d/redis_6379 restart / / restart service Stopping. Redis stoppedStarting Redis server... [root@localhost utils] # cd / var/lib/redis/6379/ [root@localhost 6379] # lsappendonly.aof dump.rdb nodes-6379.conf / / generate aof, Rdb and node files install rvm on the master server, Ruby control cluster software [root@master 6379] # gpg-- keyserver hkp://keys.gnupg.net-- recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 / / Import key file [root@master 6379] # curl-sSL https://get.rvm.io | bash-s stable / / install RVM [root @ localhost utils] # source / etc/profile.d/rvm.sh / / execute environment variable [root@localhost utils] # rvm list known / / list the versions that ruby can install [root@localhost utils] # rvm install 2.4.1 / / install version 2.4.1 [root@localhost utils] # rvm use 2.4.1 / / use rubyruby2.4.1 version Using / usr/local/rvm/gems/ruby-2.4.1 [root@localhost utils] # ruby- v / / View the current version of ruby2.4 .1p111 (2017-03-22 revision 58053) [x86_64-linux] [root@localhost utils] # gem install redis / / install Redis again to create a cluster [root@master ruby-2.4.1] # redis-cli on the master server [root@master ruby-2.4.1] # redis-cli-- cluster create 192.168.144.1596379 192.168.144.1596379 192.168.144.1541979 192.168.144.1411979 192.168.144.1411979. 168.144.160 cluster-replicas 6379-- create a cluster Each group has one master and one slave > > Performing hash slots allocation on 6 nodes...Master [0]-> Slots 0-5460Master [1]-> Slots 5461-10922Master [2]-> Slots 10923-16383Adding replica 192.168.144.155 Slots 6379 to 192.168.144.144:6379Adding replica 192.168.144.1601 to 192.168.144.154 to 192.168.144.154 to 6379M: d2aef8bb466d29891e051edd1c9c35d760c452e8 192.168.144.144 Slots: [0-5460] (5461 slots) masterM: d2aef8bb466d29891e051edd1c9c35d760c452e8 192.168.144.159masterM 6379 slots: [5461-10922] (5462 slots) masterM: d2aef8bb466d29891e051edd1c9c35d760c452e8 192.168.144.154slots 6379 slots: [10923-16383] (5461 slots) masterS: 984482d225d614b2b2b084f5c54bf197202065a0 192.168.144.141 masterS: 984482d225d614b2b2b084f5c54bf197202065a0 192.168.144.155d2aef8bb466d29891e051edd1c9c35d760c452e8 6379 replicates d2aef8bb466d29891e051edd1c9c35d760c452e8S: 984482d225d614b2b2b084f5c54bf197202065a0 192.168.144.16049 replicates d2aef8bb466d29891e051edd1c9c35d760c452e8Can I set the above configuration? (type 'yes' to accept): yes / / input 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.144.144 slots 6379) M: d2aef8bb466d29891e051edd1c9c35d760c452e8 192.168.144.144 slots 6379 slots: [0-16383] (16384 slots) master 1 additional replica (s) S: 984482d225d614b2b2b084f5c54bf197202065a0 192.168.144.155 slots: (0 slots) slave replicates d2aef8bb466d29891e051edd1c9c35d760c452e8 [OK] All nodes agree About slots configuration. > Check for open slots... > Check slots coverage... [OK] All 16384 slots covered. Verify the principle of cluster reading and writing root@master opt] # redis-cli-h 192.168.144.144-p 6379 / / Master server 1192.168.144.144 keys 6379 > set name zhangsan / / create key values for OK 192.168.144.144 keys * 1) "name" 192.168.144.144144set name zhangsan 6379 > get name "zhangsan" 192.168.144.144 > exit [root@master opt] # redis-cli-h 192.168.144 .155-p 6379 / from server 192.168.144.155 keys 6379 > integer * / / there are also 1) "name" 192.168.144.155 get name [root@master opt] # redis-cli-h 192.168.144.144-p 6379 192.168.144.144-p > hset person age 20 / establish key-value pair (integer) 1192.168.144.144 6379 by hash Hset person name lisi (integer) 1192.168.144.144keys * 1) "person" 192.168.144.144person > hget person age / / get the value of the key "20" 192.168.144.144keys 6379 > expire person 5 / set the deletion time of the key 5s (integer) 1192.168.144.144keys * 1) "person" 192.168.144.144 person 6379 > keys * (empty list or set)

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