Redis (1) —— 安装
摘要
介绍Mac OS X安装Redis基本方法
版本
Redis版本: 2.8.24
内容
下载Redis包
地址:http://download.redis.io/releases/
找到合适的版本,这里以2.8.24为例。
wget http://download.redis.io/releases/redis-2.8.24.tar.gz
安装
⇒ tar xzvf redis-2.8.24.tar.gz
输出
...
x redis-2.8.24/utils/mkrelease.sh
x redis-2.8.24/utils/redis-copy.rb
x redis-2.8.24/utils/redis-sha1.rb
x redis-2.8.24/utils/redis_init_script
x redis-2.8.24/utils/redis_init_script.tpl
x redis-2.8.24/utils/speed-regression.tcl
x redis-2.8.24/utils/whatisdoing.sh
make && install
⇒ sudo make && make install
输出中可能包含一下warning信息,可以忽略
最后会提示建议make test
使用配置工具util
在"redis-2.8.24/util"下
⇒ cd utils
⇒ sudo ./install_server.sh
输出
Password:
readlink: illegal option -- f
usage: readlink [-n] [file ...]
usage: dirname path
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Mmmmm... the default config is missing. Did you switch to the utils directory?
配置文件redis.conf
redis解压目录里有一个配置文件redis.conf ,编辑此配置文件,找到 dir ./ 这一行。redis会将内存中的数据写入文件中,而此配置就是指定数据文件保存的路径。我本机指定的目录为:
/Users/Richard/Documents/Dev/servers/redis/redis_data
编辑过后,将配置文件移动到 /usr/local/etc 目录下
sudo mv redis.conf /usr/local/etc
启动
⇒ /usr/local/bin/redis-server /usr/local/etc/redis.conf
测试连通性
设置开机自动启动redis server
新建plist文件
sudo vi /Library/LaunchDaemons/io.redis.redis-server.plist
文件内容如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>io.redis.redis-server</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/redis-server</string>
<string>/usr/local/etc/redis.conf</string>
</array>
<key>RunAtLoad</key><true/><span style="font-size:14px;"></span> </dict>
</plist>
使用launchctl设置开机自动启动
sudo launchctl load /Library/LaunchDaemons/io.redis.redis-server.plist
使用launchctl启动redis server
sudo launchctl start io.redis.redis-server
使用launchctl停止redis server
sudo launchctl stop io.redis.redis-server
扩展
在Mac下也可以使用homebrew来安装redis