實現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