tar zxvf redis-2.8.13.tar.gz
cd redis-2.8.13
make
1、安装主库
mkdir /opt/redis/sbin -p
mkdir    /opt/redis/bin -p
mkdir /data/redis/redis6379/
cp redis.conf /data/redis/redis6379/6379.conf【配置文件下拉到最底部】
cd src
cp redis-se* /opt/redis/sbin/
cp redis-check-dump /opt/redis/bin/
cp redis-check-aof /opt/redis/bin/
cp redis-cli /opt/redis/bin/
启动:
/opt/redis/sbin/redis-server /data/redis/redis6379/6379.conf
关闭:
/opt/redis/bin/redis-cli shutdown
 
系统初始化:
sed -i -r '/vm.overcommit_memory*/d' /etc/sysctl.conf
sed -i -r '/vm.swappiness*/d' /etc/sysctl.conf
echo "vm.overcommit_memory = 1" >>/etc/sysctl.conf
echo "vm.swappiness    = 1" >>/etc/sysctl.conf
/sbin/sysctl -q    -p /etc/sysctl.conf
sed -i -r '/redis soft nofile.*/d' /etc/security/limits.conf
sed -i -r '/redis hard nofile.*/d' /etc/security/limits.conf
echo "redis    soft nofile 288000" >> /etc/security/limits.conf
echo "redis hard nofile 288000" >> /etc/security/limits.conf
sed -i -r '/redis soft nproc.*/d'  /etc/security/limits.conf
sed -i -r '/redis hard nproc.*/d'  /etc/security/limits.conf
echo "redis soft nproc unlimited">>/etc/security/limits.conf
echo "redis hard nproc unlimited">>/etc/security/limits.conf
 
2、安装从库
mkdir -p /data/redis/redis6380/
cd /data/redis/redis6380/
cp ../redis6379/6379.conf 6380.conf
sed -i 's/6379/6380/g' 6380.conf     #使用替换配置文件中的6379为6380
echo "slaveof 192.168.98.199 6379" >> 6380.conf     #在6380.conf中添加slaveof ip port
 
3、启动主从
先启主库:
/opt/redis/sbin/redis-server /data/redis/redis6379/6379.conf
启动从库:
/opt/redis/sbin/redis-server /data/redis/redis6380/6380.conf
 
4、从库日志
[root@MyCentOS redis6380]# less /data/redis/6380.log
[5545] 13 Sep 22:30:18.164 # Server started, Redis version 2.8.13
[5545] 13 Sep 22:30:18.164 * The server is now ready to accept connections on port 6380
[5545] 13 Sep 22:30:18.164 * Connecting to MASTER 192.168.98.199:6379
[5545] 13 Sep 22:30:18.171 * MASTER <-> SLAVE sync started
[5545] 13 Sep 22:30:18.176 * Non blocking connect for SYNC fired the event.
[5545] 13 Sep 22:30:18.180 * Master replied to PING, replication can continue...
[5545] 13 Sep 22:30:18.180 * Partial resynchronization not possible (no cached master)
[5545] 13 Sep 22:30:18.180 * Full resync from master: 668093d0cb4a27a7d025f4d36feff13f622368d3:1
[5545] 13 Sep 22:30:18.207 * MASTER <-> SLAVE sync: receiving 18 bytes from master
[5545] 13 Sep 22:30:18.207 * MASTER <-> SLAVE sync: Flushing old data
[5545] 13 Sep 22:30:18.207 * MASTER <-> SLAVE sync: Loading DB in memory
[5545] 13 Sep 22:30:18.207 * MASTER <-> SLAVE sync: Finished with success
[5545] 13 Sep 22:30:18.208 * Background append only file rewriting started by pid 5549
[5549] 13 Sep 22:30:18.213 * SYNC append only file rewrite performed
[5549] 13 Sep 22:30:18.213 * AOF rewrite: 6 MB of memory used by copy-on-write
[5545] 13 Sep 22:30:18.277 * Background AOF rewrite terminated with success
[5545] 13 Sep 22:30:18.277 * Parent diff successfully flushed to the rewritten AOF (0 bytes)
[5545] 13 Sep 22:30:18.278 * Background AOF rewrite finished successfully
 
5、测试主从
主库:
[root@MyCentOS redis6380]# /opt/redis/bin/redis-cli -p 6379
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set fuzhi 'fuzhiceshi'
OK
127.0.0.1:6379> get fuzhi
"fuzhiceshi"
127.0.0.1:6379> info replication     【 利用 info Replication 查看复制关系】
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.98.199,port=6380,state=online,offset=1297,lag=1
master_repl_offset:1297
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:1296
从库:
[root@MyCentOS ~]# /opt/redis/bin/redis-cli -p 6380
127.0.0.1:6380> keys *
1) "fuzhi"
127.0.0.1:6380> get fuzhi
"fuzhiceshi"
127.0.0.1:6380> set ceshiku 'shifouxieru'
(error) READONLY You can't write against a read only slave.  【测试库不能写入数据】
127.0.0.1:6380> info replication
# Replication
role:slave
master_host:192.168.98.199
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:1283
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127.0.0.1:6380>
 
redis可执行文件:
redis-server : Redis服务器的daemon启动程序
redis-cli : Redis命令行操作工具。当然,你也可以用telnet根据其纯文本协议来操作
redis-benchmark : Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性能
redis-stat : Redis状态检测工具,可以检测Redis当前状态参数及延迟状况
 

6379.conf:
daemonize yes
pidfile 6379.pid
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile "/data/redis/6379.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename 6379.rdb
dir /data/redis/redis6379
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
maxclients 10000
maxmemory 100M
maxmemory-policy volatile-lru
appendonly yes
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 128
latency-monitor-threshold 0
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 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

redis单机主从搭建的更多相关文章

  1. Redis单机主从高可用性优化

    版权声明:本文由陈龙原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/127 来源:腾云阁 https://www.qclou ...

  2. linux中redis伪主从搭建

    1.解压redis.tgz到usr/local/redis下 2.在redis/下执行 make 3.在redis/src/下执行 make install PREFIX=/usr/local/red ...

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

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

  4. 实战录 | Redis的主从服务器搭建

    <实战录>导语 云端卫士<实战录>栏目定期会向粉丝朋友们分享一些在开发运维中的经验和技巧,希望对于关注我们的朋友有所裨益.本期分享人为云端卫士安全平台工程师田全磊,将带来Red ...

  5. Redis多实例及主从搭建

    主从搭建前提是服务器上已经安装好了redis, redis安装可搜索本站另一篇博客:redis安装. redis单主机多实例 一.我们首先拷贝两份文件: cp /etc/redis.conf /etc ...

  6. Redis 单机模式,主从模式,哨兵模式(sentinel),集群模式(cluster),第三方模式优缺点分析

    Redis 的几种常见使用方式包括: 单机模式 主从模式 哨兵模式(sentinel) 集群模式(cluster) 第三方模式 单机模式 Redis 单副本,采用单个 Redis 节点部署架构,没有备 ...

  7. 基于Dokcer搭建Redis集群搭建(主从集群)

    最近陆陆续续有不少园友加我好友咨询 redis 集群搭建的问题,我觉得之前写的这篇 <基于Docker的Redis集群搭建> 文章一定是有问题了,所以我花了几分钟浏览之前的文章总结了下面几 ...

  8. linux系统——Redis集群搭建(主从+哨兵模式)

    趁着这几天刚好有点空,就来写一下redis的集群搭建,我跟大家先说明,本文的redis集群因为linux服务器只是阿里云一台服务器,所以集群是redis启动不同端口,但是也能达到集群的要求.其实不同服 ...

  9. 搭建 Redis 的主从

    主从概念 ⼀个master可以拥有多个slave,⼀个slave⼜可以拥有多个slave,如此下去,形成了强⼤的多级服务器集群架构 master用来写数据,slave用来读数据,经统计:网站的读写比率 ...

随机推荐

  1. windows系统下安装composer

    使用安装程序安装 这是将 Composer 安装在你机器上的最简单的方法. 下载并且运行 Composer-Setup.exe,它将安装最新版本的 Composer 安装完成后,将composer的b ...

  2. 利用shell实现批量添加用户

    批量添加用户并设置随机密码,把添加的用户的名字和密码保存到文件中. [root@lamp scripts]# cat user.sh #!/bin/sh ` do pass=$(-) //取随机数的方 ...

  3. QQ登陆接口

    这次做了一个QQ登陆接口---简单记录一下 遇到一大坑-----QQ互联里面添加应用的时候,是网站应用,配置回调地址一定要配置  准确,到指定回调页面 否则会出现问题的.

  4. 运用google-protobuf的IM消息应用开发(前端篇)

    前言: 公司原本使用了第三方提供的IM消息系统,随着业务发展需要,三方的服务有限,并且出现问题也很难处理和排查,所以这次新版本迭代,我们的server同事呕心沥血做了一个新的IM消息系统,我们也因此配 ...

  5. jquery data属性的使用

    var func=function(){console.log("test")};$("div").data("test",func);$( ...

  6. Linux shell指令运行的原理

    shell是一种命令行解释器 对于一般用户,我们不能直接使用操作系统(kernel).而是通过 kernel的"外壳"程序,也就是所谓的shell,来与kernel沟通.    为 ...

  7. UNIX标准

    背景 人们在UNIX编程环境和C 程序设计语言的标准化方面已经做了很多工作.虽然UNIX应用 程序在不同的UNIX操作系统版本之间进行移植相当容易,但是2 0 世 纪 80年代UNIX版本种类的剧增以 ...

  8. ng自定义一个过滤器

    ng允许我们自定义指令 下面来我们自己来定义一个过滤指令:filter,返回一个函数的形式 filter(name,callback(){//name:过滤器的名字,callback:匿名函数 ret ...

  9. 浩哥解析MyBatis源码(六)——DataSource数据源模块之池型数据源

    原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6675674.html 1 回顾 上一文中解读了MyBatis中非池型数据源的源码,非池型也 ...

  10. JavaScript Array 技巧

    filter():返回该函数会返回true的项组成的数组 ,,,,]; var result = num.filter(function(item,index,array){ ); }) consol ...