侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

在redhat6.4安装redis集群【教程】

Redis  /  管理员 发布于 7年前   190

  参考:

  http://redis.io/topics/cluster-tutorial(主要是Creating a Redis Cluster using the create-cluster script部分)

  https://ruby.taobao.org/

  安装一款不熟悉的软件前先看INSTALL,README,这是习惯,生产上要建立普通用户并调节适当参数,下面是以root身份安装运行.

  下载解压并安装redis

  make test提示需要更高版本的tcl,跳到安装过程可能遇到的问题

  

wget http://download.redis.io/releases/redis-3.0.7.tar.gztar xf redis-3.0.7.tar.gz cd redis-3.0.7mkdir -p /opt/redismake testmake PREFIX=/opt/redis install

  复制两个脚本到安装的目录

 

 cp ~/redis-3.0.7/src/redis-trib.rb /opt/redis/  cp ~/redis-3.0.7/utils/create-cluster/create-cluster /opt/redis/1212 

  根据实际修改/opt/redis/create-cluster.改动的地方有几处

  a.增加了三个变量BASEDIR,BINDIR和DATADIR,

  b.修改相关命令路径,

  c.start前,先进入DATADIR,start后,返回原目录

  d.clean前,先进入DATADIR,start后,返回原目录

  e.create的host由127.0.0.1改为192.168.1.194(不改有时会报Too many Cluster redirections)

  下面是修改后的shell

 

 #!/bin/bash  # Settings  PORT=30000  TIMEOUT=2000  NODES=6  REPLICAS=1  BASEDIR=/opt/redis  BINDIR=$BASEDIR/bin  DATADIR=$BASEDIR/data   # You may want to put the above config parameters into config.sh in order to  # override the defaults without modifying this script.  if [ -a config.sh ]  then  source "config.sh"  fi  # Computed vars  ENDPORT=$((PORT+NODES))  if [ "$1" == "start" ]  then  cd $DATADIR  while [ $((PORT < ENDPORT)) != "0" ]; do  PORT=$((PORT+1))  echo "Starting $PORT"  $BINDIR/redis-server --port $PORT --cluster-enabled yes --cluster-config-file nodes-${PORT}.conf --cluster-node-timeout $TIMEOUT --appendonly yes --appendfilename appendonly-${PORT}.aof --dbfilename dump-${PORT}.rdb --logfile ${PORT}.log --daemonize yes  done  cd -  exit 0  fi  if [ "$1" == "create" ]  then  HOSTS=""  while [ $((PORT < ENDPORT)) != "0" ]; do  PORT=$((PORT+1))  HOSTS="$HOSTS 192.168.1.194:$PORT"  done  $BASEDIR/redis-trib.rb create --replicas $REPLICAS $HOSTS  exit 0  fi  if [ "$1" == "stop" ]  then  while [ $((PORT < ENDPORT)) != "0" ]; do  PORT=$((PORT+1))  echo "Stopping $PORT"  $BINDIR/redis-cli -p $PORT shutdown nosave  done  exit 0  fi  if [ "$1" == "watch" ]  then  PORT=$((PORT+1))  while [ 1 ]; do  clear  date  $BINDIR/redis-cli -p $PORT cluster nodes | head -30  sleep 1  done  exit 0  fi  if [ "$1" == "tail" ]  then  INSTANCE=$2  PORT=$((PORT+INSTANCE))  tail -f ${PORT}.log  exit 0  fi  if [ "$1" == "call" ]  then  while [ $((PORT < ENDPORT)) != "0" ]; do  PORT=$((PORT+1))  $BINDIR/redis-cli -p $PORT $2 $3 $4 $5 $6 $7 $8 $9  done  exit 0  fi  if [ "$1" == "clean" ]  then  cd $DATADIR  rm -rf *.log  rm -rf appendonly*.aof  rm -rf dump*.rdb  rm -rf nodes*.conf  cd -  exit 0  fi  echo "Usage: $0 [start|create|stop|watch|tail|clean]"  echo "start -- Launch Redis Cluster instances."  echo "create -- Create a cluster using redis-trib create."  echo "stop -- Stop Redis Cluster instances."  echo "watch -- Show CLUSTER NODES output (first 30 lines) of first node."  echo "tail -- Run tail -f of instance at base port + ID."  echo "clean -- Remove all instances data, logs, configs."123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102

  不要忘了创建数据目录mkdir -p /opt/redis/data

  根据上面的参考,启动集群和停止集群

  启动集群:先敲入/opt/redis/create-cluster start回车,再敲入/opt/redis/create-cluster create回车,再输入yes回车

  停止集群:敲入/opt/redis/create-cluster stop回车

  如果以前启动过,造成不一致数据,create时就会报错,可先/opt/redis/create-cluster clean

  测试

 

<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.8.1</version></dependency>

  声明JedisCluster Bean

@Bean public JedisCluster jedisCluster(){  Set<HostAndPort> nodes=new HashSet<>(3);  nodes.add(new HostAndPort("192.168.1.194",30001));  nodes.add(new HostAndPort("192.168.1.194",30002));  nodes.add(new HostAndPort("192.168.1.194",30003));  return new JedisCluster(nodes,2000,5); }

  测试set和get

  

 AnnotationConfigApplicationContext context= new AnnotationConfigApplicationContext(AppConfig.class);  JedisCluster jedisCluster = (JedisCluster) context.getBean("jedisCluster");  jedisCluster.set("xxx","123");  System.out.println("jedisCluster.get = " + jedisCluster.get("xxx"));

  安装过程可能遇到的问题:

  make test时,提醒You need tcl 8.5 or newer in order to run the Redis test.到http://www.tcl.tk/software/tcltk/download.html下载Tcl,

 

wget http://prdownloads.sourceforge.net/tcl/tcl8.5.19-src.tar.gztar xf tcl8.5.19-src.tar.gzcd tcl8.5.19/unix./configuremakemake testmake install

  因为create-cluster create会调用redis-trib.rb,它是一个ruby脚本,所以提示没有安装ruby,就先安装yum install -y ruby

  如果提示加载rubygems错误,使用以下办法安装rubygems

  a.https://rubygems.org/pages/download下载tgz格式的安装包(wget可能不通,在windows用旋风或迅雷下载)

  b.mount -t cifs -o username=xiejx618,password=123456 //192.168.1.115/share /share

  

cp /share/rubygems-2.6.4.tgz ./tar xf rubygems-2.6.4.tgzcd rubygems-2.6.4ruby setup.rb

  如果再提示no such file to load C rdoc/rdoc,就先安装yum install -y rdoc

  如果再提示 no such file to load C redis,就使用gem install redis -v 3.0.7

  gem又是因为墙原因无法使用默认源,就修改为淘宝源

  可能用到的几个命令

  帮助:gem sources --help

  查看源:gem sources -l

  删除源:gem sources -r https://rubygems.org/

  添加源:gem sources -a https://ruby.taobao.org/

  更新源缓存:gem sources -u


  • 上一条:
    CentOS系统中Redis数据库的安装配置指南
    下一条:
    浅谈Redis在分布式系统中的协调性运用
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在Redis中能实现的功能、常见应用介绍(0个评论)
    • 2024年Redis面试题之一(0个评论)
    • 在redis缓存常见出错及解决方案(0个评论)
    • 在redis中三种特殊数据类型:地理位置、基数(cardinality)估计、位图(Bitmap)使用场景介绍浅析(2个评论)
    • Redis 删除 key用 del 和 unlink 有啥区别?(1个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2017-12
    • 2020-03
    • 2020-05
    • 2021-04
    • 2022-03
    • 2022-05
    • 2022-08
    • 2023-02
    • 2023-04
    • 2023-07
    • 2024-01
    • 2024-02
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客