本文共 7612 字,大约阅读时间需要 25 分钟。
host1:192.168.1.9:6379 192.168.1.9:6380host2:192.168.1.106:6379 192.168.1.106:6380host3:192.168.1.110:6379 192.168.1.110:6380注意:(1)在建立redis的cluster环境时必须清空所有redis服务的所有key-value数据,没有任何数据(2)每个 redis node 节点采用相同的硬件配置、相同的密码
[root@localhost ~]# vim /app/redis/etc/redis.conf …… bind 192.168.1.9 #绑定ip …… port 6379 #绑定6379端口 …… cluster-enabled yes #开启redis的集群功能 …… cluster-config-file nodes-6379.conf #开启自动创建集群配置文件 ……
[root@localhost ~]# cp/app/redis/etc/redis.conf /app/redis/etc/redis.6380.conf [root@localhost ~]# vim /app/redis/etc/redis.6380.conf …… bind 192.168.1.9 #绑定ip …… port 6380 #绑定6380端口 …… cluster-enabled yes #开启redis的集群功能 …… cluster-config-file nodes-6379.conf #开启自动创建集群配置文件 …… :%s/6379/6380/g #配置文件底部实现全局替换,将所有6379替换为6380
[root@localhost ~]# redis-server /app/redis/etc/redis.6380.conf && redis-server /app/redis/etc/redis.conf
[root@localhost ~]# ss -tnlpState Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 511 192.168.1.9:6379 *:* users:(("redis-server",pid=7492,fd=6))LISTEN 0 511 192.168.1.9:6380 *:* users:(("redis-server",pid=7487,fd=6))LISTEN 0 511 192.168.1.9:16379 *:* users:(("redis-server",pid=7492,fd=8))LISTEN 0 511 192.168.1.9:16380 *:* users:(("redis-server",pid=7487,fd=8))
[root@localhost ruby-2.5.5]# cp redis-trib.rb /usr/bin
yum ×××tall -y vim lrzsz tree screen psmisc lsof tcpdump wget ntpdate gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools iotop bc zip unzip zlib-devel bash-completion nfs-utils automake libxml2 libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed
[root@localhost ~]# cd /data/ruby/[root@localhost ruby]# tar xf ruby-2.5.5.tar.gz[root@localhost ruby]# cd ruby-2.5.5/[root@localhost ruby-2.5.5]# ./configure && make –j 4 && make ×××tall
[root@localhost ruby-2.5.5]# yum ×××tall -y rubygems
[root@localhost ruby-2.5.5]# ln -sv /data/ruby/ruby-2.5.5/bin/gem /usr/bin/[root@localhost ruby-2.5.5]# ln -sv/data/ruby/ruby-2.5.5/ruby /usr/bin/
[root@localhost ruby-2.5.5]# gem ×××tall redis -y
[root@localhost ~]# vim /usr/local/lib/ruby/gems/2.5.0/gems/redis-4.1.2/lib/redis/client.rb#frozen_string_literal: truerequire_relative "errors"require "socket"require "cgi"class Redis class Client DEFAULTS = { :url => lambda { ENV["REDIS_URL"] }, :scheme => "redis", :host => "127.0.0.1", :port => 6379, :path => nil, :timeout => 5.0, :password => 123456, #登录密码改为123456 :db => 0, :driver => nil, ……
[root@localhost ~]# redis-trib.rb create --replicas 1 192.168.1.9:6379 192.168.1.9:6380 192.168.1.106:6379 192.168.1.106:6380 192.168.1.110:6379 192.168.1.110:6380>>> Creating cluster>>> Performing hash slots allocation on 6 nodes...Using 3 masters:192.168.1.9:6379192.168.1.106:6379192.168.1.110:6379Adding replica 192.168.1.106:6380 to 192.168.1.9:6379Adding replica 192.168.1.110:6380 to 192.168.1.106:6379Adding replica 192.168.1.9:6380 to 192.168.1.110:6379M: eed2e22136cbdca6770a46bbb2e137ab693dd16b 192.168.1.9:6379 slots:0-5460 (5461 slots) master#主服务:M#主服务id:eed2e22136cbdca6770a46bbb2e137ab693dd16b#主服务ip和端口:192.168.1.9:6379#分得的槽位区间:0-5460#一共分得的槽:5460S: 8efbcf7fdd4675c77199a2a1206f0209ac2255f3 192.168.1.9:6380 replicates e387a0ba7c95d0c27d7e28a9b57d23117711eadc#从服务:S#从服务id:8efbcf7fdd4675c77199a2a1206f0209ac2255f3#从服务ip和端口:192.168.1.9:6380#从服务所属的主服务id:e387a0ba7c95d0c27d7e28a9b57d23117711eadcM: c922b4bf56f0086609fd4fb23d987df0a77bec22 192.168.1.106:6379 slots:5461-10922 (5462 slots) masterS: a4fd89d79cdd27698bc394134b2df25b63ddb4c5 192.168.1.106:6380 replicates eed2e22136cbdca6770a46bbb2e137ab693dd16bM: e387a0ba7c95d0c27d7e28a9b57d23117711eadc 192.168.1.110:6379 slots:10923-16383 (5461 slots) masterS: 34549b777963b16e65125def8d9a8e50e27ed2a4 192.168.1.110:6380 replicates c922b4bf56f0086609fd4fb23d987df0a77bec22Can 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.1.9:6379)M: eed2e22136cbdca6770a46bbb2e137ab693dd16b 192.168.1.9:6379 slots:0-5460 (5461 slots) master 1 additional replica(s)S: a4fd89d79cdd27698bc394134b2df25b63ddb4c5 192.168.1.106:6380 slots: (0 slots) slave replicates eed2e22136cbdca6770a46bbb2e137ab693dd16bS: 8efbcf7fdd4675c77199a2a1206f0209ac2255f3 192.168.1.9:6380 slots: (0 slots) slave replicates e387a0ba7c95d0c27d7e28a9b57d23117711eadcM: c922b4bf56f0086609fd4fb23d987df0a77bec22 192.168.1.106:6379 slots:5461-10922 (5462 slots) master 1 additional replica(s)M: e387a0ba7c95d0c27d7e28a9b57d23117711eadc 192.168.1.110:6379 slots:10923-16383 (5461 slots) master 1 additional replica(s)S: 34549b777963b16e65125def8d9a8e50e27ed2a4 192.168.1.110:6380 slots: (0 slots) slave replicates c922b4bf56f0086609fd4fb23d987df0a77bec22[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.
[root@localhost ~]# redis-cli -h 192.168.1.106 -p 6380192.168.1.106:6380> auth 123456OK192.168.1.106:6380> info replication#Replicationrole:slavemaster_host:192.168.1.9master_port:6379master_link_status:down #未与主服务建立连接master_last_io_seconds_ago:-1master_sync_in_progress:0slave_repl_offset:1master_link_down_since_seconds:1560643385slave_priority:100slave_read_only:1connected_slaves:0master_replid:84865c623e15576c50c80a46ee16845b80b872d8master_replid2:0000000000000000000000000000000000000000master_repl_offset:0second_repl_offset:-1repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0
192.168.1.106:6380> config set masterauth 123456OK
192.168.1.106:6380> info replication#Replicationrole:slavemaster_host:192.168.1.9master_port:6379master_link_status:up #主从服务已建立连接master_last_io_seconds_ago:1master_sync_in_progress:0slave_repl_offset:0slave_priority:100slave_read_only:1connected_slaves:0master_replid:df9da60e308938e7a817ca08b20b58c248ad409dmaster_replid2:0000000000000000000000000000000000000000master_repl_offset:0second_repl_offset:-1repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:1repl_backlog_histlen:0
转载于:https://blog.51cto.com/14234542/2409596