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-sentinel

2.2 启动redis服务,执行src/redis-server,服务端口默认:6379

[root@app3 redis-3.0.7]# src/redis-server
25810:C 04 Aug 13:00:26.992 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
25810:M 04 Aug 13:00:26.993 * Increased maximum number of open files to 10032 (it was originally set to 1024).
  _._
  _.-``__ ''-._
  _.-`` `. `_. ''-._ Redis 3.0.7 (00000000/0) 64 bit
  .-`` .-```. ```\/ _.,_ ''-._
 ( ' , .-` | `, ) Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
 | `-._ `._ / _.-' | PID: 25810
  `-._ `-._ `-./ _.-' _.-'
 |`-._`-._ `-.__.-' _.-'_.-'|
 | `-._`-._ _.-'_.-' | http://redis.io
  `-._ `-._`-.__.-'_.-' _.-'
 |`-._`-._ `-.__.-' _.-'_.-'|
 | `-._`-._ _.-'_.-' |
  `-._ `-._`-.__.-'_.-' _.-'
  `-._ `-.__.-' _.-'
  `-._ _.-'
  `-.__.-'

25810:M 04 Aug 13:00:26.995 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
25810:M 04 Aug 13:00:26.995 # Server started, Redis version 3.0.7
25810:M 04 Aug 13:00:26.995 # 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.
25810:M 04 Aug 13:00:26.995 * The server is now ready to accept connections on port 6379

2.3 设置、查询redis值
打开另一个客户端,执行src/redis-cli启动客户端,set设置、get查询 KEY-VALUE

[root@app3 redis-3.0.7]# src/redis-cli
127.0.0.1:6379> set name zhengzhenzhen
OK
127.0.0.1:6379> get name
"zhengzhenzhen"
127.0.0.1:6379>
[root@app3 redis-3.0.7]#
三.安装redis服务

为了管理redis方便,使其开机自启动,可以将redis安装成系统服务。

3.1 执行make install

[root@app3 src]# cd ..
[root@app3 redis-3.0.7]# make install
cd src && make install
make[1]: Entering directory `/home/chenyihui/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[1]: Leaving directory `/home/chenyihui/redis-3.0.7/src'

会将make编译生成的6个可执行文件拷贝到/usr/local/bin下

[root@app1 /]# cd usr/local/bin
[root@app1 bin]# ll
total 13780
-rwxr-xr-x 1 root root    2363 May  7  2014 pcre-config
-rwxr-xr-x 1 root root   86157 May  7  2014 pcregrep
-rwxr-xr-x 1 root root  161200 May  7  2014 pcretest
-rwxr-xr-x 1 root root 3987849 Aug  5 11:47 redis-benchmark
-rwxr-xr-x 1 root root   23082 Aug  5 11:47 redis-check-aof
-rwxr-xr-x 1 root root   45861 Aug  5 11:47 redis-check-dump
-rwxr-xr-x 1 root root 4078469 Aug  5 11:47 redis-cli
lrwxrwxrwx 1 root root      27 Aug  5 11:47 redis-sentinel -> /usr/local/bin/redis-server
-rwxr-xr-x 1 root root 5640961 Aug  5 11:47 redis-server

3.2 执行./utils/install_server.sh配置redis配置之后redis能开机启动,最后successful!

[root@app3 redis-3.0.7]# ./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]
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!

查看是否已设置开机启动

[root@app3 redis-3.0.7]# chkconfig --list
...
redis_6379 0:off 1:off 2:on 3:on 4:on 5:on 6:off
...

3.3 redis服务的查看、启动、停止
查看启动情况:ps -ef|grep redis

[root@app3 redis-3.0.7]# ps -ef|grep redis
root 9009 1 0 13:19 ? 00:00:00 /usr/local/bin/redis-server *:6379
root 23907 14649 0 13:21 pts/2 00:00:00 grep redis

停止服务:/etc/init.d/redis_6379 stop

[root@app3 redis-3.0.7]# /etc/init.d/redis_6379 stop
Stopping ...
Redis stopped

启动服务:/etc/init.d/redis_6379 start

以上!

GitHub 加速计划 / li / linux-dash
6
1
下载
A beautiful web dashboard for Linux
最近提交(Master分支:3 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐