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. linux vi hjkl由来

    很远原因来自历史 I was reading about vim the other day and found out why it used hjkl keys as arrow keys. Wh ...

  2. ubuntu如何进入local、bin目录

    回到home目录,输入命令:cd /usr/local 若要进入bin目录,输入命令:cd /usr/local/bin

  3. shell学习指南-阅读笔记

    shell学习指南真不是刚开始学习shell应该看得书,虽然其中讲了简单的linux命令,shell语法等,但是每章也有些深入和生僻地方,我想如果我刚学shell看到这样的地方一定会头疼的要死.或许也 ...

  4. parentNode和parentElement区别

    parentNode跟parentElement除了前者是w3c标准,后者只ie支持 当父节点的nodeType不是1,即不是element节点的话,它的parentElement就会是null 一般 ...

  5. 【已解决】Windows下 MySQL大小写敏感 解决方案及分析

    Windows下 MySQL大小写敏感配置 zoerywzhou@163.com http://www.cnblogs.com/swje/ 作者:Zhouwan 2017-3-27 最近在window ...

  6. OpenStack_Glance

    什么是Glace Glance即image service(镜像服务),就是为创建虚拟机提供镜像的地方 为什么要有Glance 这个问题问的好,openstack就是构建Iaas平台对外提供虚拟机的啊 ...

  7. PuTsangTo-单撸游戏开发04 给角色添加基本动画

    一. 跳跃与移动的优化与完善 先给上一次的内容做一次补救,也就是上一次中还留存的,由于键盘按键事件的第一次回调与后续回调之间会间隔个小半秒带来的跳跃落地后动作延迟的情况. 最终的键盘按下回调的处理代码 ...

  8. Excel 按模板格式导出

    最近遇到一个问题,就是导出数据的时候需要自定义的表头,如图 如果自己用代码写表头的话,可能会有点复杂,而且代码量很多,所以我就想了一个办法,直接在Excel里面把表头定义好,然后把数据写入Excel模 ...

  9. Mybatis 中一对多,多对一的配置

    现在有很多电商平台,就拿这个来说吧.顾客跟订单的关系,一个顾客可以有多张订单,但是一个订单只能对应一个顾客. 一对多的顾客 <?xml version="1.0" encod ...

  10. JavaWeb之HTTP协议

    一.概念 协议是指计算机通信网络中两台计算机之间进行通信所必须共同遵守的规定或规则,超文本传输协议(HTTP)是一种通信协议,它允许将超文本标记语言(HTML)文档从Web服务器传送到客户端的浏览器. ...