溫馨提示×

溫馨提示×

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

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

CentOS 7.4如何安裝redis 4.0

發(fā)布時間:2021-11-10 11:58:42 來源:億速云 閱讀:156 作者:小新 欄目:關系型數(shù)據(jù)庫

這篇文章主要為大家展示了“CentOS 7.4如何安裝redis 4.0”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“CentOS 7.4如何安裝redis 4.0”這篇文章吧。

一、redis單實例安裝


1、安裝依賴包

[root@VM_2_13_centos redis]# yum install gcc*

2、獲取安裝文件

[root@VM_2_13_centos redis]# wget http://download.redis.io/releases/redis-4.0.9.tar.gz

3、解壓文件

[root@VM_2_13_centos redis]# tar zxvf redis-4.0.9.tar.gz

[root@VM_2_13_centos redis]# ll

total 1708

drwxrwxr-x 6 root root    4096 Mar 27 00:04 redis-4.0.9

-rw-r--r-- 1 root root 1737022 Mar 27 00:04 redis-4.0.9.tar.gz

4、編譯安裝

[root@VM_2_13_centos redis-4.0.9]# make

[root@VM_2_13_centos redis-4.0.9]# make PREFIX=/usr/local/redis install

cd src && make install

make[1]: Entering directory `/usr/local/redis/redis-4.0.9/src'

    CC Makefile.dep

make[1]: Leaving directory `/usr/local/redis/redis-4.0.9/src'

make[1]: Entering directory `/usr/local/redis/redis-4.0.9/src'

Hint: It's a good idea to run 'make test' ;)

    INSTALL install

    INSTALL install

    INSTALL install

    INSTALL install

    INSTALL install

5、查看redis的版本

[root@VM_2_13_centos ~]# redis-server --version

Redis server v=4.0.9 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=c97ec2b5e9b86914

6、啟動redis

[root@VM_2_13_centos redis]# /usr/local/redis/bin/redis-server /etc/redis/redis.conf

[root@VM_2_13_centos redis]# netstat -tuplan | grep 6379

tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      5305/redis-server 1

[root@VM_2_13_centos redis]# ps -ef | grep redis

root      5305     1  0 21:38 ?        00:00:00 /usr/local/redis/bin/redis-server 127.0.0.1:6379

root      5356 30807  0 21:39 pts/1    00:00:00 grep --color=auto redis

7、通過客戶端登錄

[root@VM_2_13_centos ~]# redis-cli

127.0.0.1:6379>

備注:如果要卸載redis,把/usr/local/redis/bin/目錄下的redis刪除即可。為了卸載干凈,你還可以把解壓和編譯的redis包及配置的redis.conf也刪除。

二、安全配置

1、設置密碼

redis的默認安裝是不設置密碼的,可以在redis.conf中進行配置

[root@VM_2_13_centos ~]# vim /etc/redis/redis.conf

requirepass qcloud@2018

或者通過命令配置

127.0.0.1:6379>CONFIG set requirepass qcloud@2018

由于Redis的性能極高,并且輸入錯誤密碼后Redis并不會進行主動延遲(考慮到Redis的單線程模型),所以攻擊者可以通過窮舉法破解Redis的密碼(1秒內(nèi)能夠嘗試十幾萬個密碼),因此在設置時一定要選擇復雜的密碼,可以用隨機密碼生成器生成。

注意:配置Redis復制的時候如果主數(shù)據(jù)庫設置了密碼,需要在從數(shù)據(jù)庫的配置文件中通過masterauth參數(shù)設置主數(shù)據(jù)庫的密碼,以使從數(shù)據(jù)庫連接主數(shù)據(jù)庫時自動使用AUTH命令認證。

驗證密碼是否有效,是否需要認證

[root@VM_2_13_centos ~]# redis-cli

127.0.0.1:6379>

127.0.0.1:6379> keys *

(error) NOAUTH Authentication required.

127.0.0.1:6379>

127.0.0.1:6379> auth qcloud@2018

OK

127.0.0.1:6379>

127.0.0.1:6379> keys *

(empty list or set)

2、禁用高危命令

目前該命令可以正常使用

127.0.0.1:6379> flushall

OK

關閉redis,但是由于上面設置了密碼,必須要認證成功后才能關閉

[root@VM_2_13_centos ~]# redis-cli shutdown

(error) NOAUTH Authentication required.

[root@VM_2_13_centos ~]# redis-cli -a qcloud@2018 shutdown

[root@VM_2_13_centos ~]#

[root@VM_2_13_centos ~]# ps -ef | grep redis

root      6144  5406  0 21:54 pts/0    00:00:00 grep --color=auto redis

修改配置文件redis.conf,增加如下行:

[root@VM_2_13_centos ~]# vim /etc/redis/redis.conf

rename-command FLUSHALL ""

rename-command CONFIG   ""

rename-command EVAL     ""

重新啟動redis

[root@VM_2_13_centos ~]# redis-server /etc/redis/redis.conf

[root@VM_2_13_centos ~]#

[root@VM_2_13_centos ~]# redis-cli

127.0.0.1:6379>

127.0.0.1:6379> keys *

(error) NOAUTH Authentication required.

127.0.0.1:6379>

127.0.0.1:6379> auth qcloud@2018

OK

127.0.0.1:6379>

127.0.0.1:6379> flushall

(error) ERR unknown command 'flushall'

127.0.0.1:6379>

127.0.0.1:6379> config

(error) ERR unknown command 'config'

127.0.0.1:6379>

127.0.0.1:6379> eval

(error) ERR unknown command 'eval'

通過上面的報錯可以發(fā)現(xiàn),在配置文件禁用的三個命令無法使用

3、綁定只能本機訪問

[root@VM_2_13_centos ~]# vim /etc/redis/redis.conf

bind 127.0.0.1

4、設置redis開啟自啟動

[root@VM_2_13_centos ~]# vim /etc/rc.d/rc.local

/usr/local/redis/bin/redis-server /etc/redis/redis.conf &

以上是“CentOS 7.4如何安裝redis 4.0”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

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

AI