在Linux上安裝Redis

環境

Redis Version:3.0.1及以上
OS:Centos 7

步驟

1. 下載到指定目錄并解壓

> cd /usr/src
> wget -c http://download.redis.io/redis-stable.tar.gz
> tar xvzf redis-stable.tar.gz

2. 構建

> cd redis-stable
> make && make install

如果由于沒有安裝gcc導致make報錯,在安裝make之后重新構建可能會報jemalloc/jemalloc.h相關錯誤,可參考
http://unix.stackexchange.com/questions/94479/jemalloc-and-other-errors-making-redis-on-centos-6-4進行修復

3. 運行安裝腳本

> utils/install_server.sh

腳本會有一系列引導

Please select the redis port for this instance: [6379]

回車選擇6379作為默認端口

Please select the redis config file name [/etc/redis/6379.conf] 

輸入/etc/redis/redis_6379.conf,作為新的配置文件,回車

Please select the redis log file name [/var/log/redis_6379.log]

回車,繼續

Please select the data directory for this instance [/var/lib/redis/6379]

回車,繼續

Please select the redis executable path [/usr/local/bin/redis-server]

回車,繼續,屏幕輸出配置如下,

Selected config:
Port           : 6379
Config file    : /etc/redis/redis_6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.

確認無誤,回車,屏幕繼續輸出

Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

安裝成功

4. 驗證是否安裝成功

> /etc/init.d/redis_6379 status

輸出

Redis is running (27186)

查看server信息

> redis-cli -p 6379 info server

看是否有正確輸出

測試是否能寫入和讀取數據

> redis-cli
127.0.0.1:6379> set test 1
OK
127.0.0.1:6379> get test
"1"

ok,沒問題,至此,安裝成功

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容