一、查检系统编译环境
yum install gcc make
rpm -qa gcc make
make-3.82-23.el7.x86_64
gcc-4.8.5-36.el7.x86_64
二、解压软件包与安装
mkdir /usr/local/redis-cluster
tar -xvf redis-6.2.5.tar.gz -C /usr/local/redis-cluster
cd /usr/local/redis-cluster/redis-6.2.5
make
三、文件和目录准备
cd /usr/local/redis-cluster
mkdir 6380 6381 6382 6383 6384 6385 #启6个redis,组成一个redis集群
ls
#将redis-cli redis.conf redis-server文件放到redis-cluster目录下,便于使用
redis-cli redis.conf redis-server
四、修改redis.conf参数,并放到6个创建的目录中
tree 6380 6381 6382 6383 6384 6385
6380
└── redis.conf
6381
└── redis.conf
6382
└── redis.conf
6383
└── redis.conf
6384
└── redis.conf
6385
└── redis.conf
#redis.conf
bind 10.133.0.243 127.0.0.1
protected-mode yes
port 6380
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /opt/redis-cluster/9001/redis.pid
loglevel notice
logfile /opt/redis-cluster/9001/redis.log
databases 16
save 900 10
save 300 100
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /opt/redis-cluster/9001
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
repl-backlog-size 209715200
slave-priority 100
requirepass !@#QWEasd
masterauth !@#QWEasd
rename-command CONFIG "GJZ_CONFIG"
rename-command FLUSHALL "GJZ_FLUSHALL"
rename-command FLUSHDB "GJZ_FLUSHDB"
rename-command SHUTDOWN "GJZ_SHUTDOWN"
maxclients 10000
maxmemory 10737418240
maxmemory-policy allkeys-lru
maxmemory-samples 5
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 200
auto-aof-rewrite-min-size 1073741824
aof-load-truncated yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
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-size -2
list-compress-depth 0
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
五、编写启动脚本
useradd redis -s /sbin/nologin
cd /usr/local/redis-cluster && cat restart.sh
#!/bin/bash
echo "stop cluster......"
/bin/pkill -9 redis
echo "start all nodes......"
/usr/local/redis-cluster/redis-server /usr/local/redis-cluster/6380/redis.conf
/usr/local/redis-cluster/redis-server /usr/local/redis-cluster/6381/redis.conf
/usr/local/redis-cluster/redis-server /usr/local/redis-cluster/6382/redis.conf
/usr/local/redis-cluster/redis-server /usr/local/redis-cluster/6383/redis.conf
/usr/local/redis-cluster/redis-server /usr/local/redis-cluster/6384/redis.conf
/usr/local/redis-cluster/redis-server /usr/local/redis-cluster/6385/redis.conf
ps -ef |grep redis
echo "OK."
六、启动Redis
cd /usr/local/redis-cluster && chmod 755 restart.sh
./restart.sh
七、创建集群
#redis-6创建集群方法
cd /usr/local/redis-cluster
./redis-cli --cluster-replicas 1 --cluster create 10.133.0.243:6380 10.133.0.243:6381 10.133.0.243:6382 10.133.0.243:6383 10.133.0.243:6384 10.133.0.243:6385 -a !@#QWEasd
报错-升级gcc版本(yum安装的gcc是4.8.5的。因此需要升级gcc,升级过程如下)
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
gcc -v