📂Redis
🔖redis
2021-08-27 15:06阅读: 469评论: 0推荐: 0

redis 6.2.5一主两从3哨兵配置

一、下载redis

复制代码
## download
wget https://download.redis.io/releases/redis-6.2.5.tar.gz
tar -xzvf  redis-6.2.5.tar.gz  -C /usr/local cd /usr/local 
mv redis-4.0.11 redis 
cd redis 
make
make PREFIX=/usr/local/redis installenv path 
在/etc/profile文件尾部增加redis环境变量,并执行 export REDIS_HOME=/usr/local/redis export PATH=$PATH:$REDIS_HOME/src 最后执行source /etc/profile使之生效
复制代码

 

  

二、配置

master.conf 主库

masterauth mypwd
requirepass mypwd
protected-mode yes
bind 192.168.5.116 #局域网ip或者外网ip
daemonize yes
logfile /codeyuguo/redis/redis.log
appendonly yes
dir /codeyuguo/redis

 

sentinel.conf 哨兵配置

复制代码
sentinel monitor mymaster 192.168.5.116 6379 1
sentinel auth-pass mymaster mypwd
sentinel down-after-milliseconds mymaster 15000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 80000
bind 192.168.5.116
protected-mode yes
daemonize yes
logfile /codeyuguo/redis/sentinel.log
appendonly yes
dir /codeyuguo/redis
复制代码

 

slave.conf 从库配置

masterauth mypwd
requirepass mypwd
protected-mode yes
bind 192.168.6.49
slaveof 192.168.5.116 6379
daemonize yes
logfile /codeyuguo/redis/redis.log

 



三、注意事项

  1. 在创建目录/codeyuguo/redis/conf,并在conf文件夹下创建上述maser.conf/slave.conf/sentinel.conf三个配置文件
  2. 总共3台节点,一个节点上配置主库和哨兵,其他两个节点上配置从库和哨兵
    1. 配置主库 执行 redis-server /codeyuguo/redis/conf/master.conf
    2. 配置从库执行 redis-server /codeyuguo/redis/conf/slave.conf
    3. 配置哨兵 执行 redis-sentinel /codeyuguo/redis/conf/sentinel.conf

四、附录

4. 1 redis启动脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
source /etc/init.d/functions
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
  
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/alidata/redis-6.2.5/redis.conf"
AUTH="Jh****"            
BIND_IP='192.168.5.116'
  
start(){
      
    if [ -f $PIDFILE ]
    then
        echo "$PIDFILE exists, process is already running or crashed"
    else
        echo "Starting Redis server..."
        $EXEC $CONF
    fi
    if [ "$?"="0"
    then 
        echo "Redis is running..."
    fi 
  
  
}
  
stop(){
  
    if [ ! -f $PIDFILE ]
    then
        echo "$PIDFILE does not exist, process is not running"
    else
        PID=$(cat $PIDFILE)
        echo "Stopping ..."
        $CLIEXEC -h $BIND_IP -a $AUTH -p $REDISPORT  SHUTDOWN 2>/dev/null
        sleep 1
        while [ -x /proc/${PID} ]
        do
            echo "Waiting for Redis to shutdown ..."
            sleep 1
        done
            echo "Redis stopped"
    fi
}
  
restart(){
    stop
    start
  
}
status(){
  
    ps -ef|grep redis-server|grep -v grep >/dev/null 2>&1
  
    if [ $? -eq 0 ];then
  
        echo "redis server is running"
  
    else
        echo "redis server is stopped"
  
    fi
      
  
}
  
  
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
          
    restart)
        restart
        ;;
          
    status)
        status
        ;;    
    *)
      
     echo "Usage: /etc/init.d/redis {start|stop|status|start}" >&2
     exit 1
esac

  

 

posted @   雪竹子  阅读(469)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起