redis(1.21)redis6.0安装

2021/7/16 19:09:58

本文主要是介绍redis(1.21)redis6.0安装,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

【1】一键安装(基于集群)

如果要装单实例,请注释掉集群参数

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
source /etc/profile
usage(){
    echo $1
    echo '$#': $#
    echo "for example: sh install_redis.sh -f redis-6.2.4.tar.gz -p 6380 -d /data/redis/
-h usage
-f redis file tar.gz
-d datadir
-p port
"
}
 
while getopts :f:d:p:h opt
do
        case "$opt" in
                h) usage && exit ;;
                f) redis_file=$OPTARG ;;
                p) port=$OPTARG ;;
                d) datadir=$OPTARG ;;
                *) usage && exit;;
        esac
done
 
if [ ! $port ];then
   port=6379
fi
 
if [ `netstat -ano|grep ${port}|wc -l` -gt 0 ];then
echo "the port have already been used:${port}"
netstat -ano|grep ${port}
exit
fi
 
 
echo -n "check gcc......"
gcc -v >/dev/null 2>&1
if [ ! $? -eq 0  ];then
echo "None"
echo "yum -y install gcc 1>/dev/null 2>gcc_error.log......"
yum -y install gcc 1>/dev/null 2>gcc_error.log
#yum -y install tcl
fi
echo "ok"
 
if [ ! $datadir ];then
datadir=/data/redis/
fi
 
if [ ! $redis_file ] || [ ! -f $redis_file ];then
echo 'redis file option not input'
usage && exit
fi
 
#------------------ redis安装 ---------------------
 
mkdir -p ${datadir}${port}_redis
dir=`echo ${redis_file} |awk -F'.tar' '{print $1}'`
 
if [ ! -d $dir ];then
  tar -zxf $redis_file
  dir=`echo ${redis_file} |awk -F'.tar' '{print $1}'`
  cd $dir
 
  echo -n " making redis....... make 1>/dev/null 2>make_error.log"
  make 1>/dev/null 2>make_error.log
  if [ ! $? -eq 0  ];then
   echo "make  error"
   exit
  fi
  # make MALLOC=libc
  echo "ok"
  cd ./src
  make PREFIX=$datadir install
 
elif [ ! -f "${dir}/src/redis-cli" ];then
  cd $dir
    make
  if [ ! $? -eq 0  ];then
   echo "make  error"
   exit
  fi
  make PREFIX=$datadir install
  # make MALLOC=libc 
elif [ ! -f "${datadir}bin/redis-cli" ];then
 cd $dir
 make PREFIX=$datadir install
fi
 
if [ `echo ${PATH}|grep ${datadir}bin|wc -l` -eq 0 ];then
echo "export PATH=${PATH}:/data/redis/bin" >> /etc/profile
source /etc/profile
fi
 
if [ -f "${datadir}${port}_redis/${port}_redis.conf" ];then
echo "redis config file:${datadir}${port}_redis/${port}_redis.conf is already exists!Please check the file info."
exit
fi
 
#------------配置文件 /data/redis/redis_6379/redis_6379.conf----------
cat <<eof>>${datadir}${port}_redis/${port}_redis.conf
#network
protected-mode no
port ${port}
 
#general
daemonize yes
pidfile ${datadir}${port}_redis/${port}_redis.pid
supervised no
loglevel notice
logfile "${datadir}${port}_redis/${port}_redis.log"
syslog-enabled no
databases 16
 
#SNAPSHOTTING
save 86400 1
stop-writes-on-bgsave-error no
rdbcompression yes
dbfilename dump.rdb
dir ${datadir}${port}_redis/
 
requirepass 123456
masterauth 123456
#rename-command FLUSHALL 1123123_FLUSHALL
#rename-command FLUSHDB  1124124_FLUSHDB
#rename-command CONFIG   1123123_CONFIG
 
#replication
#slaveof 180.153.250.135 ${port}
#slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
 
#io thread
io-threads 4
# 开启 4 个 IO 线程
io-threads-do-reads yes
#读请求解析也是用 IO 线程
 
 
#limit
maxclients 10000
maxmemory 100gb
maxmemory-policy allkeys-lru
 
#append only mode
appendonly yes
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
 
#cluster
cluster-enabled yes
    #-- 允许实例加入集群
cluster-config-file nodes-${port}.conf
    #-- 每个加入群集的实例都会有一个
cluster-node-timeout 15000
    #-- ms,节点响应超时
cluster-replica-validity-factor 10
    #-- 这个系数是 超时事件* 它 + 集群心跳检查时间;
cluster-require-full-coverage yes
    # --当为no时: 如果请求过来发现集群无法处理(比如某个主实例挂了又没有副本顶上,造成缺失部分hash槽),则可以重新分配hash槽 覆盖原有数据; yes 则必须所有hash槽 ok 状态集群才能访问                                        
cluster-migration-barrier 1
    # -- 迁移壁垒,即当某个主实例下没有副本,同时又有某个主实例下有超过1个以上的副本,则至少保留一个副本,多的则可以迁移到没有副本的实例下做副本
cluster-replica-no-failover no
    # -- 副本是否故障转移,如果为 yes 则副本无法顶替主实例自动故障转移(可以手动)
cluster-allow-reads-when-down no
    # --6.0参数,当集群不可用时,是否允许节点读写
eof
 
 
#--------------配置、启动、连接、核验-------------
redis-server ${datadir}${port}_redis/${port}_redis.conf
sleep 3
ps -ef|grep redis-server|grep -v grep
 
if [ `cat /etc/rc.local|grep "redis-server ${datadir}${port}_redis/${port}_redis.conf"|wc -l` -eq 0  ];then
echo "redis-server ${datadir}${port}_redis/${port}_redis.conf">>/etc/rc.local
fi

 



这篇关于redis(1.21)redis6.0安装的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


原文链接: https://www.cnblogs.com/gered/p/15018760.html
扫一扫关注最新编程教程