当redis6.2.1
安装完成后会在/usr/local/bin
目录下生成redis的相关文件;
第一步
切换到redis的安装目录/softWare/redis6/redis-6.2.1
找到redis.conf
文件并且将文件复制到/etc
目录下,(也可以不复制)
第二步
切换到/etc
目录下,找到redis.conf
文件,将文件中daemonize no改成yes
支持后台启动
第三步
切换到/usr/local/bin
目录启动redis并指定配置文件
第四步
通过redis的客户端连接redis进行操作
redis的配置文件 redis-conf
第一部分:
# 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 => 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.
配置大小单位开头部分定义了一些基本的度量单位,只支持bytes,不支持bit,大小写不敏感
第二部分:
################################## 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
# to customize a few per-server settings. Include files can include
# other files, so use this wisely.
#
# Note that option "include" won't be rewritten by command "CONFIG REWRITE"
# from admin or Redis Sentinel. Since Redis always uses the last processed
# 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.
#
# 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
include 一个文件内容可以包含另个文件的内容
第三部分:
################################## NETWORK #####################################
bind 127.0.0.1 -::1
上面配置指只支持本地进行访问,想要远程需要注释掉
################################## NETWORK #####################################
protected-mode yes
开启保护模式yes那么只能进行本机访问,no是支持远程访问
################################## NETWORK #####################################
port 6379
端口号默认6379
################################## NETWORK #####################################
tcp-backlog 511
设置tcp连接的数量,backlog其实是一个连接队列,在java中一次完整得连接是由三次握手和四次挥手组成的,那么在redis的backlog的队列总数=未完成三次握手队列+已完成三次握手的队列,在高并发下你需要适当提高backlog的数量,来解决客户端连接慢的问题
################################## NETWORK #####################################
timeout 0
redis连接的超时时间 0 为永不超时单位秒
################################## NETWORK #####################################
tcp-keepalive 300
心跳检测时间300秒检测一次
################################# GENERAL #####################################
daemonize no
daemonize no改成yes`支持后台启动
################################# GENERAL #####################################
pidfile /var/run/redis_6379.pid
将redis的进程号保存在redis_6379.pid文件中
################################# GENERAL #####################################
# Specify the server verbosity level.
# This can be one of:
# 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
redis的日志级别
debug开发环境非常详细的日志
verbose 类似于java的info
notice 生成上的日志级别
warning 只显示一些非常重要的日志或异常日志
################################# GENERAL #####################################
logfile ""
日志路径默认为空
################################# GENERAL #####################################
databases 16
redis数据库的数量默认0号库
################################# REPLICATION #################################
# requirepass foobared
redis设置密码的地方,默认注释掉没有密码