---
title: "redis3.0.7安装指南"
author: "stephen830"
date: "2016-04-07T09:22:04Z"
tags: []
categories: ["开源软件"]
slug: "redis3-0-7"
draft: false
lastmod: "2016-04-15T13:41:27Z"
id: 2289017
url: "https://stephen830.iteye.com/blog/2289017"
---

redis安装指南

下载最新版的redis http://redis.io/

例如:redis-3.0.7.tar.gz

1.解压并进入目录  
tar -xzvf redis-3.0.7.tar.gz  
cd redis-3.0.7

2.执行命令make  
make

3.执行命令make test(如果报错，可能是tcl未安装，请先安装tcl，执行命令  apt-get install tcl-dev)  
make test

4.执行命令make install  
make install

命令执行后redis启动命令安装在目录/usr/local/bin中

5.复制redis.conf文件到/etc目录  
cp /\*\*/redis-3.0.7/redis.conf /etc/redis.conf  
\*\*代表你的实际目录

6.运行redis  
cd /usr/local/bin  
./redis-server /etc/redis.conf &  
默认为6379端口

7.使用telnet简单测试  
telnet localhost 6379  
set key1 hello  
+OK  
get key1  
$5  
hello  
quit

8.也可以用redis-cli进行测试［redis-cli是redis的客户端］  
./redis-cli  
127.0.0.1:6379&gt; get key1  
"hello"  
127.0.0.1:6379&gt; set key2 world  
OK  
127.0.0.1:6379&gt; get key2  
"world"  
127.0.0.1:6379&gt; quit  
 

9.设置redis链接密码  
打开/etc/redis.conf文件  
找到#requirepass foobared  
去掉前面的#，把foobared修改为自己要设置的密码(比如密码设为admin)，例如  
requirepass admin

停止redis ，执行命令 ./redis-cli shutdown  (如果配置密码的话，停止redis执行命令： ./redis-cli -a admin shutdown)

./redis-server /etc/redis.conf &  
再用redis-cli连接redis，执行get命令发现报错。（这是因为设置密码了！）  
redis-cli  
127.0.0.1:6379&gt; get key1  
(error) NOAUTH Authentication required.

需要执行命令： ./redis-cli -a admin   (再次执行get命令就正常了)  
./redis-cli -a admin  
127.0.0.1:6379&gt; get key1  
"hello"  
127.0.0.1:6379&gt;

10.遇到中文存储显示  
127.0.0.1:6379&gt; get name  
"xinxin\\xe6\\x98\\x9f\\xe6\\x98\\x9f"             《－－－－显示中文的编码  
127.0.0.1:6379&gt;  
127.0.0.1:6379&gt; quit  
zhoujianqiangdeMacBook-Pro:bin zjq$ ./redis-cli -a admin --raw      //启动时候加上参数--raw  
127.0.0.1:6379&gt; get name  
xinxin星星                                   《－－－－显示中文  
127.0.0.1:6379&gt;