日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

【Linux环境搭建】十三、Linux(CentOS7) Redis集群模式和哨兵模式配置

發布時間:2024/1/1 linux 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Linux环境搭建】十三、Linux(CentOS7) Redis集群模式和哨兵模式配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、Redis集群配置

創建集群目錄

mkdir -p /usr/local/redis-cluster cd /usr/local/redis-cluster mkdir 6379 6378

修改配置文件

vi redis.conf daemonize yes port 6379 dir /usr/local/redis-cluster/6379/ cluster-enabled yes #啟動集群模式 cluster-config-file nodes-6379.conf cluster-node-timeout 5000 bind 0.0.0.0 protected-mode no appendonly yes #如果要設置密碼需要增加如下配置:#(設置redis訪問密碼) requirepass 123456#(設置集群節點間訪問密碼,跟上面一致) masterauth 123456

把修改后的配置文件,copy到6379、6378,修改第2、3、5項里的端口號,可以用批量
%s/源字符串/目的字符串/g

啟動redis:

./redis-server /usr/local/redis-cluster/6379/redis.conf ./redis-server /usr/local/redis-cluster/6378/redis.conf

查看是否啟動成功

ps -ef | grep redis

用redis-cli創建整個redis集群:
測試環境:

./redis-cli --cluster create 192.168.10.195:6379 192.168.10.195:6378 192.168.10.124:6379 192.168.10.124:6378 192.168.10.100:6379 192.168.10.100:6378 --cluster-replicas 1 -a sbjcptTest

生產環境:

./redis-cli --cluster create 10.1.8.111:6301 10.1.8.111:6302 10.1.8.112:6303 10.1.8.112:6304 10.1.8.113:6305 10.1.8.113:6306 --cluster-replicas 1 -a sbjcptTest

驗證集群:

./redis-cli -c -a sbjcptTest -h 192.168.10.195 -p 6379./redis-cli -c -a xxx -h 10.1.8.111 -p 6301./redis-cli -c -a sbjcptTest -h 10.1.8.112 -p 6301

常用命令:

# 查看集群信息 cluster info # 查看節點列表 cluster nodes

二、Redis哨兵模式配置(主備):

創建數據存放目錄

mkdir /data mkdir /data/redis mkdir /data/redis/redis-log mkdir /data/redis/data

首先配置Redis的主服務器,修改redis.conf文件如下

# 使得Redis服務器可以跨網絡訪問 bind 0.0.0.0 dir "/data/redis/data" daemonize yes logfile "/data/redis/redis-log/redis.log" # 設置密碼 requirepass "123456" # 主服務器密碼,注意:有關slaveof的配置只是配置從服務器,主服務器不需要配置 masterauth 123456

配置Redis的從服務器,修改配置文件redis.conf

# 使得Redis服務器可以跨網絡訪問 bind 0.0.0.0 dir "/data/redis/data" daemonize yes logfile "/data/redis/redis-log/redis.log"# 設置密碼 requirepass "123456"# 主服務器密碼,,這個都要配置,不然主從無法用 masterauth 123456 # 注意:有關slaveof的配置只是配置從服務器,主服務器不需要配置 slaveof 192.168.10.195 6379 # 關閉防火墻: systemctl stop firewalld.service systemctl disable firewalld.service systemctl status firewalld.service # 啟動:./redis-server ../redis.conf # 查看集群是否正常: redis-cli -h 192.168.10.195 -p 6379 -a 123456 info Replication [root@localhost src]# redis-cli -h 192.168.10.195 -p 6379 -a 123456 info Replication Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. # Replication role:master connected_slaves:2 slave0:ip=192.168.10.100,port=6379,state=online,offset=70,lag=0 slave1:ip=192.168.10.124,port=6379,state=online,offset=70,lag=0 master_replid:808f22bacf3af9192301aba5c63afff7d60f3b41 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:70 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:70# 測試 redis-cli -h 192.168.10.195 -p 6379 -a 123456 AUTH 123456 set k1 v1 exit # 測試 redis-cli -h 192.168.10.124 -p 6379 -a 123456 AUTH 123456 get k1

安裝哨兵

# 3臺Redis服務器都需執行 vi sentinel.conf mkdir /data/redis/sentinel-log dataport 26379 protected-mode no daemonize yes pidfile /var/run/redis-sentinel.pid logfile "/data/redis/sentinel-log/sentinel.log" dir /tmp sentinel monitor mymaster 192.168.10.195 6379 2 sentinel down-after-milliseconds mymaster 30000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 180000 sentinel deny-scripts-reconfig yes sentinel auth-pass mymaster 123456

啟動哨兵:

./redis-sentinel ../sentinel.conf

測試查看哨兵:

./redis-cli -h 192.168.10.195 -p 26379 INFO Sentinel./redis-cli -h 192.168.10.195 -p 6379 -a 123456 info Replication./redis-cli -h 10.1.8.112 -p 26379 INFO Sentinel./redis-cli -h 10.1.8.112 -p 6379 -a 123456 info Replication

關閉命令:

pkill redis-sentinelpkill redis-server

總結

以上是生活随笔為你收集整理的【Linux环境搭建】十三、Linux(CentOS7) Redis集群模式和哨兵模式配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。