In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Preface
The so-called cluster is to add the number of servers to provide the same services, so as to make the servers achieve a stable and efficient state. Instability exists in a single redis. When the redis service goes down, there are no services available. Redis clusters are designed to enhance the reading and writing ability of redis. In a redis cluster, each redis is called a node. In a redis cluster, there are two types of nodes: master node (master) and slave node (slave). Redis cluster is based on redis master-slave replication.
Environment
Simulate 6 servers with two servers (add network card)
Primary server Redis1:
Ens33: 192.168.52.150
Ens36: 192.168.52.153
Ens37: 192.168.52.154
Redis2 from the server:
Ens33: 192.168.52.148
Ens36: 192.168.52.155
Ens37: 192.168.52.156
Install Redis on both servers
[root@localhost ~] # yum install gcc gcc-c++ make-y # # install environment components
[root@localhost ~] # mkdir / mnt/tools
[root@localhost ~] # mount.cifs / / 192.168.100.100/tools / mnt/tools/ # # Mount
Password for root@//192.168.100.100/tools:
[root@localhost ~] # cd / mnt/tools/redis/
[root@localhost redis] # ls
Redis-5.0.7.tar.gz
[root@localhost redis] # tar xf redis-5.0.7.tar.gz-C / opt/ # # decompress
[root@localhost redis] # cd / opt/
[root@localhost opt] # ls
Redis-5.0.7 rh
[root@localhost opt] # cd redis-5.0.7/
[root@localhost redis-5.0.7] # make # # compile
[root@localhost redis-5.0.7] # make PREFIX=/usr/local/redis/ install # # installation
[root@localhost redis-5.0.7] # cd utils/
[root@localhost utils] #. / install_server.sh # # execute script to configure
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379] # # default port
Selecting default: 6379
Please select the redis config file name [/ etc/redis/6379.conf] # # configuration file
Selected default-/ etc/redis/6379.conf
Please select the redis log file name [/ var/log/redis_6379.log] # # Log File
Selected default-/ var/log/redis_6379.log
Please select the data directory for this instance [/ var/lib/redis/6379] # # data file
Selected default-/ var/lib/redis/6379
Please select the redis executable path [] / usr/local/redis/bin/redis-server
# # Executable File path
Selected config:
Port: 6379
Config file: / etc/redis/6379.conf
Log file: / var/log/redis_6379.log
Data dir: / var/lib/redis/6379
Executable: / usr/local/redis/bin/redis-server
Cli Executable: / usr/local/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied / tmp/6379.conf = > / etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
[root@localhost utils] # ln-s / usr/local/redis/bin/ / usr/local/bin/ # # easy for system identification
[root@localhost utils] # netstat-ntap | grep 6379
Tcp 0 0 127.0.0.1:6379 0.0.0.0: LISTEN 44510/redis-server
Modify the configuration file on both servers
[root@localhost utils] # vim / etc/redis/6379.conf
# bind 127.0.0.1 # # the listening address of line 70 of the note, all addresses have been monitored
Protected-mode no # # remove line 89 comment and turn off security
Port 6379 # # remove line 93 comment and open port 6379
Daemonize yes # # uncomment line 137 and start as a stand-alone process
Cluster-enabled yes # # remove the comment on line 833 and enable the cluster function
Cluster-config-file nodes-6379.conf # # remove comments on line 841, cluster name file settings
Cluster-node-timeout 15000 # # remove the comment on line 847 and set the cluster timeout
Appendonly yes # # uncomment line 700 and enable aof persistence
[root@localhost utils] # / etc/init.d/redis_6379 restart # # restart the service
Stopping...
Redis stopped
Starting Redis server...
[root@localhost utils] # cd / var/lib/redis/6379/
[root@localhost 6379] # ls
Appendonly.aof dump.rdb nodes-6379.conf # # generate aof,rdb and node files
Install rvm,Ruby control cluster software on the primary server
[root@localhost utils] # gpg-keyserver hkp://keys.gnupg.net-recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
# # Import key File
Gpg: directory'/ root/.gnupg' created
Gpg: a new profile'/ root/.gnupg/gpg.conf' has been established
Gpg: warning: the options in'/ root/.gnupg/gpg.conf' were not used during this run
Gpg: key ring'/ root/.gnupg/secring.gpg' established
Gpg: key ring'/ root/.gnupg/pubring.gpg' established
Gpg: download the key 'D39DC0E3', keys.gnupg.net from the hkp server
Gpg: / root/.gnupg/trustdb.gpg: established the database of trust degree
Gpg: key D39DC0E3: public key "Michal Papis (RVM signing)" has been imported
Gpg: no absolutely trusted keys were found
Gpg: total number of processed: 1
Gpg: imported: 1 (RSA: 1)
[root@localhost utils] # curl-sSL https://get.rvm.io | bash-s stable # # install rvm
.. / / omit the process
[root@localhost utils] # source / etc/profile.d/rvm.sh # # execute environment variables
[root@localhost utils] # rvm list known # # list the versions of ruby that can be installed
[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 ruby2.4.1 version
Ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
[root@localhost utils] # gem install redis # install Redis again
Fetching redis-4.1.3.gem
Successfully installed redis-4.1.3
Parsing documentation for redis-4.1.3
Installing ri documentation for redis-4.1.3
Done installing documentation for redis after 1 seconds
1 gem installed
[root@localhost utils] #
Add two network cards to the primary server
[root@localhost utils] # service network restart # # restart the Nic
[root@localhost utils] # systemctl stop firewalld.service # # turn off the firewall
[root@localhost utils] # setenforce 0
[root@localhost utils] # ifconfig
Ens33: flags=4163 mtu 1500
Inet 192.168.52.150 netmask 255.255.255.0 broadcast 192.168.52.255
Inet6 fe80::5134:22f5:842b:5201 prefixlen 64 scopeid 0x20
Ether 00:0c:29:0d:f1:75 txqueuelen 1000 (Ethernet)
RX packets 91575 bytes 119014065 (113.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 28442 bytes 2443621 (2.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Ens36: flags=4163 mtu 1500
Inet 192.168.52.153 netmask 255.255.255.0 broadcast 192.168.52.255
Inet6 fe80::84f1:53d8:a97a:d450 prefixlen 64 scopeid 0x20
Ether 00:0c:29:0d:f1:89 txqueuelen 1000 (Ethernet)
RX packets 128 bytes 18873 (18.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 42 bytes 6253 (KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Ens37: flags=4163 mtu 1500
Inet 192.168.52.154 netmask 255.255.255.0 broadcast 192.168.52.255
Inet6 fe80::74f5:2344:c59b:4fdb prefixlen 64 scopeid 0x20
Ether 00:0c:29:0d:f1:7f txqueuelen 1000 (Ethernet)
RX packets 107 bytes 16849 (16.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 29 bytes 4601 (4.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Add two network cards to the slave server as well
[root@slave utils] # service network restart # # restart the Nic
[root@slave utils] # systemctl stop firewalld.service # # turn off the firewall
[root@slave utils] # setenforce 0
[root@localhost utils] # ifconfig
Ens33: flags=4163 mtu 1500
Inet 192.168.52.148 netmask 255.255.255.0 broadcast 192.168.52.255
Inet6 fe80::c776:9d00:618:88f2 prefixlen 64 scopeid 0x20
Ether 00:0c:29:37:e9:25 txqueuelen 1000 (Ethernet)
RX packets 65481 bytes 86357533 (82.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 21069 bytes 1892475 (1.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Ens36: flags=4163 mtu 1500
Inet 192.168.52.155 netmask 255.255.255.0 broadcast 192.168.52.255
Inet6 fe80::d3e5:cd6b:26f8:fd1f prefixlen 64 scopeid 0x20
Ether 00:0c:29:37:e9:39 txqueuelen 1000 (Ethernet)
RX packets 143bytes 17342 (16.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 38 bytes 5940 (5.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Ens37: flags=4163 mtu 1500
Inet 192.168.52.156 netmask 255.255.255.0 broadcast 192.168.52.255
Inet6 fe80::222b:77ad:8da2:4ea6 prefixlen 64 scopeid 0x20
Ether 00:0c:29:37:e9:2f txqueuelen 1000 (Ethernet)
RX packets 114bytes 14481 (14.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 30 bytes 4661 (4.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Create a cluster on the master server
# # 6 instances are divided into three groups, each with one master and one slave
[root@localhost utils] # redis-cli-- cluster create 192.168.52.150 cluster create 6379 192.168.52.153 cluster-replicas 6379 192.168.52.154Rose 6379 192.168.52.1481979 192.168.52.1551979
# # create a cluster with one master and one slave for each group
Performing hash slots allocation on 6 nodes...
Master [0]-> Slots 0-5460
Master [1]-> Slots 5461-10922
Master [2]-> Slots 10923-16383
Adding replica 192.168.52.155:6379 to 192.168.52.150:6379
Adding replica 192.168.52.156:6379 to 192.168.52.153:6379
Adding replica 192.168.52.148:6379 to 192.168.52.154:6379
M: b9dfae79d92141a7bad172a344e0696f356a875f 192.168.52.150:6379
Slots: [0-16383] (5461 slots) master # # 128129135
M: b9dfae79d92141a7bad172a344e0696f356a875f 192.168.52.153:6379
Slots: [0-16383] (5462 slots) master
M: b9dfae79d92141a7bad172a344e0696f356a875f 192.168.52.154:6379
Slots: [0-16383] (5461 slots) master
S: ebc69ee01cf293b3af9930cac2dba03b4475336b 192.168.52.148:6379
Replicates b9dfae79d92141a7bad172a344e0696f356a875f # # 136137138 is a copy
S: ebc69ee01cf293b3af9930cac2dba03b4475336b 192.168.52.155:6379
Replicates b9dfae79d92141a7bad172a344e0696f356a875f
S: ebc69ee01cf293b3af9930cac2dba03b4475336b 192.168.52.156:6379
Replicates b9dfae79d92141a7bad172a344e0696f356a875f
...
Can I set the above configuration? (type 'yes' to accept): yes # # Select yes
Nodes configuration updated
Assign a different config epoch to each node
Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
Performing Cluster Check (using node 192.168.52.150 purl 6379)
M: b9dfae79d92141a7bad172a344e0696f356a875f 192.168.52.150:6379
Slots: [0-16383] (16384 slots) master
1 additional replica (s)
S: ebc69ee01cf293b3af9930cac2dba03b4475336b 192.168.52.155:6379
Slots: (0 slots) slave
Replicates b9dfae79d92141a7bad172a344e0696f356a875f
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
[root@localhost utils] #
Verify the principle of cluster read and write
[root@localhost utils] # redis-cli-h 192.168.52.150-p 6379 # # Master Server
192.168.52.150 6379 > set name zhangsan # # create key-value pairs
OK
192.168.52.150VR 6379 > keys
1) "name"
192.168.52.150VR 6379 > get name
"zhangsan"
192.168.52.150VR 6379 > exit
[root@localhost utils] # redis-cli-h 192.168.52.148-p 6379 # # from the server
192.168.52.148 6379 > keys # # View is also available from above.
1) "name"
192.168.52.148purl 6379 > get name
"zhangsan"
192.168.52.148purl 6379 > exit
[root@localhost utils] #
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.