Linux installation Redis 5.0

Structured as follows:

 

 

Official Redis Redis is not recommended to install on WINDOWS servers (especially in the production of a distributed object cache).

 

  linux from the master copy Redis 5.0 (two from a master) Sentinel model structures: https: //www.cnblogs.com/hmwh/p/10089430.html

  linux under Redis 5.0 Main Cluster Setup: https: //www.cnblogs.com/hmwh/category/1321360.html

1, the following new features:

1. Stream new data type. https://redis.io/topics/streams-intro

2. The new module Redis API: timer, clusters and dictionary API.

3. RDB LFU and LRU information is now stored.

Cluster Manager migration from Ruby (redis-trib.rb) to the C code redis-cli inside. Check `redis-cli --cluster help` for more information.

The ordered set of new commands: ZPOPMIN / MAX and blocking variants.

6. proactive defragmentation version 2.

7. Improvement HyperLogLog network implementation.

8. better memory reporting.

9. Many commands tape command now has a sub-HELP command.

10. When customers often connect and disconnect, the better the performance.

11. Many bug fixes and other improvements random.

12. Jemalloc upgrade to version 5.1

13. UNBLOCK client and Client ID.

14. Add a LOLWUT command. http://antirez.com/news/123

15. If it is not backward compatible API, we no longer use the "slave" word.

16. The difference between the network layer optimization.

17. Lua improvements:

- better Lua script will spread to slaves / AOF.

    - Lua script can now enter -BUSY out and state in the copy.

18. dynamically balanced HZ idle CPU usage and responsiveness.

19. Redis core has been reconstructed and improved in many ways.

 

2, Redis installed

Redis version

Operating system version

Remark

5.0.0

linux6.7

Single live

Installation source package

yum -y install make gcc*

View gcc

gcc -v

 

 

download link:

https://redis.io/

Uploaded to the / opt directory and extract (to modify the directory according to the actual situation).

takes -zxvf Redis-5.0.0.tar.gz

cd-repeat 5.0.0

make

 

 

make install

 

 

 

Successful installation.

Command in the installed / usr / local / bin /.

 

3, redis start and shut down

 

redis-server /opt/redis-5.0.0/redis.conf - no need to add the default configuration file

 

 

View port: PONG normal

 

Redis off:

shutdown

 

 

4, modify parameters

cp /opt/redis-5.0.0/redis.conf /opt/redis-5.0.0/redis.conf.bak

 

daemonize yes - formerly no, running in the background redis (start redis modified, so-called cake that figure does not appear), other modifications of the actual situation

port 6379

 

Background redis, daemon changed to yes

 

Modify IP, modified to the corresponding IP binding

 client inside the IP Case:

Can be modified to access IP (or IP, and the machine IP mapping), reboot

 

 

 

 

Setting key when there will be a command prompt (see below).

 

 

 

change Password:

 config set requirepass "redis" 修改成 redis

Write to the configuration file inside, try to restart:

Setting the system log:

loglevel warning

Production library logs and more, are impossible to see, can be set to only view important information

 

Client timeout settings:

0 30s-60s provided so as not time-out, may be provided depending on the circumstances, it is recommended

 Memory caching policy settings:

 5.0 New allkeys-lfu, volatile-lfu

Recommended for volatile-ttl, nearest to expiration policy.

 aof persistent way, recommended appendfsync everysec way that the 5.0 default, every second, always ensure data consistency, but poor performance, no more to die, do not open.

 Internet companies aof large concurrent parameter setting is very important, default is shown below: 64MB proposed to revise GB units, high concurrency Internet companies, at least 3GB or more.

 同时,由于在恢复的时候,如果持久化都是使用的aof和rdb,建议rdb文件是15分钟备份一次,太频繁影响性能。

 

性能测试:

 redis-benchmark

 

另外附带需要修改的参数:

参数说明
redis.conf 配置项说明如下:
1. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程
 daemonize no
2. 当Redis以守护进程方式运行时,Redis默认会把pid写入/var/run/redis.pid文件,可以通过pidfile指定
 pidfile /var/run/redis.pid
3. 指定Redis监听端口,默认端口为6379,作者在自己的一篇博文中解释了为什么选用6379作为默认端口,因为6379在手机按键上MERZ对应的号码,而MERZ取自意大利歌女Alessia Merz的名字
port 6379
4. 绑定的主机地址
 bind 127.0.0.1
5.当 客户端闲置多长时间后关闭连接,如果指定为0,表示关闭该功能
 timeout 300
6. 指定日志记录级别,Redis总共支持四个级别:debug、verbose、notice、warning,默认为verbose
 loglevel verbose
7. 日志记录方式,默认为标准输出,如果配置Redis为守护进程方式运行,而这里又配置为日志记录方式为标准输出,则日志将会发送给/dev/null
 logfile stdout
8. 设置数据库的数量,默认数据库为0,可以使用SELECT <dbid>命令在连接上指定数据库id
databases 16
9. 指定在多长时间内,有多少次更新操作,就将数据同步到数据文件,可以多个条件配合
save <seconds> <changes>
 Redis默认配置文件中提供了三个条件:
 save 900 1
save 300 10
save 60 10000
 分别表示900秒(15分钟)内有1个更改,300秒(5分钟)内有10个更改以及60秒内有10000个更改。

10. 指定存储至本地数据库时是否压缩数据,默认为yes,Redis采用LZF压缩,如果为了节省CPU时间,可以关闭该选项,但会导致数据库文件变的巨大
 rdbcompression yes
11. 指定本地数据库文件名,默认值为dump.rdb
dbfilename dump.rdb
12. 指定本地数据库存放目录
 dir ./
13. 设置当本机为slav服务时,设置master服务的IP地址及端口,在Redis启动时,它会自动从master进行数据同步
 slaveof <masterip> <masterport>
14. 当master服务设置了密码保护时,slav服务连接master的密码
masterauth <master-password>
15. 设置Redis连接密码,如果配置了连接密码,客户端在连接Redis时需要通过AUTH <password>命令提供密码,默认关闭
 requirepass foobared
16. 设置同一时间最大客户端连接数,默认无限制,Redis可以同时打开的客户端连接数为Redis进程可以打开的最大文件描述符数,如果设置 maxclients 0,表示不作限制。当客户端连接数到达限制时,Redis会关闭新的连接并向客户端返回max number of clients reached错误信息
maxclients 128
17. 指定Redis最大内存限制,Redis在启动时会把数据加载到内存中,达到最大内存后,Redis会先尝试清除已到期或即将到期的Key,当此方法处理 后,仍然到达最大内存设置,将无法再进行写入操作,但仍然可以进行读取操作。Redis新的vm机制,会把Key存放内存,Value会存放在swap区
 maxmemory <bytes>
18. 指定是否在每次更新操作后进行日志记录,Redis在默认情况下是异步的把数据写入磁盘,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为 redis本身同步数据文件是按上面save条件来同步的,所以有的数据会在一段时间内只存在于内存中。默认为no
appendonly no
19. 指定更新日志文件名,默认为appendonly.aof
appendfilename appendonly.aof
20. 指定更新日志条件,共有3个可选值:?
no:表示等操作系统进行数据缓存同步到磁盘(快)?
always:表示每次更新操作后手动调用fsync()将数据写到磁盘(慢,安全)?
everysec:表示每秒同步一次(折衷,默认值)
 appendfsync everysec

21. 指定是否启用虚拟内存机制,默认值为no,简单的介绍一下,VM机制将数据分页存放,由Redis将访问量较少的页即冷数据swap到磁盘上,访问多的页面由磁盘自动换出到内存中(在后面的文章我会仔细分析Redis的VM机制)
 vm-enabled no
22. 虚拟内存文件路径,默认值为/tmp/redis.swap,不可多个Redis实例共享
 vm-swap-file /tmp/redis.swap
23. 将所有大于vm-max-memory的数据存入虚拟内存,无论vm-max-memory设置多小,所有索引数据都是内存存储的(Redis的索引数据 就是keys),也就是说,当vm-max-memory设置为0的时候,其实是所有value都存在于磁盘。默认值为0
 vm-max-memory 0
24. Redis swap文件分成了很多的page,一个对象可以保存在多个page上面,但一个page上不能被多个对象共享,vm-page-size是要根据存储的 数据大小来设定的,作者建议如果存储很多小对象,page大小最好设置为32或者64bytes;如果存储很大大对象,则可以使用更大的page,如果不 确定,就使用默认值
vm-page-size 32
25. 设置swap文件中的page数量,由于页表(一种表示页面空闲或使用的bitmap)是在放在内存中的,,在磁盘上每8个pages将消耗1byte的内存。
vm-pages 134217728
26. 设置访问swap文件的线程数,最好不要超过机器的核数,如果设置为0,那么所有对swap文件的操作都是串行的,可能会造成比较长时间的延迟。默认值为4
vm-max-threads 4
27. 设置在向客户端应答时,是否把较小的包合并为一个包发送,默认为开启
 glueoutputbuf yes
28. 指定在超过一定的数量或者最大的元素超过某一临界值时,采用一种特殊的哈希算法
 hash-max-zipmap-entries 64
 hash-max-zipmap-value 512
29. 指定是否激活重置哈希,默认为开启(后面在介绍Redis的哈希算法时具体介绍)
 activerehashing yes
30. 指定包含其它的配置文件,可以在同一主机上多个Redis实例之间使用同一份配置文件,而同时各个实例又拥有自己的特定配置文件
include /path/to/local.conf

Guess you like

Origin www.cnblogs.com/cyl048/p/11261996.html