Want to run a Redis cluster, but not so many servers, so use pseudo-distributed mode, simulate, and record the installation process.
Software: redis-3.0.3.tar.gz
Cluster uptime requires at least 3 master nodes (this example creates 6 nodes, 3 primary 3 slave nodes)
Install the premise, want to have Ruby, RubyGems environment, install first:
--nogpgcheck---nogpgcheck-y installed ruby---nogpgcheck-y install rubygems# installing Ruby's Redis interface gem -redis
Installing Redis Software
/usr/local/--rf redis-3.0. 3 -ZXVF redis-3.0. 3 . TAR.GZMV Redis-3.0. 3 && make install
Create a cluster-related configuration
#创建集群需要的目录mkdir-p/usr/local/redis/cluster/16001/mkdir-p/usr/local/redis/cluster/16002/mkdir-p/usr/local/redis/cluster/16003/mkdir-p/usr/local/redis/cluster/16004/mkdir-p/usr/local/redis/cluster/16005/mkdir-p/usr/local/redis/cluster/16006/#修改配置文件redis. CONF#CP/usr/local/redis/redis.conf/usr/local/redis/cluster/16001/REDIS.CONF#CP/usr/local/redis/redis.conf/usr/local/redis/cluster/16002/REDIS.CONF#CP/usr/local/redis/redis.conf/usr/local/redis/cluster/16003/REDIS.CONF#CP/usr/local/redis/redis.conf/usr/local/redis/cluster/16004/REDIS.CONF#CP/usr/local/redis/redis.conf/usr/local/redis/cluster/16005/REDIS.CONF#CP/usr/local/redis/redis.conf/usr/local/redis/cluster/16006/Redis.conf
Example configuration file:
daemonize Nopidfile/var/run/redis.pid# modifying ports Port16001TCP-backlog511Timeout0TCP-keepalive0loglevel Noticelogfile""databases -Save the 1Save - TenSave - 10000Stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir./slave-serve-stale-Data Yesslave-read-Only Yesrepl-diskless-Sync Norepl-diskless-sync-delay5Repl-disable-tcp-Nodelay Noslave-priority -#修改为yesappendonly Yesappendfilename"appendonly.aof"Appendfsync Everysecno-appendfsync-on-rewrite Noauto-aof-rewrite-percentage -Auto-aof-rewrite-min-size 64mbaof-load-truncated Yeslua-time-limit theSlowlog-log-slower-than10000Slowlog-max-len -Latency-monitor-threshold0Notify-keyspace-events""Hash-max-ziplist-entries +Hash-max-ziplist-value -List-max-ziplist-entries +List-max-ziplist-value -Set-max-intset-entries +Zset-max-ziplist-entries -Zset-max-ziplist-value -HLL-sparse-max-bytes theactiverehashing yesclient-output-buffer-limit Normal0 0 0Client-output-buffer-limit slave 256MB 64MB -Client-output-buffer-limit pubsub 32MB 8MB -HzTenaof-rewrite-incremental-Fsync yes#========================= New ===============================daemonize Yescluster-enabled Yescluster-config-file Nodes.confcluster-node-timeout the#========================================================
To start a Redis instance:
#分别启动这6个redis实例 (At this point, the nodes are running as Redis cluster, but the cluster is not built automatically because it is still in the "I don't know you, you don't belong to me" state, each of which is a lone redis node, Or a cluster that contains only a single node) CD/usr/local/redis/cluster/16001&& redis-server redis.conf > Redis.log2>&1&CD/usr/local/redis/cluster/16002&& redis-server redis.conf > Redis.log2>&1&CD/usr/local/redis/cluster/16003&& redis-server redis.conf > Redis.log2>&1&CD/usr/local/redis/cluster/16004&& redis-server redis.conf > Redis.log2>&1&CD/usr/local/redis/cluster/16005&& redis-server redis.conf > Redis.log2>&1&CD/usr/local/redis/cluster/16006&& redis-server redis.conf > Redis.log2>&1&
# #启动之后使用命令查看redis的启动情况
Ps-ef|grep Redis
Create a cluster to communicate the above instances to each other
#创建集群, let the above instances communicate with each other (1indicates that each master is assigned a salve)/USR/LOCAL/REDIS/SRC/REDIS-TRIB.RB Create--replicas1 127.0.0.1:16001 127.0.0.1:16002 127.0.0.1:16003 127.0.0.1:16004 127.0.0.1:16005 127.0.0.1:16006
The cluster creation is complete, and you can use the following command to view the relevant information:
#查看集群目前状况redis 16001 #打印集群的信息cluster info# Lists all nodes currently known to the cluster, as well as information about those nodes. Cluster Nodes
Output information:
127.0.0.1:16002Master-0 1439345771781 2Connected5461-10922127.0.0.1:16003Master-0 1439345772286 3Connected10923-16383127.0.0.1:16001Myself,master-0 0 1Connected0-5460127.0.0.1:16004Slave 2566ea486fc30c911aafaf1b71130fd24a38dba90 1439345772791 4Connected127.0.0.1:16005Slave edea1e50bd224c6895b1904bce79e83fa07d60170 1439345772286 5Connected127.0.0.1:16006Slave ab06e033698627ce0ecd4c8c645585a1ae70cc840 1439345771276 6Connected
From the above information can be seen clearly which is the master node, from the node.
#将节点的配置文件保存到硬盘里
Cluster Saveconfig
#------------------------Test-----------------------------------
#连接端口 (can use another port test 16001, 16006)
Redis-cli-c-P 16001
127.0.0.1:16001> Set key001 v001
127.0.0.1:16001> Get key001
Normal output information, cluster establishment is successful, cluster construction is completed.
Good luck!!
Installation testing of Redis clusters (pseudo-distribution mode-master-slave replication)