小明的个人博客
一: 安装redis
最简单的方式是使用brew安装redis,如果没有安装brew,请自行安装
chen$ brew install redis
==> Caveats
To have launchd start redis now and restart at login:
brew services start redis
Or, if you don't want/need a background service you can just run:
redis-server /usr/local/etc/redis.conf
==> Summary
/usr/local/Cellar/redis/5.0.3: 13 files, 3.1MB
==> `brew cleanup` has not been run in 30 days, running now...
等待安装完毕即可。注意安完毕后,日志里会打印redis的安装目录,我的安装目录在 /usr/local/Cellar/redis/5.0.3
二:启动redis
- 方式一 进入redis安装目录,直接执行redis-srver
chenxiangmingdeMacBook-Air:~ chen$ cd /usr/local/Cellar/redis/5.0.3/
chenxiangmingdeMacBook-Air:5.0.3 chen$ redis-server
54166:C 04 Mar 2019 19:41:18.961 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
54166:C 04 Mar 2019 19:41:18.961 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=54166, just started
54166:C 04 Mar 2019 19:41:18.961 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
54166:M 04 Mar 2019 19:41:18.963 * Increased maximum number of open files to 10032 (it was originally set to 2560).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.3 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 54166
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
54166:M 04 Mar 2019 19:41:18.968 # Server initialized
54166:M 04 Mar 2019 19:41:18.969 * Ready to accept connections
- 方式二 使用brew启动
chenxiangmingdeMacBook-Air:LaunchDaemons chen$ brew services start redis
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 17, done.
remote: Counting objects: 100% (17/17), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 17 (delta 0), reused 13 (delta 0), pack-reused 0
Unpacking objects: 100% (17/17), done.
Tapped 1 command (50 files, 62.4KB).
==> Successfully started `redis` (label: homebrew.mxcl.redis)
启动成功
chenxiangmingdeMacBook-Air:LaunchDaemons chen$ redis-cli
127.0.0.1:6379> 连接成功
三:安装rdm可视化工具
mac上很多可视化连接工具都是收费的,这里推荐一款免费的,效果很不错
下载dmp文件, 点我下载,然后安装在mac上即可使用
四:设置开机自启
设置redis开机启动,使用的是Mac的launchd(launchd由操作系统内核启动,用户没有权限去进行手动启动,但可以使用launchctl命令来和launchd进行交互,借此可以控制后台守护程序的启动或终止),将redis作为用户守护(User Daemon)进程运行在后台,用户守护进程是作为系统的一部分运行在后台的非图形化程序。用户守护进程是不和用户账户关联的。
- 第一步 进入redis安装目录,将 .plist文件拷贝到 /Library/LaunchDaemons/目录下
chenxiangmingdeMacBook-Air:~ chen$ cd /usr/local/Cellar/redis/5.0.3/bin/
chenxiangmingdeMacBook-Air:5.0.3 chen$ sudo cp homebrew.mxcl.redis.plist /Library/LaunchDaemons/
Password:
- 第二步 将该文件载入到launchd里,使用launchctl命令,具体命令如下
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.redis.plist
- 第三步 现在已经成功将redis服务加入到系统启动项了,输入以下命令可以启动redis
sudo launchctl start homebrew.mxcl.redis
- 关闭redis命令如下
sudo launchctl stop homebrew.mxcl.redis
- 是不是发现名字太长了,不方便输入和记忆,那么我们可以设置它的别名
- 编辑.bash_profile,此文件在自己的用户根目录下 比如我的就在/chen/目录下
alias redis-start='sudo launchctl start homebrew.mxcl.redis'
alias redis-stop='sudo launchctl stop homebrew.mxcl.redis'
在配置文件中加入这2句代码,然后输入以下命令刷新资源
source ~/.bash_profile
直接使用别名即可启动对应的服务
redis-start 即可直接启动redis服务
小明的个人博客