Redis Sentinel安装部署

1、下载redis源文件,解压并安装

安装gcc tcl依赖

yum install -y gcc tcl

安装并验证

tar zxvf redis-4.0.6.tar.gz 
cd redis-4.0.6/
make PREFIX=/usr/local/redis install
make test

出现"\o/ All tests passed without errors!"说明安装成功

程序做软连接到bin目录,方便直接执行

ln -s /usr/local/redis/bin/redis-cli /usr/local/bin/redis-cli
ln -s /usr/local/redis/bin/redis-sentinel /usr/local/bin/redis-sentinel
ln -s /usr/local/redis/bin/redis-server /usr/local/bin/redis-server

2、新增相关目录

注意要以非root用户运行redis服务,所以对应目录也要修改相应的拥有者

新增目录

mkdir /var/lib/redis/
mkdir /var/log/redis/
mkdir /var/run/redis/
mkdir /etc/redis/

新增redis用户并设置密码

groupadd redis
useradd -g redis redis
passwd redis 

修改对应目录的拥有者

chown -R redis.redis /var/lib/redis/
chown -R redis.redis /var/log/redis/
chown -R redis.redis /var/run/redis/
chown -R redis.redis /etc/redis/

3、启动redis服务

su redis
redis-server /etc/redis/redis.conf
redis-sentinel /etc/redis/sentinel.conf &

查看服务状态

redis-cli -p 6481 -a password
redis-cli -p 26481 -a password

Redis信息

127.0.0.1:6481> info
# Server
redis_version:4.0.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:2cb183298997fd87
redis_mode:standalone
os:Linux 3.10.0-957.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:4.8.5
process_id:15961
run_id:e1f64670ddb1c4dc330a722413642eff2089f04f
tcp_port:6481
uptime_in_seconds:427
uptime_in_days:0
hz:10
lru_clock:2392597
executable:/root/redis-server
config_file:/etc/redis/redis.conf

# Clients
connected_clients:8
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:34253264
used_memory_human:32.67M
used_memory_rss:9961472
used_memory_rss_human:9.50M
used_memory_peak:34355272
used_memory_peak_human:32.76M
used_memory_peak_perc:99.70%
used_memory_overhead:34209156
used_memory_startup:487088
used_memory_dataset:44108
used_memory_dataset_perc:0.13%
total_system_memory:16655790080
total_system_memory_human:15.51G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:0.29
mem_allocator:jemalloc-4.0.3
active_defrag_running:0
lazyfree_pending_objects:0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1562673258
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:0
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_last_cow_size:0

# Stats
total_connections_received:7
total_commands_processed:2672
instantaneous_ops_per_sec:8
total_net_input_bytes:196135
total_net_output_bytes:901206
instantaneous_input_kbps:0.52
instantaneous_output_kbps:9.20
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:1
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0

# Replication
role:slave
master_host:*.*.*.*
master_port:6481
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:106644
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:9225f32503bde30c92f1245d356d6c33257910f0
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:106644
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:33554432
repl_backlog_first_byte_offset:14574
repl_backlog_histlen:92071

# CPU
used_cpu_sys:0.28
used_cpu_user:0.16
used_cpu_sys_children:0.00
used_cpu_user_children:0.00

# Cluster
cluster_enabled:0

# Keyspace
127.0.0.1:6481> 

Sentinel信息

127.0.0.1:26481> info
# Server
redis_version:4.0.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:2cb183298997fd87
redis_mode:sentinel
os:Linux 3.10.0-957.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:4.8.5
process_id:15965
run_id:030eeb1df4074566839acf333be8acc9136fcbf5
tcp_port:26481
uptime_in_seconds:336
uptime_in_days:0
hz:13
lru_clock:2392510
executable:/root/redis-sentinel
config_file:/etc/redis/sentinel.conf

# Clients
connected_clients:3
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# CPU
used_cpu_sys:0.30
used_cpu_user:0.20
used_cpu_sys_children:0.00
used_cpu_user_children:0.00

# Stats
total_connections_received:3
total_commands_processed:929
instantaneous_ops_per_sec:3
total_net_input_bytes:52722
total_net_output_bytes:5685
instantaneous_input_kbps:0.26
instantaneous_output_kbps:0.02
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0

# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=127.0.0.1:6481,slaves=2,sentinels=3

4、附录:配置文件

Master的redis.conf

protected-mode yes

port 6481

tcp-backlog 511

unixsocket "/var/run/redis/redis_6481.sock"

timeout 0

tcp-keepalive 300

daemonize yes

supervised no

pidfile /var/run/redis/redis_6481.pid

loglevel notice

logfile "/var/log/redis/redis_6481.log"

databases 16

always-show-logo yes

save 900 1
save 300 10
save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir "/var/lib/redis/"

masterauth password

slave-serve-stale-data yes

slave-read-only yes

repl-diskless-sync no

repl-diskless-sync-delay 5

repl-ping-slave-period 5

repl-timeout 60

repl-disable-tcp-nodelay no

repl-backlog-size 32mb

repl-backlog-ttl 3600

slave-priority 100

requirepass password

lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no

appendonly no

appendfilename "appendonly.aof"

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

aof-use-rdb-preamble no

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

latency-monitor-threshold 0

notify-keyspace-events ""

hash-max-ziplist-entries 512
hash-max-ziplist-value 64

list-max-ziplist-size -2

list-compress-depth 0

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

rename-command FLUSHALL ""
rename-command CONFIG   ""
rename-command EVAL     ""

slave的redis.conf

bind 0.0.0.0

protected-mode yes

port 6481

tcp-backlog 511

unixsocket "/var/run/redis/redis_6481.sock"

timeout 0

tcp-keepalive 300


daemonize yes

supervised no

pidfile /var/run/redis/redis_6481.pid

loglevel notice

logfile "/var/log/redis/redis_6481.log"

databases 16

always-show-logo yes

save 900 1
save 300 10
save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir "/var/lib/redis/"

slaveof *.*.*.* 6481

masterauth password

slave-serve-stale-data yes

slave-read-only yes

repl-diskless-sync no

repl-diskless-sync-delay 5

repl-ping-slave-period 5

repl-timeout 60

repl-disable-tcp-nodelay no

repl-backlog-size 32mb

repl-backlog-ttl 3600

slave-priority 100

requirepass password

lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no

appendonly no

appendfilename "appendonly.aof"

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

aof-use-rdb-preamble no

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

latency-monitor-threshold 0

notify-keyspace-events ""

hash-max-ziplist-entries 512
hash-max-ziplist-value 64

list-max-ziplist-size -2

list-compress-depth 0

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

rename-command FLUSHALL ""
rename-command CONFIG   ""
rename-command EVAL     ""

sentinel.conf

protected-mode no

port 26481

dir "/var/lib/redis"

sentinel myid 8a77d457a1474f32be15540baf059fc81b5bda8f

sentinel monitor mymaster *.*.*.* 6481 2

sentinel auth-pass mymaster password

sentinel config-epoch mymaster 0

logfile "/var/log/redis/sentinel_26481.log"
sentinel leader-epoch mymaster 176

maxclients 4064

# 当存在内外网时,如果想要从外网访问,最好加个ip声明
# 否则sentinel返回给的IP可能是内网的,导致外网主机无法访问
sentinel known-slave mymaster *.*.*.1 6481
sentinel known-slave mymaster *.*.*.2 6481
sentinel announce-ip "*.*.*.*.*"
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,163评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,301评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,089评论 0 352
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,093评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,110评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,079评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,005评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,840评论 0 273
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,278评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,497评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,667评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,394评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,980评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,628评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,796评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,649评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,548评论 2 352