在redhat6.4安装redis集群

参考:

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.gz
tar xf redis-3.0.7.tar.gz
cd redis-3.0.7
mkdir -p /opt/redis
make test
make 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/

根据实际修改/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 <id>   -- Run tail -f of instance at base port + ID."
echo "clean       -- Remove all instances data, logs, configs."

不要忘了创建数据目录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.gz
tar xf tcl8.5.19-src.tar.gz
cd  tcl8.5.19/unix
./configure
make
make test
make 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.tgz
cd rubygems-2.6.4
ruby setup.rb

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

如果再提示 no such file to load – 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

时间: 2024-10-06 04:13:12

在redhat6.4安装redis集群的相关文章

安装redis 集群

安装redis集群 第一步:安装相关依赖包 1):安装redis-cluster依赖:redis-cluster的依赖库在使用时有兼容问题,在reshard时会遇到各种错误,请按指定版本安装. (1)确保系统安装zlib,否则geminstall会报(no such file to load -- zlib)     #download:zlib-1.2.6.tar       ./configure      make  make install   或者 yum install zlib (

Linux安装redis集群

linux安装单机版redis已经在另一篇文章说过了,下边来搞集群,环境是新浪云服务器: redis3.0以后开始支持集群. 前言:redis用什么做集群? 用一个叫redis-trib.rb的ruby脚本.redis-trib.rb是redis官方推出的管理redis集群的工具,集成在redis的源码src目录下(redis-xxx/src/).是基于redis提供的集群命令封装成简单.便捷.实用的操作工具.redis-trib.rb是redis作者用ruby完成的.所以redis集群需要先安

离线安装redis集群

redis集群需要安装如下组件: ruby rubygems redis ---------------------------------------------------------------------------------- 离线安装ruby 1:上传ruby-2.3.1.tar.gz至服务器: 2:tar -xzvf ruby-2.3.1.tar.gz: 3:cd ruby-2.3.1 4:./configure --prefix='/opt/ruby' 5:make 6:mak

Linux离线安装redis集群

一.应用场景介绍 本文主要是介绍Redis集群在Linux环境下的安装讲解,联网环境安装较为简单,这里只说脱机的Linux环境下是如何安装的.因为大多数时候,公司的生产环境是在内网环境下,无外网,服务器处于脱机状态. 二.安装环境及工具 系统:CentOS7 工具:XShell5及Xftp5 安装包: Ruby-2.4.2 Rubygems-2.6.14 Redis-4.0.2(3.x版本才开始支持集群功能) openssl-1.1.0f 三.安装步骤 要搭建一个最简单的Redis集群,我们至少

Centos7安装Redis(集群模式)

环境:centos7.6 redis4.0模拟在一个Centos7下安装6个redis实例搭建集群 3主3从 安装wgetyum -y install wget 安装gccyum -y install gcc automake autoconf libtool make 下载rediscd /usr/local/softwarewget http://download.redis.io/releases/redis-4.0.0.tar.gz 解压tar -xzvf redis-4.0.0.tar

windows下安装redis集群

前几天在自己在本机win10 电脑下部署了redis集群. 主要通过的是网上两个博客: 如何在windows下部署redis集群:https://blog.csdn.net/zsg88/article/details/73715947 redis的一些操作:https://blog.csdn.net/mlc1218559742/article/details/52640180 原文地址:https://www.cnblogs.com/tuanz/p/9359037.html

redis安装+redis集群配置+phpredis扩展安装

安装前的准备: redis-3.0tar.gz    官网下载地址    http://redis.io/download/以下软件或直接yum安装也可(安装步骤略)tcl8.6.1-src.tar.gz               官网下载地址   http://sourceforge.jp/projects/sfnet_tcl/releases/rubygems-2.4.2.zip            官网下载地址   http://rubygems.org/pages/download/

CentOs安装Redis集群版踩的坑

1.安装ruby安装不上,连接github失败 答:route命令 查看所有网络,删除与github相同的192的无用网络. 2.# 执行创建命令(注意如下连接中的ip最好不用127.0.0.1和默认端口) ./redis-trib.rb create --replicas 1 10.211.55.5:7001 10.211.55.5:7002 10.211.55.5:7003 10.211.55.5:7004 10.211.55.5:7005 10.211.55.5:7006 时显示无法创建7

shell脚本一键安装redis集群

简介: 明天再写,上脚本 #!/bin/bash #------------------------------------------------------------------------------------------------------------------# #| Some people die at the age of 25 and don't bury themselves in the earth until they are 75 |# #-----------