zoukankan      html  css  js  c++  java
  • redis-cluster安装

    redis cluster集群安装---仅作参考
    当前安装的redis集群为
    db1:172.20.3.81
    db2:172.20.3.82
    db3:172.20.3.83

    实现目标,cluster集群三台6几点,3主3从高可用集群,具体逻辑和原理请参考官方文档
    

    1.下载对应的redis安装包--(官网下载对应的源码版本)

    	
    	mkdir /application -p && cd /application
    	
    	wget http://download.redis.io/releases/redis-3.2.9.tar.gz   #复制到另外2台上,按照自己的版本来
    	
    	scp redis-3.2.9.tar.gz 172.20.3.82:/application/
    		
    	scp redis-3.2.9.tar.gz 172.20.3.83:/application/
    

    2.编译

    	yum -y install gcc automake autoconf libtool make
    	
    	tar zxf redis-3.2.9.tar.gz -C /opt/redis_cluster/ 
    	
    	ln -s /opt/redis_cluster/redis-3.2.9/ /opt/redis_cluster/redis
    	
    	cd /opt/redis_cluster/redis
    	
    	make  && make install 
    

    3.db1 操作

    	mkdir -p /opt/redis_cluster/redis_{6380,6381}/{conf,logs,pid}
    	mkdir -p /data/redis_cluster/redis_{6380,6381}
    	
    	cat >/opt/redis_cluster/redis_6380/conf/redis_6380.conf<<EOF
    	bind 172.20.3.81
    	port 6380
    	daemonize yes
    	pidfile "/opt/redis_cluster/redis_6380/pid/redis_6380.pid"
    	logfile "/opt/redis_cluster/redis_6380/logs/redis_6380.log"
    	dbfilename "redis_6380.rdb"
    	dir "/data/redis_cluster/redis_6380/"
    	cluster-enabled yes
    	cluster-config-file nodes_6380.conf
    	cluster-node-timeout 15000
    	EOF
    	
    	
    	cd /opt/redis_cluster/
    	cp redis_6380/conf/redis_6380.conf redis_6381/conf/redis_6381.conf
    	sed -i 's#6380#6381#g' redis_6381/conf/redis_6381.conf 
    	rsync -avz /opt/redis_cluster/redis_638* 172.20.3.82:/opt/redis_cluster/
    	rsync -avz /opt/redis_cluster/redis_638* 172.20.3.83:/opt/redis_cluster/
    	redis-server /opt/redis_cluster/redis_6380/conf/redis_6380.conf
    	redis-server /opt/redis_cluster/redis_6381/conf/redis_6381.conf
    
    1. db2操作
    #按照自己的ip地址替换
    	find /opt/redis_cluster/redis_638* -type f -name "*.conf"|xargs sed -i "/bind/s#81#82#g"        
    	mkdir -p /data/redis_cluster/redis_{6380,6381}
    	redis-server /opt/redis_cluster/redis_6380/conf/redis_6380.conf
    	redis-server /opt/redis_cluster/redis_6381/conf/redis_6381.conf
    
    1. db3操作
    #按照自己的ip地址替换
    	find /opt/redis_cluster/redis_638* -type f -name "*.conf"|xargs sed -i "/bind/s#81#83#g"        
    	mkdir -p /data/redis_cluster/redis_{6380,6381}
    	redis-server /opt/redis_cluster/redis_6380/conf/redis_6380.conf
    	redis-server /opt/redis_cluster/redis_6381/conf/redis_6381.conf
    

    6.至此6个redis 实例已启动完毕,需自行确认 ps -ef |grep redis 进行确认

    7.cluster集群发现

    	redis-cli -h 172.20.3.81 -p 6380 CLUSTER MEET 172.20.3.81 6381
    	redis-cli -h 172.20.3.81 -p 6380 CLUSTER MEET 172.20.3.82 6380
    	redis-cli -h 172.20.3.81 -p 6380 CLUSTER MEET 172.20.3.82 6381
    	redis-cli -h 172.20.3.81 -p 6380 CLUSTER MEET 172.20.3.83 6380
    	redis-cli -h 172.20.3.81 -p 6380 CLUSTER MEET 172.20.3.83 6381
    

    8.分配槽位

    	redis-cli -h 172.20.3.81 -p 6380 CLUSTER ADDSLOTS {0..5461}
    	redis-cli -h 172.20.3.82 -p 6380 CLUSTER ADDSLOTS {5462..10923}
    	redis-cli -h 172.20.3.83 -p 6380 CLUSTER ADDSLOTS {10924..16383}
    	
    	测试: redis-cli -h 172.20.3.81 -p 6380 CLUSTER INFO
               redis-cli -h 172.20.3.81 -p 6380 CLUSTER nodes
    		   redis-cli -c -h 172.20.3.81 -p 6380 set k1 v1
    

    9.配置高可用

    	redis-cli -c -h db01 -p 6381 CLUSTER REPLICATE db02:6380的ID 
    	redis-cli -c -h db02 -p 6381 CLUSTER REPLICATE db03:6380的ID 
    	redis-cli -c -h db03 -p 6381 CLUSTER REPLICATE db01:6380的ID
    	#下面为模拟实列,按照自身的情况来修改
    
    
    	[root@elk1 redis_cluster]# redis-cli -c -h 172.20.3.81 -p 6380 CLUSTER NODES
    	15d285dc3e314342537be32ce53fc8e2f75c9997 172.20.3.82:6381 master - 0 1622786086573 5 connected
    	f9b397188c3bd4b98609dc60c1ad93e68f32eb41 172.20.3.81:6380 myself,master - 0 0 0 connected 0-5461
    	12937a35f7f65082441f345bc2e3faaf407b70c4 172.20.3.83:6380 master - 0 1622786083101 2 connected 10924-16383
    	0d0cc2bc33f01ccdcb9dc1ce39ae546883142c11 172.20.3.82:6380 master - 0 1622786084125 3 connected 5462-10923
    	f39fc45d571497f06a8c72b575e8617adf5ef375 172.20.3.83:6381 master - 0 1622786085144 4 connected
    	68a7556d10f1e3157c4121d1c3db84e6cdd75ddc 172.20.3.81:6381 master - 0 1622786086167 1 connected
    
    	配置第一个slave
    	redis-cli -c -h 172.20.3.81 -p 6381 CLUSTER REPLICATE 0d0cc2bc33f01ccdcb9dc1ce39ae546883142c11
    	配置第二个slave
    	redis-cli -c -h 172.20.3.82 -p 6381 CLUSTER REPLICATE 12937a35f7f65082441f345bc2e3faaf407b70c4
    	配置第三个slave
    	redis-cli -c -h 172.20.3.83 -p 6381 CLUSTER REPLICATE f9b397188c3bd4b98609dc60c1ad93e68f32eb41
    	
    	查看最终集群情况
    	[root@elk1 redis_cluster]# redis-cli -c -h 172.20.3.81 -p 6380 CLUSTER NODES
    	15d285dc3e314342537be32ce53fc8e2f75c9997 172.20.3.82:6381 slave 12937a35f7f65082441f345bc2e3faaf407b70c4 0 1622786448133 5 connected
    	f9b397188c3bd4b98609dc60c1ad93e68f32eb41 172.20.3.81:6380 myself,master - 0 0 0 connected 0-5461
    	12937a35f7f65082441f345bc2e3faaf407b70c4 172.20.3.83:6380 master - 0 1622786450174 2 connected 10924-16383
    	0d0cc2bc33f01ccdcb9dc1ce39ae546883142c11 172.20.3.82:6380 master - 0 1622786449153 3 connected 5462-10923
    	f39fc45d571497f06a8c72b575e8617adf5ef375 172.20.3.83:6381 slave f9b397188c3bd4b98609dc60c1ad93e68f32eb41 0 1622786445080 4 connected
    	68a7556d10f1e3157c4121d1c3db84e6cdd75ddc 172.20.3.81:6381 slave 0d0cc2bc33f01ccdcb9dc1ce39ae546883142c11 0 1622786447114 3 connected
    
  • 相关阅读:
    LA3971组装电脑
    LA3971组装电脑
    LA3905流星
    LA3905流星
    LA3902网络
    LA3902网络
    LA3708墓地雕塑
    洛谷 P2330 [SCOI2005]繁忙的都市(最小生成树)
    最小生成树 & 洛谷P3366【模板】最小生成树 & 洛谷P2820 局域网
    洛谷 P1372 又是毕业季I
  • 原文地址:https://www.cnblogs.com/dinghc/p/15161332.html
Copyright © 2011-2022 走看看