1. 程式人生 > >Ubuntu18.10下Redis安裝與配置

Ubuntu18.10下Redis安裝與配置

一. Redis安裝:

1. 下載Redis

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

2. 解壓安裝檔案

tar -zxvf redis-3.2.8.tar.gz

3. 解壓後的檔案移動到usr/local目錄下

sudo mv ./redis-3.2.8 /usr/local/redis/

4. 進入redis目錄

cd /usr/local/redis/

5. 生成可執行檔案

sudo make

如果執行make命令時出現錯誤, 請保證make和gcc已安裝成功

sudo apt-get install cpp
sudo apt-get install binutils
sudo apt-get install glibc
sudo apt-get install glibc-kernheaders
sudo apt-get install glibc-common
sudo apt-get install glibc-devel

sudo apt-get install glibc-source 
sudo apt-get install gcc
sudo apt-get install make

如果make和gcc已安裝成功, 還報錯, 執行下如下程式碼

cd /usr/local/redis/deps/
sudo make geohash-int hiredis jemalloc linenoise lua

6. 測試程式

sudo make test

7. 安裝程式, 預設會安裝到/usr/local/bin/

sudo make install

8.安裝完成後,進入目錄/usr/local/bin中檢視

sudo cd /usr/local/bin

sudo ll

redis-server redis伺服器
redis-cli redis命令列客戶端
redis-benchmark redis效能測試工具
redis-check-aof AOF檔案修復工具
redis-check-rdb RDB檔案檢索工具

9. 配置檔案預設目錄為/usr/local/redis/redis.conf,  移動到/etc/redis/目錄下

sudo cp /usr/local/redis/redis.conf /etc/redis/

二. Redis的配置

開啟配置檔案

sudo vim /etc/redis/redis.conf

主要的配置資訊


# 繫結ip, 如果需要遠端訪問, 則註釋掉即可
# bind 127.0.0.1

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
# 埠號, 預設是6379
port 6379

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
# 是否以守護程序執行, 預設是no, 推薦使用yes
daemonize yes

注: 守護程序(daemon)是一類在後臺執行的特殊程序,用於執行特定的系統任務。很多守護程序在系統引導的時候啟動,並且一直執行直到系統關閉。另一些只在需要的時候才啟動,完成任務後就自動結束。

# The filename where to dump the DB
# 資料庫在做持久化時儲存的檔名
dbfilename dump.rdb

# The working directory.
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
# The Append Only File will also be created inside this directory.
# Note that you must specify a directory here, not a file name.
# 資料持久化檔案存放的目錄(如果目錄不存在, 需要手動建立), 預設 ./ 表示當前目錄
# dir ./
dir /var/lib/redis

# 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 ""
logfile "/var/log/redis/redis-server.log"

# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
# 資料庫數量, 預設16個, 編號0-15
databases 16


# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
# 1) Redis replication is asynchronous, but you can configure a master to
#    stop accepting writes if it appears to be not connected with at least
#    a given number of slaves.
# 2) Redis slaves are able to perform a partial resynchronization with the
#    master if the replication link is lost for a relatively small amount of
#    time. You may want to configure the replication backlog size (see the next
#    sections of this file) with a sensible value depending on your needs.
# 3) Replication is automatic and does not need user intervention. After a
#    network partition slaves automatically try to reconnect to masters
#    and resynchronize with them.
# 主從配置, 預設不需要配置
# slaveof <masterip> <masterport>

啟動redis服務: redis-server

啟動redis客戶端: redis-cli

更多配置資訊, 請參考 http://blog.csdn.net/ljphilp/article/details/52934933