redis 集群安装

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis 集群安装相关的知识,希望对你有一定的参考价值。

版本:redis-4.0.2.tar.g

(一)创建reids节点

             我们使用3台服务器,分别为192.168.99.129,192.168.99.153,192.168.99.171三台服务器。

              192.168.99.129装 7001,7002两个节点,192.168.99.153装 7003,7004两个节点,192.168.99.171装 7005,7006两个节点.

               在192.168.99.129的 /usr/local/rediscluster 下创建 7001和7002文件夹,并且将要安装的redis拷到此两个文件夹下。其余的俩台机子也这样:

[[email protected] rediscluster]# pwd
/usr/local/rediscluster
[[email protected] rediscluster]# ls -al
total 4
drwxr-xr-x.  4 root root   28 Nov  1 08:51 .
drwxr-xr-x. 14 root root 4096 Nov  1 08:47 ..
drwxr-xr-x.  2 root root   31 Nov  1 08:49 7001
drwxr-xr-x.  2 root root    6 Nov  1 08:51 7002

(二)编译redis

(三)配置redis.conf,以7001节点为例。

port 7001
cluster-enabled yes
bind 192.168.99.129
daemonize yes
cluster-config-file 7001.conf
appendonly yes

(四)依次启动各个redis

[[email protected] src]# ./redis-server ../redis.conf 
17620:C 01 Nov 10:02:59.106 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
17620:C 01 Nov 10:02:59.106 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=17620, just started
17620:C 01 Nov 10:02:59.106 # Configuration loaded
[[email protected] src]# 
[[email protected] src]# 
[[email protected] src]# ps -ef|grep redis
root      17614      1  0 10:01 ?        00:00:00 ./redis-server 192.168.99.129:7001 [cluster]
root      17621      1  0 10:02 ?        00:00:00 ./redis-server 192.168.99.129:7002 [cluster]

(五)执行下面命令,由于centos 7中安装的 ruby版本太低,会报错

[[email protected] redis-4.0.2]#  yum install ruby
[[email protected] redis-4.0.2]# yum install rubygems

[[email protected] redis-4.0.2]# gem install redis

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

 升级ruby版本

安装curl

[[email protected] redis-4.0.2]# yum install curl

 

安装rvm

[[email protected] redis-4.0.2]# curl -L get.rvm.io | bash -s stable 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   194  100   194    0     0    246      0 --:--:-- --:--:-- --:--:--   246
100 24090  100 24090    0     0   8210      0  0:00:02  0:00:02 --:--:-- 50503
Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc
gpg: directory `/root/.gnupg created
gpg: new configuration file `/root/.gnupg/gpg.conf created
gpg: WARNING: options in `/root/.gnupg/gpg.conf are not yet active during this run
gpg: keyring `/root/.gnupg/pubring.gpg created
gpg: Signature made Sun 10 Sep 2017 04:59:21 PM EDT using RSA key ID BF04FF17
gpg: Cant check signature: No public key
Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found. Assuming you trust Michal Papis import the mpapis public key (downloading the signatures).

GPG signature verification failed for /usr/local/rvm/archives/rvm-1.29.3.tgz - https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc! Try to install GPG v2 and then fetch the public key:

    gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

or if it fails:

    command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -

the key can be compared with:

    https://rvm.io/mpapis.asc
    https://keybase.io/mpapis

 

 

根据上面的提示执行命令:

[[email protected] redis-4.0.2]# curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
[[email protected] redis-4.0.2]# curl -L get.rvm.io | bash -s stable

[[email protected] redis-4.0.2]# rvm install 2.3.3
[[email protected] redis-4.0.2]# gem install redis

 

启动集群:

./redis-trib.rb create --replicas 1 192.168.99.129:7001 192.168.99.129:7002 192.168.99.153:7003 192.168.99.153:7004 192.168.99.171:7005 192.168.99.171:7006

 

 

 进入集群进行测试:

[[email protected] src]# ./redis-cli -c -h 192.168.99.129 -p 7001   //注意必须加-c

192.168.99.129:7001> set zhang "zhang"

 

 去别的机子查看

[[email protected] src]# ./redis-cli -c -h 192.168.99.171 -p 7005
192.168.99.171:7005> get zhang
-> Redirected to slot [7942] located at 192.168.99.153:7003

 参考文章:http://www.cnblogs.com/hjwublog/p/5681700.html









以上是关于redis 集群安装的主要内容,如果未能解决你的问题,请参考以下文章

如何安装Redis集群

redis安装-模拟redis集群

Linux安装redis集群

LINUX安装REDIS集群

Linux(ubuntu)安装redis集群,redis集群搭建

redis离线集群安装