Redis安裝與配置

00潤物無聲00發表於2017-02-11

  剛裝的Centos系統,進行Redis安裝,Redis安裝挺簡單的,不過由於Centos上很多環境沒有配置,也是走了一個不斷配置的過程。分享一下


1.下載並解壓

  在redis的官網中,下載最新stable版

cd /usr/local/src/
wget http://download.redis.io/releases/redis-3.2.7.tar.gz
tar zxvf redis-3.2.7.tar.gz

2.執行make命令

[root@localhost redis-3.2.7]# make
cd src && make all
make[1]: 進入目錄“/usr/local/src/redis-3.2.7/src”
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html
(cd ../deps && make distclean)
make[2]: 進入目錄“/usr/local/src/redis-3.2.7/deps”
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd geohash-int && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
make[2]: 離開目錄“/usr/local/src/redis-3.2.7/deps”
(rm -f .make-*)
echo STD=-std=c99 -pedantic -DREDIS_STATIC='' >> .make-settings
echo WARN=-Wall -W >> .make-settings
echo OPT=-O2 >> .make-settings
echo MALLOC=jemalloc >> .make-settings
echo CFLAGS= >> .make-settings
echo LDFLAGS= >> .make-settings
echo REDIS_CFLAGS= >> .make-settings
echo REDIS_LDFLAGS= >> .make-settings
echo PREV_FINAL_CFLAGS=-std=c99 -pedantic -DREDIS_STATIC='' -Wall -W -O2 -g -ggdb   -I../deps/geohash-int -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -DUSE_JEMALLOC -I../deps/jemalloc/include >> .make-settings
echo PREV_FINAL_LDFLAGS=  -g -ggdb -rdynamic >> .make-settings
(cd ../deps && make hiredis linenoise lua geohash-int jemalloc)
make[2]: 進入目錄“/usr/local/src/redis-3.2.7/deps”
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd geohash-int && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
(echo "" > .make-cflags)
(echo "" > .make-ldflags)
MAKE hiredis
cd hiredis && make static
make[3]: 進入目錄“/usr/local/src/redis-3.2.7/deps/hiredis”
gcc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  net.c
make[3]: gcc:命令未找到
make[3]: *** [net.o] 錯誤 127
make[3]: 離開目錄“/usr/local/src/redis-3.2.7/deps/hiredis”
make[2]: *** [hiredis] 錯誤 2
make[2]: 離開目錄“/usr/local/src/redis-3.2.7/deps”
make[1]: [persist-settings] 錯誤 2 (忽略)
    CC adlist.o
/bin/sh: cc: 未找到命令
make[1]: *** [adlist.o] 錯誤 127
make[1]: 離開目錄“/usr/local/src/redis-3.2.7/src”
make: *** [all] 錯誤 2

  這是由於新安裝的Linux系統沒有安裝gcc環境,需要安裝gcc,為了方便,這裡我選擇用yum進行安裝。

# yum  install  gcc

  繼續make 

    遇到zmalloc.h:50:31: 致命錯誤:jemalloc/jemalloc.h:沒有那個檔案或目錄。 
    解決方案:make MALLOC=libc

  繼續make

    Hint: It's a good idea to run 'make test';   

#yum install tcl


3.指定安裝路徑

[root@localhost redis-3.2.7]# make PREFIX=/usr/local/redis install  

進入目錄檢視

cd /usr/local/redis/bin

redis-benchmark :Redis效能測試工具

redis-check-rdb:檢查redis資料庫

redis-sentinel:用於叢集管理
redis-check-aof :aof日誌檔案檢測工具(比如斷電造成日誌損壞,可以檢測並修復)

redis-cli:redis客戶端        

redis-server:redis服務端


複製配置檔案到/usr/local/redis目錄:

[root@localhost redis]# cp /usr/local/src/redis-3.2.7/redis.conf  ./

4.啟動

[root@localhost redis]# ./bin/redis-server ./redis.conf 

  


 已經成功開啟,伺服器埠預設:6379,終端被程式佔用;


5.設定Redis後臺進行的形式執行

[root@localhost redis]# vim redis.conf

  編輯conf配置檔案,修改如下內容;
    daemonize yes

  檢查Redis程式:

oot@localhost redis]# ps aux|grep redis

     3605  0.0  0.1  11868  1180 pts/1    S+   08:26   0:00 ./bin/redis-cli
root       3694  0.1  0.1 133432  1984 ?        Ssl  08:34   0:00 ./bin/redis-server 127.0.0.1:6379
root       3712  0.0  0.0 112660   980 pts/0    S+   08:35   0:00 grep --color=auto redis

6.使用redis-cli連線Redis,對其進行測試

[root@localhost 桌面]# cd /usr/local/redis/
[root@localhost redis]# ./bin/redis-cli 
127.0.0.1:6379> 
已經連線上伺服器;

127.0.0.1:6379> set sit www.zixue.it 
OK
127.0.0.1:6379> get sit
"www.zixue.it"
127.0.0.1:6379>


  至此安裝並測試成功。




相關文章