柚子快報激活碼778899分享:redis集群搭建(三主三從)
柚子快報激活碼778899分享:redis集群搭建(三主三從)
redis集群搭建(三主三從)
文章目錄
redis集群搭建(三主三從)一、環(huán)境準(zhǔn)備二、環(huán)境搭建三、創(chuàng)建集群四、設(shè)置密碼五、加入到開機(jī)自啟動服務(wù)六、redis故障處理再加入
一、環(huán)境準(zhǔn)備
每臺機(jī)器有兩個節(jié)點,一共六個節(jié)點(三主三從),主節(jié)點和從節(jié)點不在同一臺機(jī)器上,有條件當(dāng)然可以選擇使用6臺機(jī)器
地址端口172.24.8.26379 6380172.24.8.36379 6380172.24.8.36379 6380
二、環(huán)境搭建
首先確保防火墻處于關(guān)閉狀態(tài)否則創(chuàng)建集群時候會報錯 這種情況只需要關(guān)閉防火墻即可
systemctl stop firewalld && systemctl disable firewalld
安裝語言環(huán)境
yum -y install gcc gcc-c++
創(chuàng)建目錄 mkdir -p /data/redis/redis_cluster/6379 mkdir -p /data/redis/redis_cluster/6380 拷貝bin/redis.conf 6379和6380的目錄下面 并分別修改他們的端口 redis.conf 配置文件
bind 172.24.8.2
#requirepass oa123456
daemonize yes
pidfile /var/run/redis_6379.pid
logfile ""
stop-writes-on-bgsave-error no
dir ./
maxmemory 1GB
maxmemory-policy allkeys-lru
appendonly no
appendfilename "appendonly.aof"
no-appendfsync-on-rewrite no
aof-use-rdb-preamble yes
#新增
cluster-enabled yes
cluster-config-file nodes_6379.conf
cluster-node-timeout 15000
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
supervised no
loglevel notice
databases 16
always-show-logo yes
rdbcompression yes
rdbchecksum yes
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
appendfsync everysec
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated 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
啟動redis
bin/redis-server redis_cluster/6379/redis.conf
bin/redis-server redis_cluster/6380/redis.conf
三、創(chuàng)建集群
bin/redis-cli --cluster create 172.24.8.2:6379 172.24.8.2:6380 172.24.8.3:6379 172.24.8.3:6380 172.24.8.4:6379 172.24.8.4:6380 --cluster-replicas 1 -a oa123456
出現(xiàn)綠色表示集群創(chuàng)建成功
登錄進(jìn)去并查看集群各節(jié)點
bin/redis-cli -c -h 172.24.8.2 -p 6379
cluster nodes
cluster info
驗證集群
四、設(shè)置密碼
172.24.8.2:6379> config set requirepass oa123456
OK
172.24.8.2:6379> config rewrite
(error) NOAUTH Authentication required.
172.24.8.2:6379> auth oa123456
OK
172.24.8.2:6379> config rewrite
OK
172.24.8.2:6379>
Redis 出現(xiàn)(error)NOAUTH Authentication required 使用密碼登錄任意節(jié)點
bin/redis-cli -c -h 172.24.8.4 -p 6380 -a oa123456
五、加入到開機(jī)自啟動服務(wù)
第一個redis端口6379
vim /etc/systemd/system/redis6379.service
內(nèi)容添加如下
[Unit]
Description=redis6379-server
After=network.target
[Service]
Type=forking
ExecStart=/data/redis/bin/redis-server /data/redis/redis_cluster/6379/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
啟動與停止與開機(jī)自啟動
systemctl daemon-reload
systemctl start redis6379.service
systemctl stop redis6379.service
systemctl enable redis6379.service
第二個redis端口6380
vim /etc/systemd/system/redis6380.service
內(nèi)容添加如下
[Unit]
Description=redis6380-server
After=network.target
[Service]
Type=forking
ExecStart=/data/redis/bin/redis-server /data/redis/redis_cluster/6380/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
啟動與停止與開機(jī)自啟動
systemctl daemon-reload
systemctl start redis6380.service
systemctl stop redis6380.service
systemctl enable redis6380.service
六、redis故障處理再加入
檢查節(jié)點狀態(tài)
./redis-cli -h 172.24.8.40 -p 6380 -a oa123456
cluster nodes
可以看到2個節(jié)點失去聯(lián)系 強(qiáng)制移除故障節(jié)點
本案例nodeID分別為
2396c1bf141981ebffa199e3ac196a34d7ed7622
5699fc668ca3d3fb0d83488f74aaecc17fe8c145
cluster forget 2396c1bf141981ebffa199e3ac196a34d7ed7622
cluster forget 5699fc668ca3d3fb0d83488f74aaecc17fe8c145
重新加入集群
./redis-cli -h 172.24.8.35 -a oa123456 -p 6380 cluster meet 172.24.8.40 6380
發(fā)現(xiàn)變成五主一從
調(diào)整主從節(jié)點關(guān)系 將主節(jié)點變成從節(jié)點
./redis-cli -h 172.24.8.35 -p 6381 -a oa123456 cluster replicate 2146d339234fb9916e3510325e61047f41b04a18
bin/redis-cli -c -h 172.24.8.2 -a oa123456 --cluster add-node 172.24.8.3:6379 172.24.8.3:6380 --cluster-slave --cluster-master-id 7ff17164a1dd665448a49f6526ea
33d036709b34
搭建集群時報錯[ERR] Not all 16384 slots are covered by nodes. 其原因: 這個往往是由于主node移除了,但是并沒有移除node上面的slot,從而導(dǎo)致了slot總數(shù)沒有達(dá)到16384,其實也就是slots分布不正確。所以在刪除節(jié)點的時候一定要注意刪除的是否是Master主節(jié)點。 解決辦法: 1、使用如下命令來修復(fù)集群
# redis-cli --cluster fix host:port
bin/redis-cli --cluster fix 172.24.8.3:6379 -a oa123456
2、修復(fù)完成后再用check命令檢查下是否正確,其命令如下:
# redis-cli --cluster check host:port
bin/redis-cli --cluster check 172.24.8.3:6379 -a oa123456
redis-cli --cluster check 127.0.0.1:6379
3、如果分布不均勻那可以使用下面的方式重新分配slot
# redis-cli --cluster reshar host:port
redis-cli --cluster reshard 127.0.0.1:6379
握手
echo 'cluster meet 172.24.8.3 6379' | /data/redis/bin/redis-cli -h 172.24.8.2 -p 6379 -a "oa123456"
柚子快報激活碼778899分享:redis集群搭建(三主三從)
精彩鏈接
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。
轉(zhuǎn)載請注明,如有侵權(quán),聯(lián)系刪除。