Linux 下安裝Redis步驟
1.在官網上下載redis redis-4.0.11.tar.gz
2.解壓安裝包
[[email protected] local]# tar xvfz redis-4.0.11.tar.gz
[[email protected] local]# cd redis-4.0.11
3.編譯安裝
[[email protected] redis-4.0.11]# make
[[email protected] redis-4.0.11]# make install PREFIX=/usr/local/redis
4.啟動redis
[[email protected] local]# cd bin
[[email protected] bin]# ./redis-server /usr/local/redis/etc/redis.conf
5.測試redis
[[email protected] bin]# ./redis-cli
如果設定密碼啟動,以下方式訪問,其中admin為設定的密碼
[[email protected] bin]# ./redis-cli -a admin
6.設定後臺啟動
設定daemonize 為yes
7.redis.cnf 配置檔案說明
#修改為守護模式
daemonize yes
#設定程序鎖檔案
pidfile /usr/local/redis/redis.pid
#埠
port 6379
#客戶端超時時間
timeout 300
#日誌級別
loglevel debug
#日誌檔案位置
logfile /usr/local/redis/log-redis.log
#設定資料庫的數量,預設資料庫為0,可以使用SELECT <dbid>命令在連線上指定資料庫id
databases 8
##指定在多長時間內,有多少次更新操作,就將資料同步到資料檔案,可以多個條件配合
#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/db/
#指定是否在每次更新操作後進行日誌記錄,Redis在預設情況下是非同步的把資料寫入磁碟,如果不開啟,可能
#會在斷電時導致一段時間內的資料丟失。因為 redis本身同步資料檔案是按上面save條件來同步的,所以有
#的資料會在一段時間內只存在於記憶體中
appendonly no
#指定更新日誌條件,共有3個可選值:
#no:表示等作業系統進行資料快取同步到磁碟(快)
#always:表示每次更新操作後手動呼叫fsync()將資料寫到磁碟(慢,安全)
#everysec:表示每秒同步一次(折衷,預設值)
appendfsync everysec
# requirepass foobared :設定密碼,指定密碼admin
requirepass admin
stop-writes-on-bgsave-error no