歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> CentOS 6.7安裝redis3.0.7

CentOS 6.7安裝redis3.0.7

日期:2017/3/6 9:42:56   编辑:學習Linux

CentOS 6.7安裝redis3.0.7


CentOS 6.7安裝redis3.0.7


使用centos 6.7 live CD版本

redis官方文檔
http://redis.io/download#installation
http://www.redis.io/topics/data-types-intro

Installation

Download, extract and compile Redis with:

$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz$ tar xzf redis-3.0.7.tar.gz$ cd redis-3.0.7$ make

錯誤 1

[root@localhost redis-3.0.7]# makecd src && make allmake[1]: Entering directory `/home/mark/redis-3.0.7/src'    CC adlist.o/bin/sh: cc: command not foundmake[1]: *** [adlist.o] Error 127make[1]: Leaving directory `/home/mark/redis-3.0.7/src'make: *** [all] Error 2

原因分析

這是由於系統沒有安裝gcc環境,

解決辦法

yum  install  gcc

錯誤 2

cd src && make allmake[1]: Entering directory `/home/mark/redis-3.0.7/src'    CC adlist.oIn file included from adlist.c:34:zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directoryzmalloc.h:55:2: error: #error "Newer version of jemalloc required"make[1]: *** [adlist.o] Error 1make[1]: Leaving directory `/home/mark/redis-3.0.7/src'make: *** [all] Error 2

原因分析

在README 有這個一段話。

Allocator  Selecting a non-default memory allocator when building Redis is done by setting  the `MALLOC` environment variable. Redis is compiled and linked against libc  malloc by default, with the exception of jemalloc being the default on Linux  systems. This default was picked because jemalloc has proven to have fewer  fragmentation problems than libc malloc.  To force compiling against libc malloc, use:      % make MALLOC=libc  To compile against jemalloc on Mac OS X systems, use:      % make MALLOC=jemalloc

說關於分配器allocator, 如果有MALLOC 這個 環境變量, 會有用這個環境變量的 去建立Redis。

而且libc 並不是默認的 分配器, 默認的是 jemalloc, 因為 jemalloc 被證明 有更少的 fragmentation problems 比libc。

但是如果你又沒有jemalloc 而只有 libc 當然 make 出錯。 所以加這麼一個參數。

解決辦法

make MALLOC=libc

自此編譯完成

:)

配置redis

cd $REDIS_HOME #進入redis主目錄mkdir confcd confcp ../redis.conf redis6379.conf #默認的端口vim redis6379.conf修改:daemonize no #默認值no,該參數用於定制redis服務是否以守護模式運行。port 6379  #默認6379 , 如果你的機器有沖突 , 修改為其他端口如果不打算使用事務、管線等一堆復雜功能,僅僅把redis當成cache server使用,可以在配置文件中,找到maxmemory、maxmemory-policy這二項,參考下面修改maxmemory 4096mbmaxmemory-policy allkeys-lru即:最大允許使用4G內存,所有key全都按LRU(近期最少使用)算法淘汰,這種情況下,不用設置過期時間,只要內存使用達到上限,不怎麼使用的key自然被干掉。然後保存退出

啟動redis

使用自定義配置啟動

cd $REDIS_HOME/src./redis-server ../conf/redis6379.conf

測試

添加

cd $REDIS_HOME/src[mark@localhost src]$ ./redis-cli -p 6379 set test 'Hello Redis'OK[mark@localhost src]$ 即:指定端口6379,連接到本機redis,同時設置一個key為test,value為'Hello Redis'的緩存項(注:如果連接遠程的redis服務器,可以用類似./redis-cli -h 192.168.1.190 -p 6379 get a)

讀取

[mark@localhost src]$ ./redis-cli -p 6379 get test              "Hello Redis"[mark@localhost src]$ 

刪除

[mark@localhost src]$ ./redis-cli -p 6379 del test (integer) 1[mark@localhost src]$ ./redis-cli -p 6379 get test (nil)[mark@localhost src]$ 

小技巧

redis沒有提供批量刪除的方法,可以用下面的技巧批量刪除 ./redis-cli -p 6379  KEYS "*" | xargs ./redis-cli -p 6379 DEL

性能測試

./redis-benchmark -p 6379

http://xxxxxx/Linuxjc/1134356.html TechArticle

Copyright © Linux教程網 All Rights Reserved