Redis在Windows設定密碼的方式如下。
Redis在Windows安裝預設不用密碼即可操作,要使用密碼可在redis Windows配置文件redis.windows.conf
找到requirepass
參數並移除前面的#
取消註解,後面改為要設定的密碼,例如12345
。
redis.windows.conf
...
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
requirepass 12345
...
設定完在Redis安裝目錄輸入redis-server redis.windows.conf
啟動redis並讀取redis.windows.conf
配置。
C:\Program Files\Redis>redis-server redis.windows.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2.100 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 9804
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[9804] 08 Jun 11:41:42.388 # Server started, Redis version 3.2.100
[9804] 08 Jun 11:41:42.388 * DB loaded from disk: 0.000 seconds
[9804] 08 Jun 11:41:42.388 * The server is now ready to accept connections on port 6379
在redis-cli介面若未提供密碼進行讀取操作例如輸入GET mykey
會出現錯誤。
> GET mykey
(error) NOAUTH Authentication required.
使用AUTH <password>
輸入密碼,<password>
為在redis.windows.conf
設定的密碼12345
。
> AUTH 12345
OK
驗證成功後即可正常操作。
> GET mykey
"hello"
在Redis 6.0以後可使用Redis ACL設定不同的帳戶密碼及權限。
沒有留言:
張貼留言