linux redis 安裝


版權聲明:本文為博主原創文章,遵循 CC 4.0 by-sa 版權協議,轉載請附上原文出處鏈接和本聲明。
本文鏈接:https://blog.csdn.net/LIU_YANZHAO/article/details/79425823
本文介紹 Linux 系統安裝 Redis,以及基本配置和常用命令。

一、安裝 Redis
安裝方法和下載地址這里也有:https://redis.io/download

1、使用 ssh 連接到 linux 服務器

ssh root@ip地址

2、切換到安裝目錄

cd /www/server

3、下載 Redis 安裝包

wget http://download.redis.io/releases/redis-4.0.2.tar.gz

4、解壓之

tar xzf redis-4.0.2.tar.gz

5、編譯安裝

cd redis-4.0.2

make

至此基本安裝成功

 

二、啟動報錯解決
切換到 Redis 安裝目錄,鍵入以下命令啟動 Redis

src/redis-server redis.conf

這個時候如果直接啟動會報幾個 Warnning

1、錯誤一:

Warning: no config file specified, using the default config.

In order to specify a config file use 'redis-server /path/to/redis.conf'

解決方案:

redis-server redis.conf

 

2、其他三個常見錯誤

解決方案轉自:http://blog.csdn.net/a491857321/article/details/52006376



第一個警告:The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

意思是:TCP  backlog設置值,511沒有成功,因為 /proc/sys/net/core/somaxconn這個設置的是更小的128.

臨時解決方法:(即下次啟動還需要修改此值)

echo 511 > /proc/sys/net/core/somaxconn

永久解決方法:(即以后啟動還需要修改此值)

將其寫入/etc/rc.local文件中。

 

 

第二個警告:overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to/etc/sysctl.conf andthen reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

意思是:overcommit_memory參數設置為0!在內存不足的情況下,后台程序save可能失敗。建議在文件 /etc/sysctl.conf 中將overcommit_memory修改為1。

臨時解決方法:echo "vm.overcommit_memory=1" > /etc/sysctl.conf

永久解決方法:將其寫入/etc/sysctl.conf文件中。

 

第三個警告:you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix thisissue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain thesetting after a reboot. Redis must be restarted after THP is disabled.

意思是:你使用的是透明大頁,可能導致redis延遲和內存使用問題。執行 echo never > /sys/kernel/mm/transparent_hugepage/enabled 修復該問題。

臨時解決方法:

echo never > /sys/kernel/mm/transparent_hugepage/enabled

永久解決方法:

將其寫入/etc/rc.local文件中

 

三、修改 Redis 為后端啟動
如果我們直接執行 redis-server ,為前端執行,會出現如下圖界面,但是此時終端不管輸什么都無效了。

只能按 Ctrl+C強行退出了



 

於是我們可以配置后端啟動Redis,具體操作如下

1、編輯 redis.conf

vim redis.conf

2、修改 daemonize 的值為yes

daemonize yes 



 

3、啟動 Redis

src/redis-server redis.conf



 

四、Linux 幾個命令

1、啟動 Redis

src/redis-server   (后端啟動,不推薦使用)

src/redis-server redis.conf (前端啟動)

 

2、查詢全部啟動的端口

netstat -anp

3、關閉進程

kill -9 PID

4、查詢 redis 是否啟動

ps -ef | grep -i redis

5、啟動 客戶端

src/redis-cli



 

5、停止 Redis

src/redis-cli shutdown

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM