Redis系列-安裝部署維護篇

         Redis是個高性能的key-value數據庫,它的key具有豐富的數據結構:string,hash,list set和sorted set。作爲NOSQL,比起memcache之類,不僅僅key數據結構豐富,而且具有持久化的功能,並且能夠支持主從複製,很方便構建集羣。redis高性能很大程度上源於它是個內存型數據庫,它的高性能表現在:set操作11w/s,get操作8.1w/s,與其他類型數據庫性能差異,可以而參考:http://timyang.net/data/mcdb-tt-redis/   。爲了進一步加深對redis的理解總結,我打算寫個redis系列的博客。這裏主要談談redis安裝部署及運維維護。

1、下載安裝

[root@xsf003 tool]# wget -c http://redis.googlecode.com/files/redis-2.4.17.tar.gz    #下載
[root@xsf003 tool]# tar -zxvf redis-2.4.17.tar.gz   #解壓
[root@xsf003 tool]# cd redis-2.4.17
[root@xsf003 redis-2.4.17]# make  #編譯
[root@xsf003 redis-2.4.17]# make install #安裝
安裝完畢,常用工具會自動拷貝到/user/loca/bin目錄下。做爲服務器,我們常常還需要把redis設置成開機自啓動,源碼包中有個很好用的腳本,執行腳步根據提示輸入即可。

[root@xsf003 redis-2.4.17]# cd utils/
[root@xsf003 utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server


Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please 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] 
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

     注意執行install_server.sh,需要先進入utils目錄,不然腳本會報錯,提示找不到相應文件。安裝完服務,redis自動啓動,可以用ps命令查看到相關信息:

[root@xsf003 utils]# ps -ef | grep redis
root      4554     1  0 10:55 ?        00:00:02 /usr/local/bin/redis-server /etc/redis/6379.conf
root      4564  2808  0 10:59 pts/0    00:00:00 grep redis

2、手動啓動關閉服務

[root@xsf003 utils]# /etc/init.d/redis_6379 stop   #關閉
[root@xsf003 utils]# /etc/init.d/redis_6379 start  #啓動

也可以用下面類似的命令直接啓動關閉redis服務:

/usr/local/bin/redis-server /etc/redis/redis.conf   #指定配置文件 啓動
/usr/local/bin/redis-cli -p 6379 shutdown   # 關閉,如果默認端口6379 可以直接 /usr/local/bin/redis-cli shutdown
    

   3、通過客戶端命令行工具連接redis服務查看redis相關信息

a)連接

[root@xsf003 utils]# redis-cli 
redis 127.0.0.1:6379>

b)其他指令

redis 127.0.0.1:6379> info  #查看server版本內存使用連接等信息

redis 127.0.0.1:6379> client list  #獲取客戶連接列表

redis 127.0.0.1:6379> client kill 127.0.0.1:33441 #終止某個客戶端連接

redis 127.0.0.1:6379> dbsize #當前保存key的數量

redis 127.0.0.1:6379> save #立即保存數據到硬盤

redis 127.0.0.1:6379> bgsave #異步保存數據到硬盤

redis 127.0.0.1:6379> flushdb #當前庫中移除所有key

redis 127.0.0.1:6379> flushall #移除所有key從所有庫中

redis 127.0.0.1:6379> lastsave #獲取上次成功保存到硬盤的unix時間戳

redis 127.0.0.1:6379> monitor #實時監測服務器接收到的請求

redis 127.0.0.1:6379> slowlog len #查詢慢查詢日誌條數
(integer) 3 

redis 127.0.0.1:6379> slowlog get #返回所有的慢查詢日誌,最大值取決於slowlog-max-len配置

redis 127.0.0.1:6379> slowlog get 2 #打印兩條慢查詢日誌

redis 127.0.0.1:6379> slowlog reset #清空慢查詢日誌信息

通過以上操作,單臺服務器基本跑起來了,不過後面的路還很長很長。。。。


參考文章:

http://redis.io/topics/introduction

http://timyang.net/data/mcdb-tt-redis/

http://redis.io/commands#server

http://code.google.com/p/redis/


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章