Redis 3.0 編譯安裝

來源:互聯網
上載者:User

標籤:安裝   redis   

   

官方主站:http://www.redis.io/

:http://www.redis.cn/download.html

Command API: http://www.redis.cn/commands.html
      Redis官方文檔:http://redis.io/documentation

一.Redis 介紹:
Redis是Remote Dictionary Server的縮寫。他本質上一個Key/Value資料庫,與Memcached類似的NoSQL型資料庫,但是他的資料可以持久化的儲存在磁碟上,解決了服務重啟後資料不丟失的問題,他的值可以是string(字串)、list(列表)、sets(集合)或者是ordered sets(被排序的集合),所有的資料類型都具有push/pop、add/remove、執行服務端的並集、交集、兩個sets集中的差別等等操作,這些操作都是具有原子性的,Redis還支援各種不同的排序能力。

二.Redis 部署
1.安裝相關依賴包:
yum -y install gcc gcc-c++ cmake make

2.安裝tcmalloc包[ 嘗試採用新的記憶體配置方式 ]
Redis並沒有自己實現記憶體池,沒有在標準的系統記憶體 Clerk上再加上自己的東西。
所以系統記憶體 Clerk的效能及片段率會對Redis造成一些效能上的影響。
在最新版本中,jemalloc已經作為源碼包的一部分包含在源碼包中,所以可以直接被使用。
如果要使用tcmalloc的話,是需要自己安裝的。

tcmalloc是google-proftools( http://code.google.com/p/gperftools/downloads/list)中的一部分,
所以我們實際上需要安裝google-proftools。如果你是在64位機器上進行安裝,需要先安裝其依賴的libunwind庫,32位的系統不需要
: http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz

(1).安裝libunwind
tar zxvf libunwind-0.99-alpha.tar.gz
cd libunwind-0.99-alpha/
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install

(2).安裝gperftools
tar zxvf gperftools-2.1.tar.gz
cd gperftools-2.1
./configure --disable-cpu-profiler --disable-heap-profiler --disable-heap-checker --disable-debugalloc --enable-minimal
make && make install
cd /usr/local/lib
ln -sv libtcmalloc_minimal.so.4.1.2 libtcmalloc.so
# 加粗部分如果不做的話,後面編譯redis會報錯: usr/bin/ld: cannot find ltcmalloc
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf #如果沒有這個檔案,自己建一個
/sbin/ldconfig

3.Redis 安裝:
tar zxvf redis-3.0.0.tar.gz
cd redis-3.0.0
mkdir -p /usr/local/redis-3.0
# make prefix= install
# 將redis安裝在/bin下/usr/local/redis-3.0/bin下
# make PREFIX=/usr/local/redis-3.0 install # 此方式安裝,使用linux預設的記憶體配置方式
make PREFIX=/usr/local/redis-3.0 USE_TCMALLOC=yes FORCE_LIBC_MALLOC=yes install

4.建相關目錄,並配置redis.conf 檔案[簡單配置]
cd /usr/local/redis-3.0/
mkdir etc #存放設定檔,這裡目錄名,可建為:conf
mkdir log #存放日誌和pid檔案
mkdir data #存放資料
vim etc/redis.conf
daemonize yes
port 6379
pidfile /usr/local/redis-3.0/log/redis_6379.pid
dir /usr/local/redis-3.0/data
logfile /usr/local/redis-3.0/log/redis_6379.log

5.Redis服務啟動、關閉
(1).啟動服務:
/usr/local/redis-3.0/bin/redis-server /usr/local/redis-3.0/etc/redis.conf
註:
此命令僅有一個啟動參數,指定目錄下的設定檔,不加參數執行預設配置。
測試啟動:
/usr/local/redis-3.0/bin/redis-cli ping
返回PONG,則啟動成功。
查看連接埠是否被佔用:
netstat -ntlp |grep 6379

(2).關閉服務:
/usr/local/redis-3.0/bin/redis-cli shutdown
如果非預設連接埠,可指定連接埠:
/usr/local/redis-3.0/bin/redis-cli -p 6380 shutdown

(3).驗證redis記憶體配置方式是否在使用tcmalloc
lsof -n |grep tcmalloc
redis-ser 2754 root mem REG 253,0 1078467 1725996 /usr/local/lib/libtcmalloc_minimal.so.4.1.2

6.Redis 服務啟動指令碼
redis 本身提供了redis安裝指令碼:utils/install_server.sh
但 這個指令碼包括安裝服務,有點煩,我們直接取其安裝指令碼:
#!/bin/sh
#Configurations injected by install_server below....
EXEC=/usr/local/redis-3.0/bin/redis-server
CLIEXEC=/usr/local/redis-3.0/bin/redis-cli
PIDFILE=/usr/local/redis-3.0/log/redis_6379.pid
CONF="/usr/local/redis-3.0/etc/redis.conf"
REDISPORT="6379"

case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
status)
PID=$(cat $PIDFILE)
if [ ! -x /proc/${PID} ]
then
echo ‘Redis is not running‘
else
echo "Redis is running ($PID)"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Please use start, stop, restart or status as first argument"
;;
esac


   


Redis 3.0 編譯安裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.