Redis系列--安装helloworld以及读懂配置文件

Posted Jack__Frost

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Redis系列--安装helloworld以及读懂配置文件相关的知识,希望对你有一定的参考价值。

再开个redis系列,本系列打算不详细讲一系列的命名的了(会推荐别人写的,人家写的够详细了),我直接就是做redis方案提供,当然一开始还是讲下helloworld和配置文件好了。会逐步更新,欢迎关注。

文章结构:

(1)安装;
(2)helloworld;
(3)解析配置文件(一一罗列方便复习);
(4)重点配置


一、安装:把到官网下载好的redis压缩包放置到你想要的位置。并解压。

在这里插入图片描述

然后进入redis-3.0.4目录,执行make命令

jackfrost@jackfrost-pc:~/MyResource/Redis/redis-3.0.4$ make

问题:

如果遇到gcc没找到,那么请看以下说明:

原因:

redis是c语音编写的,需要gcc环境支持。

gcc是linux下的一个编译程序,是c程序的编译工具。GCC是GNU计划提供的编译器家族,支持C,C++,Objective-C,Java等多语音,同时能运行在x86,x86-64,IA-64,PowerPC等几乎所有硬件平台。

解决:一个安装命令(centos下的命令)

yum install gcc-c++

二、helloworld:

(1)关注第一个目录!/usr

这是一个重要目录,用户的很多应用程序和文件都放在这个目录下面,类似windows的program file目录

而我们的redis安装好后,一般就是在/usr/local/bin下面啦
在这里插入图片描述

(2)关注的第二个目录:

我们在玩redis,当然关注自己的redis目录啦!!,同时重点关注reids.conf

注意,一般我们不直接操作我们安装好的reids配置文件,因为他很重要,关乎生死,redis架构好坏。
在这里插入图片描述

(3)于是为了安全,我们要另建一个目录去操作redis.conf

在这里插入图片描述

然后就把原来的那个redis.conf复制到我们新建的目录嘛

在这里插入图片描述

想要多少份就多少份,反正操作对应好的配置文件就ok啦。

redis关键:能备份的先备份

(4)修改配置文件

把此处的no改成yes
意思是:默认情况下 redis 不是作为守护进程运行的,如果你想让它在后台运行,你就把它改成 yes。我们必须保证它不被杀死!!!
在这里插入图片描述

(5)启动并观察redis进程

使用下面命令可以看到,现在并没有开启redis嘛。

在这里插入图片描述

那么我们就启动他嘛,进入/usr/local/bin目录

要求:1.找到我们刚刚复制并修改过来的redis.conf全路径,使用redis-server命令;2. 1的命令启动后没有报错,继续使用redis-cli -p 6379 命令,ping连接一下。返回pong即成功启动!

在这里插入图片描述

这个时候我们再来观察redis的进程:就可以看到啦

在这里插入图片描述

于是我们就可以开始写我们熟悉的helloworld啦!

在这里插入图片描述

先暂时给个常见错误解决:

在这里插入图片描述

错误)misconf redis被配置以保存数据库快照,但misconf redis目前不能在硬盘上持久化。用来修改数据集合的命令不能用,请使用日志的错误详细信息。

原因:

这是由于强制停止redis快照,不能持久化引起的。edis在保存数据到硬盘时为了避免主进程假死,需要Fork一份主进程,然后在Fork进程内完成数据保存到硬盘的操作,如果主进程使用了4GB的内存,Fork子进程的时候需要额外的4GB,此时内存就不够了,Fork失败,进而数据保存硬盘也失败了。

解决:

config set stop-writes-on-bgsave-error no 命令来关闭配置项stop-writes-on-bgsave-error。详细解析


三、解析配置文件:

一开始就先全部罗列解析一次吧(其实是基本的翻译啦),,不过下面会有重点关注提醒!!

# Redis configuration file example
//redis 配置文件示例
# Note on units: when memory size is needed, it is possible to specify
//当你需要为某个配置项指定内存大小的时候,必须要带上单位
# it in the usual form of 1k 5GB 4M and so forth:
//通常的格式就是 1k 5gb 4m 
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
#
# units are case insensitive so 1GB 1Gb 1gB are all the same.
//单位是不区分大小写的,你写 1K 5GB 4M 也行
################################## INCLUDES ###################################
# Include one or more other config files here.  This is useful if you
# have a standard template that goes to all Redis servers but also need
//假如说你有一个可用于所有的 redis server 的标准配置模板,
# to customize a few per-server settings.  Include files can include
# other files, so use this wisely.
//但针对某些 server 又需要一些个性化的设置,可以使用 include 来包含一些其他的配置文件,这对你来说是非常有用的。
# Notice option "include" won't be rewritten by command "CONFIG REWRITE"
//但是要注意,include 是不能被 config rewrite 命令改写的
# from admin or Redis Sentinel. Since Redis always uses the last processed
//由于 redis 总是以最后的加工前作为一个配置指令值,所以你最好是把 include 放在这个文件的最前面,以避免在运行时覆盖配置的改变,相反,你就把它放在后面
# line as value of a configuration directive, you'd better put includes
# at the beginning of this file to avoid overwriting config change at runtime.
//如果您感兴趣的是使用包括重写配置选项,最好使用include作为最后一行。
# If instead you are interested in using includes to override configuration
# options, it is better to use include as the last line.
#
# include /path/to/local.conf
# include /path/to/other.conf

################################ GENERAL常用  #####################################
//默认情况下 redis 不是作为守护进程运行的,如果你想让它在后台运行,你就把它改成 yes。
# By default Redis does not run as a daemon. Use 'yes' if you need it.
//当redis作为守护进程运行的时候,它会写一个 pid 到 /var/run/redis.pid 文件里面。
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no
//当redis作为守护进程运行的时候,它会把 pid 默认写到 /var/run/redis.pid 文件里面,但是你可以在这里自己制定它的文件位置。
# When running daemonized, Redis writes a pid file in /var/run/redis.pid by
# default. You can specify a custom pid file location here.
pidfile /var/run/redis.pid
//监听端口号,默认为 6379,如果你设为 0 ,redis 将不在 socket 上监听任何客户端连接。
# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379
//TCP 监听的最大容纳数量
# TCP listen() backlog.
//在高并发的环境下,你需要把这个值调高以避免客户端连接缓慢的问题。
# In high requests-per-second environments you need an high backlog in order
# to avoid slow clients connections issues. Note that the Linux kernel
# will silently truncate it to the value of /proc/sys/net/core/somaxconn so
//Linux 内核会一声不响的把这个值缩小成 /proc/sys/net/core/somaxconn 对应的值,所以你要修改这两个值才能达到你的预期。
# make sure to raise both the value of somaxconn and tcp_max_syn_backlog
# in order to get the desired effect.
tcp-backlog 511
//默认情况下,redis 在 server 上所有有效的网络接口上监听客户端连接。
//你如果只想让它在一个网络接口上监听,那你就绑定一个IP或者多个IP。
# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
//示例,多个IP用空格隔开
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1
//指定 unix socket 的路径。
# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
# unixsocket /tmp/redis.sock
# unixsocketperm 700
//指定在一个 client 空闲多少秒之后关闭连接(0 就是不管它)
# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0
//tcp 心跳包。
# TCP keepalive.
//如果设置为非零,则在与客户端缺乏通讯的时候使用 SO_KEEPALIVE 发送 tcp acks 给客户端。
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
//这个之所有有用,主要由两个原因:
//1.防止死的 peers
//2.从网络的角度看连接的活跃性中间设备。
# of communication. This is useful for two reasons:
#
# 1) Detect dead peers.
# 2) Take the connection alive from the point of view of network
#    equipment in the middle.
#
# On Linux, the specified value (in seconds) is the period used to send ACKs.
# Note that to close the connection the double of the time is needed.
# On other kernels the period depends on the kernel configuration.
//推荐一个合理的值就是60秒
# A reasonable value for this option is 60 seconds.
tcp-keepalive 0
//定义日志级别。
# Specify the server verbosity level.
# This can be one of:
//可以是下面的这些值:
//debug (适用于开发或测试阶段)
# debug (a lot of information, useful for development/testing)
//基本不用的级别.许多很少有用的信息,但不是像调试级别混乱
# verbose (many rarely useful info, but not a mess like the debug level)
// (适用于生产环境)
# notice (moderately verbose, what you want in production probably)
//仅仅一些重要的消息被记录)
# warning (only very important / critical messages are logged)
loglevel notice

# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
//指定日志文件的位置
logfile ""
//要想把日志记录到系统日志,就把它改成 yes,
# To enable logging to the system logger, just set 'syslog-enabled' to yes,
//也可以可选择性的更新其他的syslog 参数以达到你的要求
# and optionally update the other syslog parameters to suit your needs.
# syslog-enabled no
//设置 syslog 的 identity。
# Specify the syslog identity.
# syslog-ident redis
//设置 syslog 的 facility,必须是 USER 或者是 LOCAL0-LOCAL7 之间的值。
# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
# syslog-facility local0
//设置数据库的数目。默认数据库是 DB 0,你可以在每个连接上使用 select <dbid> 命令选择一个不同的数据库,
# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
//但是 dbid 必须是一个介于 0 到 databasees - 1 之间的值
# dbid is a number between 0 and 'databases'-1
databases 16

################################ SNAPSHOTTING快照   ################################
//存 DB 到磁盘:
# Save the DB on disk:
//格式:save <间隔时间(秒)> <写入次数>
#   save <seconds> <changes>
//根据给定的时间间隔和写入次数将数据保存到磁盘
#   Will save the DB if both the given number of seconds and the given
#   number of write operations against the DB occurred.
//下面的例子的意思是:
/*
900 秒内如果至少有 1 个 key 的值变化,则保存
300 秒内如果至少有 10 个 key 的值变化,则保存
60 秒内如果至少有 10000 个 key 的值变化,则保存
*/
#   In the example below the behaviour will be to save:
#   after 900 sec (15 min) if at least 1 key changed
#   after 300 sec (5 min) if at least 10 keys changed
#   after 60 sec if at least 10000 keys changed
//注意:你可以注释掉所有的 save 行来停用保存功能,也可以直接一个空字符串来实现停用.
#   Note: you can disable saving completely by commenting out all "save" lines.
#
#   It is also possible to remove all the previously configured save
#   points by adding a save directive with a single empty string argument
#   like in the following example:
#
#   save ""

save 900 1
save 300 10
save 60 10000
/*
	默认情况下,如果 redis 最后一次的后台保存失败,redis 将停止接受写操作,这样以一种强硬的方式让用户知道数据不能正确的持久化到磁盘,否则就会没人注意到灾难的发生。
*/
# By default Redis will stop accepting writes if RDB snapshots are enabled
# (at least one save point) and the latest background save failed.
# This will make the user aware (in a hard way) that data is not persisting
# on disk properly, otherwise chances are that no one will notice and some
# disaster will happen.
//如果后台保存进程重新启动工作了,redis 也将自动的允许写操作。
# If the background saving process will start working again Redis will
# automatically allow writes again.
//然而你要是安装了靠谱的监控,你可能不希望 redis 这样做,那你就改成 no 好了。或者您可能希望禁用此功能,Redis会继续工作,即使磁盘有问题。
# However if you have setup your proper monitoring of the Redis server
# and persistence, you may want to disable this feature so that Redis will
# continue to work as usual even if there are problems with disk,
# permissions, and so forth.
stop-writes-on-bgsave-error yes
//是否在 dump .rdb 数据库的时候使用 LZF 压缩字符串
# Compress string objects using LZF when dump .rdb databases?
//默认都设为 yes
# For default that's set to 'yes' as it's almost always a win.
//如果你希望保存子进程节省点 cpu ,你就设置它为 no ,
# If you want to save some CPU in the saving child set it to 'no' but
//不过这个数据集可能就会比较大
# the dataset will likely be bigger if you have compressible values or keys.
rdbcompression yes

# Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
# This makes the format more resistant to corruption but there is a performance
# hit to pay (around 10%) when saving and loading RDB files, so you can disable it
# for maximum performances.
#
# RDB files created with checksum disabled have a checksum of zero that will
# tell the loading code to skip the check.
//是否校验rdb文件
rdbchecksum yes
//设置 dump 的文件位置
# The filename where to dump the DB
dbfilename dump.rdb
//工作目录
# The working directory.
//例如上面的 dbfilename 只指定了文件名,
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
//但是它会写入到这个目录下。这个配置项一定是个目录,而不能是文件名。
# Note that you must specify a directory here, not a file name.
dir ./

################################# REPLICATION主从复制 #################################
//主从复制。使用 slaveof 来让一个 redis 实例成为另一个reids 实例的副本。
//注意这个只需要在 slave 上配置。
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
//对redis复制需要了解:
//Redis复制是异步的,但你可以配置一个主停止接受写入,如果它似乎与至少一个给定数量的丛属没有连接。
# 1) Redis replication is asynchronous, but you can configure a master to
#    stop accepting writes if it appears to be not connected with at least
#    a given number of slaves.
//Redis从属可以执行部分同步主redis,如果复制链路则丢失相对少量的时间。
# 2) Redis slaves are able to perform a partial resynchronization with the
#    master if the replication link is lost for a relatively small amount of
//你可以配置复制积压大小,并根据需要选择合理的值。
#    time. You may want to configure the replication backlog size (see the next
#    sections of this file) with a sensible value depending on your needs.
//复制是自动的,不需要用户干预。在网络分区的从属会自动尝试重新连接到他们的主redis并同步。
# 3) Replication is automatic and does not need user intervention. After a
#    network partition slaves automatically try to reconnect to masters
#    and resynchronize with them.
#
# slaveof <masterip> <masterport>
//如果master设置了requirepass,那么slave要连上master,需要有master的密码才行。masterauth就是用来配置master的密码,这样可以在连上master后进行认证。
# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the slave to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the slave request.
#
# masterauth <master-password>
//当从库同主机失去连接或者复制正在进行,从机库有两种运行方式:1) 如果slave-serve-stale-data设置为yes(默认设置),从库会继续响应客户端的请求。2) 如果slave-serve-stale-data设置为no,除去INFO和SLAVOF命令之外的任何请求都会返回一个错误”SYNC with master in progress”。
# When a slave loses its connection with the master, or when the replication
# is still in progress, the slave can act in two different ways:
#
# 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
#    still reply to client requests, possibly with out of date data, or the
#    data set may just be empty if this is the first synchronization.
#
# 2) if slave-serve-stale-data is set to 'no' the slave will reply with
#    an error "SYNC with master in progress" to all the kind of commands
#    but to INFO and SLAVEOF.
#
slave-serve-stale-data yes
/*你可以配置一个 slave 实体是否接受写入操作。
通过写入操作来存储一些短暂的数据对于一个 slave 实例来说可能是有用的,
因为相对从 master 重新同步数而言,据数据写入到 slave 会更容易被删除。
但是如果客户端因为一个错误的配置写入,也可能会导致一些问题。
*/
# You can configure a slave instance to accept writes or not. Writing against
# a slave instance may be useful to store some ephemeral data (because data
# written on a slave will be easily deleted after resync with the master) but
# may also cause problems if clients are writing to it because of a
# misconfiguration.
//从 redis 2.6 版起,默认 slaves 都是只读的。
# Since Redis 2.6 by default slaves are read-only.
#
# Note: read only slaves are not designed to be exposed to untrusted clients
# on the internet. It's just a protection layer against misuse of the instance.
# Still a read only slave exports by default all the administrative commands
# such as CONFIG, DEBUG, and so forth. To a limited extent you can improve
# security of read only slaves using 'rename-command' to shadow all the
# administrative / dangerous commands.
//作为从服务器,默认情况下是只读的(yes),可以修改成NO,用于写(不建议)。
slave-read-only yes

# Replication SYNC strategy: disk or socket.
#
# -------------------------------------------------------
# WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY
# -------------------------------------------------------
/*
是否使用socket方式复制数据。目前redis复制提供两种方式,disk和socket。如果新的slave连上来或者重连的slave无法部分同步,就会执行全量同步,master会生成rdb文件。有2种方式:disk方式是master创建一个新的进程把rdb文件保存到磁盘,再把磁盘上的rdb文件传递给slave。socket是master创建一个新的进程,直接把rdb文件以socket的方式发给slave。disk方式的时候,当一个rdb保存的过程中,多个slave都能共享这个rdb文件。socket的方式就的一个个slave顺序复制。在磁盘速度缓慢,网速快的情况下推荐用socket方式。
*/
# New slaves and reconnecting slaves that are not able to continue the replication
# process just receiving differences, need to do what is called a "full
# synchronization". An RDB file is transmitted from the master to the slaves.
# The transmission can happen in two different ways:
#
# 1) Disk-backed: The Redis master creates a new process that writes the RDB
#                 file on disk. Later the file is transferred by the parent
#                 process to the slaves incrementally.
# 2) Diskless: The Redis master creates a new process that directly writes the
#              RDB file to slave sockets, without touching the disk at all.
#
# With disk-backed replication, while the RDB file is generated, more slaves
# can be queued and served with the RDB file as soon as the current child producing
# the RDB file finishes its work. With diskless replication instead once
# the transfer starts, new slaves arriving will be queued and a new transfer
# will start when the current one terminates.
#
# When diskless replication is used, the master waits a configurable amount of
# time (in seconds) before starting the transfer in the hope that multiple slaves
# will arrive and the transfer can be parallelized.
#
# With slow disks and fast (large bandwidth) networks, diskless replication
# works better.
repl-diskless-sync no

# When diskless replication is enabled, it is possible to configure the delay
# the server waits in order to spawn the child that transfers the RDB via socket
# to the slaves.
#
# This is important since once the transfer starts, it is not possible to serve
# new slaves arriving, that will be queued for the next RDB transfer, so the server
# waits a delay in order to let more slaves arrive.
#
# The delay is specified in seconds, and by default is 5 seconds. To disable
# it entirely just set it to 0 seconds and the transfer will start ASAP.
//diskless复制的延迟时间,防止设置为0。一旦复制开始,节点不会再接收新slave的复制请求直到下一个rdb传输。所以最好等待一段时间,等更多的slave连上来。
repl-diskless-sync-delay 5

# Slaves send PINGs to server in a predefined interval. It's possible to change
# this interval with the repl_ping_slave_period option. The default value is 10
# seconds.
//slave根据指定的时间间隔向服务器发送ping请求。时间间隔可以通过 repl_ping_slave_period 来设置,默认10秒
# repl-ping-slave-period 10

# The following option sets the replication timeout for:
#
# 1) Bulk transfer I/O during SYNC, from the point of view of slave.
# 2) Master timeout from the point of view of slaves (data, pings).
# 3) Slave timeout from the point of view of masters (REPLCONF ACK pings).
#
# It is important to make sure that this value is greater than the value
# specified for repl-ping-slave-period otherwise a timeout will be detected
# every time there is low traffic between the master and the slave.
//复制连接超时时间。master和slave都有超时时间的设置。master检测到slave上次发送的时间超过repl-timeout,即认为slave离线,清除该slave信息。slave检测到上次和master交互的时间超过repl-timeout,则认为master离线。需要注意的是repl-timeout需要设置一个比repl-ping-slave-period更大的值,不然会经常检测到超时。
# repl-timeout 60

# Disable TCP_NODELAY on the slave socket after SYNC?
#
# If you select "yes" Redis will use a smaller number of TCP packets and
# less bandwidth to send data to slaves. But this can add a delay for
# the data to appear on the slave side, up to 40 milliseconds with
# Linux kernels using a default configuration.
#
# If you select "no" the delay for data to appear on the slave side will
# be reduced but more bandwidth will be used for replication.
#
# By default we optimize for low latency, but in very high traffic conditions
# or when the master and slaves are many hops away, turning this to "yes" may
# be a good idea.
//是否禁止复制tcp链接的tcp nodelay参数,可传递yes或者no。默认是no,即使用tcp nodelay。如果master设置了yes来禁止tcp nodelay设置,在把数据复制给slave的时候,会减少包的数量和更小的网络带宽。但是这也可能带来数据的延迟。默认我们推荐更小的延迟,但是在数据量传输很大的场景下,建议选择yes。
repl-disable-tcp-nodelay no

# Set the replication backlog size. The backlog is a buffer that accumulates
# slave data when slaves are disconnected for some time, so that when a slave
# wants to reconnect again, often a full resync is not needed, but a partial
# resync is enough, just passing the portion of data the slave missed while
# disconnected.
#
# The bigger the replication backlog, the longer the time the slave can be
# disconnected and later be able to perform a partial resynchronization.
#
# The backlog is only allocated once there is at least a slave connected.
//复制缓冲区大小,这是一个环形复制缓冲区,用来保存最新复制的命令。这样在slave离线的时候,不需要完全复制master的数据,如果可以执行部分同步,只需要把缓冲区的部分数据复制给slave,就能恢复正常复制状态。缓冲区的大小越大,slave离线的时间可以更长,复制缓冲区只有在有slave连接的时候才分配内存。没有slave的一段时间,内存会被释放出来,默认1m。
# repl-backlog-size 1mb

# After a master has no longer connected slaves for some time, the backlog
# will be freed. The following option configures the amount of seconds that
# need to elapse, starting from the time the last slave disconnected, for
# the backlog buffer to be freed.
#
# A value of 0 means to never release the backlog.
//master没有slave一段时间会释放复制缓冲区的内存,repl-backlog-ttl用来设置该时间长度。单位为秒。
# repl-backlog-ttl 3600

# The slave priority is an integer number published by Redis in the INFO output.
# It is used by Redis Sentinel in order to select a slave to promote into a
# master if the master is no longer working correctly.
#
# A slave with a low priority number is considered better for promotion, so
# for instance if there are three slaves with priority 10, 100, 25 Sentinel will
# pick the one with priority 10, that is the lowest.
#
# However a special priority of 0 marks the slave as not able to perform the
# role of master, so a slave with priority of 0 will never be selected by
# Redis Sentinel for promotion.
#
# By default the priority is 100.
//当master不可用,Sentinel会根据slave的优先级选举一个master。最低的优先级的slave,当选master。而配置成0,永远不会被选举。
slave-priority 100

# It is possible for a master to stop accepting writes if there are less than
# N slaves connected, having a lag less or equal than M seconds.
#
# The N slaves need to be in "online" state.
#
# The lag in seconds, that must be <= the specified value, is calculated from
# the last ping received from the slave, that is usually sent every second.
#
# This option does not GUARANTEE that N replicas will accept the write, but
# will limit the window of exposure for lost writes in case not enough slaves
# are available, to the specified number of seconds.
#
# For example to require at least 3 slaves with a lag <= 10 seconds use:
//redis提供了可以让master停止写入的方式,如果配置了min-slaves-to-write,健康的slave的个数小于N,mater就禁止写入。master最少得有多少个健康的slave存活才能执行写命令。这个配置虽然不能保证N个slave都一定能接收到master的写操作,但是能避免没有足够健康的slave的时候,master不能写入来避免数据丢失。设置为0是关闭该功能。
# min-slaves-to-write 3
//延迟小于min-slaves-max-lag秒的slave才认为是健康的slave。
# min-slaves-max-lag 10
#
# Setting one or the other to 0 disables the feature.
#
# By default min-slaves-to-write is set to 0 (feature disabled) and
//设置1或另一个设置为0禁用这个特性。
# min-slaves-max-lag is set to 10.

################################## SECURITY安全 ###################################
//requirepass配置可以让用户使用AUTH命令来认证密码,才能使用其他命令。这让redis可以使用在不受信任的网络中。为了保持向后的兼容性,可以注释该命令,因为大部分用户也不需要认证。使用requirepass的时候需要注意,因为redis太快了,每秒可以认证15w次密码,简单的密码很容易被攻破,所以最好使用一个更复杂的密码。
# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared

# Command renaming.
#
# It is possible to change the name of dangerous commands in a shared
# environment. For instance the CONFIG command may be renamed into something
# hard to guess so that it will still be available for internal-use tools
# but not available for general clients.
#
# Example:
//把危险的命令给修改成其他名称。比如CONFIG命令可以重命名为一个很难被猜到的命令,这样用户不能使用,而内部工具还能接着使用。
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
#
# It is also possible to completely kill a command by renaming it into
# an empty string:
//设置成一个空的值,可以禁止一个命令
# rename-command CONFIG ""
#
# Please note that changing the name of commands that are logged into the
# AOF file or transmitted to slaves may cause problems.

################################### LIMITS 限制####################################

# Set the max number of connected clients at the same time. By default
# this limit is set to 10000 clients, however if the Redis server is not
# able to configure the process file limit to allow for the specified limit
# the max number of allowed clients is set to the current file limit
# minus 32 (as Redis reserves a few file descriptors for internal uses).
#
# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
//设置能连上redis的最大客户端连接数量。默认是10000个客户端连接。由于redis不区分连接是客户端连接还是内部打开文件或者和slave连接等,所以maxclients最小建议设置到32。如果超过了maxclients,redis会给新的连接发送’max number of clients reached’,并关闭连接。
# maxclients 10000

# Don't use more memory than the specified amount of bytes.
# When the memory limit is reached Redis will try to remove keys
# according to the eviction policy selected (see maxmemory-policy).
#
# If Redis can't remove keys according to the policy, or if the policy is
# set to 'noeviction', Redis will start to reply with errors to commands
# that would use more memory, like SET,

以上是关于Redis系列--安装helloworld以及读懂配置文件的主要内容,如果未能解决你的问题,请参考以下文章

分布式缓存技术redis学习系列——redis简介以及linux上的安装

分布式缓存技术redis学习系列——redis简介以及linux上的安装

分布式缓存技术redis学习系列——redis简介以及linux上的安装

一文读懂Redis常见对象类型的底层数据结构

redis架构系列

Redis初探,写个HelloWorld