Mac下配置Redis服务器(自启动、后台运行)

来源:互联网 发布:ubuntu 电源设置打不开 编辑:程序博客网 时间:2024/06/05 20:18

Redis服务器在从诸多文章上看来,是个极为优秀的Key-value数据库软件。其NB之处可以从这篇文章中略知一二。

PHP下使用redius可以参考这个教材:phpredis中文手册——《redis中文手册》 php版



主要参考

Installing Redis 2.6.x on Ubuntu 12.04 and running with an ‘init’ script.

mac os 下设置开机自启动服务


首先是安装,它会默认安装到/usr/local/bin下

cd /tmpwget http://redis.googlecode.com/files/redis-2.6.9.tar.gztar -zxf redis-2.6.9.tar.gzcd redis-2.6.9makesudo make install

然后下载一些配置文件(主要就是把deamon打开之类的,没对比与默认配置的区别)

wget https://github.com/ijonas/dotfiles/raw/master/etc/redis.confsudo mv redis.conf /etc/redis.conf

然后以root身份做以下事情:

在/Library/LaunchDaemons下新建com.redis.plist,内容如下:

<?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>

之后运行

sudo launchctl load /Library/LaunchDaemons/com.redis.plist

sudo launchctl start com.redis

检查一下情况:

$ cat /var/run/redis.pid 

如果出来pid的数字,说明就运行了~



安装php-redis扩展,参考于在Mac系统上安装redis服务

curl -O https://nodeload.github.com/nicolasff/phpredis/zip/mastertar -zxf mastercd phpredis-master/phpize./configuremakesudo make install# 这时候会提示一个路径# /usr/lib/php/extensions/no-debug-non-zts-20090626/# 表示已经将扩展放置在该位置vim /etc/php.ini#增加如下内容extension=redis.so#重启apachesudo httpd -k restart#查看扩展安装情况php -m |grep redis#出现 redis 表示安装成功。



对于php可以安装phpRedisAdmin,从名字上看就知道和phpMyAdmin定位差不多,不过界面确实不是一个时代的。。。

git clone https://github.com/ErikDubbelboer/phpRedisAdmin.gitcd phpRedisAdmin/git clone https://github.com/nrk/predis.git




===============================================================================

题外话,那么!如果在ubuntu上安装redis呢?

ubuntu下安装php redis


sudo apt-get install redis-server


测试redis是否安装成功:
注意:要开启redis
redis-cli
set test hello
OK
get test
"bar"


下载phpredis
sudo wget http://open.imop.us/pr.tar.gz


tar zxvf pr.tar.gz


cd phpredis


phpize //这个phpize是安装php模块的


如果没有phpize,则需要先安装php5-dev


./configure


make


make install


修改php.ini文件
extension=redis.so


重启apache



原创粉丝点击