參考文章:(http://www.javashuo.com/article/p-sepdcjpu-bo.html)html
第一部分:安裝redis
一、打開官網:https://redis.io/數據庫
二、到下載目錄解壓,而後命令拷貝到:緩存
到下載目錄:$ cd Downloads安全
sudo cp redis-4.0.10 /usr/local/app
三、切換到該目錄:cd /usr/local/redis-4.0.10/異步
四、安裝前測試命令:sudo make test測試
安裝命令:sudo make installthis
五、啓動redis命令:redis-server,okspa
第二部分:配置
如今下載頁面建立redis.conf 文件,內容以下:
#修改成守護模式
daemonize yes
#設置進程鎖文件
pidfile /usr/local/redis-4.0.10/redis.pid
#端口
port 6379
#客戶端超時時間
timeout 300
#日誌級別
loglevel debug
#日誌文件位置
logfile /usr/local/redis-4.0.10/log-redis.log
#設置數據庫的數量,默認數據庫爲0,可使用SELECT <dbid>命令在鏈接上指定數據庫id
databases 16
##指定在多長時間內,有多少次更新操做,就將數據同步到數據文件,能夠多個條件配合
#save <seconds> <changes>
#Redis默認配置文件中提供了三個條件:
save 900 1
save 300 10
save 60 10000
#指定存儲至本地數據庫時是否壓縮數據,默認爲yes,Redis採用LZF壓縮,若是爲了節省CPU時間,
#能夠關閉該#選項,但會致使數據庫文件變的巨大
rdbcompression yes
#指定本地數據庫文件名
dbfilename dump.rdb
#指定本地數據庫路徑
dir /usr/local/redis-4.0.10/db/
#指定是否在每次更新操做後進行日誌記錄,Redis在默認狀況下是異步的把數據寫入磁盤,若是不開啓,可能
#會在斷電時致使一段時間內的數據丟失。由於 redis自己同步數據文件是按上面save條件來同步的,因此有
#的數據會在一段時間內只存在於內存中
appendonly no
#指定更新日誌條件,共有3個可選值:
#no:表示等操做系統進行數據緩存同步到磁盤(快)
#always:表示每次更新操做後手動調用fsync()將數據寫到磁盤(慢,安全)
#everysec:表示每秒同步一次(折衷,默認值)
appendfsync everysec
一、先到/usr/local/redis-4.0.10/目錄備份redis.conf ,命令: sudo mv redis.conf redis.conf.backup
二、再到下載目錄:mv redis.conf /usr/local/redis-4.0.10/
三、啓動redis命令:redis-server,ok
問題:redis.set 報錯 (參考解決方法:https://www.jianshu.com/p/3aaf21dd34d6)
MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify thedata set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
****緣由****
強制關閉Redis快照致使不能持久化。
****解決方案****
將stop-writes-on-bgsave-error設置爲no
命令進入:$ redis-cli
而後輸入
127.0.0.1:6379> config set stop-writes-on-bgsave-error no
ok。