一.搭建redis cluster(本例是在测试环境搭建,所以cluster6个节点及proxy节点都在一台机器)
1.下载gcc及依赖
redis 5.0之后版本的redis-cli --cluster已经实现了集群的创建,无需依赖redis-trib.rb,包括ruby环境
gcc版本需要升级,编译安装需要gcc5.3以上

yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash

由于测试机无法连接互联网,只能手动下载安装包安装
https://ftp.jaist.ac.jp/pub/GNU/gcc/gcc-9.1.0/
下载 gcc-9.1.0.tar.gz
上传至服务器
解压

tar -xzvf gcc-9.1.0.tar.gz
cd gcc-9.1.0
./contrib/download_prerequisites#报错,手动下载依赖
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2

上传至gcc-9.1.0文件夹中
执行

./contrib/download_prerequisites
mkdir build
cd build
../configure --prefix=/usr/local/gcc9 --enable-languages=c,c++,go  --disable-multilib
make -j30
make install

2.替换链接
由于指定了安装目录,所以系统的gcc文件需要手动替换

mv  /usr/bin/gcc  /usr/bin/gcc_bak
mv /usr/bin/g++ /usr/bin/g++_bak
mv /usr/local/bin/gcc  /usr/local/bin/gcc_bak
mv /usr/local/bin/g++ /usr/local/bin/g++_bak
ln -s /usr/local/gcc9/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc9/bin/gcc /usr/local/bin/gcc
ln -s /usr/local/gcc9/bin/g++ /usr/bin/g++
ln -s /usr/local/gcc9/bin/g++ /usr/local/bin/g++
mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6_bak
ln -s /usr/local/gcc9/lib64/libstdc++.so.6.0.26 /usr/lib64/libstdc++.so.6
gcc --version # 看下版本对不对

3.安装redis6.0服务

cd /usr/local/
tar xzvf redis-6.0.6.tar.gz
mv redis-6.0.6/ redis
cd redis
make
cd src
make install PREFIX=/usr/local/redis
cp redis-trib.rb /bin/
cd /usr/local/redis/bin/
cp redis-server /bin/
cp redis-cli /bin/
mkdir /export/data/redis_cluster/630{1,2,3,4,5,6}/run -p
mkdir /export/data/redis_cluster/630{1,2,3,4,5,6}/log -p
mkdir /export/data/redis_cluster/630{1,2,3,4,5,6}/conf -p
mkdir /export/data/redis_cluster/630{1,2,3,4,5,6}/rdb -p

4.撰写redis配置文件(6个,需改端口号和路径)

vi /export/data/redis_cluster/6301/conf/redis.conf
bind 0.0.0.0
daemonize yes
pidfile /export/data/redis_cluster/6301/run/redis.pid
port 6301
tcp-backlog 511
timeout 300
tcp-keepalive 0
loglevel notice
maxmemory 1gb
logfile "/export/data/redis_cluster/6301/log/redis.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /export/data/redis_cluster/6301/rdb
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly yes
appendfilename "redis.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 15000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

5.启动服务

redis-server /export/data/redis_cluster/6301/conf/redis.conf
redis-server /export/data/redis_cluster/6302/conf/redis.conf
redis-server /export/data/redis_cluster/6303/conf/redis.conf
redis-server /export/data/redis_cluster/6304/conf/redis.conf
redis-server /export/data/redis_cluster/6305/conf/redis.conf
redis-server /export/data/redis_cluster/6306/conf/redis.conf

6.初始化集群

 redis-cli --cluster create 10.10.10.10:6301 10.10.10.10:6302 10.10.10.10:6303 10.10.10.10:6304 10.10.10.10:6305 10.10.10.10:6306 --cluster-replicas 1

二.配置redis cluster proxy
1.下载安装redis cluster proxy

https://github.com/RedisLabs/redis-cluster-proxy/tree/1.0
cd /usr/local
unzip redis-cluster-proxy-1.0.zip
cd redis-cluster-proxy-1.0
make install

2.修改配置文件
vi /usr/local/redis-cluster-proxy-1.0/proxy.conf
主要参数修改

cluster 10.10.10.10:6301
cluster 10.10.10.10:6302
cluster 10.10.10.10:6303
cluster 10.10.10.10:6304
cluster 10.10.10.10:6305
cluster 10.10.10.10:6306
port 7777
bind 0.0.0.0
threads 8
logfile "/usr/local/redis_cluster_proxy-1.0/redis_cluster_proxy.log"
enable-cross-slot yes

3.启动proxy

nohup redis-cluster-proxy -c /usr/local/redis-cluster-proxy-1.0/proxy.conf &

4.测试连接

redis-cli -p 7777
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐