服務端redis 安裝以及配置
阿新 • • 發佈:2019-01-06
環境 Ubuntu vmware
1、下載redis
登入redis官網獲取下載連結
開啟終端 使用如下命令下載redis壓縮包
wget + 壓縮包地址
2、解壓
tar zxvf redis-*.tar.gz
3、編譯
進入解壓後的redis目錄使用如下命令
make
4、安裝到指定路徑
make PREFIX=/usr/local/redis install
5、拷貝配置檔案
將解壓目錄中的redis.conf配置檔案拷貝到安裝目錄中的redis下
cp redis解壓目錄中配置檔案位置 安裝redis目錄
6、編輯配置檔案
daemonize no 設定為 yes
ps:只讀模式修改
chmod a+w 檔名
7、載入配置檔案並啟動redis
./bin/redis-server ./redis.conf
8、停止redis
./bin/redis-cli shutdown
9、日誌配置redis預設不會儲存日誌,異常的時候會在控制檯輸出一個簡單的錯誤堆疊資訊
編輯redis.conf檔案,定位到logfile屬性,在後面的""中填上你的日誌路徑
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile "/home/liupan/redis/redis/bin/redis.log"
備註:
關閉redis的時候可能會報錯,檢視日誌檔案詳細資訊
30145:M 25 Oct 11:22:53.681 # User requested shutdown...
30145:M 25 Oct 11:22:53.681 * Saving the final RDB snapshot before exiting.
30145:M 25 Oct 11:22:53.682 # Failed opening the RDB file dump.rdb (in server root dir /home/liupan/redis/redis/bin) for saving: Permission denied
30145:M 25 Oct 11:22:53.682 # Error trying to save the DB, can't exit.
大意是關閉redis的時候會儲存一個dump檔案,而你的redis可執行檔案不能在bin目錄下新建一個dump檔案。
解決方法:
1、使用管理員角色來啟動redis
sudo ./redis-server ./redis.conf
2、更改bin資料夾的許可權(有點坑,更改bin目錄下的所有檔案的使用者名稱使用者組一點用都沒有,因為bin資料夾歸屬是root,你用當前使用者跑的redis根本不能再root資料夾下新建dump檔案)
chown 使用者:使用者組 bin/
個人推薦第二種,Ubuntu無法以root身份登入,每次執行都要sudo一下