---
title: "MAC redis 安装"
author: "sys53"
date: "2014-05-04T14:05:20Z"
tags: []
categories: ["开源软件"]
slug: "mac-redis"
draft: false
lastmod: "2014-05-04T14:05:20Z"
id: 2059636
url: "https://sys53.iteye.com/blog/2059636"
---

1，下载redis源代码包

```
cd /opt
curl https://redis.googlecode.com/files/redis-2.6.14.tar.gz
tar -zxvf redis-2.6.14.tar.gz 
```

2,编译打包

 

 

```
cd redis-2.6.14 
sudo make 
```

   
此处可能会有报错：如：'stdlib.h' file not found  
主要是xcode的command line tools安装问题，因为4.4没有直接安装的地方，所以要在命命令执行如下:

```
xcode-select —install
```

   
安装完成后，再执行编译：

```
sudo make
```

   
此处可能还错误，如：  
clang: error: no such file or directory: '../deps/hiredis/libhiredis.a’  
clang: error: no such file or directory: '../deps/lua/src/liblua.a’  
此时解决方法是：

```
cd deps/
sudo make lua hiredis line noise 
```

```
cd ..
sudo make 
sudo make test
```

 (如果make test 失败，请再执行一次)

```
sudo make install
cd src
./redis_server  
```

   
到这里，基本安装成功，redis服务正常启动。

3,相关配置

```
daemonize yes  
pidfile /opt/redis/redis.pid    
port 6379  
timeout 300  
loglevel debug  
logfile /opt/redis/log-redis.log  
databases 8  
save 900 1  
save 300 10  
save 60 10000  
rdbcompression yes  
dbfilename dump.rdb  
dir /opt/redis/  
appendonly no  
appendfsync everysec  
```

   
 将上面的文件保存成redis.conf 放到redis-2.6.14目录下，然后执行命令。

```
sudo mv /opt/redis-2.6.14/src/redis-server /opt/redis/redis-server  
sudo mv /opt/redis-2.6.14/src/redis-cli /opt/redis/redis-cli  
sudo /opt/redis/redis-server redis.conf  
```

 ok，现在已经大功告成，你的redis已经成功运行起来了。  
试试看吧!

```
/opt/redis/redis-cli  
#会看到提示 redis 127.0.0.1:6379>说明已经连接服务。  
set anythink helloworld  
get anythink  
exit  
```

   
 good 看到了helloworld，说明一切正常。  
如果我需要停止redis或者需要重新启动呢？

```
cat /opt/redis/redis.pid  
#cat后会得到一个pid,我的是44277  
sudo kill 44277  
```