brew安装redis
安装之前 brew search redis
安装
1.安装redis数据库#brew install redis@4.0brew install redis# 升级redisbrew upgrade redis
启动
2.设置启动方式1: brew services start redis方式2: /usr/local/bin/redis-server /usr/local/etc/redis.conf .开机启动步骤一: 创建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.plistsudo 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第二步:移除redisbrew uninstall redis
安装包模式
下载解压编译安装
1.下载redis安装包wget http://download.redis.io/releases/redis-5.0.4.tar.gz2.解压redis安装包并且进入redis目录tar -zxvf redis-5.0.4.tar.gz && cd redis-5.0.43.编码安装#makemake 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
#绑定IPbind 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 ::1tcp-backlog 511# unixsocket /tmp/redis.sock# unixsocketperm 700timeout 0tcp-keepalive 300################################# GENERAL #####################################supervised nopidfile /var/run/redis_6379.pidloglevel noticelogfile /usr/local/redis/redis.logdatabases 16always-show-logo yes################################ SNAPSHOTTING ################################# save <seconds> <changes>save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdb################################# REPLICATION ################################## replicaof <masterip> <masterport># masterauth <master-password>replica-serve-stale-data yesreplica-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5# repl-ping-replica-period 10# repl-timeout 60repl-disable-tcp-nodelay no# repl-backlog-size 1mb# repl-backlog-ttl 3600replica-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 nolazyfree-lazy-expire nolazyfree-lazy-server-del noreplica-lazy-flush no############################## APPEND ONLY MODE ###############################appendfilename "appendonly.aof"appendfsync everysec# appendfsync nono-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yesaof-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 10000slowlog-max-len 128################################ LATENCY MONITOR ##############################latency-monitor-threshold 0############################# EVENT NOTIFICATION ##############################notify-keyspace-events ""############################### ADVANCED CONFIG ###############################hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000stream-node-max-bytes 4096stream-node-max-entries 100activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit replica 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60# client-query-buffer-limit 1gb# proto-max-bulk-len 512mbhz 10dynamic-hz yesaof-rewrite-incremental-fsync yesrdb-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/profilePATH=$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 <密码>来进行验证
