Redis is a high-performance Key-value database whose key has a rich data structure: String,hash,list set and sorted set. As a nosql, not only the key data structure is rich, but also has the persistent function, and can support the master-slave replication, it is convenient to build the cluster. Redis high performance is largely due to its memory-based database, its high performance in: Set operation 11w/s,get Operation 8.1W/S, and other types of database performance differences, you can refer to: http://timyang.net/data/mcdb-tt-redis/. To further deepen my understanding of redis, I intend to write a Redis series blog. Here we mainly talk about Redis installation and operation maintenance.
1. Download and install
[Plain] view plaincopy
[Email protected] tool]# wget-c http://redis.googlecode.com/files/redis-2.4.17.tar.gz #下载
[Email protected] tool]# TAR-ZXVF redis-2.4.17.tar.gz #解压
[Email protected] tool]# CD redis-2.4.17
[email protected] redis-2.4.17]# make #编译
[[email protected] redis-2.4.17]# make install #安装
The usual tools are automatically copied to the/user/loca/bin directory when the installation is complete. As a server, we often also need to set up Redis to boot, the source package has a very useful script, follow the footsteps of the prompt input can be.
[Plain] view plaincopy
[Email protected] redis-2.4.17]# CD utils/
[Email protected] utils]#./install_server.sh
Welcome to the Redis service installer
This script would 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!
Note that the execution of install_server.sh, you need to enter the Utils directory, or the script will be error, prompted to find the corresponding file. After the service is installed, Redis starts automatically and can be viewed with the PS command:
[Plain] view plaincopy
[Email protected] 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, manually start the shutdown service
[Plain] view plaincopy
[Email protected] utils]#/etc/init.d/redis_6379 stop #关闭
[Email protected] utils]#/etc/init.d/redis_6379 start #启动
You can also start the Shutdown Redis Service directly with a command similar to the following:
[Plain] view plaincopy
/usr/local/bin/redis-server/etc/redis/redis.conf #指定配置文件 start up
/usr/local/bin/redis-cli-p 6379 shutdown # Off, if the default port 6379 can be directly/usr/local/bin/redis-cli shutdown
3. Connect Redis service via client command line tool to view Redis related information
A) connection
[Plain] view plaincopy
[Email protected] utils]# REDIS-CLI
Redis 127.0.0.1:6379>
b) Other Directives
[Plain] view plaincopy
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 #返回所有的慢查询日志, maximum depends on Slowlog-max-len configuration
Redis 127.0.0.1:6379> Slowlog get 2 #打印两条慢查询日志
Redis 127.0.0.1:6379> slowlog Reset #清空慢查询日志信息
Through the above operation, a single server basically ran up, but the back of the road is very long ....
Reference article:
Http://redis.io/topics/introduction
http://timyang.net/data/mcdb-tt-redis/
Http://redis.io/commands#server
http://code.google.com/p/redis/
Redis Installation Deployment Maintenance