一.安裝必要包node
yum install gcc
二.linux下安裝linux
#下載wget http://download.redis.io/releases/redis-3.0.0.tar.gz tar zxvf redis-3.0.0.tar.gz cd redis-3.0.0#若是不加參數,linux下會報錯make MALLOC=libc
安裝好以後,啓動文件redis
#啓動redissrc/redis-server &#關閉redissrc/redis-cli shutdown
測試redisvim
$ src/redis-cli127.0.0.1:6379> set foo bar OK127.0.0.1:6379> get foo"bar"$
測試成功ruby
3.redis cluster集羣搭建app
創建本機測試環境測試
創建運行目錄spa
#創建redis運行目錄mkdir -p redis-server/7000/#複製默認的配置文檔cp redis-3.0.0/redis.conf redis-server/redis.default.conf#把編譯好的server複製到運行目錄cp redis-3.0.0/src/redis-server redis-server/7000/
創建獨立配置文件ssr
#在7000目錄下創建redis的配置文檔vim redis-server/7000/redis.conf
文件內容3d
#redis-server/7000/redis.confinclude /root/redis-server/redis.default.conf pidfile /var/run/redis-7000.pid port 7000cluster-enabled yes cluster-config-file redis-node-7000.conf cluster-node-timeout 5000appendonly yes
複製運行目錄(模擬集羣環境)
#複製目錄cp -R 7000/ 7001/cp -R 7000/ 7002/cp -R 7000/ 7003/cp -R 7000/ 7004/cp -R 7000/ 7005/
修改相應配置文件的端口和文件名
創建啓動腳本 redis-server/redis-start.sh
#!/bin/sh/root/redis-server/7000/redis-server /root/redis-server/7000/redis.conf & /root/redis-server/7001/redis-server /root/redis-server/7001/redis.conf & /root/redis-server/7002/redis-server /root/redis-server/7002/redis.conf & /root/redis-server/7003/redis-server /root/redis-server/7003/redis.conf & /root/redis-server/7004/redis-server /root/redis-server/7004/redis.conf & /root/redis-server/7005/redis-server /root/redis-server/7005/redis.conf &
配置集羣
安裝ruby
yum install ruby-devel.x86_64
安裝redis gem
# gem install redis Fetching: redis-3.2.1.gem (100%) Successfully installed redis-3.2.1Parsing documentation for redis-3.2.1Installing ri documentation for redis-3.2.11 gem installed
使用腳本創建集羣機制
在create的時候,加上參數--replicas 1 表示爲每一個master分配一個salve,如例子,則是3個master 3個salve
# ./redis-trib.rb create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005>>> Creating cluster Connecting to node 127.0.0.1:7000: OK Connecting to node 127.0.0.1:7001: OK Connecting to node 127.0.0.1:7002: OK Connecting to node 127.0.0.1:7003: OK Connecting to node 127.0.0.1:7004: OK Connecting to node 127.0.0.1:7005: OK>>> Performing hash slots allocation on 6 nodes... Using 6 masters:127.0.0.1:7000127.0.0.1:7001127.0.0.1:7002127.0.0.1:7003127.0.0.1:7004127.0.0.1:7005M: f3dd250e4bc145c8b9f864e82f65e00d1ba627be 127.0.0.1:7000 slots:0-2730 (2731 slots) master M: 1ba602ade59e0770a15128b193f2ac29c251ab5e 127.0.0.1:7001 slots:2731-5460 (2730 slots) master M: 4f840a70520563c8ef0d7d1cc9d5eaff6a1547a2 127.0.0.1:7002 slots:5461-8191 (2731 slots) master M: 702adc7ae9caf1f6702987604548c6fc1d22e813 127.0.0.1:7003 slots:8192-10922 (2731 slots) master M: 4f87a11d2ea6ebe9caf02c9dbd827a3dba8a53cf 127.0.0.1:7004 slots:10923-13652 (2730 slots) master M: 216bbb7da50bd130da16a327c76dc6d285f731b3 127.0.0.1:7005 slots:13653-16383 (2731 slots) master Can I set the above configuration? (type 'yes' to accept): yes>>> Nodes configuration updated>>> Assign a different config epoch to each node>>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join...>>> Performing Cluster Check (using node 127.0.0.1:7000) M: f3dd250e4bc145c8b9f864e82f65e00d1ba627be 127.0.0.1:7000 slots:0-2730 (2731 slots) master M: 1ba602ade59e0770a15128b193f2ac29c251ab5e 127.0.0.1:7001 slots:2731-5460 (2730 slots) master M: 4f840a70520563c8ef0d7d1cc9d5eaff6a1547a2 127.0.0.1:7002 slots:5461-8191 (2731 slots) master M: 702adc7ae9caf1f6702987604548c6fc1d22e813 127.0.0.1:7003 slots:8192-10922 (2731 slots) master M: 4f87a11d2ea6ebe9caf02c9dbd827a3dba8a53cf 127.0.0.1:7004 slots:10923-13652 (2730 slots) master M: 216bbb7da50bd130da16a327c76dc6d285f731b3 127.0.0.1:7005 slots:13653-16383 (2731 slots) master [OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage... [OK] All 16384 slots covered.
若是須要所有從新自動配置,則刪除全部的配置好的cluster-config-file,從新啓動全部的redis-server,而後從新執行配置命令便可