一、安装

目前,官方最新稳定版本为3.0.7

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

# cd /usr/local/

# tar xvf /root/redis-3.0.7.tar.gz

# cd redis-3.0.7/

# make

二、启动

安装完成后,在src目录下会生成启动执行程序,包括redis-server,redis-sentinel, redis-benchmark,redis-cli等

# src/redis-server

该启动方式是前台启动,如果关闭当前终端,则redis会自动关闭

正如登录信息开头Warning所显示的,这种方式启动没有使用配置文件,所以并不推荐。默认监听6379端口

:C  Feb ::30.242 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
:M Feb ::30.243 * Increased maximum number of open files to (it was originally set to ).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0. (/) bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port:
| `-._ `._ / _.-' | PID: 24649
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-' :M Feb ::30.246 # WARNING: The TCP backlog setting of cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of .
:M Feb ::30.246 # Server started, Redis version 3.0.
:M Feb ::30.246 # WARNING overcommit_memory is set to ! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
:M Feb ::30.246 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
:M Feb ::30.247 * The server is now ready to accept connections on port

关于redis-server的更多用法,可通过redis-server -h查看

# src/redis-server -h

Usage: ./redis-server [/path/to/redis.conf] [options]
./redis-server - (read config from stdin)
./redis-server -v or --version
./redis-server -h or --help
./redis-server --test-memory <megabytes> Examples:
./redis-server (run the server with default conf)
./redis-server /etc/redis/.conf
./redis-server --port
./redis-server --port --slaveof 127.0.0.1
./redis-server /etc/myredis.conf --loglevel verbose Sentinel mode:
./redis-server /etc/sentinel.conf --sentinel

配置文件中常用参数如下:

daemonize:是否以后台daemon方式运行,默认是前台方式运行,即默认值为no

pidfile:pid文件位置,默认为:/run/redis.pid

port:监听的端口号,默认为6379

bind 127.0.0.1 配置监听网卡的ip,针对有多个网卡的场景

logfile:log文件位置,默认值为stdout,使用“标准输出”,默认后台模式会输出到/dev/null

loglevel notice ,指定日志记录级别,Redis总共支持四个级别:debug,verbose,notice,warning,默认为notice

Debug:记录很多信息,用于开发和测试

Verbose:很多精简的有用信息,不像debug会记录那么多

Notice:普通的verbose,常用于生产环境

Warning:只有非常重要或者严重的信息会记录到日志

三、设置开机自启动

将启动脚本复制到/etc/init.d目录下

# cp /usr/local/redis-3.0.7/utils/redis_init_script /etc/init.d/redisd

编辑启动脚本

# vim /etc/init.d/redisd

#!/bin/sh
# chkconfig:
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem. REDISPORT=
EXEC=/usr/local/redis-3.0./src/redis-server
#EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/redis-3.0./src/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

主要做了两项修改,

一、添加了# chkconfig:2345 90 10

二、指定了redis-server和redis-cli的位置

EXEC=/usr/local/redis-3.0.7/src/redis-server

CLIEXEC=/usr/local/redis-3.0.7/src/redis-cli

注意:

PIDFILE=/var/run/redis_${REDISPORT}.pid指定了pid文件的位置

CONF="/etc/redis/${REDISPORT}.conf"指定了配置文件的位置

创建配置文件

# cd /etc/

# mkdir redis

# cp /usr/local/redis-3.0.7/redis.conf redis/6379.conf

修改配置文件

主要是设置redis以后台进程运行和pid文件的位置

daemonize yes
pidfile /var/run/redis_6379.pid

以服务方式启动redis

# /etc/init.d/redisd start

Starting Redis server...

# ps -ef |grep redis

root               : ?        :: /usr/local/redis-3.0./src/redis-server *:
root : pts/ :: grep --color=auto redis

客户端连接测试

# cd /usr/local/redis-3.0.7/src/

# ./redis-cli

127.0.0.1:> set  hello
OK
127.0.0.1:> get
"hello"

默认连接到localhost 6379,查看服务器信息,可通过info命令。

Redis入门的更多相关文章

  1. 安装redis入门

    redis官网:redis.io redis版本用的是redis-3.2.2 $ wget http://download.redis.io/releases/redis-3.2.2.tar.gz $ ...

  2. redis入门笔记(2)

    redis入门笔记(2) 上篇文章介绍了redis的基本情况和支持的数据类型,本篇文章将介绍redis持久化.主从复制.简单的事务支持及发布订阅功能. 持久化 •redis是一个支持持久化的内存数据库 ...

  3. redis入门笔记(1)

    redis入门笔记(1) 1. Redis 简介 •Redis是一款开源的.高性能的键-值存储(key-value store).它常被称作是一款数据结构服务器(data structure serv ...

  4. Redis入门指南

    随着互联网业务对性能需求日益强烈,作为Key/Value存储的Redis具有数据类型丰富和性能表现优异的特点.如果能够熟练地驾驭它,不管是把它用做缓存还是存储,对很多大型应用都很多帮助.新浪作为世界上 ...

  5. Redis入门教程:特性及数据类型的操作

    虽然Redis已经很火了,相信还是有很多同学对Redis只是有所听闻或者了解并不全面,下面是一个比较系统的Redis介绍,对Redis的特性及各种数据类型及操作进行了介绍.是一个很不错的Redis入门 ...

  6. 【原】Redis入门教程

    最近在学习Redis,写几篇文章记录一下学习过程:Redis入门教程. 1.Redis基本概念 Redis Redis Keys Redis 基本数据类型 Redis基本操作 遍历操作 Pub-Sub ...

  7. windows下使用redis,Redis入门使用,Redis基础命令

    windows下使用redis,Redis入门使用,Redis基础命令 >>>>>>>>>>>>>>>> ...

  8. Redis入门 – Jedis存储Java对象 - (Java序列化为byte数组方式)

    Redis入门 – Jedis存储Java对象 - (Java序列化为byte数组方式) 原文地址:http://alanland.iteye.com/admin/blogs/1600685(欢迎转载 ...

  9. redis入门(15)redis的数据备份和恢复

    redis入门(15)redis的数据备份和恢复

  10. redis入门(14)redis集群下的数据分区存储

    redis入门(10)redis集群下的数据分区存储

随机推荐

  1. css的书写规范+常用

    格式化: body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blo ...

  2. javascript keycode大全

    keycode    8 = BackSpace BackSpacekeycode    9 = Tab Tabkeycode   12 = Clearkeycode   13 = Enterkeyc ...

  3. About_Smarty

    Smarty是一个使用PHP写出来的模板PHP模板引擎,是目前业界最著名的PHP模板引擎之一.它分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PHP代码 ...

  4. Markdown Blog Testing

    # 测试一下markdown写法 貌似之前的文章不能再重新套用markdown语法了? 1 2 3

  5. py2exe

    1- 生成单一的exe文件: pyinstaller.py -F d:\open_txt\t.py 2- 添加必要的搜索路径: pyinstaller.py -F -p D:\python27\Lib ...

  6. SQL Server 求结果

    ;with cte as ( select  CONVERT(DATE, DATEADD(DAY, -9, GETDATE())) as paytime union all select datead ...

  7. TestNG 与 Junit的比较

    转自 http://www.blogjava.net/fanscial/archive/2005/12/14/23780.html 1.         JDK 5 Annotations (JDK ...

  8. Microservice 微服务的理论模型和现实路径

    两年前接触到了微服务的概念,面对日益膨胀的系统感觉豁然开朗.之后的两年逐步把系统按微服务的架构理念进行了重构,并将业务迁移到了新架构之上.感觉现在差不多是时候写一篇关于微服务的总结文章了. 定义 在 ...

  9. IT人生知识分享:概率与运气

    前言: 最近的人生多了些体验,也读了些许书,感觉还是有些知识是可以分享的. 今天难得周六,特意开电脑了,花几个小时写写,和大伙分享分享点知识. 以下内容,更多的需要读者思考,所以结论不会写太清晰,但一 ...

  10. Web应用程序的自动化测试库-FluentAutomation

    FluentAutomation是流畅的自动化应用编程接口,支持Selenium和WatiN 连同它们所有的风格和驱动程序.自从Fluient支持Selenium,那就意味着你可以使用Selenium ...