Redis是一個高性能的,開源key-value型數據庫。是構建高性能,可擴展的Web應用的完美解決方案,能夠內存存儲亦可持久化存儲。由於要使用跨進程,跨服務級別的數據緩存,在對比多個方案後,決定使用Redis。順便整理下Redis的安裝過程,以便查閱。html
先要檢查安裝依賴程序:linux
yum install gcc-c++
yum install -y tcl
yum install wget
目前,最新的Redist版本爲3.0,使用wget
下載,命令以下:redis
# wget http://download.redis.io/releases/redis-3.0.4.tar.gz
下載完成後,使用tar
命令解壓下載文件:數據庫
# tar -xzvf redis-3.0.4.tar.gz
切換至程序目錄,並執行make
命令編譯:緩存
# cd redis-3.0.4 # make
執行安裝命令服務器
# make install
make install
安裝完成後,會在/usr/local/bin
目錄下生成下面幾個可執行文件,它們的做用分別是:app
redis-server
:Redis服務器端啓動程序redis-cli
:Redis客戶端操做工具。也能夠用telnet根據其純文本協議來操做redis-benchmark
:Redis性能測試工具redis-check-aof
:數據修復工具redis-check-dump
:檢查導出工具
備註工具
有的機器會出現相似如下錯誤:性能
make[1]: Entering directory `/root/redis/src' You need tcl 8.5 or newer in order to run the Redis test ……
這是由於沒有安裝tcl
致使,yum
安裝便可:測試
yum install tcl
複製配置文件到/etc/
目錄:
# cp redis.conf /etc/
爲了讓Redis後臺運行,通常還須要修改redis.conf文件:
vi /etc/redis.conf
修改daemonize
配置項爲yes
,使Redis進程在後臺運行:
daemonize yes
配置完成後,啓動Redis:
# cd /usr/local/bin # ./redis-server /etc/redis.conf
檢查啓動狀況:
# ps -ef | grep redis
看到相似下面的一行,表示啓動成功:
root 18443 1 0 13:05 ? 00:00:00 ./redis-server *:6379
讓Redis
開機運行能夠將其添加到rc.local
文件,也可將添加爲系統服務service
。本文使用rc.local
的方式,添加service
請參考:Redis 配置爲 Service 系統服務 。
爲了能讓Redis在服務器重啓後自動啓動,須要將啓動命令寫入開機啓動項:
echo "/usr/local/bin/redis-server /etc/redis.conf" >>/etc/rc.local
在前面的操做中,咱們用到了使Redis進程在後臺運行的參數,下面介紹其它一些經常使用的Redis啓動參數:
redis-cli >set name david OK >get name "david"
/redis-cli -h 127.0.0.1 -p 6379 -a
redis-cli shutdown