Non-relational database-redis cluster
Redis cluster, experimental environment two servers, six nodes, each server three network cards, six nodes and three masters Three replica master servers install yum install gcc gcc-c++ make [root @ localhost ~] # yum install gcc gcc-c++ make-y # installation environment package [root@localhost ~] # mkdir / abc [root@localhost ~] # mount.cifs / / 192.168.100.25/redis / abc/ mount Password for root@//192.168.100.25/redis: [root@localhost ~] # cd / abc/ [root@localhost abc] # lsredis-5.0.7.tar.gz [root@ Localhost abc] # tar zxvf redis-5.0.7.tar.gz-C / opt/ # decompress to opt [root@localhost abc] # cd / opt/redis-5.0.7/make [root@localhost redis-5.0.7] # make PREFIX=/usr/local/redis install # install [root@localhost redis-5.0.7] # ln-s / usr/local/redis/bin/* / usr/local/bin/ # to do soft connection [root@localhost redis -5.0.7] # cd / opt/redis-5.0.7/utils/ [root@localhost utils] #. / install_server.sh 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/bin/redis-server] / usr/local/redis/bin/redis-server slave server (the same operation is not repeated) the master server configures the contents of the original configuration file of redis with "#" to facilitate writing shell scripts [root@localhost utils] # vim / Etc/redis/6379.conf # 70 bind 127.0.0.1 70 # bind 127.0.0.1 # 89 protected-mode yes 89 protected-mode no # turn off protection function # 833 # cluster-enabled yes833 cluster-enabled yes # enable cluster function # 841 # cluster-config-file nodes-6379.conf841 cluster-config-file nodes-6379.conf # enable cluster feature profile # 847 # cluster-node-timeout 15000847 cluster-node-timeout 15000 # set up cluster Timeout is 15000 seconds # 700 appendonly no 700 appendonly yes # enable AOF support [root@localhost redis] # / etc/init.d/redis_6379 restart # enable redisStopping... Waiting for Redis to shutdown... Redis stoppedStarting Redis server... [root@localhost utils] # cd / var/lib/redis/ [root@localhost redis] # cd 6379 / [root@localhost 6379] # lsappendonly.aof dump.rdb nodes-6379.conf#aof profile Rdb snapshot file, node configuration file installs rvm from the same operating master server as the server Ruby control cluster gpg-keyserver hkp://keys.gnupg.net-recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 # Import key [root@localhost 6379] # curl-sSL https://get.rvm.io | bash-s stable # find this address to install RVM [root @ localhost 6379] # cd / opt/ [root@localhost opt] # lsredis-5.0.7 rh [root@localhost opt] # vim abc.sh # rvm script is very long [root@localhost opt] # lsabc.sh redis-5 .0.7 rh [root@localhost opt] # chmod + x abc.sh [root@localhost opt] # lsabc.sh redis-5.0.7 rh [root@localhost opt] # source / etc/profile.d/rvm.sh [root@localhost opt] # rvm list known # View rvm installed version [root@localhost opt] # rvm install 2.4.1 # install rvm2.4.1 version [root@localhost opt] # rvm use 2.4.1 # use rvmUsing / usr/local/rvm / gems/ruby-2.4.1 [root@localhost opt] # ruby- v # View the version of ruby ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux] [root@localhost opt] # gem install redis # install redis
Install three network cards on the main server
192.168.136.229
192.168.136.232
192.168.136.231
Install three network cards from the server
192.168.136.185
192.168.136.233
192.168.136.234
Both servers restart network services
[root@localhost opt] # systemctl restart network
Two servers turn off firewalls and enhancements
[root@localhost opt] # systemctl stop firewalld.service
[root@localhost opt] # setenforce 0
Master server, restart redis, create cluster [root@localhost 6379] # / etc/init.d/redis_6379 restart # restart redisredis-cli-- cluster create 192.168.136.229 redisredis-cli 6379 192.168.136.229 etc/init.d/redis_6379 restart 6379 192.168.136.231etc/init.d/redis_6379 restart 6379 192.168.136.185cluster create 6379 192.168.136.233192.168.136.233lug 6379-- cluster-replicas 1Can I set the above configuration? (type 'yes' to accept): yes # appears this line of input yes with three nodes master and three replica nodes, corresponding to each other randomly, but with one master and one slave. Start verifying [root@localhost opt] # redis-cli-h 192.168.136.229-p 6379 # Log in to a master server 229192.168.136.229keys 6379 > set name zhangsan # create key pair OK192.168.136.229:6379 > keys * # View all keys 1) "name" 192.168.136.229set name zhangsan 6379 > get name # View value "zhangsan" 192.168.136.229set name zhangsan 6379 > quit [root@localhost opt] # redis-cli-h 192. 168.136.234-p 6379 # Log in to a slave server 234192.168.136.234get name * 1) "name" 192.168.136.234virtual 6379 > get name # View data No, it will prompt you to store the data in the error server (error) MOVED 5798 192.168.136.231 redis-cli-h 192.168.136.231-p 6379 # log in to the server, and you will see the data 192.168.136.231root@localhost opt 6379 > keys * 1) "name" 192.168.136.231root@localhost opt 6379 > get name "zhangsan" to establish key-value pairs by hash. Set the deletion time of the key [root@master opt] # redis-cli-h 192.168.136.229-p 6379 192.168.136.229 hset person age 20 # # establish the key-value pair (integer) 1192.168.136.2296379 > hset person name lisi (integer) 1192.168.136.229integer > keys * 1) "person" 192.168.136.229hash 6379 > hget person age # # get the key value "20" 192.168.136. 229.128keys 6379 > expire person 5 # # set key deletion time 5s (integer) 1192.168.136.229 keys * 1) "person" 192.168.136.229 keys * (empty list or set) above is all we have. Thanks for watching