Redis安装步骤

来源:互联网 发布:淘宝网伴娘礼服 编辑:程序博客网 时间:2024/05/01 15:27

本文详细介绍Redis的安装步骤。

安装环境

操作系统: Centos 6.4 ( cat /etc/redhat-release)
Redis: 3.0.7

下载编译

从Redis官网下载:

wget http://download.redis.io/releases/redis-3.0.7.tar.gz

解压:

tar -zxvf redis-3.0.7.tar.gzcd redis-3.0.7

编译:

make

如果出现找不到gcc编译器错误

yum install -y gcc

编译过程出错,找到redis README中的说明:

Allocator
Selecting a non-default memory allocator when building Redis is done by setting the MALLOC environment variable. Redis is compiled and linked against libc malloc by default, with the exception of jemalloc being the default on Linux systems. This default was picked because jemalloc has proven to have fewer
fragmentation problems than libc malloc

To force compiling against libc malloc, use:
% make MALLOC=libc
To compile against jemalloc on Mac OS X systems, use:
% make MALLOC=jemalloc

因此,由于找不到jemalloc导致出错,make的时候指定MALLOC为libc

make  MALLOC=libc

做个链接:

ln -s redis-3.0.7/src/ bin

启动使用

启动redis

nohup bin/redis-server  > log.out &

这里写图片描述

启动交互客户端:

bin/redis-cli

info命令查看redis的一些基本信息:

这里写图片描述

试用命令:
set命令设置值,get获取值:

这里写图片描述

详细命令参考:http://redis.io/commands

Redis配置

从redis发行包目录下拷贝一份默认的redis配置到/etc目录下:

cp redis-3.0.7/redis.conf /etc/redis/

启动的时候指定配置文件:

redis-server /etc/redis/redis.conf

设置密码:

requirepass youpassword

配置数据保存路径:

dir /opt/data/redis/

停止redis:
在客户端命令行:

shutdown

使用自定义配置重启:

nohup bin/redis-server /etc/redis/redis.conf >>  log/redis.out &cat log/redis.out

此时使用redis-cli登录客户端之后,需要首先授权:

127.0.0.1:6279> auth youpassword

在客户端调用save命令后,数据将被保存在/opt/data/redis/dump.rdb

127.0.0.1:6279> save
0 0
原创粉丝点击