实现3主3从的集群 虚拟机单机ip:192.168.40.128html
wget http://download.redis.io/releases/redis-4.0.10.tar.gz
tar zxvf redis-4.0.10.tar.gz
make && make PREFIX=/usr/local/redis install
,可能出现权限不够的问题,sudo一样会报错,直接使用root进行操做。sudo apt-get update
sudo apt-get install gcc
sudo apt-get install make
sudo apt-get install tcl
cd /usr/local/redis
mkdir cluster
cd cluster
mkdir 7000 7001 7002 7003 7004 7005
复制redis conf内的config文件复制到六个文件夹中,而且修改如下内容node
# 端口号 port 7000 # 后台启动 daemonize yes # 开启集群 cluster-enabled yes #集群节点配置文件 cluster-config-file nodes-7000.conf # 集群链接超时时间 cluster-node-timeout 5000 # 进程pid的文件位置 pidfile /home/ubuntu/redis-4.0.10/pid/redis-7000.pid #工做文件夹 dir "/home/ubuntu/redis-4.0.10/working" # 开启aof appendonly yes # aof文件路径 appendfilename "appendonly-7005.aof" # rdb文件路径 dbfilename dump-7000.rdb
redis 的配置文件中的bind指定的是redis服务器的网卡ip,也就是redis服务器的ippython
cd /home/ubuntu/redis-4.0.10/
touch start.link.sh
为了操做简单,建立脚本#!/bin/bash export BASE_FLOD="/usr/local/redis" {BASE_FLOD}/bin/redis-server /usr/local/redis/cluster/7000/redis.conf /usr/local/redis/bin/redis-server /usr/local/redis/cluster/7001/redis.conf /usr/local/redis/bin/redis-server /usr/local/redis/cluster/7002/redis.conf /usr/local/redis/bin/redis-server /usr/local/redis/cluster/7003/redis.conf /usr/local/redis/bin/redis-server /usr/local/redis/cluster/7004/redis.conf /usr/local/redis/bin/redis-server /usr/local/redis/cluster/7005/redis.conf #cd src #./redis-trib.rb create --replicas 1 192.168.40.128:7000 192.168.40.128:7001 192.168.40.128:7002 192.168.40.128:7003 192.168.40.128:7004 192.168.40.128:7005
其中注释的是为了简化初始启动的,ip须要跟每一个节点配置的redis.conf 中bind 属性绑定的一致,启动后能够经过ps -ef | grep redis命令查询对应的线程是否启动git
sudo apt-get install ruby rubygems -y
redis-trib.rb create --replicas 1 192.168.40.128:7000 192.168.40.128:7001 192.168.40.128:7002 192.168.40.128:7003 192.168.40.128:7004 192.168.40.128:7005
,检查配置的信息是否有错误,没有直接yes就能够. [OK] All 16384 slots covered.
表明接群启动成功。查看集群运行状态:使用命令./redis-trib.rb check 192.168.40.128:7000
,进行集群的状态检查github
redis-benchmark -h 192.168.40.128 -p 6379 -c 100 -n 100000
100个并发链接,100000个请求,检测 host 为 localhost 端口为6379的 redis 服务器性能。redis-benchmark -h 192.168.40.128 -p 6379 -q -d 100
测试存取大小为100字节的数据包的性能。redis-benchmark -t set,lpush -n 100000 -q
只测试某些操做的性能。redis-benchmark -n 100000 -q script load "redis.call(‘set’,’foo’,’bar’)"
只测试某些数值存取的性能。集群搭建初始不须要密码,启动完成后,先看每一个节点的配置文件是否有读写权限,若是没有读写权限,须要chmod修改的读写权限,经过web
./redis-cli -c -p port config set masterauth password config set requirepass password config rewrite
分别链接每一个节点进行设置
若要重启发现链接不上,修改启动脚本 redis-trib.rb.sh 99行,配置启动脚本密码启动@r = Redis.new(:host => @info[:host], :port => @info[:port], :timeout => 60,:password => "password")
redis
/* *集群链接测试 */ @Test public void testJedisCluster() { Set<HostAndPort> nodes = new LinkedHashSet<>(); //全部主机节点ip和端口 nodes.add(new HostAndPort("192.168.40.128", 7000)); nodes.add(new HostAndPort("192.168.40.128", 7001)); nodes.add(new HostAndPort("192.168.40.128", 7002)); nodes.add(new HostAndPort("192.168.40.128", 7003)); nodes.add(new HostAndPort("192.168.40.128", 7004)); nodes.add(new HostAndPort("192.168.40.128", 7005)); //没有密码 //JedisCluster cluster = new JedisCluster(nodes); //添加密码调用 JedisCluster cluster = new JedisCluster(nodes, 5000, 5000, 10, "password", new GenericObjectPoolConfig()); //cluster.zadd("test_1", String.valueOf(""),"id_2"); System.out.println(cluster.zscore("test_1", "id_1")); try { cluster.close(); } catch (IOException e) { e.printStackTrace(); } }
git clone https://github.com/kumarnitin/RedisLive.git
unzip -o -d /home/ubuntu/ RedisLive-master.zip
进入src文件夹,复制example文件,编辑数据库
"RedisServers": [ { "server": "192.168.40.128", "port" : 7000, "password" : "password" }, //...多个监听 ], "DataStoreType" : "redis", "RedisStatsServer": //存储的redis监听接口 { "server" : "127.0.0.1", "port" : 6379 }, "SqliteStatsStore" : { "path": "/home/ubuntu/redis-4.0.10/working/redislive.db" //进行存储的文件 } }
ubuntu@ubuntu:~/redis-4.0.10$ mkdir pid
ubuntu@ubuntu:~/redis-4.0.10$ mkdir log
ubuntu@ubuntu:~/redis-4.0.10$ mkdir working
`./redis-live.py
No module named redisubuntu
which python
sudo cp /usr/bin/python /usr/bin/python_cp
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.5 /usr/bin/python