您的位置:首页 > 数据库 > Redis

Redis安装

2016-12-16 10:14 99 查看
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
1
2
3
1
2
3

编译后在src下会生成6个执行文件
redis-server(启动服务端)、redis-cli(调用客户端)、redis-benchmark、redis-check-aof、redis-check-dump、redis-sentinel
1
1

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

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]#
1
2
3
4
5
6
7
1
2
3
4
5
6
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'
1
2
3
4
5
6
7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13

会将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
1
2
3
4
5
6
7
8
9
10
11
12
1
2
3
4
5
6
7
8
9
10
11
12

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!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

查看是否已设置开机启动
[root@app3 redis-3.0.7]# chkconfig --list
...
redis_6379 0:off 1:off 2:on 3:on 4:on 5:on 6:off
...
1
2
3
4
1
2
3
4

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
1
2
3
1
2
3

停止服务:/etc/init.d/redis_6379 stop
[root@app3 redis-3.0.7]# /etc/init.d/redis_6379 stop
Stopping ...
Redis stopped
1
2
3


1
2
3

启动服务:/etc/init.d/redis_6379 start
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: