Redis Cluster 2019(3)Redis Cluster on CentOS
RedisCluster2019(3)RedisClusteronCentOS
Currentreleaseisstill5.0.5
>sudoyuminstallwget
>sudoyumgroupinstall"Developmenttools"
>wgethttp://download.redis.io/releases/redis-5.0.5.tar.gz
>tarzxvfredis-5.0.5.tar.gz
>cdredis-5.0.5
>makedistclean
>make
Duringmake,wemayhavetheseissues
jemalloc/jemalloc.h:Nosuchfileordirectory
Ifso,wemayneedtorunthemakedistcleanagainandthenmake.
Preparetheinstallationdirectory
>mkdir~/tool/redis-5.0.5
>mkdir~/tool/redis-5.0.5/bin
>cpsrc/redis-server~/tool/redis-5.0.5/bin/
>cpsrc/redis-cli~/tool/redis-5.0.5/bin/
>cpsrc/redis-benchmark~/tool/redis-5.0.5/bin/
>mkdir~/tool/redis-5.0.5/conf
>cpredis.conf~/tool/redis-5.0.5/conf/
Softlink
>sudoln-s/home/carl/tool/redis-5.0.5/opt/redis-5.0.5
>sudoln-s/opt/redis-5.0.5/opt/redis
GototheRedisdirectory
>cd/opt/redis
Preparetheclusterconf
>mkdircluster-conf
>mkdircluster-conf/7001
>mkdircluster-conf/7002
Preparethedefaultconfigurationtothecluster
>cpconf/redis.confcluster-conf/7001/
>cpconf/redis.confcluster-conf/7002/
Edittheconfiguration
>vicluster-conf/7001/redis.conf
port7001
appendonlyyes
cluster-enabledyes
cluster-config-filenodes-7001.conf
cluster-node-timeout15000
bind0.0.0.0
>vicluster-conf/7002/redis.conf
port7002
appendonlyyes
cluster-enabledyes
cluster-config-filenodes-7002.conf
cluster-node-timeout15000
bind0.0.0.0
Dothesimilarthingstocentos-dev1,centos-dev2,centos-dev3,orwecanjustcopythemtoothermachines
>scpcentos-dev1:/opt/redis/cluster-conf/7001/redis.conf./cluster-conf/7001/redis.conf
>scpcentos-dev1:/opt/redis/cluster-conf/7002/redis.conf./cluster-conf/7002/redis.conf
Starttheredisserveronall3machines
>bin/redis-server./cluster-conf/7001/redis.conf
>bin/redis-server./cluster-conf/7002/redis.conf
Afterstart6nodesacross3machines,weneedtoinitthecluster,mynetworkinformationisasfollow:
192.168.56.102centos-dev1
192.168.56.111centos-dev2
192.168.56.112centos-dev3
Onmyvirtualboxmachines,Imayneedtostopthefirewallordisablethefirewall
>sudosystemctlstopfirewalld
>sudosystemctldisablefirewalld
>bin/redis-cli--clustercreate192.168.56.102:7001192.168.56.102:7002192.168.56.111:7001192.168.56.111:7002192.168.56.112:7001192.168.56.112:7002--cluster-replicas1
>>>PerformingClusterCheck(usingnode192.168.56.102:7001)
M:fc80c3e30badbc2a0e2ec025caaf5709f52090dc192.168.56.102:7001
slots:[0-5460](5461slots)master
1additionalreplica(s)
M:6f4aae743cf544c03b00cf91b50c97f61fc72c91192.168.56.112:7001
slots:[10923-16383](5461slots)master
1additionalreplica(s)
S:a32cf75ace9e645d1040699097f3f68965e1f3c9192.168.56.112:7002
slots:(0slots)slave
replicatesde80b1038ab53c35b16ee010f7576ef50788fc81
S:8f157bb59e184fe04e1a0654cefb7ca72c904234192.168.56.111:7002
slots:(0slots)slave
replicatesfc80c3e30badbc2a0e2ec025caaf5709f52090dc
S:a1f8b4433acf6b8b9a09852aafa028cd4534590e192.168.56.102:7002
slots:(0slots)slave
replicates6f4aae743cf544c03b00cf91b50c97f61fc72c91
M:de80b1038ab53c35b16ee010f7576ef50788fc81192.168.56.111:7001
slots:[5461-10922](5462slots)master
1additionalreplica(s)
[OK]Allnodesagreeaboutslotsconfiguration.
>>>Checkforopenslots...
>>>Checkslotscoverage...
[OK]All16384slotscovered.
Thentheclusterisready.
AddthebintothePATHtomakemylifeeasier
>vi~/.bash_profile
PATH=$PATH:/opt/redis/bin
Applythechange
>.~/.bash_profile
Connecttoverify
>redis-cli-c-hcentos-dev1-p7001
centos-dev1:7001>setfoobar
->Redirectedtoslot[12182]locatedat192.168.56.112:7001
OK
192.168.56.112:7001>getfoo
"bar"
192.168.56.112:7001>
Showalltheclusternodes
192.168.56.112:7001>clusternodes
6f4aae743cf544c03b00cf91b50c97f61fc72c91192.168.56.112:7001@17001myself,master-015659811640005connected10923-16383
8f157bb59e184fe04e1a0654cefb7ca72c904234192.168.56.111:7002@17002slavefc80c3e30badbc2a0e2ec025caaf5709f52090dc015659811650004connected
fc80c3e30badbc2a0e2ec025caaf5709f52090dc192.168.56.102:7001@17001master-015659811676401connected0-5460
a1f8b4433acf6b8b9a09852aafa028cd4534590e192.168.56.102:7002@17002slave6f4aae743cf544c03b00cf91b50c97f61fc72c91015659811660005connected
de80b1038ab53c35b16ee010f7576ef50788fc81192.168.56.111:7001@17001master-015659811660003connected5461-10922
a32cf75ace9e645d1040699097f3f68965e1f3c9192.168.56.112:7002@17002slavede80b1038ab53c35b16ee010f7576ef50788fc81015659811666276connected
Somewarningsneedtocare:
Warning#1
5976:M16Aug201901:01:24.396#WARNING:TheTCPbacklogsettingof511cannotbeenforcedbecause/proc/sys/net/core/somaxconnissettothelowervalueof128.
Solution:
https://www.jianshu.com/p/7319c6d6f365
>sudovi/etc/sysctl.conf
net.core.somaxconn=2048
Verifythechange
>sudosysctl-p
net.core.somaxconn=2048
Warning#2
5976:M16Aug201901:01:24.396#WARNINGovercommit_memoryissetto0!Backgroundsavemayfailunderlowmemorycondition.Tofixthisissueadd'vm.overcommit_memory=1'to/etc/sysctl.confandthenrebootorrunthecommand'sysctlvm.overcommit_memory=1'forthistotakeeffect.
Solution:
https://stackoverflow.com/questions/41203492/solving-redis-warnings-on-overcommit-memory-and-transparent-huge-pages-for-ubunt
>sudovi/etc/sysctl.conf
vm.overcommit_memory=1
Verifythechange
>sudosysctl-p
net.core.somaxconn=2048
vm.overcommit_memory=1
Warning#3
5976:M16Aug201901:01:24.396#WARNINGyouhaveTransparentHugePages(THP)supportenabledinyourkernel.ThiswillcreatelatencyandmemoryusageissueswithRedis.Tofixthisissuerunthecommand'echonever>/sys/kernel/mm/transparent_hugepage/enabled'asroot,andaddittoyour/etc/rc.localinordertoretainthesettingafterareboot.RedismustberestartedafterTHPisdisabled.
Solution:
https://github.com/docker-library/redis/issues/55
Needtosutorootusertodothis
>echonever>/sys/kernel/mm/transparent_hugepage/enabled
>echonever>/sys/kernel/mm/transparent_hugepage/defrag
>cat/sys/kernel/mm/transparent_hugepage/enabled
alwaysmadvise[never]
>cat/sys/kernel/mm/transparent_hugepage/defrag
alwaysmadvise[never]
References:
https://www.psychz.net/client/question/en/turn-off-firewall-centos-7.html
https://github.com/junegunn/redis-stat
https://www.jianshu.com/p/7319c6d6f365