資源描述:
《Redis的安裝與使用》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、Redis?的安裝與使用(單節(jié)點)IP:192.168.4.111環(huán)境:CentOS?6.6Redis?版本:redis-3.0?(考慮到?Redis3.0?在集群和性能提升方面的特性,rc?版為正式版的候選版,而且很快就出正式版)安裝目錄:/usr/local/redis用戶:root編譯和安裝所需的包:#?yum?install?gcc?tcl下載?3.0?版?Redis(當前最新版?redis-3.0.0-rc5.tar.gz,請學員們在安裝時自行選用最新版)#?cd?/usr/local/src#?wg
2、et?https://github.com/antirez/redis/archive/3.0.0-rc5.tar.gz創(chuàng)建安裝目錄:#?mkdir?/usr/local/redis解壓:#?tar?-zxvf?3.0.0-rc5.tar.gz#?mv?redis-3.0.0-rc5?redis3.0#?cd?redis3.0安裝(使用?PREFIX?指定安裝目錄):#?make?PREFIX=/usr/local/redis?install安裝完成后,可以看到/usr/local/redis?目錄下有一個?b
3、in?目錄,bin?目錄里就是?redis?的命令腳本:redis-benchmarkredis-check-aofredis-check-dumpredis-cliredis-server將?Redis?配置成服務(wù):按上面的操作步驟,Redis?的啟動腳本為:/usr/local/src/redis3.0/utils/redis_init_script將啟動腳本復(fù)制到/etc/rc.d/init.d/目錄下,并命名為?redis:#?cp?/usr/local/src/redis3.0/utils/redis
4、_init_script?/etc/rc.d/init.d/redis編輯/etc/rc.d/init.d/redis,修改相應(yīng)配置,使之能注冊成為服務(wù):#?vi?/etc/rc.d/init.d/redis#!/bin/sh##?Simple?Redis?init.d?script?conceived?to?work?on?Linux?systems#?as?it?does?use?of?the?/proc?filesystem.REDISPORT=6379EXEC=/usr/local/bin/redis-
5、serverCLIEXEC=/usr/local/bin/redis-cliPIDFILE=/var/run/redis_${REDISPORT}.pidCONF="/etc/redis/${REDISPORT}.conf"case?"$1"?instart)if?[?-f?$PIDFILE?]thenecho?"$PIDFILE?exists,?process?is?already?running?or?crashed"elseecho?"Starting?Redis?server..."$EXEC?$CON
6、Ffi;;stop)if?[?!?-f?$PIDFILE?]thenecho?"$PIDFILE?does?not?exist,?process?is?not?running"elsePID=$(cat?$PIDFILE)echo?"Stopping?..."$CLIEXEC?-p?$REDISPORT?shutdownwhile?[?-x?/proc/${PID}?]doecho?"Waiting?for?Redis?to?shutdown?..."sleep?1doneecho?"Redis?stopped
7、"fi;;*)echo?"Please?use?start?or?stop?as?first?argument";;esac查看以上?redis?服務(wù)腳本,關(guān)注標為橙色的幾個屬性,做如下幾個修改的準備:(1)?在腳本的第一行后面添加一行內(nèi)容如下:#chkconfig:?2345?80?90(如果不添加上面的內(nèi)容,在注冊服務(wù)時會提示:service?redis?does?not?support?chkconfig)(2)?REDISPORT?端口保持?6379?不變;(注意,端口名將與下面的配置文件名有關(guān))(3)
8、?EXEC=/usr/local/bin/redis-server?改為?EXEC=/usr/local/redis/bin/redis-server(4)?CLIEXEC=/usr/local/bin/redis-cli?改為?CLIEXEC=/usr/local/redis/bin/redis-cli(5)?配置文件設(shè)置:創(chuàng)建?redis?配置文件目錄#?mkdir?/usr/lo