Redis 介绍和安装

Redis简单介绍

特点

  • 高性能 Key-Value服务器
  • 多种数据结构
  • 丰富的功能
  • 高可用的分布式支持

特性

  • 速度快 : 使用的是内存
  • 功能丰富 :发布订阅,事务,pipeline
  • 持久化 : redis所有的数据保存在内存中,对数据的更新将异步的保存在磁盘上。
  • 简单
  • 多种数据结构 : String/Blobs/Bitmaps,Hash Tables(objects!),Linked Lists,Sets,Sorted Sets
  • 主从复制
  • 支持多种编辑语言
  • 高可用,分布式

典型场景

  • 缓存系统 : app server -> cache -> storage
  • 计数器 : 如微博转发数等
  • 消息队列系统
  • 排行榜
  • 社交网络
  • 实时系统

Redis安装
官网: https://redis.io/

# 下载软件包
wget http://download.redis.io/releases/redis-4.0.11.tar.gz
# 解压缩
tar -xzf redis-4.0.11.tar.gz
# 创建软链接
sudo ln -s redis-4.0.11 redis
# 进入目录
cd redis
# 编译安装
make && make install

Redis可执行文件介绍

redis-server : redis 服务器
redis-cli  :  Redis命令行客服端
redis-benchmark : redis性能基准测试
redis-check-aof : AOF 文件修复工具
redis-check-dump :RDB文件检查工具
redis-sentinel :Sentine服务器(2.8以后)

redis启动

# 简单启动 redis
redis-server
# 动态启动
redis-server --port 6380
#配置文件启动
redis-server configpath
  • 生产环境建议配置文件启动
  • 单机多实例配置文件可以用端口区分开

验证Redis启动

# 查看进程
ps -ef | grep redis
# 查看端口
netstat -antp | grep redis
# ping
redis-cli -h ip -p port ping

redis客服端连接

# 连接redis server
redis-cli -h 10.10.79.150 -p 6384
# 测试 ping ;回复pong ok
ping

Redis客服端状态值

# 状态回复
ping / pong
# 错误回复
hget hllo / error ....
# 整数回复
incr hello
# 字符串回复
get hello
# 多行字符串回复
mget hello foo

常用配置

# 是否以守护进程启动
daemonize  yes/no
# 使用那个端口,默认端口6379
port
# Rdis系统日志,只是一个文件名
logfile
# Redis工作目录,日志文件也在这个目录中
dir

编写配置文件

因redis是单进程的,所以一般会配置多个实例,配置文件一般一端口号区分 redis-6379.conf

# 去除空格,注释查看,并重定向
cat redis-8381.conf | grep -v "#" |grep -v "^$" > redis-6382

# 全部的配置参数
 # 工作目录
dir "/opt/redis/data"
 # 6381端口启动
port 6381
 # 守护进程启动
daemonize yes
 # 日志文件名称
logfile "6381.log"

bind 127.0.0.1
protected-mode yes

tcp-backlog 511
timeout 0
tcp-keepalive 300

supervised no
pidfile /var/run/redis_6379.pid
loglevel notice

databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb

slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

以配置文件启动

redis-server config/reis-6381.conf

猜你喜欢

转载自www.cnblogs.com/nirao/p/9759087.html