redis 4.0.9 cluster 单台

安装redis
 

yum install -y wget gcc
wget http://download.redis.io/releases/redis-4.0.9.tar.gz
tar xzf redis-4.0.9.tar.gz
cd redis-4.0.9
#编译
make  install

单台cluster

1 修改配置

  新建6001 ,6002 ,6003,6004,6005 ,6006  6个文件

1) 复制 cp redis.conf   /home/redis/6001

redis.conf 修改 redis-6001.conf

vi redis-6001.conf  如下:

port 6001
cluster-enabled yes
cluster-config-file "nodes-6001.conf"
cluster-node-timeout 5000

dir "/home/redis/6001"
bind 172.31.71.128
pidfile "/home/redis/6001/6001_pid.pid"
daemonize yes

# Generated by CONFIG REWRITE
masterauth "test1234"
requirepass "test1234"
notify-keyspace-events "gxE"

2)复制  cp redis.conf   /home/redis/6002

redis.conf 修改 redis-6002.conf

vi redis-6002.conf  如下:

port 6002
cluster-enabled yes
cluster-config-file "nodes-6002.conf"
cluster-node-timeout 5000

dir "/home/redis/6001"
bind 172.31.71.128
pidfile "/home/redis/6001/6001_pid.pid"
daemonize yes

# Generated by CONFIG REWRITE
masterauth "test1234"
requirepass "test1234"
notify-keyspace-events "gxE"

2 启动

1) ./src/redis-server /home/redis/6001/redis-6001.conf

2) ./src/redis-server /home/redis/6002/redis-6002.conf

3) ./src/redis-server /home/redis/6003/redis-6003.conf

4) ./src/redis-server /home/redis/6004/redis-6004.conf

5) ./src/redis-server /home/redis/6005/redis-6005.conf

6) ./src/redis-server /home/redis/6006/redis-6006.conf

用:ps -ef|grep redis 查看是否起动成功

[root@localhost redis-4.0.9]# ps -ef|grep redis
root       2234   1828  0 04:49 pts/0    00:00:00 vi redis-6002.conf
root       2273      1  0 04:54 ?        00:00:00 ./src/redis-server 172.31.71.128:6001 [cluster]
root       2278      1  0 04:54 ?        00:00:00 ./src/redis-server 172.31.71.128:6002 [cluster]
root       2284      1  0 04:54 ?        00:00:00 ./src/redis-server 172.31.71.128:6003 [cluster]
root       2289      1  0 04:55 ?        00:00:00 ./src/redis-server 172.31.71.128:6004 [cluster]
root       2294      1  0 04:55 ?        00:00:00 ./src/redis-server 172.31.71.128:6005 [cluster]
root       2299      1  0 04:55 ?        00:00:00 ./src/redis-server 172.31.71.128:6006 [cluster]
root       2331   1828  0 05:12 pts/0    00:00:00 grep --color=auto redis

3 集群起动(单机版)

3.1安装ruby

#yum install ruby -y
#再安装redis插件
#gem install redis


wget https://github.com/postmodern/ruby-install/archive/v0.8.1.tar.gz
tar xzvf v0.8.1.tar.gz
cd ruby-install-0.8.1/bin/
#看下ruby的最新版本列表
./ruby-install --latest
#安装
./ruby-install ruby 2.7.8
会输出Successfully installed ruby 2.7.8 into /opt/rubies/ruby-2.78
ln -s /opt/rubies/ruby-2.7.8/bin/ruby /usr/bin/ruby
ln -s /opt/rubies/ruby-2.7.8/bin/gem /usr/bin/gem
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
#再安装redis插件

gem install redis

3.2 起动 redis集群

至少6个

>>> Creating cluster
*** ERROR: Invalid configuration for cluster creation.
*** Redis Cluster requires at least 3 master nodes.
*** This is not possible with 2 nodes and 1 replicas per node.
*** At least 6 nodes are required.

正确命令:

./src/redis-trib.rb create --replicas 1 172.31.71.128:6001 172.31.71.128:6002 172.31.71.128:6003 172.31.71.128:6004 172.31.71.128:6005 172.31.71.128:6006

返回如下则表示成功:

[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

3.3常见出错1 :

Traceback (most recent call last):
        2: from ./src/redis-trib.rb:25:in `

'
        1: from /opt/rubies/ruby-2.7.8/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
/opt/rubies/ruby-2.7.8/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require': cannot load such file -- redis (LoadError)

需要安装 相对应版本

下载

wget https://cache.ruby-lang.org/pub/ruby/ruby-2.5.0.tar.gz
tar xf ruby-2.5.0.tar.gz

进入ruby目录

cd ruby-2.5.0
./configure 
2 make && make install

3.4 常见出错2 :

gem install redis

[root@localhost redis-4.0.9]# gem install redis
ERROR:  SSL verification error at depth 3: certificate has expired (10)
ERROR:  Certificate /O=Digital Signature Trust Co./CN=DST Root CA X3 expired at 2021-09-30T14:01:15Z
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    SSL_connect returned=1 errno=0 state=error: certificate verify failed (certificate has expired) (https://index.ruby-china.com/quick/Marshal.4.8/redis-5.0.6.gemspec.rz)
~                                                                                                                                                          下载

wget wget https://rubygems.org/downloads/redis-4.2.3.gem

安装指定的redis模块

gem install -l /apps/redis-4.2.3.gem

4 访问redis集群

  redis-cli -h 172.31.71.128 -p 6001 -a 123456 -c


5集群节点查看


## 登录集群后
cluster nodes

[root@localhost redis-4.0.9]# redis-cli -h 172.31.71.128 -p 6001 -a 123456 -c
172.31.71.128:6001> cluster nodes
2110c7f67c001fac71691dd64cec4051b93cadfa 172.31.71.128:6005@16005 slave c4824984fafba7dda4c55975f7f8745234a6968e 0 1686560943122 5 connected
26555850fc80419c44d96a4c0e58b20d0af8bbf2 172.31.71.128:6003@16003 master - 0 1686560942119 3 connected 10923-16383
0e1d949ce8785f798ba0e17c2aa2155a6d99df8e 172.31.71.128:6006@16006 slave 26555850fc80419c44d96a4c0e58b20d0af8bbf2 0 1686560942519 6 connected
3389a66d84d6462b4dbf5cc228c3a060465773b3 172.31.71.128:6004@16004 slave 258d00326ff3b038e1d5af6b4d06423a31161ce7 0 1686560943122 4 connected
c4824984fafba7dda4c55975f7f8745234a6968e 172.31.71.128:6002@16002 master - 0 1686560943523 2 connected 5461-10922
258d00326ff3b038e1d5af6b4d06423a31161ce7 172.31.71.128:6001@16001 myself,master - 0 1686560941000 1 connected 0-5460


6  集群状态查看
## 登录集群后
cluster info

[root@localhost redis-4.0.9]#  redis-cli -h 172.31.71.128 -p 6001 -a 123456 -c
172.31.71.128:6001> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:1433
cluster_stats_messages_pong_sent:1407
cluster_stats_messages_sent:2840
cluster_stats_messages_ping_received:1402
cluster_stats_messages_pong_received:1433
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:2840

                                                                 
~                                    

你可能感兴趣的:(Redis,redis,数据库,java)