Mac Install Redis

目标

1、安装并启动Redis
2、熟悉配置文件
3、关闭Redis

环境( sw_vers命令)

ProductName: Mac OS X
ProductVersion: 10.13.6
BuildVersion: 17G65
RedisVersion: 4.0.9

安装

方式一:官网下载并本地编译,移步https://blog.csdn.net/jason_m_ho/article/details/80007330
方式二:使用brew安装(这里使用此种方式)

1、执行安装命令

brew install -v redis
安装成功

2、查看配置文件
默认配置文件:
/usr/local/etc/redis.conf
/usr/local/etc/redis-sentinel.conf
BD目录:
/usr/local/var/db/redis/dump.rdb

官网上对于如何配置redis的描述:
Redis is able to start without a configuration file using a built-in default configuration, however this setup is only recommended for testing and development purposes.
The proper way to configure Redis is by providing a Redis configuration file, usually called redis.conf.

意思是:
如果启动时不指定配置文件,redis会使用程序中内置的默认配置.但是只有在开发和测试阶段才考虑使用内置的默认配置,正式环境最好还是提供配置文件,并且一般命名为redis.conf

启动redis

1、修改默认配置文件:/usr/local/etc/redis.conf

bind 127.0.0.1 ::1
bind 127.0.0.1
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300

################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /usr/local/var/run/redis.pid when daemonized.
daemonize no


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


# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT  where
# dbid is a number between 0 and 'databases'-1
databases 16

################################ SNAPSHOTTING  ################################

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

# The working directory.
dir /usr/local/var/db/redis/

################################# REPLICATION #################################
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

################################## SECURITY ###################################

################################### LIMITS ####################################

############################## APPEND ONLY MODE ###############################
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

################################ LUA SCRIPTING  ###############################
lua-time-limit 5000

################################ REDIS CLUSTER  ###############################


################################## SLOW LOG ##################################

slowlog-max-len 128

################################ LATENCY MONITOR ##############################

latency-monitor-threshold 0

############################# EVENT NOTIFICATION ##############################

notify-keyspace-events ""

############################### ADVANCED CONFIG ###############################
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

2、执行启动命令:

$ redis-server /usr/local/etc/redis.conf

3、启动成功

➜  ~ redis-server /usr/local/etc/redis.conf
5079:C 01 Sep 22:27:31.816 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
5079:C 01 Sep 22:27:31.817 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=5079, just started
5079:C 01 Sep 22:27:31.817 # Configuration loaded
5079:M 01 Sep 22:27:31.818 * Increased maximum number of open files to 10032 (it was originally set to 4864).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 4.0.9 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 5079
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

5079:M 01 Sep 22:27:31.819 # Server initialized
5079:M 01 Sep 22:27:31.819 * DB loaded from disk: 0.000 seconds
5079:M 01 Sep 22:27:31.819 * Ready to accept connections

4、检测redis服务器是否启动

重新打开一个终端窗口,输入命令
$ redis-cli ping
该终端输出 pong
说明服务器运作正常。

关闭Redis

方式一:
在执行启动命令的终端窗口使用ctrl+c,此时第一个窗口输出
然后在另外一个终端窗口执行
$ redis-cli ping
输出
Could not connect to Redis at 127.0.0.1:6379: Connection refused
说明确实已关闭

方式二:
在另外一个终端窗口执行$ redis-cli shutdown,此时第一个窗口输出

5079:M 01 Sep 22:33:45.757 # User requested shutdown...
5079:M 01 Sep 22:33:45.757 * Saving the final RDB snapshot before exiting.
5079:M 01 Sep 22:33:45.757 * DB saved on disk
5079:M 01 Sep 22:33:45.757 * Removing the pid file.
5079:M 01 Sep 22:33:45.757 # Redis is now ready to exit, bye bye...

你可能感兴趣的:(Mac Install Redis)