[root@localhost local]# tar -xzf redis-5.0.5.tar.gz [root@localhost local]# cd redis-5.0.5 [root@localhost redis-5.0.5]# make [root@localhostredis-5.0.5]# cd ./src #进入到redis-5.0.5/src 文件目录下 [root@localhost src]# make test # Hint: It's a good idea to run 'make test' ;) INSTALL install INSTALL install INSTALL install INSTALL install INSTALL install #redis 可执行脚本都在 utils目录下 [root@localhost redis-5.0.5]# ls utils/ build-static-symbols.tcl hashtable redis_init_script.tpl cluster_fail_time.tcl hyperloglog redis-sha1.rb corrupt_rdb.c install_server.sh releasetools create-cluster lru speed-regression.tcl generate-command-help.rb redis-copy.rb whatisdoing.sh graphs redis_init_script
# 为方便将集群中多个配置文件放在一块管理,可以新建一个redis-conf目录,放置多个redis实例的启动配置文件 [root@localhost redis-conf]# ls redis.conf [root@localhost redis-conf]# vi redis.conf # 将redis改为后台运行 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized. daemonize yes #容许远程访问(宿主机访问) #bind 127.0.0.1 # 设置密码 requirepass foofoo
# 本地客户端登录测试 [root@localhost redis-5.0.5]# redis-cli 127.0.0.1:6379> 127.0.0.1:6379> set test foo (error) NOAUTH Authentication required # 提示需要密码认证 127.0.0.1:6379> AUTH foofoo #输入密码 OK 127.0.0.1:6379> set test foo OK 127.0.0.1:6379> get test "foo"
设置redis开机启动
1 2
[root@localhost redis-conf]# vi /etc/rc.d/rc.local redis-server /usr/local/redis-5.0.5/redis-conf
# WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
# WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command'sysctl vm.overcommit_memory=1'for this to take effect.
# WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. * Ready to accept connections
2.3 测试redis集群情况
登录其中一个redis实例并测试,提示没有slot
1 2 3 4 5
[root@localhost redis-cluster]# redis-cli -p 23451 -c 127.0.0.1:23451> AUTH foofoo OK 127.0.0.1:23451> set test foo (error) CLUSTERDOWN Hash slot not served
[root@localhost redis-cluster]# redis-cli --cluster create 127.0.0.1:23451 127.0.0.1:23452 127.0.0.1:23453 127.0.0.1:23454 127.0.0.1:23455 127.0.0.1:23456 --cluster-replicas 1 -a foofoo Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 127.0.0.1:23455 to 127.0.0.1:23451 Adding replica 127.0.0.1:23456 to 127.0.0.1:23452 Adding replica 127.0.0.1:23454 to 127.0.0.1:23453 >>> Trying to optimize slaves allocation for anti-affinity [WARNING] Some slaves are in the same host as their master
[root@localhost redis-cluster]# redis-cli -p 23451 -c 127.0.0.1:23451> AUTH foofoo OK 127.0.0.1:23451> set test foo -> Redirected to slot [6918] located at 127.0.0.1:23452 (error) NOAUTH Authentication required
[root@localhost redis-cluster]# redis-cli -p 23451 a foofoo -c 127.0.0.1:23451> set test foo -> Redirected to slot [6918] located at 127.0.0.1:23452 OK 127.0.0.1:23452> set cluster-test 11 -> Redirected to slot [14783] located at 127.0.0.1:23453 OK 127.0.0.1:23453> get test -> Redirected to slot [6918] located at 127.0.0.1:23452 "foo"