redis安装

简介:

redis介绍

  1. Redis和Memcached类似,也属于k-v数据存储
  2. Redis官网 redis.io,当前最新稳定版4.0.1
  3. 支持更多value类型,除了和string外,还支持hash、lists(链表)、sets(集合)和sorted sets(有序集合)
  4. redis使用了两种文件格式:全量数据(RDB)和增量请求(aof)。全量数据格式是把内存中的数据写入磁盘,便于下次读取文件进行加载。增量请求文件则是把内存中的数据序列化为操作请求,用于读取文件进行replay得到数据,这种类似于mysql binlog。
  5. redis的存储分为内存存储、磁盘存储和log文件三部分

redis安装

1、[root@centos7-2 package]# wget http://download.redis.io/releases/redis-4.0.2.tar.gz
2、[root@centos7-2 package]# tar zxf redis-4.0.2.tar.gz 
[root@centos7-2 package]# cd redis-4.0.2 
[root@centos7-2 redis-4.0.2]# make #直接make
3、[root@centos7-2 redis-4.0.2]# echo $?
0
4、make PREFIX=/usr/local/redis install
5、[root@centos7-2 bin]# cp /data/package/redis-4.0.2/redis.conf /etc/
[root@centos7-2 ~]# mkdir -p /tmp/logs/
[root@centos7-2 ~]# touch /tmp/logs/redis.log && mkdir /data/redis #新建数据目录及日志文件

6、[root@centos7-2 bin]# grep -E -v '^$|^#' /etc/redis.conf 
bind 127.0.0.1 #只能当前IP可以连接
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes #后台启动
supervised no
pidfile /var/run/redis_6379.pid #定义pid文件
loglevel notice
logfile "/tmp/logs/redis.log" #日志文件
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
dir /data/redis #数据库data目录
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 yes #开启aof日志,开启后会在dir定义的目录生成appendonly.aof文件 
appendfilename "appendonly.aof"
appendfsync everysec ##指定记录日志的规则:always(只要有变动就记录)、everysec(每秒记录一次)、no(不记录)
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

7、将/usr/local/redis/bin加入环境变量

8、启动
[root@centos7-2 ~]# redis-server /etc/redis.conf
9、查看端口
[root@centos7-2 ~]# netstat -nutlp| grep redis
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 18001/redis-server
10、测试是否正常

[root@centos7-2 ~]# redis-cli 
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> SET key1 100
OK
127.0.0.1:6379> get key1
"100"

Redis持久化相关参数

  1. save 900 1 #表示每15分钟且至少有1个key改变,就触发一次持久化
  2. save 300 10 #表示每5分钟且至少有10个key改变,就触发一次持久化
  3. save 60 10000 #表示每60秒至少有10000个key改变,就触发一次持久
  4. save “” #这样可以禁用rdb持久化
  5. appendonly yes #如果是yes,则开启aof持久化
  6. appendfilename “appendonly.aof” # 指定aof文件名字
  7. appendfsync everysec #指定fsync()调用模式,有三种no(不调用fsync),always(每次写都会调用fsync),everysec(每秒钟调用一次fsync)。第一种最快,第二种数据最安全,但性能会差一些,第三种为这种方案,默认为第三种。

本文转自 jiekegz  51CTO博客,原文链接:http://blog.51cto.com/jacksoner/2049312

相关文章
人工智能 缓存 前端开发
12206 66
人工智能 自然语言处理 安全
1148 0
Web App开发 人工智能 API
1458 1
人工智能 JavaScript 开发工具
4843 17
人工智能 Java BI
1537 1
人工智能 JavaScript 测试技术
2470 2
开发工具 Swift git
1988 6
人工智能 JavaScript 测试技术
1219 4