-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-redis.sh
83 lines (81 loc) · 2.03 KB
/
install-redis.sh
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
#!/bin/sh
#BASE_PATH=$(cd "$(dirname "$0")";pwd)
BASE_PATH=$HOME
err() {
echo $1
exit 0
}
cd $BASE_PATH
[ -d redis-conf ] || mkdir redis-conf
[ -d redis-log ] || mkdir redis-log
[ -z $REDIS_HOME ] && err "REDIS_HOME is requried"
[ -f $redis-conf/$2 ] && err "port is allready used"
case $1 in
"master")
[ $# -gt 1 ] || { echo "err! such as: sh install.sh master 3679"; exit 0; }
echo "installing master redis, port $2";
(cat << EOF
#当前redis端口定义:
port $2
#当前redis主机地址:
bind 0.0.0.0
#redis 守护进程设置:
daemonize yes
#保护模式:
protected-mode no
#redis日志:
logfile "$BASE_PATH/redis-log/$2.log"
EOF
) > redis-conf/$2.conf
;;
"slave")
[ $# -gt 3 ] || { echo "err! such as: sh install.sh slave 3680 127.0.0.1 3679"; exit 0; }
echo "installing slave redis, port $2, slaveof $3:$4";
(cat << EOF
#当前redis端口定义:
port $2
#当前redis主机地址:
bind 0.0.0.0
#redis 守护进程设置:
daemonize yes
#保护模式:
protected-mode no
#redis日志:
logfile "$BASE_PATH/redis-log/$2.log"
#设置主机
slaveof $3 $4
EOF
) > redis-conf/$2.conf
;;
"sentinel")
[ $# -gt 3 ] || { echo "err! such as: sh install.sh sentinel 23679 127.0.0.1 3679"; exit 0; }
echo "install sentinel redis, port $2";
(cat << EOF
#当前redis端口定义:
port $2
#当前redis主机地址:
bind 0.0.0.0
#redis 守护进程设置:
daemonize yes
#保护模式:
protected-mode no
#redis日志:
logfile "$BASE_PATH/redis-log/$2.log"
#哨兵监控主机配置
sentinel monitor mymaster $3 $4 2
#哨兵链接失效时间(单位:毫秒)
sentinel down-after-milliseconds mymaster 30000
#redis失效时转移设置
sentinel parallel-syncs mymaster 1
#redis转移时间设置
sentinel failover-timeout mymaster 5000
EOF
) > redis-conf/$2.conf
;;
*)
[ $# -gt 1 ] || { echo "usage: sh install-redis.sh <master|slave|sentinel> <port> [master ip] [master port]"; exit 0; }
;;
esac
echo "config file : $BASE_PATH/redis-conf/$2.conf"
echo "log file : $BASE_PATH/redis-log/$2.log"
echo "install finished."