找了02,03,04三台机器,04做主,02做从,03做客户端。

都使用jumbo install redis安装了Redis(server+client)。

在 02 从的 ~/.jumbo/etc/redis.conf 里

slaveof <masterip> 6379

在04 主的 ~/.jumbo/etc/redis.conf 里

appendonly yes

appendfsync everysec

主从都要改:

daemonize yes

logfile "/home/work/.jumbo/var/log/redis/redis.log"

然后先启动主,再启动从,都使用

redis-server (因为deamonize为true,所以不用&)

报如下错误:

7652:C 05 Oct 16:59:37.203 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf

7652:M 05 Oct 16:59:37.207 # Creating Server TCP listening socket *:6379: unable to bind socket

然后发现居然是因为没有指定配置文件:

redis-server ~/.jumbo/etc/redis.conf

这样就可以了。

然后跑到03上,用客户端访问:

redis-cli  -h 10.117.146.16 -p 6379

发现:

Could not connect to Redis at 10.117.146.16:6379: Connection refused
Could not connect to Redis at 10.117.146.16:6379: Connection refused
not connected>

然后也发现从机一直报error log:

36855:S 05 Oct 17:10:57.379 * Connecting to MASTER 10.117.146.16:6379
36855:S 05 Oct 17:10:57.379 * MASTER <-> SLAVE sync started
36855:S 05 Oct 17:10:57.379 # Error condition on socket for SYNC: Connection refused

先把从Redis关了,用客户端:

$ redis-cli
127.0.0.1:6379> shutdown
not connected>
not connected> quit

然后再看Redis配置文件 vi ~/.jumbo/etc/redis.conf

有如下内容:

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1

所以,注释掉最后一行。重新启动。

然后又开始报这样的错:

12487:M 05 Oct 17:16:46.170 # Creating Server TCP listening socket *:6379: unable to bind socket

在redis.conf里面加上下面这行:

# bind 127.0.0.1
bind 0.0.0.0

重新启动:redis-server ~/.jumbo/etc/redis.conf

然后 ps xu | grep redis 可以看到:

work     23986  0.0  0.0 79428 2104 ?        Ssl  17:18   0:00 redis-server 0.0.0.0:6379

在03机器上可以访问:

redis-cli -h 10.117.x.x -p 6379
10.117.146.16:6379>

然后可以看到aof文件位置在:

$ ls -la ~/.jumbo/var/lib/redis/appendonly.aof
-rw-r--r-- 1 work work 0 Oct 5 17:06 /home/work/.jumbo/var/lib/redis/appendonly.aof

然后从Redis的日志有:

25089:S 05 Oct 17:22:59.018 * MASTER <-> SLAVE sync started
25089:S 05 Oct 17:22:59.018 * Non blocking connect for SYNC fired the event.
25089:S 05 Oct 17:22:59.019 * Master replied to PING, replication can continue...
25089:S 05 Oct 17:22:59.019 * Partial resynchronization not possible (no cached master)
25089:S 05 Oct 17:22:59.019 * Full resync from master: 64377169e1e5fc029ad8e584e24947a53d4f8fa0:1
25089:S 05 Oct 17:22:59.103 * MASTER <-> SLAVE sync: receiving 76 bytes from master
25089:S 05 Oct 17:22:59.104 * MASTER <-> SLAVE sync: Flushing old data
25089:S 05 Oct 17:22:59.104 * MASTER <-> SLAVE sync: Loading DB in memory
25089:S 05 Oct 17:22:59.104 * MASTER <-> SLAVE sync: Finished with success

主Redis的日志有:

23986:M 05 Oct 17:22:59.020 * Slave 10.117.x.x:6379 asks for synchronization
23986:M 05 Oct 17:22:59.020 * Full resync requested by slave 10.117.146.21:6379
23986:M 05 Oct 17:22:59.020 * Starting BGSAVE for SYNC with target: disk
23986:M 05 Oct 17:22:59.020 * Background saving started by pid 40323
40323:C 05 Oct 17:22:59.076 * DB saved on disk
40323:C 05 Oct 17:22:59.076 * RDB: 0 MB of memory used by copy-on-write
23986:M 05 Oct 17:22:59.104 * Background saving terminated with success
23986:M 05 Oct 17:22:59.104 * Synchronization with slave 10.117.x.x:6379 succeeded

以下是先用客户端访问主,再访问从的结果:

$ redis-cli -h 10.117.146.16 -p 6379
10.117.146.16:6379> zadd page_rank 10 google.com
(integer) 1
10.117.146.16:6379> zadd page_rank 9 baidu.com 8 bing.com
(integer) 2
10.117.146.16:6379> zrange page_rank 0 -1 withscores
1) "bing.com"
2) "8"
3) "baidu.com"
4) "9"
5) "google.com"
6) "10"
10.117.146.16:6379> zrange page_rank 0 -1
1) "bing.com"
2) "baidu.com"
3) "google.com"
10.117.146.16:6379> quit $ redis-cli -h 10.117.146.21 -p 6379
10.117.146.21:6379> zrange page_rank 0 -1 withscores
1) "bing.com"
2) "8"
3) "baidu.com"
4) "9"
5) "google.com"
6) "10"
10.117.146.21:6379> zrange page_rank 0 -1
1) "bing.com"
2) "baidu.com"
3) "google.com"
10.117.146.21:6379> quit

而此时查看主和从的日志,都没有明显的日志,因为日志开在了notice级别:

主:
40323:C 05 Oct 17:22:59.076 * RDB: 0 MB of memory used by copy-on-write
23986:M 05 Oct 17:22:59.104 * Background saving terminated with success
23986:M 05 Oct 17:22:59.104 * Synchronization with slave 10.117.146.21:6379 succeeded

从:
25089:S 05 Oct 17:22:59.019 * Partial resynchronization not possible (no cached master)
25089:S 05 Oct 17:22:59.019 * Full resync from master: 64377169e1e5fc029ad8e584e24947a53d4f8fa0:1
25089:S 05 Oct 17:22:59.103 * MASTER <-> SLAVE sync: receiving 76 bytes from master
25089:S 05 Oct 17:22:59.104 * MASTER <-> SLAVE sync: Flushing old data
25089:S 05 Oct 17:22:59.104 * MASTER <-> SLAVE sync: Loading DB in memory
25089:S 05 Oct 17:22:59.104 * MASTER <-> SLAVE sync: Finished with success

而aof文件,相比于刚才,已经有了增加:

$ ls -la ~/.jumbo/var/lib/redis/appendonly.aof
-rw-r--r-- 1 work work 149 Oct 5 17:28 /home/work/.jumbo/var/lib/redis/appendonly.aof 刚刚是:

$ ls -la ~/.jumbo/var/lib/redis/appendonly.aof
-rw-r--r-- 1 work work 0 Oct 5 17:06 /home/work/.jumbo/var/lib/redis/appendonly.aof

然后通过客户端分别关掉两个server:

$ redis-cli -h 10.117.146.21 -p 6379
10.117.146.21:6379> SHUTDOWN save
not connected> quit
$ redis-cli -h 10.117.146.16 -p 6379
10.117.146.16:6379> SHUTDOWN save
not connected>
not connected> quit

然后再次分别启动,来监测aof文件是否会自动加载。

用客户端连接,发现数据都还在,如下所示:

$ redis-cli -h 10.117.x.x -p 6379
10.117.x.x:6379> zrange page_rank 0 -1 withscores
1) "bing.com"
2) "8"
3) "baidu.com"
4) "9"
5) "google.com"
6) "10"
10.117.x.x:6379>

所以,aof文件是自动加载的。Redis的持久化是生效的。

再说一下Redis的密码验证:

现在安装的目录里配置文件位置:/home/work/.jumbo/etc/redis.conf

在master上:
# requirepass foobared
requirepass [用户名] 在slave上:
# masterauth <master-password>
masterauth [用户名]

然后重启。重启方法见前文。

之后访问的时候,会出现没有权限的情况,需要在命令前指定权限,或者在redis-cli参数里用 -a 加权限:

$ redis-cli -h 10.117.146.16 -p 6379
10.117.146.16:6379> keys *
(error) NOAUTH Authentication required.
10.117.146.16:6379> auth [用户名]
OK
10.117.146.16:6379> keys *
1) "age"
2) "testName"
3) "newset"
4) "k2"
5) "myhash"
6) "page_rank"
7) "myset"
8) "k1"
9) "myzset"
10) "myset2"
11) "k5"
12) "mylist"
13) "k3"
10.117.146.16:6379> quit $ redis-cli -h 10.117.146.16 -p 6379 -a [用户名]
10.117.146.16:6379> keys *
1) "age"
2) "testName"
3) "newset"
4) "k2"
5) "myhash"
6) "page_rank"
7) "myset"
8) "k1"
9) "myzset"
10) "myset2"
11) "k5"
12) "mylist"
13) "k3"
10.117.146.16:6379> quit $ redis-cli -h 10.117.146.16 -p 6379
10.117.146.16:6379> keys *
(error) NOAUTH Authentication required.
10.117.146.16:6379> auth abc
(error) ERR invalid password

Redis安装、主从配置及aof使用的更多相关文章

  1. docker+redis安装与配置,主从+哨兵模式

    docker+redis安装与配置 docker安装redis并且使用redis挂载的配置启动 1.拉取镜像 docker pull redis:3.2 2.准备准备挂载的目录和配置文件 首先在/do ...

  2. CentO7 安装 redis, 主从配置,Sentinel集群故障转移切换

        一.Redis的安装(前提是已经安装了EPEL)   安装redis: yum -y install redis 启动/停止/重启 Redis 启动服务: systemctl start re ...

  3. linux下安装redis及主从配置

    安装比较简单,确保linux安装有gcc # gcc -v 查看gcc版本,如果没有yum安装即可 安装开始 1.redis-3.2.8.tar.gz 上传至服务器 (百度网盘:http://pan. ...

  4. docker Redis的主从配置

    redis是k-v型nosql数据库,支持字符串(string).列表(list).集合(set).散列(hash).有序集合(zset:形如member:score的散列集合,其中member为成员 ...

  5. redis安装和配置(一)

    Redis 的官方下载站是http://redis.io/download 怎么安装 Redis 数据库呢?下面将介绍Linux 版本的安装方法 步骤一: 下载Redis 下载安装包:wget htt ...

  6. CentOS 下 redis 安装与配置

    CentOS 下 redis 安装与配置   1.到官网上找到合适版本下载解压安装 [root@java src]# wget -c http://redis.googlecode.com/files ...

  7. redis 安装及配置

    一.安装Redis 1.到官网下载redis最新版本,我下载的是 http://redis.io/ 2.拷贝redis-3.0.3到/usr/local目录 3.解压缩sudo tar -zxf re ...

  8. Redis入门 -- Redis安装与配置

    Redis入门 -- Redis安装与配置 Redis的安装 Redis的安装,我这里使用的是虚拟机. 为了让主机和虚拟机之间可以顺利通信,按照以下步骤进行: 1. 将网络连接模式改为桥接 2. re ...

  9. windows下redis安装和配置

    windows下redis安装和配置 redis介绍 Redis是一个开源,高级的键值存储和一个适用的解决方案,用于构建高性能,可扩展的Web应用程序. Redis有三个主要特点,使它优越于其它键值数 ...

  10. Redis安装与配置Redis安装与配置

    今天在使用Redis的时候遇到了一些问题,这个问题的解决,发现很多人使用Redis的时候没有一点安全意识.所以又重温了一下Redis,觉得应该写一下Redis的安全和配置. Redis安装与配置Red ...

随机推荐

  1. CentOS7.6安装AMD显卡驱动

    1.检查自己的显卡类型[root@localhost amdgpu-pro-18.50-708488-rhel-7.6]# lspci | grep -i vga03:00.0 VGA compati ...

  2. Error:Unable to make the module:***, related gradle configuration was not found. Please, re-import the Gradle project and try again.

    打开idea的 View -> Tool Windows -> Gradle.然后点击 Refresh

  3. asp.net传多个值到其它页面的方法

    网站开发中,在页面之间的跳转,经常会用到传值,其中可能会传递多个值. 一.CommadArgument传多个值到其他页面. 像Gridview dataList repeater等数据绑定控件中,可以 ...

  4. 七牛刷新接口PHP实现

    <?php require_once '../autoload.php'; use Qiniu\Auth; use Qiniu\Http\Client; $accessKey = 'access ...

  5. HDU 6025 Coprime Sequence

    枚举,预处理. 预处理前缀$gcd$与后缀$gcd$,枚举删哪一个即可. #include <bits/stdc++.h> using namespace std; int T,n; ]; ...

  6. UVA12995 Farey Sequence [欧拉函数,欧拉筛]

    洛谷传送门 Farey Sequence (格式太难调,题面就不放了) 分析: 实际上求分数个数就是个幌子,观察可以得到,所求的就是$\sum^n_{i=2}\phi (i)$,所以直接欧拉筛+前缀和 ...

  7. 图形管线之旅 Part3

    原文:<A trip through the Graphics Pipeline 2011> 翻译:往昔之剑   转载请注明出处   此时,我们一路上通过多个驱动层和命令处理器将draw ...

  8. 安卓 Activity Fragment 生命周期

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 活动:  创建->启动->获得焦点->暂停->停止->销毁 ...

  9. 【可持久化并查集】BZOJ3673-可持久化并查集 by zky

    颓了十多天别问我再干嘛,在补学校作业 啊,开学了……我的夏天…… [题目大意] n个集合 m个操作 操作: 1 a b 合并a,b所在集合 2 k 回到第k次操作之后的状态(查询算作操作) 3 a b ...

  10. 【期望DP】BZOJ2318-[Spoj4060]Game with probability Problem

    [题目大意] Alice和Bob在玩一个游戏.有n个石子在这里,Alice和Bob轮流投掷硬币,如果正面朝上,则从n个石子中取出一个石子,否则不做任何事.取到最后一颗石子的人胜利.Alice在投掷硬币 ...