1.下载Redis的安装包
wget http://download.redis.io/releases/redis-3.2.6.tar.gz 这个比直接去官网下载速度快
2.解压缩安装命令如下:
tar xvfz redis-3.2.6.tar.gz
sudo make
sudo make install
sudo make test
3.以下摘抄网上
创建两个文件夹,bin用于存放命令,etc拥有存放配置文件。
duanxz@ubuntu:~/soft/redis-3.0.7/src$ sudo mkdir -p /usr/local/redis/bin
duanxz@ubuntu:~/soft/redis-3.0.7/src$ sudo mkdir -p /usr/local/redis/etc
-p是递归创建。
接下来,将redis-2.8.19文件夹下的redis.conf复制到/usr/local/redis/etc/
并将src目录下的7个命令文件(绿色的),移动到/usr/local/redis/bin/
duanxz@ubuntu:~/soft/redis-3.0.7/src$ cd ..
duanxz@ubuntu:~/soft/redis-3.0.7$ ls
00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests
BUGS deps MANIFESTO runtest sentinel.conf utils
CONTRIBUTING INSTALL README runtest-cluster src
duanxz@ubuntu:~/soft/redis-3.0.7$ sudo mv ./redis.conf /usr/local/redis/etc/
duanxz@ubuntu:~/soft/redis-3.0.7$ cd src
duanxz@ubuntu:~/soft/redis-3.0.7/src$ sudo mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentinel redis-server /usr/local/redis/bin/
duanxz@ubuntu:~/soft/redis-3.0.7/src$
但实际上我只看到这六个文件,所以改改命令,去掉redis-check-dump :
sudo mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-sentinel redis-server /usr/local/redis/bin/
4.启动redis
sudo redis-server /usr/local/redis/etc/redis.conf
查看是否启动
ps -ef | grep redis
关闭redis
sudo
pkill redis-server
sudo
netstat
-tunpl |
grep
6379
Redis+Sentinel配置
1. cd /usr/local 2. sudo chown -R jack:jack redis/
2.配置文件
1)主配置文件redis_master_6301.conf
# Redis configuration file example
################################## INCLUDES ###################################
# include /path/to/local.conf
# include /path/to/other.conf
################################ GENERAL #####################################
daemonize yes
pidfile ./run/redis_slaver1_6315.pid
port 6301
tcp-backlog 511
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1
# unixsocket /tmp/redis.sock
# unixsocketperm 700
timeout 0
tcp-keepalive 0
loglevel notice
logfile "./run/logs/log_master_6301.log"
databases 16
################################ SNAPSHOTTING ################################
save ""
# save 900 1
# save 300 10
# save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum no
dbfilename dump_6301.rdb
dir ./run/data
################################# REPLICATION #################################
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
# repl-ping-slave-period 10
# repl-timeout 60
repl-disable-tcp-nodelay no
# repl-backlog-size 1mb
# repl-backlog-ttl 3600
slave-priority 100
# min-slaves-to-write 3
# min-slaves-max-lag 10
################################## SECURITY ###################################
# rename-command CONFIG ""
################################### LIMITS ####################################
# maxclients 10000
# maxmemory <bytes>
# maxmemory-policy noeviction
# maxmemory-samples 5
############################## APPEND ONLY MODE ###############################
appendonly no
appendfilename "appendonly_6301.aof"
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
################################ LUA SCRIPTING ###############################
lua-time-limit 5000
################################ REDIS CLUSTER ###############################
# cluster-enabled yes
# cluster-config-file nodes-6379.conf
# cluster-node-timeout 15000
# cluster-slave-validity-factor 10
# cluster-migration-barrier 1
# cluster-require-full-coverage yes
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128
################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0
############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""
############################### ADVANCED CONFIG ###############################
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
protected-mode no
2)从配置文件redis_slave_6315.conf,redis_slave_6316.conf,redis_slave_6317.conf
# Redis configuration file example
################################## INCLUDES ###################################
# include /path/to/local.conf
# include /path/to/other.conf
################################ GENERAL #####################################
daemonize yes
pidfile ./run/redis_slaver1_6315.pid
port 6315
tcp-backlog 511
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1
# unixsocket /tmp/redis.sock
# unixsocketperm 700
timeout 0
tcp-keepalive 0
loglevel notice
logfile "./run/logs/log_slaver1_6315.log"
databases 16
################################ SNAPSHOTTING ################################
save ""
# save 900 1
# save 300 10
# save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum no
dbfilename dump_6315.rdb
dir ./run/data
################################# REPLICATION #################################
slaveof 192.168.244.201 6301
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
# repl-ping-slave-period 10
# repl-timeout 60
repl-disable-tcp-nodelay no
# repl-backlog-size 1mb
# repl-backlog-ttl 3600
slave-priority 80
# min-slaves-to-write 3
# min-slaves-max-lag 10
################################## SECURITY ###################################
# rename-command CONFIG ""
################################### LIMITS ####################################
# maxclients 10000
# maxmemory <bytes>
# maxmemory-policy noeviction
# maxmemory-samples 5
############################## APPEND ONLY MODE ###############################
appendonly no
appendfilename "appendonly_6315.aof"
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
################################ LUA SCRIPTING ###############################
lua-time-limit 5000
################################ REDIS CLUSTER ###############################
# cluster-enabled yes
# cluster-config-file nodes-6379.conf
# cluster-node-timeout 15000
# cluster-slave-validity-factor 10
# cluster-migration-barrier 1
# cluster-require-full-coverage yes
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128
################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0
############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""
############################### ADVANCED CONFIG ###############################
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
protected-mode no
3)redis_sentinel_26302.conf和<span style="line-height:21.6px">redis_sentinel_26303.conf的配置要用绝对路径
# Example sentinel.conf
port 26301
daemonize yes
logfile "/usr/local/redis/run/logs/sentinellog_m1_26301.log"
#master1
sentinel myid d09ec0e7f2e30c6497bdc750c91d79b6c862fc71
sentinel monitor master1 192.168.244.201 6301 2
sentinel down-after-milliseconds master1 5000
#sentinel auth-pass master1 19870801
sentinel failover-timeout master1 18000
protected-mode no
3.主从哨兵的启动命令如下:
sudo redis-server /usr/local/redis/etc/redis_master_6301.conf
sudo redis-server /usr/local/redis/etc/redis_slave_6315.conf
sudo redis-server /usr/local/redis/etc/redis_slave_6316.conf
sudo redis-server /usr/local/redis/etc/redis_slave_6317.conf
sudo redis-sentinel /usr/local/redis/etc/redis_sentinel_26301.conf
sudo redis-sentinel /usr/local/redis/etc/redis_sentinel_26302.conf
sudo redis-sentinel /usr/local/redis/etc/redis_sentinel_26303.conf
关闭进程命令
sudo pkill redis-server
sudo pkill redis-sentinel
4.查看进程是否都已经启动:
七个进程都已经启动
遇到的一个坑,无论哪个配置最后不加下面这个到配置文件.conf里面,连接的时候都会报
protected-mode no
查看master的状态:
查看slave的状态:
查看sentinel的状态:
Redis desktop manager也连接成功
参考的资料如下:
http://www.cnblogs.com/duanxz/p/5423064.html
http://blog.csdn.net/vtopqx/article/details/49247285
验证时,报错DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified
http://blog.csdn.net/alaska_bibi/article/details/52594639