一、Redis简介
Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。从2010年3月15日起,Redis的开发工作由VMware主持。从2013年5月开始,Redis的开发由Pivotal赞助。
二、Redis安装
1、下载Redis安装包
[root@ chenc01 ~]# wget http://download.redis.io/releases/redis-4.0.6.tar.gz
--2020-03-19 17:34:31-- http://download.redis.io/releases/redis-4.0.6.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1723533 (1.6M) [application/x-gzip]
Saving to: ‘redis-4.0.6.tar.gz’
100%[==========================================================================================================>] 1,723,533 608KB/s in 2.8s
2020-03-19 17:35:31 (608 KB/s) - ‘redis-4.0.6.tar.gz’ saved [1723533/1723533]
[root@ chenc01 ~]# ls
anaconda-ks.cfg redis-4.0.6.tar.gz
2、解压压缩包
[root@ chenc01 ~]# tar -zxvf redis-4.0.6.tar.gz
redis-4.0.6/
redis-4.0.6/.gitignore
redis-4.0.6/00-RELEASENOTES
redis-4.0.6/BUGS
redis-4.0.6/CONTRIBUTING
redis-4.0.6/COPYING
redis-4.0.6/INSTALL
redis-4.0.6/MANIFESTO
.................................
[root@ chenc01 ~]# ls
anaconda-ks.cfg redis-4.0.6 redis-4.0.6.tar.gz
3、yum安装gcc依赖
[root@ chenc01 ~]# yum -y install gcc
4、跳转到redis解压目录下
[root@ chenc01 ~]# cd redis-4.0.6/
[root@ chenc01 redis-4.0.6]# ls
00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests
BUGS deps MANIFESTO runtest sentinel.conf utils
CONTRIBUTING INSTALL README.md runtest-cluster src
5、编译安装
[root@ chenc01 ~]# make MALLOC=libc
[root@ chenc01 redis-4.0.6]# cd src && make install
CC Makefile.dep
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
6、启动redis
make完后 redis-2.8.17目录下会出现编译后的redis服务程序redis-server,还有用于测试的客户端程序redis-cli,两个程序位于安装目录 src 目录下:
下面启动redis服务
[root@ chenc01 src]# ./redis-server
2851:C 19 Mar 18:41:33.087 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
2851:C 19 Mar 18:41:33.087 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=2851, just started
2851:C 19 Mar 18:41:33.087 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.6 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 2851
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
2851:M 19 Mar 18:41:33.088 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
2851:M 19 Mar 18:41:33.088 # Server initialized
2851:M 19 Mar 18:41:33.088 # 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.
2851:M 19 Mar 18:41:33.088 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
2851:M 19 Mar 18:41:33.088 * Ready to accept connections
redis启动成功,但是这种启动方式需要一直打开窗口,不能进行其他操作,不太方便。
按 ctrl + c可以关闭窗口。
7、修改配置文件
第一步:修改redis.conf文件
将
daemonize no
修改为
daemonize yes
第二步:指定redis.conf文件启动
[root@ chenc01 src]# ./redis-server /usr/local/redis-4.0.6/redis.conf
17465:C 19 Mar 18:51:48.896 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
17465:C 19 Mar 18:51:48.897 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=17465, just started
17465:C 19 Mar 18:51:48.897 # Configuration loaded
启动redis服务进程后,就可以使用测试客户端程序redis-cli和redis服务交互了。 比如:
[root@ chenc01 src]# ./redis-cli
127.0.0.1:6379> set one time
OK
127.0.0.1:6379> get one
"time"