首頁  >  文章  >  資料庫  >  詳解如何安裝和設定Redis(Linux環境)

詳解如何安裝和設定Redis(Linux環境)

青灯夜游
青灯夜游轉載
2021-07-06 12:10:261734瀏覽

如何安裝Redis?以下這篇文章跟大家介紹Linux環境下安裝和設定Redis的方法。

詳解如何安裝和設定Redis(Linux環境)

【相關推薦:Redis影片教學

一、準備好gcc 環境

yum install gcc-c++

出現以下日誌,代表安裝成功。 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

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

#2、下載並安裝Redis執行指令:wget http://download.redis.io/releases/redis-5.0.7.ta​​r.gz。下載完成之後進行解壓縮。再先後執行

make

make install#指令。

[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        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'

三、啟動輸入指令:

redis-server redis.conf

,啟動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...
但這種啟動沒有辦法在這個

tab

頁下做任何操作了,因為這個時候使用Ctrl c之後,就變成了這個樣子。也就是關閉了Redis,這種方式就是前台啟動。

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

四、後台啟動開啟

redis.conf

檔案。這也是詳解如何安裝和設定Redis(Linux環境)Redis

的設定檔。

daemonize yes

修改為yes

[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預設不是以守護程式的方式運行,可以透過該設定項修改,使用yes啟用守護進程,啟用守護程式後,Redis會把pid寫到一個pidfile中,在/var/run/redis_6379.pid檔中。

再次啟動

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

五、連接Redis

config set requirepass 123456

設定密碼

##我們發現竟然不需要密碼就可以進入

Redis。那怎麼設定呢? requirepass foobared:設定 Redis 連線密碼,如果設定了連線密碼,客戶端在連線Redis

時需要透過

AUTH password

指令提供密碼,預設是關閉。

1、臨時設定

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

2、永久設定

[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>
詳解如何安裝和設定Redis(Linux環境)#找到如圖所示的內容,將註解放開設定自己的密碼。

詳解如何安裝和設定Redis(Linux環境)

然後重新啟動

Redis

[root@root redis-5.0.7]# redis-cli -p 6379 -a xxx
可以看到第一次ping的時候提示我需要身份驗證。

auth xxx這是連線後輸入密碼。也可以在連線的時候輸入:rrreee

線上體驗:
try.redis.io/

本文轉載自:https://juejin.cn /post/6979019298543140901#heading-4

作者:程式設計師小傑##更多程式相關知識,請造訪:

程式設計教學###! ! ###

以上是詳解如何安裝和設定Redis(Linux環境)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:juejin.cn。如有侵權,請聯絡admin@php.cn刪除