您的位置:首页 > 数据库 > Redis

Redis集群搭建与简单使用

2017-07-11 14:28 495 查看
转自http://www.cnblogs.com/wuxl360/p/5920330.html

Redis集群搭建

1  安装redis 

wget http:
//download
.redis.io
/releases/redis-3
.2.4.
tar
.gz


..make (install)..




cd src
cp redis-trib.rb /usr/local/bin/



分别启动各个redis,关键是conf

  conf配置

port  7000                                        //端口7000,7002,7003
bind 本机ip                                       //默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访问对应的端口,无法创建集群
daemonize    yes                               //redis后台运行
pidfile  /var/run/redis_7000.pid          //pidfile文件对应7000,7001,7002
cluster-enabled  yes                           //开启集群  把注释#去掉
cluster-config-file  nodes_7000.conf   //集群的配置  配置文件首次启动自动生成 7000,7001,7002
cluster-node-timeout  15000                //请求超时  默认15秒,可自行设置
appendonly  yes                           //aof日志开启  有需要就开启,它会每次写操作都记录一条日志 


redis-server redis_cluster/7000/redis.conf

3  创建集群

redis-trib.rb  create  --replicas  1  192.168.31.245:7000 192.168.31.245:7001  192.168.31.245:7002 192.168.31.210:7003  192.168.31.210:7004  192.168.31.210:7005


redis使用

在第一台机器上连接集群的7002端口的节点,在另外一台连接7005节点,连接方式为 redis-cli
-h 192.168.31.245 -c -p 7002  ,加参数 -C 可连接到集群,因为上面 redis.conf 将 bind 改为了ip地址,所以 -h 参数不可以省略。

在7005节点执行命令  set hello world 
在7002节点执行命令   get
hello  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: