redis单机主从搭建

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、从库日志

[[email protected] 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、测试主从

主库:

[[email protected] 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

从库:

[[email protected] ~]# /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

时间: 2024-08-01 10:31:43

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

Redis的主从搭建

Redis在作为可内存持久化的Key-Value数据库是使用的过程中是可以做主从服务的.在Redis的大规模集群中Redis的主从服务就是集群实现的基础,在Redis的主从服务中有以下几个优点: 1.master可以有多个slave. 2.除了多个slave连到相同的master外,slave也可以连接其它slave形成图状结构. 3.主从复制不会阻塞master.也就是说当一个或多个slave与master进行初次同步数据时,master 可以继续处理客户端发来的请求.相反slave在初次同步

Redis单机主从高可用性优化

版权声明:本文由陈龙原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/127 来源:腾云阁 https://www.qcloud.com/community redis是一款高性能的内存数据库,本文侧重描述redis在主从模式下遇到的一些问题以及如何调优,特别是在云环境下遇到的一些特殊问题,至于redis如何使用以及数据结构等,可以百度,网上有大量的资料. 主结点 在非集群环境的情况下,使用redis主从模式来保证业务的高

Ubuntu 18.04 配置 Redis 单机主从

安装 sudo apt update sudo apt install redis 测试(以下为正常) [email protected]:~$ redis-cli 127.0.0.1:6379> ping PONG 使用 systemctl 管理 redis # 查看状态 $ systemctl status redis # 启动redis $ systemctl start redis #重启redis $ systemctl restart redis # 停止redis $ system

实战录&#160;| Redis的主从服务器搭建

<实战录>导语 云端卫士<实战录>栏目定期会向粉丝朋友们分享一些在开发运维中的经验和技巧,希望对于关注我们的朋友有所裨益.本期分享人为云端卫士安全平台工程师田全磊,将带来Redis的主从服务器搭建. Redis是一个简单快捷的key-value存储系统.它提供了丰富的数据存储结构,包括 lists, sets, ordered sets 以及 hashes ,当然还有和Memcached一样的 strings结构.同时Redis提供还对这些数据结构的丰富操作. Redis哨兵模式介

搭建 Redis 的主从

主从概念 ?个master可以拥有多个slave,?个slave?可以拥有多个slave,如此下去,形成了强?的多级服务器集群架构 master用来写数据,slave用来读数据,经统计:网站的读写比率是10:1 通过主从配置可以实现读写分离 master和slave都是一个redis实例(redis服务) 主从配置 配置主 查看当前主机的ip地址 ifconfig 修改etc/redis/redis.conf文件 sudo vi redis.confbind 192.168.26.128 重启r

Centos6.7 Redis3.2.8的主从搭建

首先参看一下redis 3.2.8的安装 传送门:biubiubiu 飞去吧:http://www.cnblogs.com/bing-yu12/p/6582086.html 我的主从搭建: redis 主环境: centos 6.7 ip:192.168.184.3 redis 3.2.8 redis.conf的重要配置: bind 127.0.0.1选项后面加上192.168.184.3 让外部机器也可以访问该ip iptables规则清除 selinux关闭:setenforce 0 或者v

redis集群搭建及注意事项

上一篇:redis的安装及注意事项 这里,在一个Linux虚拟机上搭建6个节点的redis伪集群,思路很简单,一台虚拟机上开启6个redis实例,每个redis实例有自己的端口.这样的话,相当于模拟出了6台机器了,然后在以这6个实例组建redis集群就可以了. 前提:redis已经安装,目录为/usr/local/redis-4.0.1 redis集群是用的ruby脚本,所以要想执行该脚本,需要ruby环境..对应redis的源码src目录下的redis-trib.rb,redis-trib.r

通过jedis连接redis单机成功,使用redis客户端可以连接集群,但使用JedisCluster连接redis集群一直报Could not get a resource from the pool

一,问题描述: (如题目)通过jedis连接redis单机成功,使用JedisCluster连接redis集群一直报Could not get a resource from the pool 但是使用redis客户端可以连接集群(我使用的redis desktop manager) 在java中通过jedis连接redis单机也成功,但使用JedisCluster连接redis集群一直报Could not get a resource from the pool, 我以命令行方式操作是没问题的

Windows PHP 环境下 Redis开发环境搭建

1.redis简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set --有序集合)和hashs(哈希类型).这些数据类型都支持push/pop.add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的.在此基础上,redis支持各种不同方式的排序.与memcached一样,为了保证效率,数据都是缓存在内存中.区别的是redi