Configure Redis cluster to two machines and 6 instances for the environment.
Operating system CentOS Linux release 7 64-bit
Install dependencies: Download Redis-3.3.1.gem separately this package will correspond to the OS version
Yum-y install tcl yum-y install ruby ruby-devel rubygems rpm-buildgem Install Redis
Unzip the installation:
Cd/usr/local/tar zxvf redis-3.2.3.tar.gzcd redis-3.2.3make && make install
Create a bin, redis6379, redis6380, redis6381 four directories under 172.16.25.220/usr/local/webapp
mkdir binmkdir Redis6379mkdir Redis6380mkdir redis6381
Create a bin, redis6379, redis6380, redis6381 four directories under 172.16.25.72/usr/local/webapp
mkdir binmkdir Redis6379mkdir Redis6380mkdir redis6381
Create the configuration file on both machines and start:
CD/USR/LOCAL/REDIS-3.2.3/SRC/CP mkreleasehdr.sh redis-benchmark redis-sentinel redis-server redis-trib.rb redis-cli/ Usr/local/webapp/bincd/usr/local/webapp/redis6379/touch redis-6379.confcp/usr/local/webapp/redis6379/ redis-6379.conf/usr/local/webapp/redis6380/redis-6380.confcp/usr/local/webapp/redis6379/redis-6379.conf/usr/ Local/webapp/redis6381/redis-6381.confsed-i ' s/6379/6380/g '/usr/local/webapp/redis6380/redis-6380.confsed-i ' s/ 6379/6381/g '/usr/local/webapp/redis6381/redis-6381.conf/usr/local/webapp/bin/redis-server/usr/local/webapp/ redis6379/redis-6379.conf/usr/local/webapp/bin/redis-server/usr/local/webapp/redis6380/redis-6380.conf/usr/ Local/webapp/bin/redis-server/usr/local/webapp/redis6381/redis-6381.conf
Create a cluster (execute on one of the servers)
CD/USR/LOCAL/WEBAPP/BIN/./REDIS-TRIB.RB Create--replicas 1 172.16.25.220:6379 172.16.25.72:6379 172.16.25.220:6380 172.16.25.72:6380 172.16.25.220:6381 172.16.25.72:6381
Cluster Status View:
./redis-cli -c -h 172.16.25.220 -p 6380172.16.25.220:6380> cluster nodes3b64702727c2e047f255ebb6eb111359990fba85 172.16.25.72:6379 master - 0 1478249255421 2 connected 5461-10922a0ac9b45dd7bfabeb7036278c13efb744794adc8 172.16.25.72:6380 master - 0 1478249256423 7 connected 0-5460f612b1d6e362c52ac606a627bcc27a95224ce2b3 172.16.25.220:6381 slave 3b64702727c2e047f255ebb6eb111359990fba85 0 1478249254919 5 connected954200fe3b22806af5afc035cdf0a25899c14ecd 172.16.25.220:6380 myself,slave ca66b71a3e2b7bf75885720b4c7bd3015dd732a1 0 0 3 connectedca66b71a3e2b7bf75885720b4c7bd3015dd732a1 172.16.25.72:6381 master - 0 1478249254419 8 connected 10923-163832b2b3a1885a9a2b64060b20322d3c425b64ca063 172.16.25.220:6379 slave a0ac9b45dd7bfabeb7036278c13efb744794adc8 0 1478249255921 7 connected
To add authentication capabilities to the Redis cluster cluster:
Login The cluster after configuring the password (I test here does not take effect) ./redis-cli -c -h 172.16.25.72 -p 6379config set masterauth mypasswdconfig set requirepass mypasswdconfig Rewrite modify the configuration file: Add the following two lines requirepass "mypasswd" masterauth "mypasswd" Stop redis./redis-cli -c -h 172.16.25.220 -p 6379 shutdown./redis-cli -c -h 172.16.25.220 -p 6380 shutdown./redis-cli -c -h 172.16.25.220 -p 6381 shutdown./ redis-cli -c -h 172.16.25.72 -p 6381 shutdown ./redis-cli -c -h 172.16.25.72 -p 6380 shutdown./redis-cli -c -h 172.16.25.72 -p 6379 shutdown Modify a file under the Redis tool that modifies the gem, I here is the default installation, the path is as follows:/usr/local/share/gems/gems/redis-3.3.1/lib /REDIS/CLIENT.RBVIM /USR/LOCAL/SHARE/GEMS/GEMS/REDIS-3.3.1/LIB/REDIS/CLIENT.RB Start redisservice Redis6379 startservice redis6380 startservice redis6381 start Landing ./redis-cli -c -h 172.16.25.220 -p 6380172.16.25.220:6380> cluster nodesnoauth authentication required.172.16.25.220:6380> auth mypasswdok172.16.25.220:6380> cluster nodes3b64702727c2e047f255ebb6eb111359990fba85 172.16.25.72:6379 master - 0 1478249211338 2 connected 5461-10922a0ac9b45dd7bfabeb7036278c13efb744794adc8 172.16.25.72:6380 master - 0 1478249211839 7 connected 0-5460f612b1d6e362c52ac606a627bcc27a95224ce2b3 172.16.25.220:6381 slave 3b64702727c2e047f255ebb6eb111359990fba85 0 1478249210836 5 connected954200fe3b22806af5afc035cdf0a25899c14ecd 172.16.25.220:6380 myself,slave ca66b71a3e2b7bf75885720b4c7bd3015dd732a1 0 0 3 connectedca66b71a3e2b7bf75885720b4c7bd3015dd732a1 172.16.25.72:6381 master - 0 1478249212341 8 connected 10923-163832b2b3a1885a9a2b64060b20322d3c425b64ca063 172.16.25.220:6379 slave A0ac9b45dd7bfabeb7036278c13efb744794adc8 0 1478249210334 7 connected172.16.25.220:6380> ./redis-cli -c -h 172.16.25.220 -p 6380 -a mypasswd172.16.25.220:6380 > cluster nodes3b64702727c2e047f255ebb6eb111359990fba85 172.16.25.72:6379 master - 0 1478249255421 2 connected 5461-10922a0ac9b45dd7bfabeb7036278c13efb744794adc8 172.16.25.72:6380 master - 0 1478249256423 7 connected 0-5460f612b1d6e362c52ac606a627bcc27a95224ce2b3 172.16.25.220:6381 slave 3b64702727c2e047f255ebb6eb111359990fba85 0 1478249254919 5 connected954200fe3b22806af5afc035cdf0a25899c14ecd 172.16.25.220:6380 myself,slave ca66b71a3e2b7bf75885720b4c7bd3015dd732a1 0 0 3 connectedca66b71a3e2b7bf75885720b4c7bd3015dd732a1 172.16.25.72:6381 master - 0 1478249254419 8 connected 10923-163832b2b3a1885a9a2b64060b20322d3c425b64ca063 172.16.25.220:6379 slave A0ac9b45dd7bfabeb7036278c13efb744794adc8 0 1478249255921 7 connected172.16.25.220:6380> Stop a password-certified cluster ./redis-cli -c -a "MYPASSWD" -h 172.16.25.220 -p 6379 Shutdown
Configure self-booting:
If configured as self-booting, then the relevant permissions will become root permissions, please consider carefully. The script from startup is given below for informational purposes only.
Under/ETC/INIT.D, write script redis6379 and give +x permissions, and then configure the boot level
Chkconfig--add redis6379
Chkconfig--level 345 redis6379 on
The script is as follows:
cat /etc/init.d/redis6379 #!/bin/bash#chkconfig:345 61 61path=/usr/local/bin:/sbin:/usr/ Bin:/bin redisport=6379 exec=/usr/local/bin/redis-server redis_cli=/usr/local/bin/redis-cli pidfile=/usr/local/ webapp/redis6379/redis_6379.pid conf= "/usr/local/webapp/redis6379/redis-6379.conf" case "$" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already Running or crashed " else echo "Starting redis server ..." $ exec $CONF fi if [ "$?" = "0" ] then echo "redis is running ... " fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running " else pid=$ (cat $PIDFILE) echo "stopping  ..." $REDIS _cli -p $REDISPORT SHUTDOWN while [ -x ${pidfile} ] do echo "waiting for redis to shutdown  ..." sleep 1 done echo "redis stopped" fi ;; restart|force-reload) ${0} stop ${0} start ;; *) echo "usage: /etc/init.d/redis { Start|stop|restart|force-reload} " ≫&2 exit 1 esac ### ###########################
The configuration file for the
Redis is as follows:
bind 172.16.25.220protected-mode yesport 6379cluster-enabled yescluster-config-file Nodes.confcluster-node-timeout 5000tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised nopidfile /usr/local/webapp/redis6379/redis_6379.pidloglevel noticelogfile /usr/local/webapp/redis6379/redis_6379.logdatabases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir /usr/local/webapp/redis6379slave-serve-stale-data yesslave-read-only Yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100appendonly yesappendfilename "Appendonly.aof" appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events "" hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size - 2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yesrequirepass "mypasswd" masterauth "MYPASSWD"
This article is from the "just out of the shell of the Birds" blog, please be sure to keep this source http://qhd2004.blog.51cto.com/629417/1869544
redis3.2.3 cluster configuration