Redis 安裝(ubuntu/mac/windows)_初步使用

Redis 安裝(ubuntu/mac/windows)

前言

Redis是常用基於內存的Key-Value數據庫,比Memcache更先進,支持多種數據結構,高效,快速。用Redis可以很輕鬆解決高併發的數據訪問問題;作爲實時監控信號處理也非常不錯。

ubuntu16.04下安裝redis

  • 安裝Redis服務器端
 sudo apt-get install redis-server

安裝完成後,Redis服務器會自動啓動,我們檢查Redis服務器程序

  • 檢查Redis服務器系統進程
root@iZj6c51e3fbtaydnscnwf8Z:~# ps -aux|grep redis
root      4225  0.0  0.0  14224   916 pts/3    S+   01:14   0:00 grep --color=auto redis            
redis    31479  0.0  0.2  40136  3028 ?        Ssl  Jan02   0:19 /usr/bin/redis-server *:6379       
root@iZj6c51e3fbtaydnscnwf8Z:~# 
  • 通過啓動命令檢查Redis服務器狀態
root@iZj6c51e3fbtaydnscnwf8Z:~# netstat -nlt|grep 6379
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN                          
tcp6       0      0 :::6379                 :::*                    LISTEN                          
root@iZj6c51e3fbtaydnscnwf8Z:~# 

通過啓動命令,查看當前redis狀態

root@iZj6c51e3fbtaydnscnwf8Z:~# sudo /etc/init.d/redis-server status
● redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2019-01-02 19:03:53 CST; 6h ago
     Docs: http://redis.io/documentation,
           man:redis-server(1)
  Process: 31463 ExecStopPost=/bin/run-parts --verbose /etc/redis/redis-server.post-down.d (code=exi
ted, status=0/SUCCESS)
  Process: 31457 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
  Process: 31451 ExecStop=/bin/run-parts --verbose /etc/redis/redis-server.pre-down.d (code=exited, 
status=0/SUCCESS)
  Process: 31480 ExecStartPost=/bin/run-parts --verbose /etc/redis/redis-server.post-up.d (code=exit
ed, status=0/SUCCESS)
  Process: 31477 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCES
S)
  Process: 31471 ExecStartPre=/bin/run-parts --verbose /etc/redis/redis-server.pre-up.d (code=exited
, status=0/SUCCESS)
 Main PID: 31479 (redis-server)
   CGroup: /system.slice/redis-server.service
           └─31479 /usr/bin/redis-server *:6379

Jan 02 19:03:53 iZj6c51e3fbtaydnscnwf8Z systemd[1]: Stopped Advanced key-value store.
Jan 02 19:03:53 iZj6c51e3fbtaydnscnwf8Z systemd[1]: Starting Advanced key-value store...
Jan 02 19:03:53 iZj6c51e3fbtaydnscnwf8Z systemd[1]: Started Advanced key-value store.
root@iZj6c51e3fbtaydnscnwf8Z:~# 
  • 訪問Redis 訪問redis有本地訪問和遠程訪問
    安裝Redis服務器,會自動地一起安裝Redis命令行客戶端程序。
    在本機輸入redis-cli命令就可以啓動,客戶端程序訪問Redis服務器。
    本機:
root@iZj6c51e3fbtaydnscnwf8Z:~# redis-cli
127.0.0.1:6379> status                                                                              
(error) ERR unknown command 'status'
127.0.0.1:6379> help                                                                                
redis-cli 3.0.6
Type: "help @<group>" to get a list of commands in <group>
      "help <command>" for help on <command>
      "help <tab>" to get a list of possible help topics
      "quit" to exit
127.0.0.1:6379> 

遠程訪問,需要在遠程端本地,配置redis環境,安裝redis即可。如果是windos,訪問如下:
在這裏插入圖片描述

  • 修改Redis的配置 使用Redis的訪問賬號
    默認情況下,訪問Redis服務器是不需要密碼的,爲了增加安全性我們需要設置Redis服務器的訪問密碼。設置訪問密碼爲redisredis。
    用vi打開Redis服務器的配置文件redis.conf
sudo vi /etc/redis/redis.conf
#取消註釋requirepass
requirepass redisredis
  • 讓Redis服務器被遠程訪問

默認情況下,Redis服務器不允許遠程訪問,只允許本機訪問,所以我們需要設置打開遠程訪問的功能。
用vi打開Redis服務器的配置文件redis.conf

sudo vi /etc/redis/redis.conf

#註釋bind
#bind 127.0.0.1
  • 修改後,重啓Redis服務器
    重啓redis:systemctl restart redies.service

mac下安裝redis

  • 安裝 使用brew 安裝即可
ogon:~ wfc$ brew install redis
Error: Another active Homebrew update process is already in progress.
Please wait for it to finish or terminate it to continue.
Warning: redis 4.0.11 is already installed and up-to-date
To reinstall 4.0.11, run `brew reinstall redis`
bogon:~ wfc$ brew uninstall redis
Uninstalling /usr/local/Cellar/redis/4.0.11... (13 files, 2.8MB)
redis 4.0.2 1 is still installed.
Remove all versions with `brew uninstall --force redis`.
bogon:~ wfc$ brew uninstall --force redis
Uninstalling redis... (26 files, 5.6MB)
bogon:~ wfc$ brew install redis
Updating Homebrew...
Warning: redis 4.0.11 is already installed and up-to-date
To reinstall 4.0.11, run `brew reinstall redis`
bogon:~ wfc$ cd /usr/local
bogon:local wfc$ ls -l
  • 配置文件路徑: /usr/local/etc/redis.conf 更改配置文件,參看ubuntu 安裝環境,修改配置文件

Mac使用Redis參考
啓動服務: redis-server
正式執行命令行:redis-cli

mac環境下,Redis客戶端:redis-desktop-manager
Redis桌面管理工具Mac版是一款基於Qt5的跨平臺Redis桌面管理軟件,支持C++編寫,響應迅速,性能好。但不支持數據庫備份與恢復。
官方現在是收費的,其他的渠道基本上也都要花錢購買,購買完分享給大家。
csdn 資源下載推薦:
https://download.csdn.net/download/itjavawfc/10894504

windows下安裝redis

官網:https://redis.io/
最終會指向 github 地址:https://github.com/MicrosoftArchive/redis
在這裏插入圖片描述

在這裏插入圖片描述

下載得到的文件目錄,輸入: redis-server.exe redis.windows.conf 當你看見標誌性圖騰,就代表安裝成功了。

Windows 下初步使用

  • 配置好命令環境,下載目錄直接配置到系統變量path下
  • 在下載目錄下,直接單擊redis-server.exe 命令執行.出現圖騰窗口,代表服務啓動了
  • 另啓一個窗口,輸入命令redis-cli.exe -h 127.0.0.1 -p 6379 結果如下,就可以進行基本命令操作了。
    在這裏插入圖片描述
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章