Mac安裝
使用Mac系統安裝,可以使用brew包管理工具也可以使用原始碼編譯安裝。
brew包管理工具安裝
# 搜尋Redis
kert@192 ~ % brew search redis
==> Formulae
hiredis
redis
redis-leveldb
redis@3.2
redis@4.0
==> Casks
another-redis-desktop-manager redis redisinsight
#安裝Redis(預設安裝最新版本)
kert@192 ~ % brew install redis
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/services).
No changes to formulae.
Warning: Treating redis as a formula. For the cask, use homebrew/cask/redis
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/redis-6.0.9.catalina.bottle.tar.gz
######################################################################## 100.0%
==> Pouring redis-6.0.9.catalina.bottle.tar.gz
==> Caveats
To have launchd start redis now and restart at login:
brew services start redis
Or, if you don't want/need a background service you can just run:
redis-server /usr/local/etc/redis.conf
==> Summary
? /usr/local/Cellar/redis/6.0.9: 13 files, 3.9MB
管理服務
# 啟動服務
brew services start redis
# 重啟服務
brew services restart redis
# 停止服務
brew services stop redis
原始碼安裝
直接到官網下載Redis原始碼,下載地址:redis.io/download
解壓並安裝
tar xzf redis-6.0.8.tar.gz cd redis-6.0.8 make && make install
Linux安裝
yum包管理工具安裝
[root@VM-51-113-centos ~]# yum install redis
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
................................
Resolving Dependencies
--> Running transaction check
---> Package redis.x86_64 0:3.2.12-2.el7 will be installed
--> Processing Dependency: libjemalloc.so.1()(64bit) for package: redis-3.2.12-2.el7.x86_64
--> Running transaction check
---> Package jemalloc.x86_64 0:3.6.0-1.el7 will be installed
--> Finished Dependency Resolution
.................................
Total download size: 648 k
Installed size: 1.7 M
...........................
Installed:
redis.x86_64 0:3.2.12-2.el7
Dependency Installed:
jemalloc.x86_64 0:3.6.0-1.el7
原始碼安裝
由於Mac和Linux都是基於Unix,安裝方式一致。依次執行下面的每一行命令即可。
wget http://download.redis.io/releases/redis-6.0.8.tar.gz
tar xzf redis-6.0.8.tar.gz
cd redis-6.0.8
make && make install
安裝優化
在文章中提到的原始碼安裝,我們都是採用的直接使用原始碼安裝,這裡有個小技巧,可以對日後的升級有所幫助。就是對原始碼檔案建立一個軟連線。以後升級直接對原始碼目錄替換即可。下面的命令就是將下載的Redis原始碼建立一個軟體列到 /opt/redis/6.0.8目錄。
ln -s redis-6.0.8/ /opt/redis/6.0.8/
cd /opt/redis/6.0.8/ && make && make install
Linux建立軟連線 ln -s 原始檔 目標檔案
本作品採用《CC 協議》,轉載必須註明作者和本文連結