Linux下設定redis訪問密碼

2021-09-13 09:11:28 字數 1776 閱讀 8138

今天伺服器安裝了redis,為了安全設定一下訪問redis-server的密碼。
我們伺服器已經安裝了redis,現在通過命令檢視下redis的程序:

[root@lnp ~]# ps -aux|grep redis

root 7374 0.0 0.0 145312 7524 ? ssl 16:37 0:00 redis-server 192.168.17.105:6379

root 10692 0.0 0.0 112724 984 pts/7 s+ 16:54 0:00 grep --color=auto redis

可以看到我們的redis-server的服務位址為192.168.17.105,埠為6379,對外訪問的時候需要指定對應的ip和埠:

redis-cli -h 192.168.17.105 -p 6379
查詢redis安裝目錄

> whereis redis

redis: /usr/local/redis

我們可以看到redis在該目錄下安裝,然後找到配置檔案redis.conf

> find /usr/local/redis/ -name redis.conf

/usr/local/redis/etc/redis.conf

修改配置檔案:

vim redis.conf
改該配置檔案即可:

# requirepass foobared

requirepass 123 指定密碼123

redis-server /usr/local/redis/etc/redis.conf
通過密碼-a訪問:

> redis-cli -h 192.168.17.105 -p 6379 -a 123
執行結果:

[root@lnp etc]# redis-cli

could not connect to redis at 127.0.0.1:6379: connection refused

could not connect to redis at 127.0.0.1:6379: connection refused

not connected> exit

[root@lnp etc]# redis-cli -h 192.168.17.105 -p 6379

192.168.17.105:6379> keys *

(error) noauth authentication required.

192.168.17.105:6379> exit

[root@lnp etc]# redis-cli -h 192.168.17.105 -p 6379 -a 123

warning: using a password with '-a' option on the command line inte***ce may not be safe.

192.168.17.105:6379> keys *

(empty list or set)

192.168.17.105:6379> exit

Linux下設定Redis開機自啟

1 設定redis.conf 中daemonize 為yes 確保守護程序開啟。2 vi etc init.d redis 內容如下,然後儲存退出。chkconfig 2345 10 90 description start and stop redis path usr local bin sbi...

Linux下設定網絡卡

linux下設定網絡卡的速率和模式 mii tool f 100basetx fd eth0 把網絡卡eth0設定為100m的全雙工模式 還可以用 ethtool ethtool s eth0 speed 100 duplex full autoneg on 檢視機器上的網絡卡裝置 lspci 檢視...

Linux下設定時間

提供兩種最根本有效的方式,就是更改時區。這裡以更改為國內上海時間例子,其他地方時區同理。備份檔案 mv etc localtime etc localtime.bak 複製時區檔案 cp usr share zoneinfo asia shanghai etc localtime 這裡選擇了亞洲下的...