集群式部署redis
介绍:
三台机器
001、002、003 然后再三台机器上面都部署redis_6379、redis_6380做主从,然后三台机器上面做集群
1、安装/解压redis
mkdir -p /data/applications/
wget https://download.redis.io/releases/redis-5.0.14.tar.gz
tar -xzf ./redis-5.0.14.tar.gz
cd ./redis-5.0.14/
2、编译-指定目录--/data/applications/redis
make && make install PREFIX=/data/applications/redis
3、创建工作/数据目录
mkdir -p /data/applications/redis/{conf,data,log}
4、创建主从配置文件目录(6379/6380服务)
mkdir -p /data/applications/redis/conf/{6379,6380}
4、编写redis配置文件(两个文件配置内容几乎一致,只有端口指定不一样)
vim /data/applications/redis/conf/6379/redis.conf
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /data/applications/redis/data/redis.pid
#打开集群
cluster-enabled yes
cluster-config-file /data/applications/redis/conf/6379/redis_node.conf
#节点互连超时时间,毫秒为单位
cluster-node-timeout 5000
#开启主从切换,50s超时主从切换。
cluster-require-full-coverage no
cluster-slave-validity-factor 10
#设置密码
requirepass abcabc
#设置主从同步密码
masterauth abcabc
loglevel notice
logfile /data/applications/redis/log/redis.log
databases 16
always-show-logo yes
#关闭rdb
#save 900 1
#save 300 10
#save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
#dbfilename dump.rdb
dir /data/applications/redis/data
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
#开启aof模式
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
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
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
5、配置服务化,编写6379、6380的redis服务
sudo vi /etc/systemd/system/redis-6379.service
[Unit]
Description=Redis Server
Documentation=https://redis.io/
Requires=network.target
After=network.target[Service]
Type=forking
User=huace
Group=huace
ExecStart=/data/applications/redis/bin/redis-server /data/applications/redis/conf/6379/redis.conf
ExecStop=/data/applications/redis/bin/redis-cli shutdown
Restart=on-failure[Install]
WantedBy=multi-user.target
sudo vi /etc/systemd/system/redis-6380.service
6、服务自启/启动服务/重载服务化
sudo systemctl daemon-reload
sudo systemctl enable redis-6379.service
sudo systemctl enable redis-6380.service
sudo systemctl start redis-6379
sudo systemctl start redis-6380
7、查看redis服务端口--验证
netstat -lntp
8、初始化redis
cd /data/applications/redis/bin/
./redis-cli -a abcabc --cluster create 所有机器的ip:6379 所有机器:6380 --cluster-replicas 1
./redis-cli -a abcabc cluster info