Linux安装配置Redis
Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API.这里使用目的:需求是实时匹配一个号码所属地区,且并发量发。那就需要将号码段对应的地区编码表存储到redis,大概30W条,如果实时连接数据库不实际。
一.下载
官网下载,可自选版本,点击进入下载,这里下载了redis-3.0.7
二.编译
2.1执行make编译redis$ tar -zxzf redis-3.0.7.tar.gz
$ cd redis-3.0.7
$ make编译后在src下会生成6个执行文件redis-server(启动服务端)、redis-cli(调用客户端)、redis-benchmark、redis-check-aof、redis-check-dump、redis-sentinel2.2 启动redis服务,执行src/redis-server,服务端口默认:6379
2.3 设置、查询redis值
打开另一个客户端,执行src/redis-cli启动客户端,set设置、get查询 KEY-VALUE# src/redis-cli
127.0.0.1:6379> set name dingwei
OK
127.0.0.1:6379> get name
"dingwei"
127.0.0.1:6379> get name
"dingwei"
127.0.0.1:6379> get name
"dingwei"
三.安装redis服务
为了管理redis方便,使其开机自启动,可以将redis安装成系统服务。
3.1 执行make install# make install
cd src && make install
make: Entering directory `/usr/local/src/redis-3.0.7/src'
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make: Leaving directory `/usr/local/src/redis-3.0.7/src'会将make编译生成的6个可执行文件拷贝到/usr/local/bin下-rwxr-xr-x. 1 root root 2363 9月 5 2016 pcre-config
-rwxr-xr-x. 1 root root 89407 9月 5 2016 pcregrep
-rwxr-xr-x. 1 root root 191915 9月 5 2016 pcretest
-rwxr-xr-x 1 root root 4589139 3月 31 14:48 redis-benchmark
-rwxr-xr-x 1 root root 22185 3月 31 14:48 redis-check-aof
-rwxr-xr-x 1 root root 45403 3月 31 14:48 redis-check-dump
-rwxr-xr-x 1 root root 4698354 3月 31 14:48 redis-cli
lrwxrwxrwx 1 root root 12 3月 31 14:48 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 6471319 3月 31 14:48 redis-server3.2 执行./utils/install_server.sh配置redis配置之后redis能开机启动,最后successful!# ./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:
Selecting default: 6379
Please select the redis config file name
Selected default - /etc/redis/6379.conf
Please select the redis log file name
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance
Selected default - /var/lib/redis/6379
Please select the redis executable path
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
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!
查看是否已设置开机启动# chkconfig --list redis_6379
redis_6379 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
3.3 redis服务的查看、启动、停止
查看启动情况:ps -ef|grep redis# ps -ef | grep redis
root 20219 1 0 15:00 ? 00:00:01 /usr/local/bin/redis-server *:6379
root 20432 19788 0 15:10 pts/2 00:00:00 grep redis
停止服务:/etc/init.d/redis_6379 stop# service redis_6379 stop
Stopping ...
Redis stopped
启动服务:/etc/init.d/redis_6379 start# service redis_6379 start
Starting Redis server...
页:
[1]