当前位置: 首页 > 工具软件 > Tendis > 使用案例 >

tendis环境部署

南门祯
2023-12-01

1、主机信息

hostnameipport
node01192.168.56.10151001、51002、51003
node02192.168.56.10251001、51002、51003
node03192.168.56.10351001、51002、51003

注意:tendis和redis-cluster 一样,在服务启动之后会默认使用一个port + 10000 。例如 51001 端口的服务还有默认使用一个61001的端口。所以在port规划避免使用 60000以上的端口。

2、安装

下载 :wget https://github.com/Tencent/Tendis/releases/download/2.4.2-rocksdb-v5.13.4/tendisplus-2.4.2-rocksdb-v5.13.4.tgz

解压: tar zxf tendisplus-2.4.2-rocksdb-v5.13.4.tgz && mv tendisplus-2.4.2-rocksdb-v5.13.4 tendisplus-2.4.2

执行脚本:

#!/bin/sh

echo 'export PATH=$PATH:/root/tendisplus-2.4.2/bin' >> /etc/profile
source /etc/profile

basePath="/root/tendisplus-2.4.2/"  #解压包的路径
netCard="enp0s3"					#网卡名称 通过网卡获取本机ip
portList="51001 51002 51003"        #tendis cluster规划的 port
dataPath="/data/scripts"            #tendis数据存放路径

#获取本地IP
ipAddr=`ifconfig |grep -A 1 "${netCard}"|sed -n "2p"|awk '{print $2}'`

for port in $portList 
do
	cd $basePath
	cp -r scripts scripts${port}

	#start.sh
	sed -i "2i path=\`which tendisplus\`" scripts${port}/start.sh
	sed -i "s#../bin/tendisplus #\#../bin/tendisplus #g" scripts${port}/start.sh
	echo "\$path scripts${port}/tendisplus.conf" >> scripts${port}/start.sh

	sed -i "s#home#${dataPath}${port}#g" scripts${port}/start.sh #修改数据路径
	#sed -i 's#scripts/#scripts${port}/#g' scripts${port}/start.sh

	#stop.sh
	sed -i "2i path=\`which redis-cli\`" scripts${port}/stop.sh
	sed -i "s/127.0.0.1/${ipAddr}/g" scripts${port}/stop.sh
	sed -i "s/51002/${port}/g" scripts${port}/stop.sh
	sed -i "s#../bin/redis-cli#\${path}#" scripts${port}/stop.sh

	#configure
	sed -i "s/51002/${port}/g" scripts${port}/tendisplus.conf
	sed -i "2i bind 0.0.0.0" scripts${port}/tendisplus.conf
	sed -i "2i cluster-enabled yes" scripts${port}/tendisplus.conf  #开启集群模式
	sed -i "s#./home#${dataPath}${port}#g" scripts${port}/tendisplus.conf
	
	echo "sh scripts${port}/start.sh" >>startAll.sh
	echo "sh scripts${port}/stop.sh"  >>stopAll.sh

done
 

启动:sh startAall.sh

3.配置tendis集群环境配置

3.1、将所有node加入集群:

注意:redis-cli 使用的是 “192.168.56.101 51001” 登录操作,故操作忽略此ip+port的操作

redis-cli -h 192.168.56.101 -p 51001 cluster meet 192.168.56.101 51002
redis-cli -h 192.168.56.101 -p 51001 cluster meet 192.168.56.101 51003
redis-cli -h 192.168.56.101 -p 51001 cluster meet 192.168.56.102 51001
redis-cli -h 192.168.56.101 -p 51001 cluster meet 192.168.56.102 51002
redis-cli -h 192.168.56.101 -p 51001 cluster meet 192.168.56.102 51003
redis-cli -h 192.168.56.101 -p 51001 cluster meet 192.168.56.103 51001
redis-cli -h 192.168.56.101 -p 51001 cluster meet 192.168.56.103 51002
redis-cli -h 192.168.56.101 -p 51001 cluster meet 192.168.56.103 51003

3.2、分配solt

redis-cli -h 192.168.56.101 -p 51001 cluster addslots {0..5461}
redis-cli -h 192.168.56.101 -p 51002 cluster addslots {5462..10922}
redis-cli -h 192.168.56.101 -p 51003 cluster addslots {10923..16383}

3.3、获取master的 uuid

redis-cli -h 192.168.56.101 -p 51001 cluster nodes
c3407556239732f0b2d350969f8067ece7587a95 192.168.56.101:51001@61001 myself,master - 0 1631691108000 4 connected 0-5461
981563423d298e9bef3725e431d69098dfa4dcc5 192.168.56.101:51003@61003 master - 0 1631691110178 2 connected 10923-16383
4d004a360d8c85250e5184bd878c12d419d8e895 192.168.56.101:51002@61002 master - 0 1631691111183 1 connected 5462-10922

3.4、设置master的从库

redis-cli -h 192.168.56.102 -p 51001 cluster replicate c3407556239732f0b2d350969f8067ece7587a95
redis-cli -h 192.168.56.102 -p 51002 cluster replicate 4d004a360d8c85250e5184bd878c12d419d8e895
redis-cli -h 192.168.56.102 -p 51003 cluster replicate 981563423d298e9bef3725e431d69098dfa4dcc5

redis-cli -h 192.168.56.103 -p 51001 cluster replicate c3407556239732f0b2d350969f8067ece7587a95
redis-cli -h 192.168.56.103 -p 51002 cluster replicate 4d004a360d8c85250e5184bd878c12d419d8e895
redis-cli -h 192.168.56.103 -p 51003 cluster replicate 981563423d298e9bef3725e431d69098dfa4dcc5

4.predixy 服务配置

下载:

https://github.com/joyieldInc/predixy/releases/download/1.0.5/predixy-1.0.5-bin-amd64-linux.tar.gz

解压:

tar zxf predixy-1.0.5-bin-amd64-linux.tar.gz

修改配置:
涉及两个文件:cluster.conf predixy.conf

文件cluster.conf 
	ClusterServerPool {
    MasterReadPriority 60
    StaticSlaveReadPriority 50
    DynamicSlaveReadPriority 50
    RefreshInterval 1
    ServerTimeout 1
    ServerFailureLimit 10
    ServerRetryTimeout 1
    KeepAlive 120
    Servers {
		##写所有节点的ip+port
        + 192.168.56.101:51001
        + 192.168.56.101:51002
        + 192.168.56.101:51003
        + 192.168.56.102:51001
        + 192.168.56.102:51002
        + 192.168.56.102:51003
        + 192.168.56.103:51001
        + 192.168.56.103:51002
        + 192.168.56.103:51003
    }
}

启动: ./bin/predixy conf/predixy.conf

 类似资料: