溫馨提示×

溫馨提示×

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

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

怎么安裝和配置Redis

發(fā)布時間:2021-07-06 13:54:20 來源:億速云 閱讀:176 作者:小新 欄目:關(guān)系型數(shù)據(jù)庫

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

一、準(zhǔn)備好 gcc 環(huán)境

yum install gcc-c++

出現(xiàn)以下日志,代表安裝成功。Package gcc-c++-4.8.5-39.el7.x86_64 already installed and latest version

Loaded plugins: fastestmirror
Determining fastest mirrors
base                                                                     | 3.6 kB  00:00:00     
docker-ce-stable                                                         | 3.5 kB  00:00:00     
epel                                                                     | 4.7 kB  00:00:00     
extras                                                                   | 2.9 kB  00:00:00     
nginx                                                                    | 2.9 kB  00:00:00     
updates                                                                  | 2.9 kB  00:00:00     
(1/7): epel/x86_64/group_gz                                              |  95 kB  00:00:00     
(2/7): epel/x86_64/updateinfo                                            | 1.0 MB  00:00:00     
(3/7): docker-ce-stable/x86_64/primary_db                                |  45 kB  00:00:00     
(4/7): extras/7/x86_64/primary_db                                        | 205 kB  00:00:00     
(5/7): updates/7/x86_64/primary_db                                       | 3.0 MB  00:00:00     
(6/7): epel/x86_64/primary_db                                            | 6.8 MB  00:00:00     
(7/7): nginx/x86_64/primary_db                                           |  55 kB  00:00:02     
Package gcc-c++-4.8.5-39.el7.x86_64 already installed and latest version
Nothing to do
[root@root ~]#

二、下載并安裝Redis

執(zhí)行命令:wget http://download.redis.io/releases/redis-5.0.7.tar.gz。下載完成之后進(jìn)行解壓。再先后執(zhí)行 make、make install命令。

[root@root /]# cd usr/java
[root@root java]# mkdir redis
[root@root java]# cd redis/
[root@root redis]# wget http://download.redis.io/releases/redis-5.0.7.tar.gz
[root@root redis]# tar -zxvf redis-5.0.7.tar.gz
[root@root redis]# cd redis-5.0.7
[root@root redis-5.0.7]# make
[root@root redis-5.0.7]# make install

三、啟動

輸入命令:redis-server redis.conf ,啟動Redis。看到以下頁面代表啟動成功。

[root@root redis-5.0.7]# redis-server redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 12513
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'

但是這種啟動沒有辦法在這個tab頁下做任何操作了,因為這個時候使用Ctrl+c之后,就變成了這個樣子。也就是關(guān)閉了Redis,這種方式是前臺啟動。

^C13082:signal-handler (1594381754) Received SIGINT scheduling shutdown...
13082:M 10 Jul 2020 19:49:14.132 # User requested shutdown...
13082:M 10 Jul 2020 19:49:14.132 * Saving the final RDB snapshot before exiting.
13082:M 10 Jul 2020 19:49:14.135 * DB saved on disk
13082:M 10 Jul 2020 19:49:14.135 * Removing the pid file.
13082:M 10 Jul 2020 19:49:14.135 # Redis is now ready to exit, bye bye...

四、后臺啟動

打開redis.conf 文件。這也是Redis的配置文件。

[root@root redis-5.0.7]# vim redis.conf 
#打開之后,在命令窗口按下/輸入daem然后回車

怎么安裝和配置Redis

修改為yes

daemonize yes

Redis默認(rèn)不是以守護(hù)進(jìn)程的方式運(yùn)行,可以通過該配置項修改,使用yes啟用守護(hù)進(jìn)程,啟用守護(hù)進(jìn)程后,Redis會把pid寫到一個pidfile中,在/var/run/redis_6379.pid文件中。

再次啟動

[root@root redis-5.0.7]# redis-server redis.conf 
13352:C 10 Jul 2020 19:54:34.301 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
13352:C 10 Jul 2020 19:54:34.301 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=13352, just started
13352:C 10 Jul 2020 19:54:34.301 # Configuration loaded

五、連接Redis

[root@root redis-5.0.7]# redis-cli 
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> config get requirepass
#查看密碼
1) "requirepass"
2) ""
127.0.0.1:6379>

設(shè)置密碼

我們發(fā)現(xiàn)竟然不需要密碼就可以進(jìn)入Redis。那怎么設(shè)置呢?

requirepass foobared:設(shè)置 Redis 連接密碼,如果配置了連接密碼,客戶端在連接 Redis 時需要通過 AUTH password命令提供密碼,默認(rèn)是關(guān)閉。

1、臨時設(shè)置

config set requirepass 123456

2、永久設(shè)置

[root@root redis-5.0.7]# vim redis.conf
#打開之后,在命令窗口按下/輸入 requirepass 然后回車

找到如圖所示的內(nèi)容,將注釋放開設(shè)置自己的密碼。

怎么安裝和配置Redis

怎么安裝和配置Redis

然后重啟Redis

[root@root redis-5.0.7]# redis-server redis.conf 
[root@root redis-5.0.7]# redis-cli 
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth xxx
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>

可以看到第一次ping的時候提示我需要身份驗證。auth xxx這是連接后輸入密碼。也可以在連接的時候輸入:

[root@root redis-5.0.7]# redis-cli -p 6379 -a xxx

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

向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