redis數據庫部署及持久化
----------------------------------------安裝----------------------------------------
wget http://download.redis.io/releases/redis-5.0.4.tar.gz tar zxvf redis-5.0.4.tar.gz -C /usr/local/ mv /usr/local/redis-5.0.4 /usr/local/redis cd /usr/local/redis make
修改配置文件
bind 0.0.0.0 #配置監聽地址 protected-mode no #關閉保護模式,允許外網連接數據庫 daemonize yes #開啟以後臺方式運行 logfile"/usr/local/redis/log/redis.log" #日誌文件路徑 dir /usr/local/redis/ #dump快照存放路徑
mkdir /usr/local/redis/log;touch /usr/local/redis/log/redis.log #創建日誌文件
創建命令鏈接
ln -s /usr/local/redis/src/redis-cli /usr/local/bin/redis ln -s /usr/local/redis/src/redis-cli /usr/local/bin/redis-cli ln -s /usr/local/redis/src/redis-server /usr/local/bin/redis-server
設置redis開機自啟動
echo "redis-server /usr/local/redis/redis.conf" >> /etc/rc.local chmod +x /etc/rc.local
啟動redis服務
redis-server /usr/local/redis/redis.conf
測試連接
redis-cli
----------------------------------------安裝過程可能出現的問題----------------------------------------
1.CentOS默認沒有安裝gcc,這會導致我們無法make成功
yum install gcc-c++ -y #解決辦法:yum安裝開發環境
2.make時報如下錯誤:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
#include <jemalloc/jemalloc.h>
^
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/root/redis-5.0.4/src‘
make: *** [all] Error 2
原因是jemalloc重載了Linux下的ANSI C的malloc和free函數
make MALLOC=libc #解決辦法:make時添加參數
3.make之後,會出現一句提示
Hint: To run ‘make test‘ is a good idea ;)
但是不測試,通常是可以使用的;若我們運行make test ,會有如下提示
[[email protected] src]$ make test
You need tcl 8.5 or newer in order to run the Redis test
make: ***[test] Error_1
yum install tcl -y #解決辦法:yum安裝tcl8.5
redis數據庫部署及持久化