版权声明:本文为博主原创文章,欢迎转载,转载请保留或注明出处
本文转自:http://www.cnblogs.com/lgeng/p/6623336.html

一,单机多实例:
Redis官网: https://redis.io/
1,安装:

yum -y install gcc gcc-c++    #安装编译工具

[root@localhost data]# wget http://download.redis.io/releases/redis-3.2.8.tar.gz
[root@localhost data]# tar xzf redis-3.2..tar.gz
[root@localhost data]# cd redis-3.2.
[root@localhost data]# make
[root@localhost data]# mv redis-3.2. /usr/local/redis 注意:可直接 yum install redis -y 安装

启动:(默认启动6379端口)
[root@localhost redis]# /usr/local/redis/src/redis-server 

 
 

2,验证:使用 redis-cli命令验证 (注意路径)
[root@localhost src]# /usr/local/redis/src/redis-cli -p
127.0.0.1:> keys *
(empty list or set)
127.0.0.1:> set k1 v1
OK
127.0.0.1:> keys *
) "k1"
127.0.0.1:> get k1
"v1"
127.0.0.1:>
127.0.0.1:>

3,配置环境变量 
输入redis-server和redis-cli命令,每次输入完整的路径
将路径添加到PATH变量中

echo 'PATH=${PATH}:/usr/local/redis/src/' >> /etc/profile
source /etc/profile #<== 重新加载配置文件

二,单机多实例

创建不同实例的数据存放目录 分别创建6380,6381,6382 三个实例
每个实例目录中分别创建 conf,db,log目录,并拷贝配置文件到conf中

[root@localhost /]# mkdir -p  /data/redis/{,,}/{conf,db,log}
[root@localhost /]# cp /usr/local/redis/redis.conf /data/redis//conf/
[root@localhost /]# cp /usr/local/redis/redis.conf /data/redis//conf/
[root@localhost /]# cp /usr/local/redis/redis.conf /data/redis//conf/
[root@localhost /]#
[root@localhost /]# cd /data/redis
[root@localhost redis]# ls [root@localhost redis]# tree
.
├──
│ ├── conf
│ │ └── redis.conf
│ ├── db
│ └── log
├──
│ ├── conf
│ │ └── redis.conf
│ ├── db
│ └── log
└──
├── conf
│ └── redis.conf
├── db
└── log directories, files
[root@localhost redis]#
[root@localhost redis]#

修改配置文件:

将redis.conf修改为对应的实例参数,修改部分如下



[root@localhost redis]# grep "6380\|daemonize" /conf/redis.conf
daemonize yes                     <== daemon进程运行
pidfile /data/redis//redis.pid     <== 进程id存放文件
port     <== 端口
logfile /data/redis//log/redis.log     <== 日志目录
dir /data/redis//db/     <== db目录
[root@localhost redis]#
[root@localhost redis]# grep "" /conf/redis.conf
daemonize yes
pidfile /data/redis//redis.pid
port
logfile /data/redis//log/redis.log
dir /data/redis//db/
[root@localhost redis]#
[root@localhost redis]# grep "" /conf/redis.conf
daemonize yes
pidfile /data/redis//redis.pid
port
logfile /data/redis//log/redis.log
dir /data/redis//db/
[root@localhost redis]#
[root@localhost redis]#

启动实例:

[root@localhost redis]# redis-server /data/redis//conf/redis.conf
[root@localhost redis]# redis-server /data/redis//conf/redis.conf
[root@localhost redis]# redis-server /data/redis//conf/redis.conf
[root@localhost redis]#
[root@localhost redis]# netstat -ntlp | grep -E ":6380|:6381|:6382"
tcp 127.0.0.1: 0.0.0.0:* LISTEN /redis-server
tcp 127.0.0.1: 0.0.0.0:* LISTEN /redis-server
tcp 127.0.0.1: 0.0.0.0:* LISTEN /redis-server
[root@localhost redis]#
[root@localhost redis]#

验证(略) redis-cli -p 6380 ; redi-cli -p 6381 ; redis-cli -p 6382

三,配置主从同步
修改从库配置,6380实例为主库,  从库为 6381,6382


[root@localhost ~]# vim /data/redis//conf/redis.conf
[root@localhost ~]# vim /data/redis//conf/redis.conf ################################# REPLICATION ################################# # Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
# ) Redis replication is asynchronous, but you can configure a master to
# stop accepting writes if it appears to be not connected with at least
# a given number of slaves.
# ) Redis slaves are able to perform a partial resynchronization with the
# master if the replication link is lost for a relatively small amount of
# time. You may want to configure the replication backlog size (see the next
# sections of this file) with a sensible value depending on your needs.
# ) Replication is automatic and does not need user intervention. After a
# network partition slaves automatically try to reconnect to masters
# and resynchronize with them.
#
# slaveof <masterip> <masterport>
slaveof 127.0.0.1 # If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the slave to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the slave request.
#
# masterauth <master-password> # When a slave loses its connection with the master, or when the replication
# is still in progress, the slave can act in two different ways:
#
# ) if slave-serve-stale-data is set to 'yes' (the default) the slave will
# still reply to client requests, possibly with out of date data, or the
# data set may just be empty if this is the first synchronization.
#
# ) if slave-serve-stale-data is set to 'no' the slave will reply with
# an error "SYNC with master in progress" to all the kind of commands

验证:

先在主库上info一下

[root@localhost ]# redis-cli -p  "info"
.
.此处略去n行
.
# Replication
role:master            <== 角色:master
connected_slaves:                      <== slave链接数
slave0:ip=127.0.0.1,port=,state=online,offset=,lag= <== slave 的信息
slave1:ip=127.0.0.1,port=,state=online,offset=,lag=
master_repl_offset:
repl_backlog_active:
repl_backlog_size:
repl_backlog_first_byte_offset:
repl_backlog_histlen:

看看从库

[root@localhost ]# redis-cli -p  "info"
...
.此处略去n行
....
# Replication
role:slave         <==角色 slave
master_host:127.0.0.1   <==master主机
master_port:      <== master端口
master_link_status:up <== 链接状态 up
master_last_io_seconds_ago:
master_sync_in_progress:
slave_repl_offset:
slave_priority:
slave_read_only:
connected_slaves:
master_repl_offset:
repl_backlog_active:
repl_backlog_size:
repl_backlog_first_byte_offset:
repl_backlog_histlen:
[root@localhost ]# redis-cli -p  "info"
...
.此处略去n行
....
# Replication
role:slave
master_host:127.0.0.1
master_port:
master_link_status:up
master_last_io_seconds_ago:
master_sync_in_progress:
slave_repl_offset:
slave_priority:
slave_read_only:
connected_slaves:
master_repl_offset:
repl_backlog_active:
repl_backlog_size:
repl_backlog_first_byte_offset:
repl_backlog_histlen:


在主库上写入数据:

[root@localhost ]# redis-cli -p
127.0.0.1:> set k1 v1
OK
127.0.0.1:> keys *
) "k1"
127.0.0.1:> get k1
"v1"
127.0.0.1:>

从库上查看是否已同步
[root@localhost ]# redis-cli -p
127.0.0.1:> keys *
) "k1"
127.0.0.1:> get k1
"v1"
127.0.0.1:>
127.0.0.1:> exit
[root@localhost ]# redis-cli -p
127.0.0.1:> keys *
) "k1"
127.0.0.1:> get k1
"v1"
127.0.0.1:>

主库删除数据:

[root@localhost ]# redis-cli -p
127.0.0.1:> keys *
) "k1"
127.0.0.1:> del k1
(integer)
127.0.0.1:> keys *
(empty list or set)
127.0.0.1:>

从库查看

[root@localhost ]# redis-cli -p
127.0.0.1:> keys *
(empty list or set)
127.0.0.1:> exit
[root@localhost ]# redis-cli -p
127.0.0.1:> keys *
(empty list or set)
127.0.0.1:>
127.0.0.1:> exit
[root@localhost ]#

END

本文转自:http://www.cnblogs.com/lgeng/p/6623336.html


Redis单机配置多实例,实现主从同步的更多相关文章

  1. redis master配置了密码进行主从同步

    1.如果master不设置密码,那么直接在slave服务器配置slaveof即可 配置如下 #slaveof ip 端口 slaveof 配置好我们看下redis的日志 看是否同步成功 :S Jan ...

  2. redis多实例与主从同步及高级特性(数据过期机制,持久化存储)

    redis多实例 创建redis的存储目录 vim /usr/local/redis/conf/redis.conf #修改redis的配置文件 dir /data/redis/ #将存储路径配置修改 ...

  3. redis配置文件详解及实现主从同步切换

    原理:redis复制是怎么进行工作 如果设置了一个slave,不管是在第一次链接还是重新链接master的时候,slave会发送一个同步命令 然后master开始后台保存,收集所有对修改数据的命令.当 ...

  4. MySQL多实例,主从同步

    由于背景原因,所做的主从同步还是要基于MySQL 5.1的版本,主从同步主要是一个数据库读写访问原来的数据库热度过大,需要做到使用从库对读分压. MySQL主从同步介绍     MySQL 支持单双向 ...

  5. Redis 单机和多实例部署

    作者:北京运维 1. 安装环境说明 OS 版本:CentOS 7.5.1804 Redis 版本:redis-3.2.12 Redis 下载页面:http://download.redis.io/re ...

  6. mysql数据库的多实例与主从同步。

    1.MySQL的多实例: 多实例的特点:能够有效地利用服务器的资源,节约服务器的资源 MySQL多实例的配置有两种,第一是使用一个配置文件,这种方法不推荐使用,容易出错:第二种是用多个配置文件,这种方 ...

  7. CentOS7安装配置MariaDB(mysql)数据主从同步

    CentOS7安装MariaDB并配置主从同步 环境声明: 防火墙firewalld及SElinux均为关闭状态 主库节点:192.168.0.63 从库节点:192.168.0.64 配置主库节点: ...

  8. Linux centosVMware MySQL主从介绍、准备工作、配置主、配置从、测试主从同步

    一.MySQL主从介绍 MySQL主从又叫做Replication.AB复制.简单讲就是A和B两台机器做主从后,在A上写数据,另外一台B也会跟着写数据,两者数据实时同步的 MySQL主从是基于binl ...

  9. Redis单机配置以及集群(sentinel、jediscluster)配置

    最近一直在使用Redis作为缓存数据库,在使用当中,刚开始没有注意配置问题. 1.纯粹的注入单机模式 <bean id="jedisPoolConfig" class=&qu ...

随机推荐

  1. <meta> 标签 和<title> 标签

    <meta> 标签 主流浏览器都支持 <meta> 标签. 标签定义及使用说明 元数据(Metadata)是数据的数据信息. <meta> 标签提供了 HTML 文 ...

  2. Js的reduce()方法

    Js 数组reduce()方法应用一个函数针对数组的两个值(从左到右),以减至一个值. 语法:array.reduce(callback[, initialValue]) 参数说明: 1)callba ...

  3. WEB项目挂载到IIS session过期

    莫名丢失问题: 1.可能是因为系统内部连续的抛出了5次以上的异常 导致进程重启(当前所有在线用户) 2.IIS6 以上默认配置进程,session存在进程内其实是在W3wp.exe中这个进程不稳定,在 ...

  4. 利用OpenStreetMap(OSM)数据搭建一个地图服务

     http://www.cnblogs.com/LBSer/p/4451471.html 图 利用OSM数据简单发布的北京地图服务   一.OSM是什么 开放街道图(OpenStreetMap,简称O ...

  5. springmvc实现视频上传+进度条

    前台表单: <form id="uploadform" method="post" enctype="multipart/form-data&q ...

  6. pip 使用豆瓣源

    pip 使用豆瓣源 由于pip 默认使用Python的官方源pypi.python.org/pypi,导致我们经常使用pip装包时速度过慢或者无法安装(请求超时)等问题, 所以国内用户建议使用pip ...

  7. Android 中使用 dlib+opencv 实现动态人脸检测

    1 概述 完成 Android 相机预览功能以后,在此基础上我使用 dlib 与 opencv 库做了一个关于人脸检测的 demo.该 demo 在相机预览过程中对人脸进行实时检测,并将检测到的人脸用 ...

  8. 通过apt-get安装JDK8

    安装python-software-properties $sudo apt-get install python-software-properties $sudo apt-get install ...

  9. 【原】Java学习笔记021 - Object

    package cn.temptation; public class Sample01 { public static void main(String[] args) { // 类 Object: ...

  10. KASAN实现原理【转】

    1. 前言 KASAN是一个动态检测内存错误的工具.KASAN可以检测全局变量.栈.堆分配的内存发生越界访问等问题.功能比SLUB DEBUG齐全并且支持实时检测.越界访问的严重性和危害性通过我之前的 ...