标签: redislinuxcentos
2017-02-24 13:46 384人阅读 评论(0) 收藏 举报
 分类:
Linux安装工具(2) 

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

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

解压 :

  1. # tar zxf redis-3.2.8.tar.gz

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

  1. [root@bogon local]# cd redis-3.2.8
  2. [root@bogon redis-3.2.8]# ll

编译命令是make

  1. [root@bogon redis-3.2.8]# make
  2. cd src && make all
  3. make[1]: 进入目录“/usr/local/redis-3.2.8/src”
  4. rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html
  5. (cd ../deps && make distclean)
  6. make[2]: 进入目录“/usr/local/redis-3.2.8/deps”

编译过程中出现报错

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

提示gcc命令未找到,这是因为redis没有安装gcc编译器没安装
这时候只要安装编译器即可

  1. [root@bogon redis-3.2.8]# yum install -y gcc g++ gcc-c++ make

安装完成提示

  1. 已安装:
  2. gcc.x86_64 0:4.8.5-11.el7                                               gcc-c++.x86_64 0:4.8.5-11.el7
  3. 作为依赖被安装:
  4. 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
  5. 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
  6. 更新完毕:
  7. make.x86_64 1:3.82-23.el7
  8. 作为依赖被升级:
  9. 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
  10. libstdc++.x86_64 0:4.8.5-11.el7
  11. 完毕!

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

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

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

  1. [root@bogon redis-3.2.8]# make
  2. cd src && make all
  3. make[1]: 进入目录“/usr/local/redis-3.2.8/src”
  4. CC adlist.o
  5. In file included from adlist.c:34:0:
  6. zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
  7. #include <jemalloc/jemalloc.h>
  8. ^
  9. 编译中断。
  10. make[1]: *** [adlist.o] 错误 1
  11. make[1]: 离开目录“/usr/local/redis-3.2.8/src”
  12. make: *** [all] 错误 2

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

  1. 原因分析
  2. 在README 有这个一段话。
  3. Allocator
  4. ---------
  5. Selecting a non-default memory allocator when building Redis is done by setting
  6. the `MALLOC` environment variable. Redis is compiled and linked against libc
  7. malloc by default, with the exception of jemalloc being the default on Linux
  8. systems. This default was picked because jemalloc has proven to have fewer
  9. fragmentation problems than libc malloc.
  10. To force compiling against libc malloc, use:
  11. % make MALLOC=libc
  12. To compile against jemalloc on Mac OS X systems, use:
  13. % make MALLOC=jemalloc
  14. 说关于分配器allocator, 如果有MALLOC  这个 环境变量, 会有用这个环境变量的 去建立Redis。
  15. 而且libc 并不是默认的 分配器, 默认的是 jemalloc, 因为 jemalloc 被证明 有更少的 fragmentation problems 比libc。
  16. 但是如果你又没有jemalloc 而只有 libc 当然 make 出错。 所以加这么一个参数。

我应该就是这个问题

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

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

  1. [root@bogon redis-3.2.8]# make MALLOC=libc

编译成功:

其中出现了两个警告

  1. ldo.c: 在函数‘f_parser’中:
  2. ldo.c:496:7:<span style="color:#ff0000;background-color: rgb(204, 204, 204);"> <strong>警告</strong></span>:未使用的变量‘c’ [-Wunused-variable]
  3. int c = luaZ_lookahead(p->z);
  1. liblua.a(loslib.o):在函数‘os_tmpname’中:
  2. loslib.c:(.text+0x28c): 警告:the use of `tmpnam' is dangerous, better use `mkstemp'

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

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

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

  1. [root@bogon src]# ./redis-server
  2. 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
  3. 28198:M 24 Feb 14:04:55.230 * Increased maximum number of open files to 10032 (it was originally set to 1024).
  4. _._
  5. _.-``__ ''-._
  6. _.-``    `.  `_.  ''-._           Redis 3.2.8 (00000000/0) 64 bit
  7. .-`` .-```.  ```\/    _.,_ ''-._
  8. (    '      ,       .-`  | `,    )     Running in standalone mode
  9. |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
  10. |    `-._   `._    /     _.-'    |     PID: 28198
  11. `-._    `-._  `-./  _.-'    _.-'
  12. |`-._`-._    `-.__.-'    _.-'_.-'|
  13. |    `-._`-._        _.-'_.-'    |           http://redis.io
  14. `-._    `-._`-.__.-'_.-'    _.-'
  15. |`-._`-._    `-.__.-'    _.-'_.-'|
  16. |    `-._`-._        _.-'_.-'    |
  17. `-._    `-._`-.__.-'_.-'    _.-'
  18. `-._    `-.__.-'    _.-'
  19. `-._        _.-'
  20. `-.__.-'
  21. 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.
  22. 28198:M 24 Feb 14:04:55.234 # Server started, Redis version 3.2.8

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

我试过几个命令

  1. [root@bogon src]# ./redis-server -d
  1. [root@bogon src]# ./redis-server redis.conf
  1. [root@bogon src]# $redis-server
  1. [root@bogon src]# $redis-server$
  2. bash: -server$: 未找到命令...
  3. [root@bogon src]# $redis-server$
  4. bash: -server$: 未找到命令...
  5. [root@bogon src]# $redis-server $
  6. bash: -server: 未找到命令...
  7. [root@bogon src]# ./redis-server $
  8. 28241:C 24 Feb 14:07:23.503 # Fatal error, can't open config file '$'
  9. [root@bogon src]# ps -ef|grep redis
  10. root      28244   4439  0 14:07 pts/0    00:00:00 grep --color=auto redis
  11. [root@bogon src]# ./redis-cli
  12. Could not connect to Redis at 127.0.0.1:6379: Connection refused
  1. not connected> exit
  2. [root@bogon src]# redis-server ./redis.conf
  3. bash: redis-server: 未找到命令...
  4. [root@bogon src]# $redis-server ./redis.conf
  5. bash: -server: 未找到命令...
  6. [root@bogon src]# $ redis-server ./redis.conf
  7. bash: $: 未找到命令...
  8. [root@bogon src]# $ redis-server redis.conf

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

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

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

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

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

  1. [root@bogon src]# cd ../
  2. [root@bogon redis-3.2.8]# make install
  3. cd src && make install
  4. make[1]: 进入目录“/usr/local/redis-3.2.8/src”
  5. Hint: It's a good idea to run 'make test' ;)
  6. INSTALL install
  7. INSTALL install
  8. INSTALL install
  9. INSTALL install
  10. INSTALL install
  11. make[1]: 离开目录“/usr/local/redis-3.2.8/src”
  12. [root@bogon redis-3.2.8]#

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

  1. [root@bogon redis-3.2.8]# ./utils/install_server.sh
  2. Welcome to the redis service installer
  3. This script will help you easily set up a running redis server
  4. Please select the redis port for this instance: [6379] 6379^H^H^C

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

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

  1. [root@bogon redis-3.2.8]# ./utils/install_server.sh
  2. Welcome to the redis service installer
  3. This script will help you easily set up a running redis server
  4. Please select the redis port for this instance: [6379]
  5. Selecting default: 6379
  6. Please select the redis config file name [/etc/redis/6379.conf]
  7. Selected default - /etc/redis/6379.conf
  8. Please select the redis log file name [/var/log/redis_6379.log]
  9. 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>
  10. Please select the data directory for this instance [/var/lib/redis/6379]
  11. Selected default - /var/lib/redis/6379
  12. Please select the redis executable path [/usr/local/bin/redis-server]
  13. Selected config:
  14. Port           : 6379
  15. Config file    : /etc/redis/6379.conf
  1. <span style="color:#ff0000;">---这个Config file 位置的6379.conf文件是你将来修改远程连接时的文件位置,,设置密码,远程连接都需要来这里</span>
  1. Log file       : /var/log/redis_6379.log
  2. Data dir       : /var/lib/redis/6379
  3. Executable     : /usr/local/bin/redis-server
  4. Cli Executable : /usr/local/bin/redis-cli
  5. Is this ok? Then press ENTER to go on or Ctrl-C to abort.
  6. Copied /tmp/6379.conf => /etc/init.d/redis_6379
  1. <span style="color:#ff0000;">---->记住这个路径,如果上面改名以后服务名没有改变的时候可以到这里修改文件名 并且进入文件 将里面带有redis_6379 文件名改掉,我只改了两三个地方</span>
  1. Installing service...
  2. Successfully added to chkconfig!
  3. Successfully added to runlevels 345!
  4. Starting Redis server...
  5. Installation successful!

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

我都是默认的 回车继续

  1. Starting Redis server...

执行成功!!

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

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

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

  1. [root@bogon redis-3.2.8]# chkconfig --list
  2. 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
  3. 如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
  4. 欲查看对特定 target 启用的服务请执行
  5. 'systemctl list-dependencies [target]'。
  6. jexec           0:关 1:开 2:开 3:开 4:开 5:开 6:关
  7. netconsole      0:关 1:关 2:关 3:关 4:关 5:关 6:关
  8. network         0:关 1:关 2:开 3:开 4:开 5:开 6:关
  9. redis_6379      0:关 1:关 2:开 3:开 4:开 5:开 6:关

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

好了开机列表有了

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

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

  1. [root@bogon redis-3.2.8]# ps -ef|grep redis
  2. root      28679      1  0 14:15 ?        00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
  3. root      28807   4439  0 14:16 pts/0    00:00:00 grep --color=auto redis
  4. [root@bogon redis-3.2.8]# service redis_6379 stop
  5. Stopping ...
  6. Waiting for Redis to shutdown ...
  7. Redis stopped
  8. [root@bogon redis-3.2.8]# ps -ef|grep redis
  9. root      28830   4439  0 14:17 pts/0    00:00:00 grep --color=auto redis

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

  1. [root@bogon redis-3.2.8]# service redis_6379 start
  2. Starting Redis server...
  3. [root@bogon redis-3.2.8]# ps -ef|grep redis
  4. root      28843      1  0 14:17 ?        00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
  5. root      28847   4439  0 14:17 pts/0    00:00:00 grep --color=auto redis

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

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

  1. [root@bogon redis-3.2.8]# ./src/redis-cli
  2. 127.0.0.1:6379> keys *
  3. (empty list or set)

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

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

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

最后 设置允许远程访问:

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

  1. Config file    : /etc/redis/6379.conf

------

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

打开注释,后面设置密码

  1. requirepass 123456

-----

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

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

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

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

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

  1. ./redis-server redis.conf

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

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

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

  1. [root@bogon log]# systemctl start redisd
  2. Warning: redisd.service changed on disk. Run 'systemctl daemon-reload' to reload units.
  3. [root@bogon log]# cd /
  4. [root@bogon /]# systemctl daemon-reload
  5. [root@bogon /]# systemctl start redisd
  6. [root@bogon /]# ps -ef|grep redis
  7. root      33443      1  0 16:00 ?        00:00:00 /usr/local/bin/redis-server *:6379
  8. root      34249   4439  0 16:08 pts/0    00:00:00 grep --color=auto redis
  9. [root@bogon /]#

执行

  1. <pre name="code" class="html">[root@bogon /]# systemctl daemon-reload</pre>
  2. <pre></pre>
  3. <p></p>
  4. <pre></pre>
  5. <p></p>
  6. <p>然后启动 就可以了 </p>
  7. <p>有一段摘自网上的讲解  有兴趣的朋友可以看一下</p>
  8. <p></p>
  9. <pre name="code" class="html">Part III. 使用Redis启动脚本设置开机自启动
  10. 启动脚本
  11. 推荐在生产环境中使用启动脚本方式启动redis服务。启动脚本 redis_init_script 位于位于Redis的 /utils/ 目录下。
  12. #大致浏览下该启动脚本,发现redis习惯性用监听的端口名作为配置文件等命名,我们后面也遵循这个约定。
  13. #redis服务器监听的端口
  14. REDISPORT=6379
  15. #服务端所处位置,在make install后默认存放与`/usr/local/bin/redis-server`,如果未make install则需要修改该路径,下同。
  16. EXEC=/usr/local/bin/redis-server
  17. #客户端位置
  18. CLIEXEC=/usr/local/bin/redis-cli
  19. #Redis的PID文件位置
  20. PIDFILE=/var/run/redis_${REDISPORT}.pid
  21. #配置文件位置,需要修改
  22. CONF="/etc/redis/${REDISPORT}.conf"
  23. 配置环境
  24. 1. 根据启动脚本要求,将修改好的配置文件以端口为名复制一份到指定目录。需使用root用户。
  25. mkdir /etc/redis
  26. cp redis.conf /etc/redis/6379.conf
  27. 2. 将启动脚本复制到/etc/init.d目录下,本例将启动脚本命名为redisd(通常都以d结尾表示是后台自启动服务)。
  28. cp redis_init_script /etc/init.d/redisd
  29. 3.  设置为开机自启动
  30. 此处直接配置开启自启动 chkconfig redisd on 将报错误: service redisd does not support chkconfig
  31. 参照 此篇文章 ,在启动脚本开头添加如下两行注释以修改其运行级别:
  32. #!/bin/sh
  33. # chkconfig:   2345 90 10
  34. # description:  Redis is a persistent key-value database
  35. #
  36. 再设置即可成功。
  37. #设置为开机自启动服务器
  38. chkconfig redisd on
  39. #打开服务
  40. service redisd start
  41. #关闭服务
  42. service redisd stop</pre>地址是:http://blog.csdn.net/duerbin3/article/details/45313461
  43. <p></p>
  44. <p>共同学习!!<br>
  45. <br>
  46. </p>
  47. <p><span style="font-family:Microsoft YaHei; color:#666666"><span style="font-size:15px"><br>
  48. </span></span><br>
  49. </p>
  50. <p><br>
  51. <br>
  52. </p>
  53. <p><br>
  54. <br>
  55. <br>
  56. <br>
  57. <br>
  58. </p>
  59. <p><br>
  60. <br>
  61. <br>
  62. </p>
 
 

Linux下安装redis报错信息的更多相关文章

  1. linux下安装redis报错问题。

    1.使用tar -xzvf redis-2.4.5.tar.gz来解压安装包 2.使用make命令来编译Redis 如果出现错误需要查看是否缺少gcc gcc-c++ zmalloc.h:50:31: ...

  2. window下安装redis报错: creating server tcp listening socket 127.0.0.1:6379: bind No error

    window下安装redis报错: creating server tcp listening socket 127.0.0.1:6379: bind No error 解决: 如果没有配置环境,在安 ...

  3. linux下安装php报错configure: error: Cannot find MySQL header files under /usr/include/mysql.

    linux下安装php报错configure: error: Cannot find MySQL header files under /usr/include/mysql. 2013-03-04 1 ...

  4. Linux-Linux下安装redis报错"undefined reference to__sync_add_and_fetch_4"解决办法

    如果出现这种错误可以在make的时候加上CFLAGS="-march=i686" 即 make CFLAGS="-march=i686" ----------- ...

  5. Linux 下安装Python报错:zlib not available

    问题描述: 在Linux下安装Python时出现一个错误:zipimport.ZipImportError: can't decompress data; zlib not available 详细错 ...

  6. Linux下安装vim-plug报错:Failed to connect to raw.githubusercontent.com port 443: Connection refused

    安装vim-plug时,输入以下命令: curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.c ...

  7. Linux下安装php报错:libxml2 not found. Please check your libxml2 installation

    ubuntu/debian: apt-get install libxml2-dev centos/redhat: yum install libxml2-devel

  8. Windows安装redis报错处理(转!)

    要谈则谈,要打便打! ---2019.5.9,贸易战 转自:http://www.yayihouse.com/yayishuwu/chapter/1297 安装redis报错信息 [9204] 15 ...

  9. Linux下Oracle11G RAC报错:在安装oracle软件时报file not found一例

    Linux下Oracle11G RAC报错:在安装oracle软件时报file notfound一例 1.现象 之前安装一切都比較顺利,安装oracle软件时,进度到30%时报错:file not f ...

随机推荐

  1. How to: Use the Entity Framework Model First in XAF 如何:在 XAF 中使用EF ModelFirst

    This topic demonstrates how to use the Model First entity model and a DbContext entity container in ...

  2. Docker Compose部署Nexus3时的docker-compose,yml代码

    场景 Docker-Compose简介与Ubuntu Server 上安装Compose: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...

  3. 松软科技web课堂:随机Math.random()

    Math.random() 返回 0(包括) 至 1(不包括) 之间的随机数: 实例 Math.random(); // 返回随机数 JavaScript 随机整数 Math.random() 与 M ...

  4. 理解 Flutter 中的 Key

    概览 在 Flutter 中,大概大家都知道如何更新界面视图: 通过修改 Stata 去触发 Widget 重建,触发和更新的操作是 Flutter 框架做的. 但是有时即使修改了 State,Flu ...

  5. Java_foreach不能remove

    foreach 阿里巴巴java开发手册 [强制]不要在foreach循环里进行元素的remove/add操作.remove元素请使用Iterator方式,如果并发操作,需要对Iterator对象加锁 ...

  6. [PHP] RBAC权限与审批流的简单数据库构想

    权限部分:功能权限+数据权限 控制权限是界面按钮菜单的权限控制,数据权限是数据范围的控制 role(角色) ----------------- |id | ----------------- |nam ...

  7. MATLAB实例:绘制折线图

    MATLAB实例:绘制折线图 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 条形图的绘制见:MATLAB实例:绘制条形图 用MATLAB将几组不同的数 ...

  8. 将Excel表结构导入到Powerdesigner

    我们经常会在excel中设计整理表结构,整理完需要导入到Powerdesigner中,可以通过以下脚本来实现快速,具体操作方法: 打开PowerDesigner,新建模型,点击Tools|Execut ...

  9. [考试反思]1113csp-s模拟测试113:一念

    在这么考下去可以去混女队了2333 两天总分rank14,退役稳稳的 的确就是没状态.满脑子都是<包围保卫王国>ddp/LCT/ST,没好好考试. 我太菜了写题也写不出来考试也考不好(显然 ...

  10. 图解SynchronousQueue原理-公平模式

    SynchronousQueue原理详解-公平模式 一.介绍 SynchronousQueue是一个双栈双队列算法,无空间的队列或栈,任何一个对SynchronousQueue写需要等到一个对Sync ...