首页 文章资讯内容详情

Linux下安装redis报错信息

2026-06-01 3 花语

本文内容纲要:

-redis在Linux安装报错

redis在Linux安装报错

标签:redislinuxcentos

2017-02-2413:46384人阅读评论(0)收藏举报

分类:

Linux安装工具(2)

版权声明:本文为博主原创文章,未经博主允许不得转载。

1.下载Redis-3.2.8.tar.gz压缩包

解压:

[plain]viewplaincopy

#tarzxfredis-3.2.8.tar.gz

解压以后需要编译,切到redis解压目录下,(ll是查看当前目录)

[plain]viewplaincopy

[root@bogonlocal]#cdredis-3.2.8 [root@bogonredis-3.2.8]#ll

编译命令是make

[plain]viewplaincopy

[root@bogonredis-3.2.8]#make cdsrc&&makeall make[1]:进入目录“/usr/local/redis-3.2.8/src” rm-rfredis-serverredis-sentinelredis-cliredis-benchmarkredis-check-rdbredis-check-aof*.o*.gcda*.gcno*.gcovredis.infolcov-html (cd../deps&&makedistclean) make[2]:进入目录“/usr/local/redis-3.2.8/deps”

编译过程中出现报错

[html]viewplaincopy

make[3]:进入目录“/usr/local/redis-3.2.8/deps/hiredis” gcc-std=c99-pedantic-c-O3-fPIC-Wall-W-Wstrict-prototypes-Wwrite-strings-g-ggdbnet.c make[3]:gcc:命令未找到 make[3]:***[net.o]错误127 make[3]:离开目录“/usr/local/redis-3.2.8/deps/hiredis” make[2]:***[hiredis]错误2 make[2]:离开目录“/usr/local/redis-3.2.8/deps” make[1]:[persist-settings]错误2(忽略) CCadlist.o /bin/sh:cc:未找到命令 make[1]:***[adlist.o]错误127 make[1]:离开目录“/usr/local/redis-3.2.8/src” make:***[all]错误2

提示gcc命令未找到,这是因为redis没有安装gcc编译器没安装

这时候只要安装编译器即可

[html]viewplaincopy

[root@bogonredis-3.2.8]#yuminstall-ygccg++gcc-c++make

安装完成提示

[html]viewplaincopy

已安装: gcc.x86_640:4.8.5-11.el7gcc-c++.x86_640:4.8.5-11.el7 作为依赖被安装: cpp.x86_640:4.8.5-11.el7glibc-devel.x86_640:2.17-157.el7_3.1glibc-headers.x86_640:2.17-157.el7_3.1 kernel-headers.x86_640:3.10.0-514.6.2.el7libmpc.x86_640:1.0.1-3.el7libstdc++-devel.x86_640:4.8.5-11.el7 更新完毕: make.x86_641:3.82-23.el7 作为依赖被升级: glibc.x86_640:2.17-157.el7_3.1glibc-common.x86_640:2.17-157.el7_3.1libgcc.x86_640:4.8.5-11.el7libgomp.x86_640:4.8.5-11.el7 libstdc++.x86_640:4.8.5-11.el7 完毕!

如果gcc编译器安装过程中报错,可以到百度搜索解决,欢迎评论中补充!!

------------------------------

编译器安装完成之后再redis-3.2.8目录下执行make命令

[html]viewplaincopy

[root@bogonredis-3.2.8]#make cdsrc&&makeall make[1]:进入目录“/usr/local/redis-3.2.8/src” CCadlist.o Infileincludedfromadlist.c:34:0: zmalloc.h:50:31:致命错误:jemalloc/jemalloc.h:没有那个文件或目录 #include<jemalloc/jemalloc.h> ^ 编译中断。 make[1]:***[adlist.o]错误1 make[1]:离开目录“/usr/local/redis-3.2.8/src” make:***[all]错误2

又出现错误,上网查了之后说是

[html]viewplaincopy

原因分析 在README有这个一段话。 Allocator --------- Selectinganon-defaultmemoryallocatorwhenbuildingRedisisdonebysetting the`MALLOC`environmentvariable.Redisiscompiledandlinkedagainstlibc mallocbydefault,withtheexceptionofjemallocbeingthedefaultonLinux systems.Thisdefaultwaspickedbecausejemallochasproventohavefewer fragmentationproblemsthanlibcmalloc. Toforcecompilingagainstlibcmalloc,use: %makeMALLOC=libc TocompileagainstjemalloconMacOSXsystems,use: %makeMALLOC=jemalloc 说关于分配器allocator,如果有MALLOC这个环境变量,会有用这个环境变量的去建立Redis。 而且libc并不是默认的分配器,默认的是jemalloc,因为jemalloc被证明有更少的fragmentationproblems比libc。 但是如果你又没有jemalloc而只有libc当然make出错。所以加这么一个参数。

我应该就是这个问题

没有jemalloc而只有libc当然make出错。

这时候在编译过程时增加一个参数

[html]viewplaincopy

[root@bogonredis-3.2.8]#makeMALLOC=libc

编译成功:

其中出现了两个警告

[html]viewplaincopy

ldo.c:在函数‘f_parser’中: ldo.c:496:7:警告:未使用的变量‘c’[-Wunused-variable] intc=luaZ_lookahead(p->z);

[html]viewplaincopy

liblua.a(loslib.o):在函数‘os_tmpname’中: loslib.c:(.text+0x28c):警告:theuseof`tmpnamisdangerous,betteruse`mkstemp

说实在的由于时间关系,警告没有考虑是怎么回事,如果有人愿意分享一下不胜感激!

===============

现在redis可以说能用了,执行命令启动redis后还需要再打开一个窗口执行server-cli测试

[html]viewplaincopy

[root@bogonsrc]#./redis-server 28198:C24Feb14:04:55.227#Warning:noconfigfilespecified,usingthedefaultconfig.Inordertospecifyaconfigfileuse./redis-server/path/to/redis.conf 28198:M24Feb14:04:55.230*Increasedmaximumnumberofopenfilesto10032(itwasoriginallysetto1024). _._ _.-``__-._ _.-```.`_.-._Redis3.2.8(00000000/0)64bit .-``.-```.```\/_.,_-._ (,.-`|`,)Runninginstandalonemode |`-._`-...-`__...-.``-._|`_.-|Port:6379 |`-._`._/_.-|PID:28198 `-._`-._`-./_.-_.- |`-._`-._`-.__.-_.-_.-| |`-._`-.__.-_.-|http://redis.io `-._`-._`-.__.-_.-_.- |`-._`-._`-.__.-_.-_.-| |`-._`-.__.-_.-| `-._`-._`-.__.-_.-_.- `-._`-.__.-_.- `-.__.- `-.__.- 28198:M24Feb14:04:55.234#WARNING:TheTCPbacklogsettingof511cannotbeenforcedbecause/proc/sys/net/core/somaxconnissettothelowervalueof128. 28198:M24Feb14:04:55.234#Serverstarted,Redisversion3.2.8

这样太麻烦,我想有没有别的办法让他后台运行呢?

我试过几个命令

[html]viewplaincopy

[root@bogonsrc]#./redis-server-d

[html]viewplaincopy

[root@bogonsrc]#./redis-serverredis.conf

[html]viewplaincopy

[root@bogonsrc]#$redis-server

[html]viewplaincopy

[root@bogonsrc]#$redis-server$ bash:-server$:未找到命令... [root@bogonsrc]#$redis-server$ bash:-server$:未找到命令... [root@bogonsrc]#$redis-server$ bash:-server:未找到命令... [root@bogonsrc]#./redis-server$ 28241:C24Feb14:07:23.503#Fatalerror,cantopenconfigfile$ [root@bogonsrc]#ps-ef|grepredis root282444439014:07pts/000:00:00grep--color=autoredis [root@bogonsrc]#./redis-cli CouldnotconnecttoRedisat127.0.0.1:6379:Connectionrefused

[html]viewplaincopy

notconnected>exit [root@bogonsrc]#redis-server./redis.conf bash:redis-server:未找到命令... [root@bogonsrc]#$redis-server./redis.conf bash:-server:未找到命令... [root@bogonsrc]#$redis-server./redis.conf bash:$:未找到命令... [root@bogonsrc]#$redis-serverredis.conf

都不可以,只能继续上网搜

网上搜索了一下发现百度经验的一片分享:

http://jingyan.baidu.com/article/6dad507510ea07a123e36e95.html

设置如何开机启动我就照做了:(主要是记录自己的操作和总结经验以下拷贝的会比较多)

首先是执行makeinstall。会将make编译生成的可执行文件拷贝到/usr/local/bin目录下;

[html]viewplaincopy

[root@bogonsrc]#cd../ [root@bogonredis-3.2.8]#makeinstall cdsrc&&makeinstall make[1]:进入目录“/usr/local/redis-3.2.8/src” Hint:Itsagoodideatorunmaketest;) INSTALLinstall INSTALLinstall INSTALLinstall INSTALLinstall INSTALLinstall make[1]:离开目录“/usr/local/redis-3.2.8/src” [root@bogonredis-3.2.8]#

接下来懵了,不知道怎么回事卡住了

[html]viewplaincopy

[root@bogonredis-3.2.8]#./utils/install_server.sh Welcometotheredisserviceinstaller Thisscriptwillhelpyoueasilysetuparunningredisserver Pleaseselecttheredisportforthisinstance:[6379]6379^H^H^C

我开始以为提示我输入6379我输入了一下,但是打回车,删也删不掉,只好Ctrl+c退出,

后来重新执行:./utils/install_server.sh

[html]viewplaincopy

[root@bogonredis-3.2.8]#./utils/install_server.sh Welcometotheredisserviceinstaller Thisscriptwillhelpyoueasilysetuparunningredisserver Pleaseselecttheredisportforthisinstance:[6379] Selectingdefault:6379 Pleaseselecttheredisconfigfilename[/etc/redis/6379.conf] Selecteddefault-/etc/redis/6379.conf Pleaseselecttheredislogfilename[/var/log/redis_6379.log] Selecteddefault-/var/log/redis_6379.log----这里如果觉得使用不习惯可以试着把redis_6379改为redisd(或者自己喜欢的名字,作为启动redis服务时的名字) Pleaseselectthedatadirectoryforthisinstance[/var/lib/redis/6379] Selecteddefault-/var/lib/redis/6379 Pleaseselecttheredisexecutablepath[/usr/local/bin/redis-server] Selectedconfig: Port:6379 Configfile:/etc/redis/6379.conf

[html]viewplaincopy

---这个Configfile位置的6379.conf文件是你将来修改远程连接时的文件位置,,设置密码,远程连接都需要来这里

[html]viewplaincopy

Logfile:/var/log/redis_6379.log Datadir:/var/lib/redis/6379 Executable:/usr/local/bin/redis-server CliExecutable:/usr/local/bin/redis-cli Isthisok?ThenpressENTERtogoonorCtrl-Ctoabort. Copied/tmp/6379.conf=>/etc/init.d/redis_6379

[html]viewplaincopy

---->记住这个路径,如果上面改名以后服务名没有改变的时候可以到这里修改文件名并且进入文件将里面带有redis_6379文件名改掉,我只改了两三个地方

[html]viewplaincopy

[html]viewplaincopy

Installingservice... Successfullyaddedtochkconfig! Successfullyaddedtorunlevels345! StartingRedisserver... Installationsuccessful!

发现原来是[6379]是提示的默认值直接敲回车会继续执行,也就是说每一次卡住都是提示是否修改默认值,

我都是默认的回车继续

[html]viewplaincopy

StartingRedisserver...

执行成功!!

到这里redis基本上已经安装成功了,

但是以我严谨的态度,我决定查看一下到底安装成功有什么体现!

接下来查看开机启动列表里面有没有redis服务

[html]viewplaincopy

[root@bogonredis-3.2.8]#chkconfig--list 注意:该输出结果只显示SysV服务,并不包含原生systemd服务。SysV配置数据可能被原生systemd配置覆盖。 如果您想列出systemd服务,请执行systemctllist-unit-files。 欲查看对特定target启用的服务请执行 systemctllist-dependencies[target]。 jexec0:关1:开2:开3:开4:开5:开6:关 netconsole0:关1:关2:关3:关4:关5:关6:关 network0:关1:关2:开3:开4:开5:开6:关 redis_63790:关1:关2:开3:开4:开5:开6:关

1-6这几项都代表什么可以去百度一下,如果有人懂得希望可以评论解释下我反正不知道

好了开机列表有了

查看一下进程中有没有redis,并且停止服务看一下剩下什么

(停止redis的进程可以用kill+28679结束pid停用服务)

[html]viewplaincopy

[root@bogonredis-3.2.8]#ps-ef|grepredis root286791014:15?00:00:00/usr/local/bin/redis-server127.0.0.1:6379 root288074439014:16pts/000:00:00grep--color=autoredis [root@bogonredis-3.2.8]#serviceredis_6379stop Stopping... WaitingforRedistoshutdown... Redisstopped [root@bogonredis-3.2.8]#ps-ef|grepredis root288304439014:17pts/000:00:00grep--color=autoredis

然后再次启动redis服务,并且查看进程

[html]viewplaincopy

[root@bogonredis-3.2.8]#serviceredis_6379start StartingRedisserver... [root@bogonredis-3.2.8]#ps-ef|grepredis root288431014:17?00:00:00/usr/local/bin/redis-server127.0.0.1:6379 root288474439014:17pts/000:00:00grep--color=autoredis

好了redis的服务现在听我话了,然后我再试一下客户端能不能用

在刚安装完以后我查看一下全部的keys

[html]viewplaincopy

[root@bogonredis-3.2.8]#./src/redis-cli 127.0.0.1:6379>keys* (emptylistorset)

告诉我是空的,我就放心了

剩下的就是redis的操作了,不多说了Linux安装完成!

=============================

最后设置允许远程访问:

找到上面的6379.conf配置文件修改里面的三个地方即可

[html]viewplaincopy

Configfile:/etc/redis/6379.conf

------

修改密码时可以试试来这里配置文件的这个位置#requirepass

打开注释,后面设置密码

[html]viewplaincopy

requirepass123456

-----

1bind:127.0.0.1默认是没有注释掉的,给他注释掉

2redis3.2后新增protected-mode配置,默认是yesprotected-mode设置为no关闭保护

3daemonize默认是yes如果被注释了就打开注释并且设置为no

开启这三个就可以实现远程访问

注意:在设置.conf文件时如果是手动启动需要到redis根目录的redis.conf所在目录下启动

[html]viewplaincopy

./redis-serverredis.conf

这是需要配置文件的时候这样启动,配置文件就会生效了但是我不喜欢手动启动之后需要重新开一个窗口,所以我让他开机自启了

-------------

按照上面修改以后如果不能启动服务了

[html]viewplaincopy

[root@bogonlog]#systemctlstartredisd Warning:redisd.servicechangedondisk.Runsystemctldaemon-reloadtoreloadunits. [root@bogonlog]#cd/ [root@bogon/]#systemctldaemon-reload [root@bogon/]#systemctlstartredisd [root@bogon/]#ps-ef|grepredis root334431016:00?00:00:00/usr/local/bin/redis-server*:6379 root342494439016:08pts/000:00:00grep--color=autoredis [root@bogon/]#

执行

[html]viewplaincopy

\[root@bogon/\]\#systemctldaemon-reload

然后启动就可以了

有一段摘自网上的讲解有兴趣的朋友可以看一下

PartIII.使用Redis启动脚本设置开机自启动 启动脚本 推荐在生产环境中使用启动脚本方式启动redis服务。启动脚本redis_init_script位于位于Redis的/utils/目录下。 #大致浏览下该启动脚本,发现redis习惯性用监听的端口名作为配置文件等命名,我们后面也遵循这个约定。 #redis服务器监听的端口 REDISPORT=6379 #服务端所处位置,在makeinstall后默认存放与`/usr/local/bin/redis-server`,如果未makeinstall则需要修改该路径,下同。 EXEC=/usr/local/bin/redis-server #客户端位置 CLIEXEC=/usr/local/bin/redis-cli #Redis的PID文件位置 PIDFILE=/var/run/redis_${REDISPORT}.pid #配置文件位置,需要修改 CONF="/etc/redis/${REDISPORT}.conf" 配置环境 根据启动脚本要求,将修改好的配置文件以端口为名复制一份到指定目录。需使用root用户。 mkdir/etc/redis cpredis.conf/etc/redis/6379.conf 将启动脚本复制到/etc/init.d目录下,本例将启动脚本命名为redisd(通常都以d结尾表示是后台自启动服务)。 cpredis_init_script/etc/init.d/redisd 设置为开机自启动 此处直接配置开启自启动chkconfigredisdon将报错误:serviceredisddoesnotsupportchkconfig 参照此篇文章,在启动脚本开头添加如下两行注释以修改其运行级别: #!/bin/sh #chkconfig:23459010 #description:Redisisapersistentkey-valuedatabase # 再设置即可成功。 #设置为开机自启动服务器 chkconfigredisdon #打开服务 serviceredisdstart #关闭服务 serviceredisdstop地址是:http://blog.csdn.net/duerbin3/article/details/45313461

共同学习!!

本文内容总结:redis在Linux安装报错,

原文链接:https://www.cnblogs.com/liu2-/p/6914159.html