【Linux环境搭建】十三、Linux(CentOS7) Redis集群模式和哨兵模式配置
生活随笔
收集整理的這篇文章主要介紹了
【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 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集群模式和哨兵模式配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 模拟支付宝支付功能
- 下一篇: Linux下飞鸽传书项目设计书,linu