brew安装redis
安装之前 brew search redis
安装
1.安装redis数据库
#brew install redis@4.0
brew install redis
# 升级redis
brew upgrade redis
启动
2.设置启动
方式1: brew services start redis
方式2: /usr/local/bin/redis-server /usr/local/etc/redis.conf &
#3.开机启动
步骤一: 创建launchd启动文件
sudo vim /Library/LaunchDaemons/redis-server.plist
#which redis 查看redis的安装位置
#find / -name redis.conf 查看reids.conf的位置
#使用redis-cli连接后,输入 info server可以获取 redis的安装位置和配置文件
------------------------------------------------------------------------------------------------------------
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>redis-server</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/redis/bin/redis-server</string>
<string>/usr/local/etc/redis.conf</string>
</array>
<key>RunAtLoad</key>
<true />
</dict>
</plist>
------------------------------------------------------------------------------------------------------------
步骤二: 加载launchd启动文件
sudo launchctl load /Library/LaunchDaemons/redis-server.plist
sudo launchctl start redis-server
修改redic.conf配置文件
sudo vim /usr/local/etc/redis.conf , 之后 参考
查看
查看redis文件所在地
whereis redis && which redis && find / -name redis
查看redis进程
ps -ef |grep redis 或 ps aux | grep redis
查看brew正在运行的服务
brew services list
查看端口
netstat -lnp|grep 6379
关闭与卸载
第一步:查看reids 是否在运行,如果在运行则先关闭
方式1: kill -9 <pid进程>
方式2: sudo pkill redis-server
方式3: redis-cli shutdown
方式1: brew services stop redis
第二步:移除redis
brew uninstall redis
安装包模式
下载解压编译安装
1.下载redis安装包
wget http://download.redis.io/releases/redis-5.0.4.tar.gz
2.解压redis安装包并且进入redis目录
tar -zxvf redis-5.0.4.tar.gz && cd redis-5.0.4
3.编码安装
#make
make PREFIX=/usr/local/redis install
#拷贝redis.conf到安装目录
#cp redis.conf /usr/local/redis
下载Redis时,如果出现报如下错误:wget: unable to resolve host address “download.redis.io”
vim /etc/resolv.conf nameserver 8.8.8.8 #google域名服务器 nameserver 8.8.4.4 #google域名服务器
修改redis的配置 redis.conf
4.修改redis.conf配置文件ggdG 全删ggyG 全部复制ggvG ggVG 高亮显示 sudo vim/usr/local/redis/redis.conf
#绑定IP
bind 0.0.0.0
#绑定端口, 默认是6379, 需要「安全组配置」开放端口
port 6379
#后台启动
daemonize yes
#保护模式
protected-mode no
#指定持久化方式
appendonly yes
#设置密码
requirepass 123456
#指定数据存放路径rdb存放的路径
dir /usr/local/redis
# ./redis-server /path/to/redis.conf
################################## INCLUDES ###################################
# include /path/to/local.conf
# include /path/to/other.conf
################################## MODULES #####################################
# loadmodule /path/to/my_module.so
# loadmodule /path/to/other_module.so
################################## NETWORK #####################################
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
tcp-backlog 511
# unixsocket /tmp/redis.sock
# unixsocketperm 700
timeout 0
tcp-keepalive 300
################################# GENERAL #####################################
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile /usr/local/redis/redis.log
databases 16
always-show-logo yes
################################ SNAPSHOTTING ################################
# save <seconds> <changes>
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
################################# REPLICATION #################################
# replicaof <masterip> <masterport>
# masterauth <master-password>
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
# repl-ping-replica-period 10
# repl-timeout 60
repl-disable-tcp-nodelay no
# repl-backlog-size 1mb
# repl-backlog-ttl 3600
replica-priority 100
# min-replicas-to-write 3
# min-replicas-max-lag 10
# replica-announce-ip 5.5.5.5
# replica-announce-port 1234
################################## SECURITY ###################################
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
################################### CLIENTS ####################################
# maxclients 10000
############################## MEMORY MANAGEMENT ################################
# maxmemory <bytes>
# maxmemory-policy noeviction
# maxmemory-samples 5
# replica-ignore-maxmemory yes
############################# LAZY FREEING ####################################
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
############################## APPEND ONLY MODE ###############################
appendfilename "appendonly.aof"
appendfsync everysec
# appendfsync 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 yes
################################ LUA SCRIPTING ###############################
lua-time-limit 5000
################################ REDIS CLUSTER ###############################
# cluster-enabled yes
# cluster-config-file nodes-6379.conf
# cluster-node-timeout 15000
# cluster-replica-validity-factor 10
# cluster-migration-barrier 1
# cluster-require-full-coverage yes
# cluster-replica-no-failover no
########################## CLUSTER DOCKER/NAT support ########################
# cluster-announce-ip 10.1.1.5
# cluster-announce-port 6379
# cluster-announce-bus-port 6380
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
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
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
# client-query-buffer-limit 1gb
# proto-max-bulk-len 512mb
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
# lfu-log-factor 10
# lfu-decay-time 1
########################### ACTIVE DEFRAGMENTATION #######################
# activedefrag yes
# active-defrag-ignore-bytes 100mb
# active-defrag-threshold-lower 10
# active-defrag-threshold-upper 100
# active-defrag-cycle-min 5
# active-defrag-cycle-max 75
# active-defrag-max-scan-fields 1000
配置文件redis.conf 参数改动点
方法一 编辑 vim /usr/local/redis/redis.conf
- bind 0.0.0.0 绑定IP
- port 6379 绑定端口, 默认是6379, 需要「安全组配置」开放端口
- daemonize yes 后台启动
- appendonly yes 指定持久化方式
- protected-mode no 关闭保护模式
- requirepass 123456 设置密码
- dir /usr/local/redis/log 指定数据存放路径rdb存放的路径
方法二 修改redis服务器的参数配置
- 127.0.0.1:6379 > config set daemonize “no”
- 127.0.0.1:6379 > config set protected-mode “no”
- 127.0.0.1:6379 > config set requirepass 123456
设置全局变量
- 为redis设置全局变量vim ~/.bash_profile或 vim /etc/profile
#设置暂时性全局变量
export PATH=$PATH:/usr/local/redis/bin
#设置永久性全局变量 vim ~/.bash_profile 或者 vim /etc/profile
PATH=$PATH:/usr/local/redis/bin
使用永久性全局变量别忘了使文件生效 source ~/.bash_profile 或 source /etc/profile
启动
6.启动redis服务
/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf &
登录
redis-cli -h 119.23.72.172 [ -p 6379] [-a 密码]
redis-cli -h 119.23.72.172 -p 6379 -a 123456
- -h ip地址
- -p 端口
- -a 连接redis的密码
- 选择这种登录会出现:warning: Using a password with ‘-a’ or ‘-u’ option on the command line interface may not be safe.
- 如果使用了会提示,也可以使用命令 auth <密码>来进行验证