安装redis脚本
# 1.安装脚本
可选redis4.0.11或者redis5.0.8
#!/bin/bash
# read -p "please input your server IP like 192.168.0.9: " redisip
# echo $redisip
echo -e " Please choose REDIS version:
$WHITE 1)$WHITE $redis_version1;
$WHITE 2)$WHITE $redis_version2;"
echo -e "$WHITE"
# 判断
while :; do
echo
read -p "Please input the number of your choose:" redis_version_select
if [[ ! $redis_version_select =~ ^[1,2]$ ]]; then
echo -e "\033[0mPlease input 1 or 2\033[33m"
else
break
fi
done
case $redis_version_select in
1)
echo "you choose $redis_version1"
if [ -d "$redis_install_dir/redis-4.0.11" ]; then
echo "本机redis存在..."
else
pushd $src_dir >/dev/null 2>&1
echo "正在解压redis安装包请稍后.."
unzip $redis_zip -d /home/$user &>/dev/null
chmod a+x -R $redis_install_dir/$redis_version1
rm -rf /$redis_install_dir/$redis_version1/redis_cluster/7000/data/*
rm -rf /$redis_install_dir/$redis_version1/redis_cluster/7001/data/*
cd $redis_install_dir/$redis_version1/src
echo "开始启动服务器redis 27000"
echo "bind $serverip" >>$redis_install_dir/$redis_version1/redis_cluster/7000/redis_7000.conf
echo "bind $serverip" >>$redis_install_dir/$redis_version1/redis_cluster/7001/redis_7001.conf
./redis-server ../redis_cluster/7000/redis_7000.conf
echo "开始启动服务器redis 27001"
./redis-server ../redis_cluster/7001/redis_7001.conf
popd >/dev/null 2>&1
echo "--------------------本机安装redis4.0.11成功--------------------"
fi
;;
2)
echo "you choose $redis_version2"
if [ -d "$redis_install_dir/redis-5.0.8" ]; then
echo "本机redis存在..."
else
echo "正在解压redis安装包请稍后.."
install_redis() {
pushd $src_dir >/dev/null 2>&1
unzip $redis_zip5 -d $redis_install_dir &>/dev/null
popd >/dev/null 2>&1
}
install_redis
echo "正在启动redis"
config_redis() {
pushd $src_dir >/dev/null 2>&1
chmod a+x -R /home/$user/redis-5.0.8/
cd /home/$user/redis-5.0.8/utils/create-cluster
sed -i "/reids_pwd=smartdbm/ a\\ip=$serverip" create-cluster
./create-cluster start
echo "start redis success"
popd >/dev/null 2>&1
}
config_redis
sleep 2
echo "--------------------本机安装redis5.0.8成功-----------------"
fi
;;
esac
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
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
# 3.create-cluster解读
#!/bin/bash
# Settings
PORT=26999
TIMEOUT=2000
NODES=2
REPLICAS=1
reids_pwd=smartdbm
ip=$(ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:")
# Computed vars
ENDPORT=$((PORT+NODES))
if [ "$1" == "start" ]
then
while [ $((PORT < ENDPORT)) != "0" ]; do
PORT=$((PORT+1))
echo "Starting $PORT"
/home/smartmining/redis-5.0.8/src/redis-server --port $PORT --bind $ip --masterauth $reids_pwd --requirepass $reids_pwd --protected-mode no --cluster-enabled yes --cluster-config-file nodes-${PORT}.conf --cluster-node-timeout $TIMEOUT --appendonly yes --appendfilename appendonly-${PORT}.aof --dbfilename dump-${PORT}.rdb --logfile ${PORT}.log --daemonize yes
done
# cp $(pwd)/redis.conf /etc/
# cd /home/smartmining/redis-5.0.8/src/
# ./redis-server /etc/redis.conf &>/dev/null
exit 0
fi
if [ "$1" == "stop" ]
then
while [ $((PORT < ENDPORT)) != "0" ]; do
PORT=$((PORT+1))
echo "Stopping $PORT"
/home/smartmining/redis-5.0.8/src/redis-cli -a $reids_pwd -h $ip -p $PORT shutdown nosave
done
kill -9 $(ps -ef | grep redis | grep -v grep | awk '{print $2}')
exit 0
fi
if [ "$1" == "clean" ]
then
cd /home/smartmining/redis-5.0.8/utils/create-cluster
rm -rf *.log
rm -rf appendonly*.aof
rm -rf dump*.rdb
rm -rf nodes*.conf
exit 0
fi
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
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