標籤:安裝redis redis
下載redis
http://download.redis.io/releases/redis-2.8.13.tar.gz
使用root使用者安裝redis
[[email protected] ~]# iduid=0(root) gid=0(root) groups=0(root)[[email protected] ~]# ls -l redis-2.8.13.tar.gz-rw-r--r-- 1 oracle oinstall 1227538 Oct 23 14:53redis-2.8.13.tar.gz解壓[[email protected] ~]# tar xzf redis-2.8.13.tar.gz[[email protected] ~]# ls -ld redis-2.8.13drwxrwxr-x 6 root root 4096 Jul 14 2014 redis-2.8.13[[email protected] ~]# cd redis-2.8.13[[email protected] redis-2.8.13]# ls00-RELEASENOTES CONTRIBUTING deps Makefile README runtest sentinel.conf testsBUGS COPYING INSTALL MANIFESTO redis.conf runtest-sentinel src utils這裡推薦是make && make test && make install輸出內容太多了,並沒有完全貼出來。[[email protected] redis-2.8.13]# makecd src && make allmake[1]: Entering directory `/root/redis-2.8.13/src‘….Hint: To run ‘make test‘ is a good idea ;)make[1]: Leaving directory `/root/redis-2.8.13/src‘[[email protected] redis-2.8.13]# make testcd src && make testmake[1]: Entering directory `/root/redis-2.8.13/src‘You need tcl 8.5 or newer in order to run the Redis testmake[1]: *** [test] Error 1make[1]: Leaving directory `/root/redis-2.8.13/src‘make: *** [test] Error 2[[email protected] redis-2.8.13]# make installcd src && make installmake[1]: Entering directory `/root/redis-2.8.13/src‘ Hint: To run ‘make test‘ is a good idea ;) INSTALL install INSTALL install INSTALL install INSTALL install INSTALL installmake[1]: Leaving directory `/root/redis-2.8.13/src‘
初始化一個服務
拷貝可執行檔到/usr/local/[[email protected] redis-2.8.13]# cp utils /usr/local/ -rf直接在/root/redis-2.8.13/utils中運行install_server.sh指令碼,初始化一個連接埠號碼為6379的服務[[email protected] utils]# ./install_server.shWelcome to the redis service installerThis script will help you easily set up a running redisserver Please select the redis port for this instance: [6379] #選擇連接埠號碼Selecting default: 6379Please select the redis config file name[/etc/redis/6379.conf] #選擇設定檔Selected default - /etc/redis/6379.confPlease select the redis log file name[/var/log/redis_6379.log] #選擇log檔案Selected default - /var/log/redis_6379.logPlease select the data directory for this instance[/var/lib/redis/6379] #選擇資料檔案目錄Selected default - /var/lib/redis/6379 Please select the redis executable path[/usr/local/bin/redis-server] #選擇redis-server的執行路徑Selected config:Port : 6379Config file :/etc/redis/6379.confLog file :/var/log/redis_6379.logData dir :/var/lib/redis/6379Executable :/usr/local/bin/redis-serverCli Executable : /usr/local/bin/redis-cliIs this ok? Then press ENTER to go on or Ctrl-C to abort.Copied /tmp/6379.conf => /etc/init.d/redis_6379Installing service...Successfully added to chkconfig!Successfully added to runlevels 345!Starting Redis server...Installation successful!另外重新設定一個6378,選擇跟剛才的類似[[email protected] utils]# ./install_server.shWelcome to the redis service installerThis script will help you easily set up a running redisserver Please select the redis port for this instance: [6379] 6378 #只需要改動這個位置Please select the redis config file name[/etc/redis/6378.conf]Selected default - /etc/redis/6378.confPlease select the redis log file name[/var/log/redis_6378.log]Selected default - /var/log/redis_6378.logPlease select the data directory for this instance[/var/lib/redis/6378]Selected default - /var/lib/redis/6378Please select the redis executable path[/usr/local/bin/redis-server]Selected config:Port : 6378Config file :/etc/redis/6378.confLog file :/var/log/redis_6378.logData dir :/var/lib/redis/6378Executable :/usr/local/bin/redis-serverCli Executable : /usr/local/bin/redis-cliIs this ok? Then press ENTER to go on or Ctrl-C to abort.Copied /tmp/6378.conf => /etc/init.d/redis_6378Installing service...Successfully added to chkconfig!Successfully added to runlevels 345!Starting Redis server...Installation successful!
驗證是否安裝成功
[[email protected] utils]#/etc/init.d/redis_6378 status #查看redis狀態Redis is running (9487)[[email protected] utils]# /etc/init.d/redis_6378 stop #關閉redisStopping ...Redis stopped[[email protected] utils]# /etc/init.d/redis_6378 start #啟動redisStarting Redis server...添加開機自啟動服務[[email protected] utils]# chkconfig redis_6378 on 2345[[email protected] utils]# chkconfig --list redis_6378redis_6378 0:off 1:off 2:on 3:on 4:on 5:on 6:off使用redis-cli來設定值和擷取值[[email protected] utils]# /usr/local/bin/redis-cli #預設調用6379連接埠127.0.0.1:6379> set k1 1OK127.0.0.1:6379> exit[[email protected] utils]# /usr/local/bin/redis-cli -p 6378 #-p 參數可以指定連接埠訪問127.0.0.1:6378> set ke1 aOK127.0.0.1:6378> get ke1"a" #這裡可以通過get方式擷取值,就說明安裝成功了127.0.0.1:6378> quit[[email protected] utils]# /usr/local/bin/redis-cli -p 6379127.0.0.1:6379> get k1"1"127.0.0.1:6379>訪問遠程redis,直接通過-h 參數就可以指定IP地址,進行遠端存取了[[email protected] utils]# /usr/local/bin/redis-cli -h 192.168.10.140 -p 6379192.168.10.140:6379> get k1"1"192.168.10.140:6379> get ka(nil)192.168.10.140:6379> get ke1(nil)
本文出自 “名字長一點會好記” 部落格,請務必保留此出處http://xiaoyiyi.blog.51cto.com/1351449/1705708
(一)使用源碼包方式安裝redis-2.8.13