Mac下配置Redis服务器(自启动、后台运行)
Mac下配置Redis服务器(自启动、后台运行)123 brew installredisln-f /usr/local/Cellar/redis/2.8.13/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/launchctl load ~/Library/LaunchAgents/h
Mac下配置Redis服务器(自启动、后台运行)
brew install redis
ln -f /usr/local/Cellar/redis/2 .8.13 /homebrew .mxcl.redis.plist ~ /Library/LaunchAgents/
launchctl load ~ /Library/LaunchAgents/homebrew .mxcl.redis.plist
|
注:上面启动文件所在的路径根据安装的版本来决定哦,比如我当前安装的版本是2.8.13
如果不了解homebrew的,可以查看下面这篇文章:
Mac开发者利器-Homebrew介绍及安装
http://levi.yii.so/archives/1742
最后,再次谢谢 @唐余猛 童鞋
—— levi,2014-09-01注
Redis服务器在从诸多文章上看来,是个极为优秀的Key-value数据库软件。其NB之处可以从这篇文章中略知一二。
PHP下使用redius可以参考这个教材:phpredis中文手册——《redis中文手册》 php版
在Mac OS上安装redis
首先是安装,它会默认安装到/usr/local/bin下
1
2
3
4
5
6
|
cd /tmp
wget http: //redis .googlecode.com /files/redis-2 .6.9. tar .gz
tar -zxf redis-2.6.9. tar .gz
cd redis-2.6.9
make
sudo make install
|
然后下载一些配置文件(主要就是把deamon打开之类的,没对比与默认配置的区别)
1
2
3
|
wget https: //github .com /ijonas/dotfiles/raw/master/etc/redis .conf
sudo mv redis.conf /etc/redis .conf
sudo /usr/local/bin/redis-server redis.conf
|
说到这里备注下,如果没有目录权限,是无法建立
- /var/log/redis/redis.log
- /var/lib/redis/
导致redis启动失败
ok,现在已经大功告成,你的redis已经成功运行起来了。
试试看吧!
1
2
3
4
5
|
/opt/redis/redis-cli
#会看到提示 redis 127.0.0.1:6379>说明已经连接服务。
set anythink helloworld
get anythink
exit
|
good 看到了helloworld,说明一切正常。
如果我需要停止redis或者需要重新启动呢?
1
2
3
4
|
cat /opt/redis/redis .pid
#cat后会得到一个pid,我的是44277
sudo kill 44277
# 启动方法和之前一样。
|
设置开机自启动、后台运行
然后以root身份做以下事情:
在/Library/LaunchDaemons下新建com.redis.plist,内容如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<? xml version = "1.0" encoding = "UTF-8" ?>
<! 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 >com.redis</ string >
< key >RunAtLoad</ key >
< true />
< key >ProgramArguments</ key >
< array >
< string >/usr/local/bin/redis-server</ string >
< string >/etc/redis.conf</ string >
</ array >
</ dict >
</ plist >
|
之后运行
1
2
|
sudo launchctl load /Library/LaunchDaemons/com .redis.plist
sudo launchctl start com.redis
|
感谢 @唐余猛 指正,已修正拼错的命令名称
检查一下情况:
1
|
$ cat /var/run/redis .pid
|
如果出来pid的数字,说明就运行了~
安装php-redis扩展
如果你需要在PHP中使用redis,那么请继续往下看
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
curl -O https: //nodeload .github.com /nicolasff/phpredis/zip/master
tar -zxf master
cd phpredis-master/
phpize
. /configure
make
sudo make install
# 这时候会提示一个路径
# /usr/lib/php/extensions/no-debug-non-zts-20090626/
# 表示已经将扩展放置在该位置
vim /etc/php .ini
#增加如下内容
extension=redis.so
#重启apache
sudo httpd -k restart
#查看扩展安装情况
php -m | grep redis
#出现 redis 表示安装成功。
|
如果执行phpize提示如下错误
Cannot find autoconf. Please check your autoconf installation
and the $PHP_AUTOCONF environment variable.
Then, rerun this script.
请分别下载M4,autoconf编译安装
1
2
|
curl -O http: //ftp .gnu.org /gnu/m4/m4-1 .4.9. tar .gz
curl -O http: //ftp .gnu.org /gnu/autoconf/autoconf-2 .62. tar .gz
|
注意,以上使用的apache、php均为MacOS自带的,如果是自己安装的phpize请指定绝对路径。
图形管理工具
另:redis还有一个基于WEB的图形界面管理工具,叫phpRedisAdmin,如果刚开启服务会出现一些Undefined index,过一会就好了。如果想试试可以使用如下命令安装(git推荐使用SourceTree安装)该管理工具支持String、Hash、List、Set、Zset
1
2
3
|
git clone https: //github .com /ErikDubbelboer/phpRedisAdmin .git
cd phpRedisAdmin/
git clone https: //github .com /nrk/predis .git
|
最后,有什么问题,大家可以给我留言哦,别忘了关注我的博客哦:
http://list.qq.com/cgi-bin/qf_invite?id=b6eb34388fd016582957d6e50d005146e24fe6b166ee66c0
更多推荐
所有评论(0)