redis缓存服务器集群搭建

一、安装redis

1.下载redis

[root@redis ~]# wget http://download.redis.io/releases/redis-4.0.11.tar.gz

2.安装编译

[root@redis ~]# tar xf redis-4.0.11.tar.gz -C /usr/local/
[root@redis ~]# cd /usr/local/redis-4.0.11/
[root@redis redis-4.0.11]# make
[root@redis local]# ln -s /usr/local/redis-4.0.11/ /usr/local/redis

3.创建目录

[root@redis ~]# mkdir /redis-server-cluster
[root@redis redis-server-cluster]# mkdir 700{0..5}
[root@redis redis-server-cluster]# cp /usr/local/redis/src/redis-server 7000/
[root@redis redis-server-cluster]# cp /usr/local/redis/redis.conf 7000/

[root@redis redis-server-cluster]# vim 7000/redis.conf 
    port 7000                            //每个节点的端口号
    bind 10.30.162.73                    //绑定的机器IP
    cluster-enabled yes                  //启动集群模式
    cluster-config-file nodes-7001.conf     
    cluster-node-timeout 5000
    appendonly yes

#将配置文件拷贝到7000-7005,更改端口号,并且将cluster-config-file 更改
[root@redis redis-server-cluster]# cp 7000/redis.conf 7001 7002 7003 7004 7005

  

4.启动各个节点,并测试

 [root@redis redis-server-cluster]# ./7001/redis-server 7001/redis.conf &          //每个节点都需要启动

[root@redis redis-server-cluster]# ps axu | grep redis root 21647 0.0 1.0 151456 10060 pts/1 Rl 14:44 0:00 ./7001/redis-server 10.30.162.75:7001 [cluster] root 21655 0.0 1.0 151456 10060 pts/1 Rl 14:44 0:00 ./7003/redis-server 10.30.162.75:7003 [cluster] root 21665 0.0 1.0 151456 10060 pts/1 Rl 14:44 0:00 ./7002/redis-server 10.30.162.75:7002 [cluster] root 21675 0.0 1.0 147360 10064 pts/1 Rl 14:45 0:00 ./7000/redis-server 10.30.162.75:7000 [cluster] root 21797 0.0 1.0 151456 10060 pts/1 Sl 14:47 0:00 ./7004/redis-server 10.30.162.75:7004 [cluster] root 21807 0.0 1.0 147360 10064 pts/1 Sl 14:47 0:00 ./7005/redis-server 10.30.162.75:7005 [cluster] root 21815 0.0 0.0 112704 968 pts/1 R+ 14:47 0:00 grep --color=auto redis

  

二、安装Ruby

1.安装基本包

[root@redis ~]# yum -y install ruby

2.安装redis的Ruby接口程序

[root@redis ~]# gem install redis

    Fetching: redis-4.0.3.gem (100%)
    ERROR:  Error installing redis:
    redis requires Ruby version >= 2.2.2.

[root@redis ~]# ruby -v
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]        //当前版本为2.0.0,要成功安装Ruby接口程序,版本要大于2.2.2

[root@redis ~]# gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB 

[root@redis ~]# curl -L get.rvm.io | bash -s stable
[root@redis ~]# find / -name rvm -print
[root@redis ~]# source /usr/local/rvm/scripts/rvm

#删除旧版本
[root@redis ~]# rvm remove 2.0.0 

#查看rvm库中ruby的版本
[root@redis ~]# rvm list known
[root@redis ~]# rvm install 2.5.1

#查看版本
[root@redis ~]# ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

#设置默认版本
[root@redis ~]# rvm use 2.5.1 --default

#再次安装redis的Ruby接口程序
[root@redis ~]# gem install redis
 
[root@redis src]# ./redis-trib.rb create --replicas 1 10.30.162.73:7000 10.30.162.73:7001 10.30.162.73:7002 10.30.162.73:7003 10.30.162.73:7004 10.30.162.73:7005

"出现下述即成功"
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.

  

3.测试

[root@redis src]# ./redis-cli -h 10.30.162.73 -p 7001
10.30.162.73:7001> 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:2
cluster_stats_messages_ping_sent:283
cluster_stats_messages_pong_sent:286
cluster_stats_messages_meet_sent:2
cluster_stats_messages_sent:571
cluster_stats_messages_ping_received:283
cluster_stats_messages_pong_received:285
cluster_stats_messages_meet_received:3
cluster_stats_messages_received:571

10.30.162.73:7001> cluster node
(error) ERR Wrong CLUSTER subcommand or number of arguments
10.30.162.73:7001> cluster nodes
6df6da2e003bcc5c76455d6f8d335f49cf910524 10.30.162.73:7005@17005 slave 1626d805cb2a4c9a1561743fcda33ce6f84674b8 0 1541141615000 6 connected
4a4f8b6e6bddc0840527f488088736c9bc4b07e8 10.30.162.73:7003@17003 slave cc37a7951e8a8be9d2d23d2325564d3b9ed439c0 0 1541141615448 4 connected
1626d805cb2a4c9a1561743fcda33ce6f84674b8 10.30.162.73:7002@17002 master - 0 1541141616455 3 connected 10923-16383
891b582ecd16e542b9ce3f243b51eddd84b61eae 10.30.162.73:7001@17001 myself,master - 0 1541141614000 2 connected 5461-10922
cc37a7951e8a8be9d2d23d2325564d3b9ed439c0 10.30.162.73:7000@17000 master - 0 1541141615549 1 connected 0-5460
2e019cbeb4fd91b965e2dc7d07bf7a4f2e78f596 10.30.162.73:7004@17004 slave 891b582ecd16e542b9ce3f243b51eddd84b61eae 0 1541141615000 5 connected

  

posted @ 2018-11-02 15:03  情浅凉心  阅读(684)  评论(0编辑  收藏  举报