文档章节

redis 安装及安装遇到的问题解决

Sheamus
 Sheamus
发布于 2016/07/15 16:10
字数 2163
阅读 2317
收藏 1
点赞 0
评论 0

公司项目需要解决大并发问题,需采用nosql 数据库。前一个项目采用memcache做为提升系统的并发分布式缓存,memcache 采用简单 key-value 的方式,存储在内存中,当然数据过大肯定不行了,断电了内存东西也丢失了可怜

         redis呢?redis 部分存储在磁盘上。内存中当然是存在的,不然咋混得下去呢。最主要是它支持的类型好几个呢,根据业务场景当然需要选择合适的方式不。redis(key、hash、list、set、sortedset、string)具体就不一一列举咯。

开始安装:

 

安装环境 centos6.5

 

1、获取安装文件

wget http://download.redis.io/redis-stable.tar.gz

 

2、解压文件

tar xzvf redis-stable.tar.gz

 

3、进入目录

cd redis-stable

 

4、编译

make

 

5、安装

make install

 

6、设置配置文件路径

mkdir -p /etc/redis

cp redis.conf /etc/redis

 

7、修改配置文件

vi /etc/redis/redis.conf


仅修改: daemonize yes 

 

8、启动


/usr/local/bin/redis-server /etc/redis/redis.conf

 

9、查看启动


ps -ef | grep redis  

 

 

10、使用客户端

 

redis-cli

>set name hello

OK

>get name

"hello"

 

 

情况顺利就这样子咯。关键是心情不好就报上好几个错,当时我就遇上了。其实我也是在google找到的答案咯。

  问题就是这样的:

   1、不能编译没有GCC 编译工具


安装报错:
问题1:make时可能会报如下错误
cc -c -std=c99 -pedantic -O2 -Wall -W   -g -rdynamic -ggdb   adlist.c
make: cc:命令未找到
make: *** [adlist.o] 错误 127


解决方法:安装gcc
命令如下:yum install gcc






2、make时可能会报如下错误:
collect2: ld returned 1 exit status
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/usr/local/redis/src'
make: *** [all] Error 2


解决办法:
编辑src/.make-settings里的OPT,改为OPT=-O2 -march=i686




3、make时可能会报如下错误:
cc: error: ../deps/hiredis/libhiredis.a: No such file or directory


cc: error: ../deps/lua/src/liblua.a: No such file or directory


cc: error: ../deps/jemalloc/lib/libjemalloc.a: No such file or directory


make: *** [redis-server] Error 1




分别进入redis下的deps下的hiredis、lua 运行make
注意:jemalloc下可能要先运行./configure,然后make
回到src目录运行 make  


结果还是报cc: error: ../deps/lua/src/liblua.a: No such file or directory


这下子我把redis的解压包 删除掉 rm -rf redis-stable 
重新解压  进入redis-stable  make  还真没报错了。

    

  好了,这样子总算解决了问题,下面是官网提供的安装文档。

 

官网:

RedisCommandsClientsDocumentationCommunityDownloadIssuesLicense

Redis Quick Start

This is a quick start document that targets people without prior experience with Redis. Reading this document will help you:

  • Download and compile Redis to start hacking.
  • Use redis-cli to access the server.
  • Use Redis from your application.
  • Understand how Redis persistence works.
  • Install Redis more properly.
  • Find out what to read next to understand more about Redis.

Installing Redis

The suggested way of installing Redis is compiling it from sources as Redis has no dependencies other than a working GCC compiler and libc. Installing it using the package manager of your Linux distribution is somewhat discouraged as usually the available version is not the latest.

You can either download the latest Redis tar ball from the redis.io web site, or you can alternatively use this special URL that always points to the latest stable Redis version, that is, http://download.redis.io/redis-stable.tar.gz.

In order to compile Redis follow this simple steps:

wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make

At this point you can try if your build works correctly typing make test, but this is an optional step. After the compilation the src directory inside the Redis distribution is populated with the different executables that are part of Redis:

  • redis-server is the Redis Server itself.
  • redis-cli is the command line interface utility to talk with Redis.
  • redis-benchmark is used to check Redis performances.
  • redis-check-aof and redis-check-dump are useful in the rare event of corrupted data files.

It is a good idea to copy both the Redis server than the command line interface in proper places using the following commands:

  • sudo cp redis-server /usr/local/bin/
  • sudo cp redis-cli /usr/local/bin/

In the following documentation I assume that /usr/local/bin is in your PATH environment variable so you can execute both the binaries without specifying the full path.

Starting Redis

The simplest way to start the Redis server is just executing the redis-server binary without any argument.

$ redis-server
[28550] 01 Aug 19:29:28 # Warning: no config file specified, using the default config. In order to specify a config file use 'redis-server /path/to/redis.conf'
[28550] 01 Aug 19:29:28 * Server started, Redis version 2.2.12
[28550] 01 Aug 19:29:28 * The server is now ready to accept connections on port 6379
... and so forth ...

In the above example Redis was started without any explicit configuration file, so all the parameters will use the internal default. This is perfectly fine if you are starting Redis just to play a bit with it or for development, but for production environments you should use a configuration file.

To start Redis with a configuration file just give the full path of the configuration file to use as the only Redis argument, for instance: redis-server /etc/redis.conf. You can use the redis.conf file included in the root directory of the Redis source code distribution as a template to write your configuration file.

Check if Redis is working

External programs talk to Redis using a TCP socket and a Redis specific protocol. This protocol is implemented in the Redis client libraries for the different programming languages. However to make hacking with Redis simpler Redis provides a command line utility that can be used to send commands to Redis. This program is called redis-cli.

The first thing to do in order to check if Redis is working properly is sending a PING command using redis-cli:

$ redis-cli ping
PONG

Running redis-cli followed by a command name and its arguments will send this command to the Redis instance running on localhost at port 6379. You can change the host and port used by redis-cli, just try the --help option to check the usage information.

Another interesting way to run redis-cli is without arguments: the program will start into an interactive mode where you can type different commands:

$ redis-cli                                                                
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379> set mykey somevalue
OK
redis 127.0.0.1:6379> get mykey
"somevalue"

At this point you can talk with Redis. It is the right time to pause a bit with this tutorial and start the fifteen minutes introduction to Redis data types in order to learn a few Redis commands. Otherwise if you already know a few basic Redis commands you can keep reading.

Using Redis from your application

Of course using Redis just from the command line interface is not enough as the goal is to use it from your application. In order to do so you need to download and install a Redis client library for your programming language. You'll find afull list of clients for different languages in this page.

For instance if you happen to use the Ruby programming language our best advice is to use the Redis-rb client. You can install it using the command gem install redis (also make sure to install the SystemTimer gem as well).

These instructions are Ruby specific but actually many library clients for popular languages look quite similar: you create a Redis object and execute commands calling methods. A short interactive example using Ruby:

>> require 'rubygems'
=> false
>> require 'redis'
=> true
>> r = Redis.new
=> #<Redis client v2.2.1 connected to redis://127.0.0.1:6379/0 (Redis v2.3.8)>
>> r.ping
=> "PONG"
>> r.set('foo','bar')
=> "OK"
>> r.get('foo')
=> "bar"

Redis persistence

You can learn how Redis persisence works in this page, however what is important to understand for a quick start is that by default, if you start Redis with the default configuration, Redis will spontaneously save the dataset only from time to time (for instance after at least five minutes if you have at least 100 changes in your data), so if you want your database to persist and be reloaded after a restart make sure to call the SAVE command manually every time you want to force a data set snapshot. Otherwise make sure to shutdown the database using the SHUTDOWN command:

$ redis-cli shutdown

This way Redis will make sure to save the data on disk before quitting. Reading the persistence page is strongly suggested in order to better understand how Redis persistence works.

Installing Redis more properly

Running Redis from the command line is fine just to hack a bit with it or for development. However at some point you'll have some actual application to run on a real server. For this kind of usage you have two different choices:

  • Run Redis using screen.
  • Install Redis in your Linux box in a proper way using an init script, so that after a restart everything will start again properly.

A proper install using an init script is strongly suggested. The following instructions can be used to perform a proper installation using the init script shipped with Redis 2.4 in a Debian or Ubuntu based distribution.

We assume you already copied redis-server and redis-cli executables under /usr/local/bin.

  • Create a directory where to store your Redis config files and your data:

    sudo mkdir /etc/redis
    sudo mkdir /var/redis
    
  • Copy the init script that you'll find in the Redis distribution under the utils directory into /etc/init.d. We suggest calling it with the name of the port where you are running this instance of Redis. For example:

    sudo cp utils/redis_init_script /etc/init.d/redis_6379
    
  • Edit the init script.

    sudo vi /etc/init.d/redis_6379
    

Make sure to modify REDIS_PORT accordingly to the port you are using. Both the pid file path and the configuration file name depend on the port number.

  • Copy the template configuration file you'll find in the root directory of the Redis distribution into /etc/redis/ using the port number as name, for instance:

    sudo cp redis.conf /etc/redis/6379.conf
    
  • Create a directory inside /var/redis that will work as data and working directory for this Redis instance:

    sudo mkdir /var/redis/6379
    
  • Edit the configuration file, making sure to perform the following changes:

  • Set daemonize to yes (by default it is set to no).
  • Set the pidfile to /var/run/redis_6379.pid (modify the port if needed).
  • Change the port accordingly. In our example it is not needed as the default port is already 6379.
  • Set your preferred loglevel.
  • Set the logfile to /var/log/redis_6379.log
  • Set the dir to /var/redis/6379 (very important step!)
  • Finally add the new Redis init script to all the default runlevels using the following command:

    sudo update-rc.d redis_6379 defaults
    

You are done! Now you can try running your instance with:

/etc/init.d/redis_6379 start

Make sure that everything is working as expected:

  • Try pinging your instance with redis-cli.
  • Do a test save with redis-cli save and check that the dump file is correctly stored into /var/redis/6379/ (you should find a file called dump.rdb).
  • Check that your Redis instance is correctly logging in the log file.
  • If it's a new machine where you can try it without problems make sure that after a reboot everything is still working.

Note: in the above instructions we skipped many Redis configurations parameters that you would like to change, for instance in order to use AOF persistence instead of RDB persistence, or to setup replication, and so forth. Make sure to read the redis.conf file (that is heavily commented) and the other documentation you can find in this web site for more information.

This website is open source software developed by Citrusbyte
The Redis logo was designed by Carlos Prioglio. See more credits.

Sponsored by

本文转载自:http://blog.csdn.net/jy0902/article/details/19248299

共有 人打赏支持
Sheamus

Sheamus

粉丝 42
博文 213
码字总数 29920
作品 0
海淀
程序员
CentOS 6.5 安装 Redis 执行 make #error "Newer version of jemalloc required"

CentOS 6.5 安装 Redis 执行 make #error "Newer version of jemalloc required" 根据你系统安装时或之后安装的选项的情况,可能在安装的过程中遇到不同的问题; 就像今天遇到的一台机器,安...

锅巴跑跑
2016/11/30
150
0
安装redis和php-redis扩展的那点事

是在centos7环境下进行安装,由于yum中没有redis的rpm包直接下载,需要编译,首先通过yum安装gcc make,以下是安装redis的步骤: 1、安装gcc make: yum install gcc make -y 2、下载redis,...

RitaChen
2016/11/15
165
0
ubuntu14.04安装Scrapy和redis时遇到的问题,及解决方法

准备好 Ubuntu14.04 System. 1. 安装 scrapy: 1) 按照这个 http://doc.scrapy.org/en/1.0/topics/ubuntu.html#topics-ubuntu 但是可能会遇到下面的问题: 尝试了以下方式解决了该问题: 1>>s...

Airship
2015/12/27
48
0
Centos7.4安装Redis

当前目录是:/usr/devtools/ 第一步:在线下载redis安装包 第二步:解压 第三步:编译 执行make命令后可能出现如下问题 坑 1 :提示找不到cc命令 解决方法:配置编译环境,执行以下安装命令 ...

人觉非常君
07/05
0
0
redis安装部署(1)

redis3 部署 部署 在日前的工作中,需要重新搭建一套演示环境;环境需要零零碎碎的第三方应用很多,包括了 zookeeper , kafka ,redis ,mongodb ;环境也来来回回的部署了多次,也有遇到各种问...

alex
2015/12/20
98
0
在deian 8.7中,编译安装redis-server 3.2.8

一 步骤 (默认假设是root用户) 1 下载 wget http://download.redis.io/releases/redis-3.2.8.tar.gz 2 解压 tar -zxvf redis-3.2.8.tar.gz && cd redis-3.2.8 3 make test #这一步会进行编......

kyonon
2017/11/09
0
0
Redis在CentOS下安装

本人因为是一直是.NET的开发,所以对Linux的不是太熟悉,只是之前学习过在虚拟机里面进行安装测试过,所以在安装的过程中,会有一些环境上的问题。 本文写下来也是希望有像我这样的新人看到的...

07/11
0
0
Redis源码安装 CentOS7

获取官方最新源码 官方下载 地址:http://redis.io/download 选择一个稳定版本下载,当前稳定版本3.0.6。 下载源码 cd /tmp wget http://download.redis.io/releases/redis-3.0.6.tar.gz 编译...

Corlang
2016/01/14
18
0
Linux下Redis的安装和使用

0.前言 推荐一个虚拟机工具:Oracle VM VirtualBox 之前弄了个阿里云,最低配置512内存,开始感觉不错,后来感觉内存不够用,启动个服务器和mysql就没内存了,然后mysql会自动关闭,就以为是内存不够...

蛙牛
2014/03/22
6K
2
Centos7(7.2)服务器javaweb项目运行环境配置

mysql安装(yum方式安装) CentOS7的yum源中默认是没有mysql的。为了解决这个问题,我们要先下载mysql的repo源。 1. 下载mysql的repo源 $ wget http://repo.mysql.com/mysql-community-relea...

陈俊凯
2016/11/09
57
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

CoreText进阶(五)- 文字排版样式和效果

CoreText进阶(五)- 文字排版样式和效果 效果 以下是三个设置了不同属性的效果图 第一个设置了文字颜色为红色,字体为16号 第二个设置了文字颜色为灰色,字体为16号,对其为居中 第三个设置...

aron1992
27分钟前
1
0
10.23 linux任务计划cron~10.27 target介绍

crontab命令被用来提交和管理用户的需要周期性执行的任务,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动crond进程,crond进程每分钟会定期检查是...

洗香香
38分钟前
0
0
告警系统主脚本、告警系统配置文件、告警系统监控项目

20.20 告警系统主脚本 告警系统主脚本 main.sh内容 #!/bin/bash#Written by aming.# 是否发送邮件的开关export send=1# 过滤ip地址export addr=`/sbin/ifconfig |grep -A1 "en...

lyy549745
41分钟前
0
0
Don’t Repeat Yourself

在软件工程中,Don’t Repeat Yourself(DRY)是软件开发的原则,旨在减少重复,用抽象代替它,使用数据规范化来避免冗余。 这个原则在维基百科上是说是由Andy Hunt和Dave Thomas《The Pragmat...

woshixin
43分钟前
0
0
搭建webpack项目框架

作者:汪娇娇 时间:2018年6月4日 一、说明 随着业务发展和前端人员的增加,搭建一个通用框架以及制定统一规范就成了必然。对于选型这方面,一开始好像就没考虑其他框架,直接选了webpack。w...

娇娇jojojo
50分钟前
0
0
Java基础——面向对象(内部类)

声明:本栏目所使用的素材都是凯哥学堂VIP学员所写,学员有权匿名,对文章有最终解释权;凯哥学堂旨在促进VIP学员互相学习的基础上公开笔记。 内部类: 1.有名内部类 2.无名内部类 内部类申请...

凯哥学堂
58分钟前
0
0
HttpClient内部三个超时时间的区别

RequestConfig requestConfig = RequestConfig.custom() .setConnectionRequestTimeout(config.connReqTimeout) //从连接池中获取连接的超时时间 ......

1713716445
今天
0
0
每天一个命令SCP

每天一个命令:SCP scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的。可能会稍微影响一下速...

河图再现
今天
0
0
cron/chkconfig/systemd/unit/target

linux任务计划 : cron工具 任务计划在运维工作中用到的比较多,大部分系统管理工作都是通过定期自动执行某个脚本来完成。 查看linux中任务计划的配置文件: /etc/crontab [root@yolks-001 ~]...

Hi_Yolks
今天
1
0
ftp攻略

Vsftpd完全攻略(一)ftp原理与vsftp安装:https://www.iyunv.com/thread-44698-1-1.html Vsftpd完全攻略(二)设置匿名用户也支持下载和上传与创建目录:https://www.iyunv.com/forum.php?mo...

寰宇01
今天
1
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部