Home Database Mysql Tutorial Linux 下编译安装 Redis

Linux 下编译安装 Redis

Jun 07, 2016 pm 02:58 PM
linux

Redis还提供了丰富的客户端,以便支持现阶段流行的大多数编程语言。Redis自身使用ANSI C来编写,并且能够在不产生外部依赖(exte

Redis是一款开源的、高性能的键-值存储(key-value store)。它常被称作是一款数据结构服务器(data structure server)。Redis的键值可以包括字符串(strings)、哈希(hashes)、列表(lists)、集合(sets)和 有序集合(sorted sets)等数据类型。 对于这些数据类型,你可以执行原子操作。例如:对字符串进行附加操作(append);递增哈希中的值;向列表中增加元素;计算集合的交集、并集与差集等。

为了获得优异的性能,Redis采用了内存中(in-memory)数据集(dataset)的方式。根据使用场景的不同,你可以每隔一段时间将数据集转存到磁盘上来持久化数据,或者在日志尾部追加每一条操作命令。

Redis同样支持主从复制(master-slave replication),并且具有非常快速的非阻塞首次同步(non-blocking first synchronization)、网络断开自动重连等功能。同时Redis还具有其它一些特性,其中包括简单的check-and-set机制、 pub/sub和配置设置等,以便使得Redis能够表现得更像缓存(cache)。

Redis还提供了丰富的客户端,以便支持现阶段流行的大多数编程语言。详细的支持列表可以参看Redis官方文档: /clients。Redis自身使用ANSI C来编写,并且能够在不产生外部依赖(external dependencies)的情况下运行在大多数POSIX系统上,例如:Linux、*BSD、OS X和Solaris等。

Redis的安装

说明:Redis的安装版本选取为2.2.6,安装包为redis-2.2.6.tar.gz,系统平台为CentOS 5.5。

1. 解压安装包

使用tar -xzvf redis-2.2.6.tar.gz来解压安装包。假设Redis 解压后目录为redis-2.2.6,绝对路径使用$REDIS_HOME来表示。其目录结构如下所示:

Linux 下编译安装 Redis

 

其中,README和INSTALL中包含了编译、安装Redis的简单说明,在正式开始之前请先阅读这两个文件。

2. 编译

进入$REDIS_HOME/src目录,,使用make命令来编译Redis,该编译过程将会产生redis-server二进制文件。

3. 测试

在编译Redis完成之后,最好使用make test命令进行一下测试,但是该步不是必须的。

4. 安装
使用make install来完成Redis的安装。Redis的所有二进制文件将会被安装在/usr/local/bin目录下。

Redis的运行和测试:

假设Redis安装在/usr/local/bin目录下,并且该目录包含在$PATH环境变量的搜索目录中。那么便可以使用redis-server来 运行Redis。如果Redis安装在其他目录中,可以使用/path/to/redis-server来启动Redis,或者将Redis的安装目录添 加到$PATH的搜索目录中。

Redis自带了一个称为redis-cli的命令行客户端,该客户端会在运行make命令的时候自动编译。用户可以使用该客户端完成Redis的一些简单测试或操作。

使用redis-cli来启动该客户端,启动后命令行前缀为:redis>。用户可以在此进行后续操作,这类似于MySQL的命令行模式。

例如,使用如下命令来存储key-value对:

Linux 下编译安装 Redis

 

使用get命令来获取所存储的值:

Linux 下编译安装 Redis

 

至此,Redis的安装和简单测试便完成了。需要注意的是,在运行make test命令的时候,有时候会出现如下错误:
(cd ..; tclsh8.5 tests/test_helper.tcl --tags "" --file "")
/bin/sh: tclsh8.5: command not found
make: *** [test] Error 127
之所以会出现该错误是因为在运行make test命令时,需要Tcl 8.5的库,而CentOS 5.5自带的版本为8.4。用户可以使用如下命令来查看:

Linux 下编译安装 Redis

 

此时,你可以到Tcl的官方网站下载8.5版本,并按照Tcl的安装说明自行安装便可。安装完成后,使用ldconfig再次查看:

Linux 下编译安装 Redis


此时,再次运行make test命令便可。

1、从官网下载和解压源代码
wget
tar xzf redis-2.2.5.tar.gz
cd redis-2.2.5

2、编译,并使用tcmalloc加速

make USE_TCMALLOC=yes

3、启动redis
./redis-server ./redis.conf

4、验证是否在使用tcmalloc
lsof -n |grep tcmalloc
redis-ser 26689 root mem REG 253,3 1800221 4182039 /usr/local/lib/libtcmalloc.so.0.1.0
redis-ser 26694 root mem REG 253,3 1800221 4182039 /usr/local/lib/libtcmalloc.so.0.1.0
redis-ser 26697 root mem REG 253,3 1800221 4182039 /usr/local/lib/libtcmalloc.so.0.1.0
redis-ser 26701 root mem REG 253,3 1800221 4182039 /usr/local/lib/libtcmalloc.so.0.1.0

下面关于Redis的文章您也可能喜欢,不妨参考下:

Ubuntu 14.04下Redis安装及简单测试

Redis主从复制基本配置

Redis集群明细文档

Ubuntu 12.10下安装Redis(图文详解)+ Jedis连接Redis

Redis系列-安装部署维护篇

CentOS 6.3安装Redis

Redis安装部署学习笔记

Redis配置文件redis.conf 详解

Redis 的详细介绍:请点这里
Redis 的下载地址:请点这里

本文永久更新链接地址

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Apr 01, 2025 pm 03:06 PM

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

How to efficiently integrate Node.js or Python services under LAMP architecture? How to efficiently integrate Node.js or Python services under LAMP architecture? Apr 01, 2025 pm 02:48 PM

Many website developers face the problem of integrating Node.js or Python services under the LAMP architecture: the existing LAMP (Linux Apache MySQL PHP) architecture website needs...

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

How to configure apscheduler timing task as a service on macOS? How to configure apscheduler timing task as a service on macOS? Apr 01, 2025 pm 06:09 PM

Configure the apscheduler timing task as a service on macOS platform, if you want to configure the apscheduler timing task as a service, similar to ngin...

Can the Python interpreter be deleted in Linux system? Can the Python interpreter be deleted in Linux system? Apr 02, 2025 am 07:00 AM

Regarding the problem of removing the Python interpreter that comes with Linux systems, many Linux distributions will preinstall the Python interpreter when installed, and it does not use the package manager...

Four ways to implement multithreading in C language Four ways to implement multithreading in C language Apr 03, 2025 pm 03:00 PM

Multithreading in the language can greatly improve program efficiency. There are four main ways to implement multithreading in C language: Create independent processes: Create multiple independently running processes, each process has its own memory space. Pseudo-multithreading: Create multiple execution streams in a process that share the same memory space and execute alternately. Multi-threaded library: Use multi-threaded libraries such as pthreads to create and manage threads, providing rich thread operation functions. Coroutine: A lightweight multi-threaded implementation that divides tasks into small subtasks and executes them in turn.

How to open web.xml How to open web.xml Apr 03, 2025 am 06:51 AM

To open a web.xml file, you can use the following methods: Use a text editor (such as Notepad or TextEdit) to edit commands using an integrated development environment (such as Eclipse or NetBeans) (Windows: notepad web.xml; Mac/Linux: open -a TextEdit web.xml)

See all articles