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--Redis Cluster of NoSQL

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

Share

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

The experimental environment uses two servers to simulate six servers (adding network cards) master server M1 192.168.13.128 master server M2 192.168.13.135 master server M3 192.168.13.136 slave server S1 192.168.13.129 slave server S2 192.168.13.137 slave server S3 192.168.13.1381 Install localhost [root @ root] # yum install gcc gcc-c++ make-y # # installation environment components [root@localhost ~] # mount.cifs / / 192.168.100.3/LNMP-C7 / mnt/ # # mount Password for root@//192.168.100.3/LNMP-C7 on both servers: [root@localhost ~] # cd / mnt/ [root@localhost mnt] # tar zxvf redis-5.0.7.tar.gz-C / Opt/ # # decompress [root@localhost mnt] # cd / opt/redis-5.0.7/ [root@localhost redis-5.0.7] # make # # compile [root@localhost redis-5.0.7] # make PREFIX=/usr/local/redis/ install # # install [root@localhost redis-5.0.7] # cd utils/ [root@localhost utils] #. / install_server.sh # # execute script to configure 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] # # default port Selecting default: 6379Please select the redis config file name [/ etc/redis/6379.conf] # # configuration file Selected default-/ etc/redis/6379.confPlease select the redis log file name [/ var/log/redis_6379.log] # # log file Selected default-/ var/log/redis_6379.logPlease select the data directory for this instance [/ var/lib/redis/6379] # # data file Selected default-/ var/lib/redis/6379Please select the redis executable path [] / usr/local/redis/bin/redis-server## executable file path [root@localhost utils] # ln-s / usr/local/redis/bin/* / usr/local/bin/ # # it is convenient for the system to identify [root@localhost utils] # netstat-ntap | grep 6379tcp 00127.0.0. 1RV 6379 0.0.0. 0. 0. * LISTEN 44510/redis-server 2 Modify the listening 127th address of the configuration file [root@localhost utils] # vim / etc/redis/6379.conf # bind 127.0.0.1 # comment 70 on two servers, protected-mode no # # remove line 89, close security port 6379 # #, remove line 93, open port 6379daemonize yes # #, remove line 137 Start cluster-enabled yes # # with independent process to remove line 833 comments, enable cluster function cluster-config-file nodes-6379.conf # # to remove line 841 comments, cluster name file settings cluster-node-timeout 15000 # # to remove line 847 comments, cluster timeout settings appendonly yes # # to remove line 700 comments 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 3 Install rvm on the primary 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 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 the rubyruby2.4.1 version Using / usr/local/rvm/gems/ruby-2.4.1 [root@localhost utils] # ruby- v # # to view the current ruby2.4.1 version ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux] [root@localhost utils ] # gem install redis # install Redis4 again Add two network cards to the primary server

[root@master ruby-2.4.1] # service network restart # # restart the network card [root@master ruby-2.4.1] # systemctl stop firewalld.service # # turn off the firewall [root@master ruby-2.4.1] # setenforce 05, and add two network cards to the slave server.

[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 06, create a cluster on the master server # # 6 instances are divided into three groups Each group of one master and one slave [root@master ruby-2.4.1] # redis-cli-- cluster create 192.168.13.128purl 6379 192.168.13.129 cluster create 6379 192.168.13.135purl 6379 192.168.13.136REV 6379 192.168.13.137RU 6379 192.168.13.138purl 6379-- cluster-replicas 1 # 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.13.137Slots 6379 to 192.168.13.128:6379Adding replica 192.168.13.1386379 to 192.168.13.129:6379Adding replica 192.168.13.136 Slots 6379 to 192.168.13.13513 6379M: 6e0414dbd3045b2793b07be884d7335fd008a72d 192.168.13.1286379 Slots: [0-5460] (5461 slots) master # # 128 129135 Master M: cdea81d9007892c55c637e3416993d30fe297ba3 192.168.13.129 slots 6379 slots: [5461-10922] (5462 slots) masterM: 6e0414dbd3045b2793b07be884d7335fd008a72d 192.168.13.135 masterM 6379 slots: [10923-16383] (5461 slots) masterS: 6e0414dbd3045b2793b07be884d7335fd008a72d 192.168.13.13615 6379 replicates 6e0414dbd3045b2793b07be884d7335fd008a72d # # 136137138 is a copy of S: cdea81d9007892c55c637e3416993d30fe297ba3 192.168.13.13713 379 replicates 6e0414dbd3045b2793b07be884d7335fd008a72dS: cdea81d9007892c55c637e3416993d30fe297ba3 192.168.13.13813 6379 replicates cdea81d9007892c55c637e3416993d30fe297ba3...Can I set the above configuration? (type 'yes' to accept): yes # # Select yes7 Verify the principle of cluster reading and writing [root@master opt] # redis-cli-h 192.168.13.129-p 6379 # # main server 192.168.13.129 set name zhangsan # # create keys to OK 192.168.13.129 keys * 1) "name" 192.168.13.129set name zhangsan 6379 > get name "zhangsan" 192.168.13.129Ze6379 > exit [root@master opt] # redis-cli-h 192.168.13.137-p 6379 # # 1) "name" 192.168.13.137get name "zhangsan" [root@master opt] # redis-cli-h 192.168.13.128-p 6379 192.168.13.128root@master opt 6379 > hset person age 20 # # establish a key-value pair (integer) 1192.168.13.1286379 > hset person name lisi (integer) 1192.168.13.1286379 by hash .128integer 6379 > keys * 1) "person" 192.168.13.128purl 6379 > hget person age # # get the value of the key "20" 192.168.13.128hget person age 6379 > expire person 5 # # set the deletion time of the key 5s (integer) 1192.168.13.128hget person age 6379 > keys * 1) "person" 192.168.13.1288hget person age 6379 > keys * (empty list or set) Thank you for reading!

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