设为首页 收藏本站
查看: 1319|回复: 0

[经验分享] Linux下安装redis报错信息

[复制链接]

尚未签到

发表于 2017-12-21 17:33:39 | 显示全部楼层 |阅读模式
  1.下载Redis-3.2.8.tar.gz 压缩包
  解压 :
[plain] view plain copy

  • # tar zxf redis-3.2.8.tar.gz
解压以后 需要编译,切到redis解压目录下 ,(ll 是查看当前目录)[plain] view plain copy

  • [iyunv@bogon local]# cd redis-3.2.8
  • [iyunv@bogon redis-3.2.8]# ll
  编译命令是make
[plain] view plain copy

  • [iyunv@bogon redis-3.2.8]# make
  • cd src && make all
  • make[1]: 进入目录“/usr/local/redis-3.2.8/src”
  • rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html
  • (cd ../deps && make distclean)
  • make[2]: 进入目录“/usr/local/redis-3.2.8/deps”
编译过程中出现报错[html] view plain copy

  • make[3]: 进入目录“/usr/local/redis-3.2.8/deps/hiredis”
  • gcc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  net.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 (忽略)
  •     CC adlist.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] view plain copy

  • [iyunv@bogon redis-3.2.8]# yum install -y gcc g++ gcc-c++ make
  安装完成提示
[html] view plain copy

  • 已安装:
  •   gcc.x86_64 0:4.8.5-11.el7                                               gcc-c++.x86_64 0:4.8.5-11.el7

  • 作为依赖被安装:
  •   cpp.x86_64 0:4.8.5-11.el7                           glibc-devel.x86_64 0:2.17-157.el7_3.1          glibc-headers.x86_64 0:2.17-157.el7_3.1
  •   kernel-headers.x86_64 0:3.10.0-514.6.2.el7          libmpc.x86_64 0:1.0.1-3.el7                    libstdc++-devel.x86_64 0:4.8.5-11.el7

  • 更新完毕:
  •   make.x86_64 1:3.82-23.el7

  • 作为依赖被升级:
  •   glibc.x86_64 0:2.17-157.el7_3.1     glibc-common.x86_64 0:2.17-157.el7_3.1     libgcc.x86_64 0:4.8.5-11.el7     libgomp.x86_64 0:4.8.5-11.el7
  •   libstdc++.x86_64 0:4.8.5-11.el7

  • 完毕!
如果gcc编译器安装过程中报错,可以到百度搜索解决,欢迎评论中补充!!  ------------------------------
  编译器安装完成之后再redis-3.2.8目录下执行make命令
[html] view plain copy

  • [iyunv@bogon redis-3.2.8]# make
  • cd src && make all
  • make[1]: 进入目录“/usr/local/redis-3.2.8/src”
  •     CC adlist.o
  • In file included from adlist.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] view plain copy

  • 原因分析
  • 在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

  • 说关于分配器allocator, 如果有MALLOC  这个 环境变量, 会有用这个环境变量的 去建立Redis。

  • 而且libc 并不是默认的 分配器, 默认的是 jemalloc, 因为 jemalloc 被证明 有更少的 fragmentation problems 比libc。

  • 但是如果你又没有jemalloc 而只有 libc 当然 make 出错。 所以加这么一个参数。
  我应该就是这个问题
  没有jemalloc 而只有 libc 当然 make 出错。
  这时候在编译过程时增加一个参数
[html] view plain copy

  • [iyunv@bogon redis-3.2.8]# make MALLOC=libc
编译成功:  其中出现了两个警告
[html] view plain copy

  • ldo.c: 在函数‘f_parser’中:
  • ldo.c:496:7:<span style="color:#ff0000;background-color: rgb(204, 204, 204);"> <strong>警告</strong></span>:未使用的变量‘c’ [-Wunused-variable]
  •    int c = luaZ_lookahead(p->z);
[html] view plain copy

  • liblua.a(loslib.o):在函数‘os_tmpname’中:
  • loslib.c:(.text+0x28c): 警告:the use of `tmpnam' is dangerous, better use `mkstemp'
  说实在的 由于时间关系,警告没有考虑是怎么回事,如果有人愿意分享一下不胜感激!
  ===============
  现在redis可以说能用了,执行命令启动redis后 还需要再打开一个窗口执行server-cli测试
[html] view plain copy

  • [iyunv@bogon src]# ./redis-server
  • 28198:C 24 Feb 14:04:55.227 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
  • 28198:M 24 Feb 14:04:55.230 * Increased maximum number of open files to 10032 (it was originally set to 1024).
  •                 _._
  •            _.-``__ ''-._
  •       _.-``    `.  `_.  ''-._           Redis 3.2.8 (00000000/0) 64 bit
  •   .-`` .-```.  ```\/    _.,_ ''-._
  • (    '      ,       .-`  | `,    )     Running in standalone mode
  • |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
  • |    `-._   `._    /     _.-'    |     PID: 28198
  •   `-._    `-._  `-./  _.-'    _.-'
  • |`-._`-._    `-.__.-'    _.-'_.-'|
  • |    `-._`-._        _.-'_.-'    |           http://redis.io
  •   `-._    `-._`-.__.-'_.-'    _.-'
  • |`-._`-._    `-.__.-'    _.-'_.-'|
  • |    `-._`-._        _.-'_.-'    |
  •   `-._    `-._`-.__.-'_.-'    _.-'
  •       `-._    `-.__.-'    _.-'
  •           `-._        _.-'
  •               `-.__.-'

  • 28198:M 24 Feb 14:04:55.234 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
  • 28198:M 24 Feb 14:04:55.234 # Server started, Redis version 3.2.8
  这样太麻烦,我想有没有别的办法让他后台运行呢?
  我试过几个命令
[html] view plain copy

  • [iyunv@bogon src]# ./redis-server -d
[html] view plain copy

  • [iyunv@bogon src]# ./redis-server redis.conf
[html] view plain copy

  • [iyunv@bogon src]# $redis-server
[html] view plain copy

  • [iyunv@bogon src]# $redis-server$
  • bash: -server$: 未找到命令...
  • [iyunv@bogon src]# $redis-server$
  • bash: -server$: 未找到命令...
  • [iyunv@bogon src]# $redis-server $
  • bash: -server: 未找到命令...
  • [iyunv@bogon src]# ./redis-server $
  • 28241:C 24 Feb 14:07:23.503 # Fatal error, can't open config file '$'
  • [iyunv@bogon src]# ps -ef|grep redis
  • root      28244   4439  0 14:07 pts/0    00:00:00 grep --color=auto redis
  • [iyunv@bogon src]# ./redis-cli
  • Could not connect to Redis at 127.0.0.1:6379: Connection refused
[html] view plain copy

  • not connected> exit
  • [iyunv@bogon src]# redis-server ./redis.conf
  • bash: redis-server: 未找到命令...
  • [iyunv@bogon src]# $redis-server ./redis.conf
  • bash: -server: 未找到命令...
  • [iyunv@bogon src]# $ redis-server ./redis.conf
  • bash: $: 未找到命令...
  • [iyunv@bogon src]# $ redis-server redis.conf
  都不可以,只能继续上网搜
  网上搜索了一下发现百度经验的一片分享:
  http://jingyan.baidu.com/article/6dad507510ea07a123e36e95.html
  设置如何开机启动我就照做了:(主要是记录自己的操作和总结经验 以下拷贝的会比较多)
  首先是  执行make install。会将make编译生成的可执行文件拷贝到/usr/local/bin目录下;
[html] view plain copy

  • [iyunv@bogon src]# cd ../
  • [iyunv@bogon redis-3.2.8]# make install
  • cd src && make install
  • make[1]: 进入目录“/usr/local/redis-3.2.8/src”

  • Hint: It's a good idea to run 'make test' ;)

  •     INSTALL install
  •     INSTALL install
  •     INSTALL install
  •     INSTALL install
  •     INSTALL install
  • make[1]: 离开目录“/usr/local/redis-3.2.8/src”
  • [iyunv@bogon redis-3.2.8]#
  接下来 懵了,不知道怎么回事卡住了
[html] view plain copy

  • [iyunv@bogon redis-3.2.8]# ./utils/install_server.sh
  • Welcome to the redis service installer
  • This script will help you easily set up a running redis server

  • Please select the redis port for this instance: [6379] 6379^H^H^C
我开始以为提示我输入6379 我输入了一下,但是打回车,删也删不掉,只好Ctrl+c退出,  后来重新执行:./utils/install_server.sh
[html] view plain copy

  • [iyunv@bogon redis-3.2.8]# ./utils/install_server.sh
  • Welcome to the redis service installer
  • This script will help you easily set up a running redis server

  • Please select the redis port for this instance: [6379]
  • Selecting default: 6379
  • Please select the redis config file name [/etc/redis/6379.conf]
  • Selected default - /etc/redis/6379.conf
  • Please select the redis log file name [/var/log/redis_6379.log]
  • Selected default - /var/log/redis_6379.log<span style="white-space:pre">    </span><span style="color:#ff0000;"><strong>----这里如果觉得使用不习惯 可以试着把redis_6379 改为redisd(或者自己喜欢的名字,作为启动redis服务时的名字</strong>)</span><span style="white-space:pre">   </span>
  • Please select the data directory for this instance [/var/lib/redis/6379]
  • Selected default - /var/lib/redis/6379
  • Please select the redis executable path [/usr/local/bin/redis-server]
  • Selected config:
  • Port           : 6379
  • Config file    : /etc/redis/6379.conf
[html] view plain copy

  • <span style="color:#ff0000;">---这个Config file 位置的6379.conf文件是你将来修改远程连接时的文件位置,,设置密码,远程连接都需要来这里</span>
[html] view plain copy

  • Log file       : /var/log/redis_6379.log
  • Data dir       : /var/lib/redis/6379
  • Executable     : /usr/local/bin/redis-server
  • Cli Executable : /usr/local/bin/redis-cli
  • Is this ok? Then press ENTER to go on or Ctrl-C to abort.
  • Copied /tmp/6379.conf => /etc/init.d/redis_6379
[html] view plain copy

  • <span style="color:#ff0000;">---->记住这个路径,如果上面改名以后服务名没有改变的时候可以到这里修改文件名 并且进入文件 将里面带有redis_6379 文件名改掉,我只改了两三个地方</span>
[html] view plain copy


[html] view plain copy

  • Installing service...
  • Successfully added to chkconfig!
  • Successfully added to runlevels 345!
  • Starting Redis server...
  • Installation successful!
  发现原来是 [6379] 是提示的默认值 直接敲回车会继续执行,也就是说 每一次卡住 都是提示是否修改默认值,
  我都是默认的 回车继续
[html] view plain copy

  • Starting Redis server...
执行成功!!  到这里redis基本上已经安装成功了,
  但是以我严谨的态度,我决定查看一下到底安装成功有什么体现!
  接下来 查看开机启动列表里面 有没有redis服务
[html] view plain copy

  • [iyunv@bogon redis-3.2.8]# chkconfig --list

  • 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
  •       如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
  •       欲查看对特定 target 启用的服务请执行
  •       'systemctl list-dependencies [target]'。

  • jexec           0:关 1:开 2:开 3:开 4:开 5:开 6:关
  • netconsole      0:关 1:关 2:关 3:关 4:关 5:关 6:关
  • network         0:关 1:关 2:开 3:开 4:开 5:开 6:关
  • redis_6379      0:关 1:关 2:开 3:开 4:开 5:开 6:关
1-6这几项都代表什么可以去百度一下 ,如果有人懂得 希望可以评论解释下 我反正不知道 DSC0000.gif   好了开机列表有了
  查看一下进程中有没有redis,并且停止服务看一下剩下什么
  (停止redis的进程 可以用kill+28679 结束pid停用服务)
[html] view plain copy

  • [iyunv@bogon redis-3.2.8]# ps -ef|grep redis
  • root      28679      1  0 14:15 ?        00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
  • root      28807   4439  0 14:16 pts/0    00:00:00 grep --color=auto redis
  • [iyunv@bogon redis-3.2.8]# service redis_6379 stop
  • Stopping ...
  • Waiting for Redis to shutdown ...
  • Redis stopped
  • [iyunv@bogon redis-3.2.8]# ps -ef|grep redis
  • root      28830   4439  0 14:17 pts/0    00:00:00 grep --color=auto redis
  然后再次启动redis服务,并且查看进程
[html] view plain copy

  • [iyunv@bogon redis-3.2.8]# service redis_6379 start
  • Starting Redis server...
  • [iyunv@bogon redis-3.2.8]# ps -ef|grep redis
  • root      28843      1  0 14:17 ?        00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
  • root      28847   4439  0 14:17 pts/0    00:00:00 grep --color=auto redis
  好了 redis的服务现在听我话了 ,然后我再试一下客户端能不能用
  在刚安装完以后我查看一下全部的keys
[html] view plain copy

  • [iyunv@bogon redis-3.2.8]# ./src/redis-cli
  • 127.0.0.1:6379> keys *
  • (empty list or set)
告诉我是空的 ,我就放心了 DSC0001.gif   剩下的就是redis的操作了 ,不多说了 Linux安装完成!
  =============================
  最后 设置允许远程访问:
  找到上面的6379.conf配置文件 修改里面的三个地方即可
[html] view plain copy

  • Config file    : /etc/redis/6379.conf
  ------
  修改密码时可以试试来这里 配置文件的这个位置   # requirepass
  打开注释,后面设置密码
[html] view plain copy

  • requirepass 123456
  -----
  1 bind :127.0.0.1 默认是没有注释掉的 ,给他注释掉
  2   redis3.2后新增protected-mode配置,默认是yesprotected-mode 设置为no 关闭保护
  3  daemonize  默认是yes  如果被注释了就打开注释 并且设置为no
  开启这三个就可以实现远程访问
  注意:在设置 .conf文件时 如果是手动启动 需要到redis根目录的redis.conf所在目录下 启动
[html] view plain copy

  • ./redis-server redis.conf
这是需要配置文件的时候 这样启动,配置文件就会生效了 但是我不喜欢手动启动 之后需要重新开一个窗口,所以我让他开机自启了  -------------
  按照上面修改以后如果不能启动服务了
[html] view plain copy

  • [iyunv@bogon log]# systemctl start redisd
  • Warning: redisd.service changed on disk. Run 'systemctl daemon-reload' to reload units.
  • [iyunv@bogon log]# cd /
  • [iyunv@bogon /]# systemctl daemon-reload
  • [iyunv@bogon /]# systemctl start redisd
  • [iyunv@bogon /]# ps -ef|grep redis
  • root      33443      1  0 16:00 ?        00:00:00 /usr/local/bin/redis-server *:6379
  • root      34249   4439  0 16:08 pts/0    00:00:00 grep --color=auto redis
  • [iyunv@bogon /]#
  执行
[html] view plain copy

  • <pre name="code" class="html">[iyunv@bogon /]# systemctl daemon-reload</pre>
  • <pre></pre>
  • <p></p>
  • <pre></pre>
  • <p></p>
  • <p>然后启动 就可以了 </p>
  • <p>有一段摘自网上的讲解  有兴趣的朋友可以看一下</p>
  • <p></p>
  • <pre name="code" class="html">Part III. 使用Redis启动脚本设置开机自启动
  • 启动脚本
  • 推荐在生产环境中使用启动脚本方式启动redis服务。启动脚本 redis_init_script 位于位于Redis的 /utils/ 目录下。

  • #大致浏览下该启动脚本,发现redis习惯性用监听的端口名作为配置文件等命名,我们后面也遵循这个约定。
  • #redis服务器监听的端口
  • REDISPORT=6379
  • #服务端所处位置,在make install后默认存放与`/usr/local/bin/redis-server`,如果未make install则需要修改该路径,下同。
  • 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"
  • 配置环境
  • 1. 根据启动脚本要求,将修改好的配置文件以端口为名复制一份到指定目录。需使用root用户。

  • mkdir /etc/redis
  • cp redis.conf /etc/redis/6379.conf
  • 2. 将启动脚本复制到/etc/init.d目录下,本例将启动脚本命名为redisd(通常都以d结尾表示是后台自启动服务)。

  • cp redis_init_script /etc/init.d/redisd
  • 3.  设置为开机自启动

  • 此处直接配置开启自启动 chkconfig redisd on 将报错误: service redisd does not support chkconfig
  • 参照 此篇文章 ,在启动脚本开头添加如下两行注释以修改其运行级别:

  • #!/bin/sh
  • # chkconfig:   2345 90 10
  • # description:  Redis is a persistent key-value database
  • #
  • 再设置即可成功。

  • #设置为开机自启动服务器
  • chkconfig redisd on
  • #打开服务
  • service redisd start
  • #关闭服务
  • service redisd stop</pre>地址是:http://blog.csdn.net/duerbin3/article/details/45313461
  • <p></p>
  • <p>共同学习!!<br>
  • <br>
  • </p>
  • <p><span style="font-family:Microsoft YaHei; color:#666666"><span style="font-size:15px"><br>
  • </span></span><br>
  • </p>
  • <p><br>
  • <br>
  • </p>
  • <p><br>
  • <br>
  • <br>
  • <br>
  • <br>
  • </p>
  • <p><br>
  • <br>
  • <br>
  • </p>


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-426561-1-1.html 上篇帖子: Redis四(Set操作) 下篇帖子: redis哨兵模式
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表