《实战录》导语

云端卫士《实战录》栏目定期会向粉丝朋友们分享一些在开发运维中的经验和技巧,希望对于关注我们的朋友有所裨益。本期分享人为云端卫士安全平台工程师田全磊,将带来Redis的主从服务器搭建。

Redis是一个简单快捷的key-value存储系统。它提供了丰富的数据存储结构,包括 lists, sets, ordered sets 以及 hashes ,当然还有和Memcached一样的 strings结构。同时Redis提供还对这些数据结构的丰富操作。

Redis哨兵模式介绍

Redis 的 Sentinel 功能用于管理多个 Redis 服务器,它主要提供了监控,提醒和自动故障迁移的功能。

1.监控(Monitoring): Sentinel 会不断地检查你的主服务器和从服务器是否运作正常。

2.提醒(Notification): 当被监控的某个 Redis 服务器出现问题时, Sentinel 可以通过 API 向管理员或者其他应用程序发送通知。

3.自动故障迁移(Automatic failover): 当一个主服务器不能正常工作时, Sentinel 会开始一次自动故障迁移操作, 它会将失效主服务器的其中一个从服务器升级为新的主服务器, 并让失效主服务器的其他从服务器改为复制新的主服务器; 当客户端试图连接失效的主服务器时, 集群也会向客户端返回新主服务器的地址, 使得集群可以使用新主服务器代替失效服务器。

安装

下载redis-2.8.19.tar.gz

解压tar zxf redis-2.8.19.tar.gz

安装cd redis-2.8.19

make && make install

每台机器上都同样安装redis

Redis主从环境搭建

一主:192.168.24.147

两从:192.168.24.148,192.168.24.149

(1)主192.168.24.147配置

目录:conf/redis_6379.conf

启动命令 src/redis-server conf/redis_6379.conf

daemonize yes

pidfile /export/Data/redis_pid/redis_6379.pid

port 6379

# tcp-backlog 511

timeout 300

tcp-keepalive 0

loglevel notice

logfile /export/Logs/redis/redis_6379.log

databases 16

stop-writes-on-bgsave-error yes

rdbcompression yes

dbfilename 6379.rdb

dir /export/Data/redis_data/6379

slave-serve-stale-data yes

slave-read-only yes

repl-disable-tcp-nodelay no

repl-backlog-size 128mb

maxmemory 2g

appendonly no

appendfilename 6379.aof

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 1024

# notify-keyspace-events ""

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 512mb 256mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

rename-command keys jkeys

(2)从192.168.24.148配置

目录:conf/redis_6379.conf

启动命令 src/redis-server conf/redis_6379.conf

daemonize yes

slaveof 192.168.24.147 6379

pidfile /export/Data/redis_pid/redis_6379.pid

port 6379

# tcp-backlog 511

timeout 300

tcp-keepalive 0

loglevel notice

logfile /export/Logs/redis/redis_6379.log

databases 16

stop-writes-on-bgsave-error yes

rdbcompression yes

dbfilename 6379.rdb

dir /export/Data/redis_data/6379

slave-serve-stale-data yes

slave-read-only yes

repl-disable-tcp-nodelay no

repl-backlog-size 128mb

maxmemory 2g

appendonly no

appendfilename 6379.aof

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 1024

# notify-keyspace-events ""

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 512mb 256mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

rename-command keys jkeys

(3)从192.168.24.149配置

目录:conf/redis_6379.conf

启动命令 src/redis-server conf/redis_6379.conf

daemonize yes

slaveof 192.168.24.147 6379

pidfile /export/Data/redis_pid/redis_6379.pid

port 6379

# tcp-backlog 511

timeout 300

tcp-keepalive 0

loglevel notice

logfile /export/Logs/redis/redis_6379.log

databases 16

stop-writes-on-bgsave-error yes

rdbcompression yes

dbfilename 6379.rdb

dir /export/Data/redis_data/6379

slave-serve-stale-data yes

slave-read-only yes

repl-disable-tcp-nodelay no

repl-backlog-size 128mb

maxmemory 2g

appendonly no

appendfilename 6379.aof

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 1024

# notify-keyspace-events ""

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 512mb 256mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

rename-command keys jkeys

实战录 | Redis的主从服务器搭建的更多相关文章

  1. 关于mysql集群主从服务器搭建

    在高并发流量下,数据库往往是服务端的瓶颈,由于数据库数据需要确保落地,同时保证数据同步,数据即时性,有效性的问题,导致数据库不能像平常后端程序一样负载均衡. 那么在大并发下,该如何缓解数据库的压力呢? ...

  2. redis的主从模式搭建及注意事项

    前言:本文先分享下如何搭建redis的主从模式配置,以及主从模式配置的注意事项.后续会继续分享如何实现一个高可用的redis服务,redis的Sentinel 哨兵模式及集群搭建. 安装: 1,yum ...

  3. sql server 分布式查询 和 主从服务器搭建

    1. 8K 对应的SQL语句限制  select  *  from openquery (recei    连接服务器名称 执行的sql 语句放在   SELECT @@SERVERNAME  在本地 ...

  4. windows下用一台机器配置分布式redis(主从服务器)

    目录1.Replication的工作原理2.如何配置Redis主从复制 1.Replication的工作原理在Slave启动并连接到Master之后,它将主动发送一条SYNC命令.此后Master将启 ...

  5. redis源码搭建以及配置主从服务器

    2018-10-25 关闭防火墙: systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service # ...

  6. Redis服务器搭建/配置/及Jedis客户端的使用方法

    摘要 Redis服务器搭建.常用参数含意说明.主从配置.以及使用Jedis客户端来操作Redis Redis服务器搭建 安装 在命令行执行下面的命令: $ wget http://download.r ...

  7. redis之单机和主从环境搭建

    单机环境搭建 官网http://redis.io/download下载xxx.tar.gz二进制压缩包,注意下载2.8+版本,2.8之前的版本之前从服务器不支持部分重复制,2.6之前的版本不支持set ...

  8. 【Redis】Redis 主从模式搭建

    主从模式介绍 Redis虽然读取写入的速度都特别快,但是也会产生读压力特别大的情况.为了分担读压力,Redis支持主从复制,Redis的主从结构可以采用一主多从或者级联结构,Redis主从复制可以根据 ...

  9. 高级运维(六):源码安装Redis缓存服务、常用Redis数据库操作指令、配置Redis主从服务器

    一.源码安装Redis缓存服务 目标: 本案例要求先快速搭建好一台Redis服务器,并测试该缓存服务器: 1> 设置变量test,值为123 2> 查看变量test的值 3> 设置计 ...

随机推荐

  1. Android学习笔记(二)

    Google在Android4.0之后加入了Action Bar的功能.但是有时候标题栏会相当占用屏幕空间,使得内容区域变小,这里演示如何隐藏标题栏. 隐藏标题栏的方法很简单,打开上节的FirstAc ...

  2. 字符串--java中判断字符串是否为数字的方法的几种方法?

    ava中判断字符串是否为数字的方法: 1.用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = 0; i < ...

  3. python的中文编码问题

    下文转自 http://blog.csdn.net/mayflowers/article/details/1568852 1.        在Python中使用中文 在Python中有两种默认的字符 ...

  4. css学习笔记(5)

    <style>*{margin:0; padding:0;}ul{ list-style:none;}li{ height:30px; width:100px; background:#F ...

  5. logstash 1.5.3 配置使用redis做续传

    logstash是ELK中的一员大将, redis插件也是<The Logstash Book>中介绍的一个很好用的玩意儿. 之前,用比较小的集群部署的时候,没有介入redis中间件,所以 ...

  6. 在sqlserver 中with(nolock)详解

      所有Select加 With (NoLock)解决阻塞死锁        在查询语句中使用 NOLOCK 和 READPAST  处理一个数据库死锁的异常时候,其中一个建议就是使用 NOLOCK  ...

  7. 51. Word Search

    Word Search Given a 2D board and a word, find if the word exists in the grid. The word can be constr ...

  8. 52. Sort Colors && Combinations

    Sort Colors Given an array with n objects colored red, white or blue, sort them so that objects of t ...

  9. C++引用与指针

    在做函数参数时, 引用不可以设置默认值, 指针可以 void fun(const string& url,  string* domain = NULL); 另const放在函数后面, 表示这 ...

  10. C++ 如何有效地使用对话框

    Q:如何在对话框中加入工具条 在 OnInitDialog 中加入下面代码: BOOL CYourDlg::OnInitDialog() { CDialog::OnInitDialog(); // C ...