溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Redis知識點

發(fā)布時間:2020-06-30 11:41:26 來源:網(wǎng)絡(luò) 閱讀:498 作者:linux200801 欄目:數(shù)據(jù)庫

1、關(guān)于配置文件

redis啟動如果不顯式地指定配置文件,則默認(rèn)不使用任何配置文件,而是使用它自己的默認(rèn)配置。所以,如果修改了配置文件的內(nèi)容,但若啟動時沒有顯式地指定它,則對它的修改不會有任何效果。

 

如果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復(fù)制

(1)在同一臺主機(jī)的不同實例之間實現(xiàn)復(fù)制:只需在slave實例的配置文件中,添加:

slaveof master_ip master_port

就可以了;

(2)在不同主機(jī)之間實現(xiàn)復(fù)制:除了實現(xiàn)(1)中的配置之外,還需要:

A.在master的配置文件中注釋掉監(jiān)聽地址 bind一行

B.將protected-mode的值由yes改為no(僅限沒有設(shè)置bind并且沒有設(shè)置密碼的時候)


設(shè)置密碼:

在配置文件中加入

requirepass redis

以上“redis”即為密碼。保存后重啟master的服務(wù)。

[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設(shè)置密碼之后,slave是無法與其進(jìn)行同步的,此時要修改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 <master-password>

masterauth redis

保存并重啟slave服務(wù)。


遇到的一個問題:

在虛擬機(jī)不同主機(jī)(192.168.1.111和192.168.1.112)之間配置redis復(fù)制,slave端已經(jīng)加入“slaveof Redis知識點192.168.1.111 6378”,并且在master注釋掉bind,但無法實現(xiàn)復(fù)制,在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

有如下結(jié)果:

[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,就可以正常實現(xiàn)復(fù)制了。該參數(shù)是3.2版本之后加入的新特性。


(未完待續(xù))

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI