redis介绍
Rdis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统。它支持存储的value类型相对更多,包括string、list、set、zset和hash。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作。在此基础上,Redis支持各种不同方式的排序。它应用非常广泛如:缓存、排行榜、计数器、分布式锁、消息系统等。
安装
- 环境准备
系统版本 CentOS 7
软件版本Redis-5.0.5
1、从官网获取redis软件安装包,地址http://redis.io/download,并将其传到linux系统,放到/usr/local目录并将其解压重命名文redis
[root@izwz98qymta5zk0d5fw0mhz ~]# ls
prometheus redis-5.0.5.tar.gz
[root@izwz98qymta5zk0d5fw0mhz ~]# mv redis-5.0.5.tar.gz /usr/local
[root@izwz98qymta5zk0d5fw0mhz ~]# cd /usr/local/
[root@izwz98qymta5zk0d5fw0mhz local]# ls
aegis bin etc games include lib lib64 libexec redis-5.0.5.tar.gz sbin share src
[root@izwz98qymta5zk0d5fw0mhz local]# tar xzf redis-5.0.5.tar.gz
[root@izwz98qymta5zk0d5fw0mhz local]# ls
aegis bin etc games include lib lib64 libexec redis-5.0.5 redis-5.0.5.tar.gz sbin share src
[root@izwz98qymta5zk0d5fw0mhz local]# mv redis-5.0.5 redis
2、进入redis目录make命令编译redis
[root@izwz98qymta5zk0d5fw0mhz local]# cd redis
[root@izwz98qymta5zk0d5fw0mhz local]# make
3、编译完成后,进入src文件夹,执行make install进行Redis安装
[root@izwz98qymta5zk0d5fw0mhz src]# make install PREFIX=/usr/local/redis
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL in
配置
1、为了方便管理,将Redis文件中的conf配置文件和常用命令移动到统一文件中
创建etc目录
[root@izwz98qymta5zk0d5fw0mhz src]# cd ..
[root@izwz98qymta5zk0d5fw0mhz redis]# mkdir etc
[root@izwz98qymta5zk0d5fw0mhz redis]# ls
00-RELEASENOTES BUGS COPYING etc Makefile README.md runtest runtest-moduleapi sentinel.conf tests
bin CONTRIBUTING deps INSTALL MANIFESTO redis.conf runtest-cluster runtest-sentinel src utils
cp相关文件到etc和bin目录(cp前面加\ 表示拷贝直接覆盖不进行询问)
[root@izwz98qymta5zk0d5fw0mhz redis]# cp redis.conf /usr/local/redis/etc/
[root@izwz98qymta5zk0d5fw0mhz src]# \cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server /usr/local/redis/bin/
2、执行Redis-server 命令,启动Redis 服务
[root@izwz98qymta5zk0d5fw0mhz redis]# cd bin/
[root@izwz98qymta5zk0d5fw0mhz bin]# ls
mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server
[root@izwz98qymta5zk0d5fw0mhz bin]# ./redis-server
31615:C 25 Aug 2019 14:44:35.950 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
31615:C 25 Aug 2019 14:44:35.950 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=31615, just started
31615:C 25 Aug 2019 14:44:35.950 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.5 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 31615
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
31615:M 25 Aug 2019 14:44:35.952 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
31615:M 25 Aug 2019 14:44:35.952 # Server initialized
31615:M 25 Aug 2019 14:44:35.952 # 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.
31615:M 25 Aug 2019 14:44:35.952 # 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.
31615:M 25 Aug 2019 14:44:35.952 * Ready to accept connections
注意:这里直接执行Redis-server 启动的Redis服务,是在前台直接运行的(效果如上图),也就是说,执行完该命令后,如果Lunix关闭当前会话,则Redis服务也随即关闭。正常情况下,启动Redis服务需要从后台启动,并且指定启动配置文件
3、后台启动redis服务
a)首先编辑conf文件,将daemonize属性改为yes和添加日志文件(表明需要在后台运行)
[root@izwz98qymta5zk0d5fw0mhz redis]# vi etc/redis.conf
daemonize yes
logfile "/var/log/redis/redis.log"
b)再次启动redis服务,并指定启动服务配置文件
[root@izwz98qymta5zk0d5fw0mhz log]# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
[root@izwz98qymta5zk0d5fw0mhz log]# ps -aux |grep redis
root 31634 0.1 0.4 153884 7664 ? Ssl 14:58 0:00 /usr/local/redis/bin/redis-server 127.0.0.1:6379
root 31639 0.0 0.0 112704 976 pts/0 R+ 14:59 0:00 grep --color=auto redis
c)用本地客户端命令连接
[root@izwz98qymta5zk0d5fw0mhz bin]# ./redis-cli
127.0.0.1:6379>
4、远程连接redis服务器
/**
* 修改redis.conf配置文件
*/
// 1. 注释掉bind绑定配置
// 2. 搜索并修改为 protected-mode no。关闭保护模式,使其他主机的客户端能够连接到该Redis服务器。
// 3. 搜索并修改为 requirepass yourpassword。防止外部未知主机的客户端破解并进行Redis连接,设置连接密码。
// 4. 注意:如果你的redis服务器是在阿里云服务器上自建的,默认redis端口6379是不允许外部访问的。解决办法:在阿里云控制台的安全组管理中,开启6379端口。
网友评论