一、下載,解壓和編譯Redis
?
1 2 3 4 5 | #?cd?/tmp??? #?wget?http://download.redis.io/releases/redis-3.0.1.tar.gz???? #?tar?xzf?redis-3.0.1.tar.gz???? #?cd?redis-3.0.1???? #?make |
?
二、下載、安裝tclsh
?
測試編譯:
1 | #?make?test |
得到如下錯誤信息:??
1 2 3 4 5 6 | cd?src?&&?make?test???? make[1]:?Entering?directory?`/tmp/redis-3.0.1/src'???? You?need?tcl?8.5?or?newer?in?order?to?run?the?Redis?test???? make[1]:?***?[test]?Error?1???? make[1]:?Leaving?directory?`/tmp/redis-3.0.1/src'???? make:?***?[test]?Error?2 |
Redis在make test有使用到tclsh對Redis進行測試,所有需要將tclsh安裝好。
tclsh下載可以直接從官網http://www.tcl.tk/software/tcltk/download.html下載其最新版
1 2 3 4 5 6 | #?cd?/tmp???? #?wget?http://prdownloads.sourceforge.net/tcl/tcl8.6.4-src.tar.gz???? #?tar?xzvf?tcl8.6.4-src.tar.gz???? #?cd?tcl8.6.4/unix?????#windows進入tcl8.6.4/win???? #?./configure?--prefix=/usr/local/tcl8.6.4?--enable-64bit??#enable-64bit對64系統生效???? #?make?&&?make?install |
安裝完成之后需要將tclsh添加到PATH中,并使其生效 ??
????
1 | #?vim?/etc/profile |
???
PATH=/usr/local/tcl8.6.4/bin:$PATH ? ?
export PATH ? ?
???
1 | #?source?/etc/profile |
這樣tclsh就已經安裝完成了。
?
三、再次測試編譯
1 2 | #?cd?/tmp/redis-3.0.1???? #?make?test |
將會收到信息: ??
All tests passed without errors!
?
四、簡單試用(生產環境略過)
?
在src目錄下,編譯后的二進制文件可用。運行Redis服務端:
1 | #?src/redis-server |
你可以用內置的客戶端與Redis交互:
1 | #?src/redis-cli |
??
redis> set foo bar ? ?
OK ? ?
redis> get foo ? ?
"bar"
?
五、安裝redis到指定目錄
?
也可以將redis安裝到指定的/usr/local/redis目錄下:
1 | #?make?PREFIX=/usr/local/redis?install |
?
六、配置redis
?
為redis配置PATH:
1 | #vi?/etc/profile?#添加下行內容 |
PATH=$PATH:/usr/local/redis/bin
export PATH
??
1 | #source?/etc/profile |
1 | #cp?redis.conf?/etc/ |
1 | #vi?/etc/sysctl.conf?#添加vm.overcommit_memory=1,否則出現如下警告 |
1 2 | #?WARNING?overcommit_memory?is?set?to?0!?Background?save?may?fail?under?low?memory?condition.?To?fix?this?issue?add?'vm.overcommit_memory?=?1'?to?/etc/sysctl.conf?and?then reboot?or?run?the?command?'sysctl?vm.overcommit_memory=1'?for?this?to?take?effect. |
#vi /etc/redis.conf? #對應行修改為下面內容 ? ?
daemonize yes ? ?
logfile /var/log/redis.log
?
七、編寫服務管理腳本
?
1 | #vi?/etc/init.d/redis |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #!/bin/sh??? #chkconfig:?345?86?14???? #description:?Startup?and?shutdown?script?for?Redis???? ?? ?PROGDIR= /usr/local/redis ?#安裝路徑???? PROGNAME=redis-server???? DAEMON=$PROGDIR/$PROGNAME???? CONFIG= /etc/redis .conf???? PIDFILE= /var/run/redis .pid???? DESC= "redis?daemon" ????SCRIPTNAME= /etc/rc .d /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???? ???????? ;;???? esac ????exit ?0 |
1 | #chmod?+x?/etc/init.d/redis |
?
八、設置開機啟動
?
1 2 3 | #chkconfig?--add?redis??? #chkconfig?--level?35?redis?on???? #chkconfig?--list?redis |
九、啟動、關閉服務
前臺以配置文件啟動:
1 | #?redis-server?/etc/redis.conf?#默認情況下redis前端運行,并把日志輸出到屏幕上 |
生產環境直接以服務啟動:
1 2 | #?service?redis?start #?netstat?-tnlp?|grep?6379 |
以命令關閉服務:
1 | #?redis-cli?shutdown |
生產環境直接以服務關閉:
1 | #?service?redis?stop |
十、測試
# redis-cli
127.0.0.1:6379> info
# Server
redis_version:3.0.1
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:6d627ecdac18555f
redis_mode:standalone
os:Linux 2.6.32-358.el6.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.4.7
process_id:6173
run_id:aedc790ab2d0eb75f3d5afe10c6af937d16955b0
tcp_port:6379
uptime_in_seconds:706
uptime_in_days:0
hz:10
lru_clock:6829896
config_file:/etc/redis.conf
...
...
參見:http://redis.io/download
本文轉自UltraSQL51CTO博客,原文鏈接:?http://blog.51cto.com/ultrasql/1656480,如需轉載請自行聯系原作者