1. 程式人生 > >Linux安裝Redis-3.2.8流程和問題

Linux安裝Redis-3.2.8流程和問題

以下是參考的一篇文章,基本上文章描述的問題都遇到了,也參考解決了。在這裡記錄下,以備後用。主要問題是依賴包和cpu64位不支援問題。需要改動的redis配置。

安裝依賴包

#yum install gcc gcc-c++ tcl -y

PS:遇到的問題

a、如果不安裝tcl,後面make test的時候回報錯,如下:

cd src && make test
make[1]: Entering directory `/root/redis-3.0.3/src’
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] Error 1
make[1]: Leaving directory `/root/redis-3.0.3/src’
make: *** [test] Error 2


 b、make的時候報錯(版本3.0.3)

#make
cd src && make all
make[1]: Entering directory `/root/redis-3.0.3/src’
    CC adlist.o
In file included from adlist.c:34:
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error “Newer version of jemalloc required”
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/root/redis-3.0.3/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   #新增一個引數
………………
Hint: It’s a good idea to run ‘make test’ ??
make[1]: Leaving directory `/root/redis-3.0.3/src’


開始編譯安裝redis-3.0.7

#tar xf redis-3.0.7.tar.gz
#cd redis-3.0.7
#make  
…………
Hint: It’s a good idea to run ‘make test’ ??
make[1]: Leaving directory `/root/redis-3.0.7/src’
#make test
………………
\o/ All tests passed without errors!
Cleanup: may take some time… OK
make[1]: Leaving directory `/root/redis-3.0.7/src’
到這裡已經編譯安裝OK了!


我這裡自定義路徑,把redis安裝到/usr/local/redis/目錄下,操作如下:
#mkdir -pv /usr/local/redis/bin
#cd /root/redis-3.0.7/src
#cp  redis-benchmark /usr/local/redis/bin
#cp  redis-check-aof /usr/local/redis/bin
#cp  redis-check-dump /usr/local/redis/bin
#cp  redis-cli /usr/local/redis/bin
#cp  redis-server /usr/local/redis/bin
#cp redis-sentinel /usr/local/redis/bin/
#cp redis-trib.rb /usr/local/redis/bin/
設定環境變數:
#vim /etc/profile
PATH=$PATH:/usr/local/redis/bin
#source /etc/profile
建立conf目錄:
#mkdir /usr/local/redis/conf
建立log目錄
#mkdir -pv /usr/local/redis/log/
建立配置檔案:
#cp /root/redis-3.0.7/redis.conf  /usr/local/redis/conf
#cp /root/redis-3.0.7/sentinel.conf  /usr/local/redis/conf


配置檔案
可為redis服務啟動指定配置檔案,配置檔案redis.conf在Redis根目錄下。
 
vim /usr/redis/conf/redis.conf
Shell程式碼  編輯redis.conf
#修改daemonize為yes,即預設以後臺程式方式執行(還記得前面手動使用&號強制後臺執行嗎)。  
daemonize no  
#可修改預設監聽埠  
port 6379  
#修改生成預設日誌檔案位置  
logfile “/home/futeng/logs/redis.log”  
#配置持久化檔案存放位置  
dir /home/futeng/data/redisData 

啟動時指定配置檔案
redis-server ./redis.conf  
#如果更改了埠,使用`redis-cli`客戶端連線時,也需要指定埠,例如:  
redis-cli -p 6380  

啟動
#加上`&`號使redis以後臺程式方式執行  ,redis的bin目錄下執行
./redis-server &  


#檢測後臺程序是否存在  
ps -ef |grep redis  
  
#檢測6379埠是否在監聽  
netstat -lntp | grep 6379  
  
#使用`redis-cli`客戶端檢測連線是否正常  操作redis key=》value
./redis-cli  
127.0.0.1:6379> keys *  
(empty list or set)  
127.0.0.1:6379> set key “hello world”  
OK  
127.0.0.1:6379> get key  
“hello world”  



#設定為開機自啟動伺服器  
chkconfig redisd on  
#開啟服務  
service redisd start  
#關閉服務  
service redisd stop