Redis知识点
admin
2023-06-06 22:01:57
0

1、关于配置文件

redis启动如果不显式地指定配置文件,则默认不使用任何配置文件,而是使用它自己的默认配置。所以,如果修改了配置文件的内容,但若启动时没有显式地指定它,则对它的修改不会有任何效果。

 

如果redis_6379里配置文件是/etc/redis/6379.conf,则使用redis-server /etc/redis/6379.conf启动,与使用/etc/init.d/redis_6379start启动是启动的同一个实例。

 

vim /etc/init.d/redis_6379

 

#!/bin/sh
#Configurations injected by  install_server below....
 
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/etc/redis/6379.conf"
REDISPORT="6379"

2、Redis复制

(1)在同一台主机的不同实例之间实现复制:只需在slave实例的配置文件中,添加:

slaveof master_ip master_port

就可以了;

(2)在不同主机之间实现复制:除了实现(1)中的配置之外,还需要:

A.在master的配置文件中注释掉监听地址 bind一行

B.将protected-mode的值由yes改为no(仅限没有设置bind并且没有设置密码的时候)


设置密码:

在配置文件中加入

requirepass redis

以上“redis”即为密码。保存后重启master的服务。

[root@host103 ~]# /etc/init.d/redis_6379 restart
Stopping ...
Redis stopped
Starting Redis server...
[root@host103 ~]# redis-cli -p 6379 info
NOAUTH Authentication required.
[root@host103 ~]# redis-cli -p 6379
127.0.0.1:6379> keys * 
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth redis
OK
127.0.0.1:6379> keys *
1) "c"
2) "d"
3) "a"
4) "b"
5) "e"

在master设置密码之后,slave是无法与其进行同步的,此时要修改slave的配置文件:

slaveof 127.0.0.1 6379

# 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 

masterauth redis

保存并重启slave服务。


遇到的一个问题:

在虚拟机不同主机(192.168.1.111和192.168.1.112)之间配置redis复制,slave端已经加入“slaveof Redis知识点192.168.1.111 6378”,并且在master注释掉bind,但无法实现复制,在slave上显示:

redis-cli -p 6379 info


Redis知识点

查看slave端的日志:

tail -n200 /var/log/redis_6379.log


Redis知识点

 在112上运行如下命令:

[root@host112 log]# telnet 192.168.1.111 6379

有如下结果:

[root@host112 log]# telnet 192.168.1.111 6379

Trying 192.168.1.111...

Connected to 192.168.1.111.

Escape character is '^]'.

-DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

Connection closed by foreign host.


参考http://arui.me/index.php/archives/151/

将master的这一项protected-mode由yes改为no,就可以正常实现复制了。该参数是3.2版本之后加入的新特性。


(未完待续)

相关内容

热门资讯

香江警花,即将绽放于星空之间 潮新闻客户端 记者 屠晨昕 今天(23日)上午,神舟二十三号载人飞行任务新闻发布会,给了整个香港乃至...
美官员披露美伊即将签署协议的更... △霍尔木兹海峡(资料图)据美国方面23日消息,美国和伊朗即将达成一份协议,其中包括将停火再延长60天...
现代AI系统通过图灵测试首获证... 美国加州大学圣迭戈分校科学家开展了一项实证研究,首次证明现代人工智能(AI)系统通过了图灵测试。相关...
强劲“中国心” 国产自研600... 5月23日,内蒙古锡林郭勒盟上空传来轰鸣声:由我国自主研制的600公斤推力级F406涡扇发动机,双发...
留神峪矿难获救矿工讲述:自救器... 5月22日晚7时29分,山西留神峪煤矿发生瓦斯爆炸事故,已致82人死亡。据央视新闻,事故发生后,留神...
预祝圆满成功!李家超与黎家盈视... 据凤凰卫视报道,神舟二十三号载人飞船即将发射,乘组成员包括首位来自香港的航天员黎家盈。香港特区行政长...
《给阿嬷的情书》,票房超10亿... 据网络平台数据截至5月24日,2026年度电影总票房(含预售)已突破151亿元!其中,电影《给阿嬷的...
美媒称伊朗同意放弃高浓缩铀库存 新华社华盛顿5月23日电(记者黄强 颜亮)据美国媒体23日报道,作为美国与伊朗即将达成的协议中的一个...
全自动洗衣机进水管漏水怎么办 造成全自动洗衣机进水管漏水,要根据原因寻找解决办法,1、由于洗衣机进水管使用年限过长,部分出现损坏,...
电视机闪屏一下又黑屏 问答:1、电视显示屏出现短路或损坏等问题。2、电视的信号源出现干扰。3、电视内部的小零件损坏,如屏幕...