CentOS7.4如何安裝redis4.0

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

成都創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站設(shè)計(jì)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的濉溪網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

一、redis單實(shí)例安裝


1、安裝依賴包

[root@VM_2_13_centos redis]# yum install gcc*

2、獲取安裝文件

[root@VM_2_13_centos redis]# wgethttp://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、啟動(dòng)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、設(shè)置密碼

redis的默認(rèn)安裝是不設(shè)置密碼的,可以在redis.conf中進(jìn)行配置

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

requirepass qcloud@2018

或者通過命令配置

127.0.0.1:6379>CONFIG set requirepass qcloud@2018

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

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

驗(yàn)證密碼是否有效,是否需要認(rèn)證

[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

關(guān)閉redis,但是由于上面設(shè)置了密碼,必須要認(rèn)證成功后才能關(guān)閉

[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     ""

重新啟動(dòng)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'

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

3、綁定只能本機(jī)訪問

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

bind 127.0.0.1

4、設(shè)置redis開啟自啟動(dòng)

[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)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

文章名稱:CentOS7.4如何安裝redis4.0
URL鏈接:http://muchs.cn/article0/gdihoo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、網(wǎng)站排名、微信小程序網(wǎng)站收錄、企業(yè)建站、品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化