一、安裝
1.官方:http://www.redis.cn/download.html
2.下載、解壓、編譯
wget http://download.redis.io/releases/redis-2.8.18.tar.gz tar xzf redis-2.8.18.tar.gz cd redis-2.8.18 make
(註:執行make時可能會出現的錯誤:1.未安裝gcc,請先:yum intsall gcc;2.安裝報錯 error: jemalloc/jemalloc.h: No such file or directory;解決方案:make 換==》make MALLOC = libc)
3.設定檔指定到自訂/use/local/redis
mkdir /usr/local/redis cp src/redis-server /usr/local/redis cp src/redis-benchmark /usr/local/redis cp src/redis-cli /usr/local/redis cp redis.conf /usr/local/redis
4.測試並啟動
cd /usr/local/redis ./redis-server redis.conf
二、通過自訂指令碼,設定開機啟動
1.啟動指令碼
注意:預設的redis.conf檔案參數是前台啟動的,修改daemonize no為daemonize yes則為後台啟動。
vi /etc/init.d/redis
將一下指令碼複製到/etc/init.d/redis
#!/bin/sh#chkconfig:2345 80 90#description: Startup and shutdown script for Redis PROGDIR=/usr/local/redis #安裝路徑PROGNAME=redis-serverDAEMON=$PROGDIR/$PROGNAMECONFIG=/usr/local/redis/redis.conf PIDFILE=/var/run/redis.pidDESC="redis daemon"SCRIPTNAME=/etc/init.d/redis start(){ if test -x $DAEMON then echo -e "Starting $DESC: $PROGNAME" if $DAEMON $CONFIG then echo -e "OK" else echo -e "failed" fi else echo -e "Couldn't find Redis Server ($DAEMON)" fi} stop(){ if test -e $PIDFILE then echo -e "Stopping $DESC: $PROGNAME" if kill `cat $PIDFILE` then echo -e "OK" else echo -e "failed" fi else echo -e "No Redis Server ($DAEMON) running" fi} restart(){ echo -e "Restarting $DESC: $PROGNAME" stop start} list(){ ps aux | grep $PROGNAME} case $1 in start) start ;; stop) stop ;; restart) restart ;; list) list ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|list}" >&2 exit 1 ;;esacexit 0
2.增加服務並設定開機啟動
chmod +x /etc/init.d/redis chkconfig --add redis chkconfig --level 345 redis on chkconfig --list redis
3.測試
ps -ef |grep redis //是否已經有redis執行個體service redis stopservice redis start
4.開放6379連接埠,供遠端連線
vi /etc/sysconfig/iptables //開放6379
service iptables restart //重啟
5.遠端連線:兩種方式
a.安裝:
sudo apt-get install redis-tools
b.直接telnet