Linux下安裝redis報錯信息


 

redis在Linux安裝報錯

標簽: redislinuxcentos
 分類:

1.下載Redis-3.2.8.tar.gz 壓縮包

解壓 :

 

[plain]  view plain  copy
 
  1. # tar zxf redis-3.2.8.tar.gz  
解壓以后 需要編譯,切到redis解壓目錄下 ,(ll 是查看當前目錄)

 

 

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

 

編譯命令是make 

 

[plain]  view plain  copy
 
  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”  
編譯過程中出現報錯

 

 

[html]  view plain  copy
 
  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編譯器沒安裝
這時候只要安裝編譯器即可

 

 

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

安裝完成提示

 

 

[html]  view plain  copy
 
  1. 已安裝:  
  2.   gcc.x86_64 0:4.8.5-11.el7                                               gcc-c++.x86_64 0:4.8.5-11.el7                                                
  3.   
  4. 作為依賴被安裝:  
  5.   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           
  6.   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             
  7.   
  8. 更新完畢:  
  9.   make.x86_64 1:3.82-23.el7                                                                                                                             
  10.   
  11. 作為依賴被升級:  
  12.   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      
  13.   libstdc++.x86_64 0:4.8.5-11.el7      
  14.   
  15. 完畢!  
如果gcc編譯器安裝過程中報錯,可以到百度搜索解決,歡迎評論中補充!!

 

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

編譯器安裝完成之后再redis-3.2.8目錄下執行make命令

 

[html]  view plain  copy
 
  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  

又出現錯誤,上網查了之后說是

 

 

[html]  view plain  copy
 
  1. 原因分析  
  2. 在README 有這個一段話。  
  3.   
  4. Allocator    
  5. ---------    
  6.    
  7. Selecting a non-default memory allocator when building Redis is done by setting    
  8. the `MALLOC` environment variable. Redis is compiled and linked against libc    
  9. malloc by default, with the exception of jemalloc being the default on Linux    
  10. systems. This default was picked because jemalloc has proven to have fewer    
  11. fragmentation problems than libc malloc.    
  12.    
  13. To force compiling against libc malloc, use:    
  14.    
  15.     % make MALLOC=libc    
  16.    
  17. To compile against jemalloc on Mac OS X systems, use:    
  18.    
  19.     % make MALLOC=jemalloc  
  20.   
  21. 說關於分配器allocator, 如果有MALLOC  這個 環境變量, 會有用這個環境變量的 去建立Redis。  
  22.   
  23. 而且libc 並不是默認的 分配器, 默認的是 jemalloc, 因為 jemalloc 被證明 有更少的 fragmentation problems 比libc。  
  24.   
  25. 但是如果你又沒有jemalloc 而只有 libc 當然 make 出錯。 所以加這么一個參數。  

 

我應該就是這個問題

沒有jemalloc 而只有 libc 當然 make 出錯。

這時候在編譯過程時增加一個參數

 

[html]  view plain  copy
 
  1. [root@bogon redis-3.2.8]# make MALLOC=libc  
編譯成功:

 

其中出現了兩個警告

 

[html]  view plain  copy
 
  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);  
[html]  view plain  copy
 
  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測試

 

[html]  view plain  copy
 
  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.   
  22. 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.  
  23. 28198:M 24 Feb 14:04:55.234 # Server started, Redis version 3.2.8  

這樣太麻煩,我想有沒有別的辦法讓他后台運行呢?

 

我試過幾個命令

 

[html]  view plain  copy
 
  1. [root@bogon src]# ./redis-server -d  
[html]  view plain  copy
 
  1. [root@bogon src]# ./redis-server redis.conf  
[html]  view plain  copy
 
  1. [root@bogon src]# $redis-server  
[html]  view plain  copy
 
  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  
[html]  view plain  copy
 
  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目錄下;

 

[html]  view plain  copy
 
  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.   
  6. Hint: It's a good idea to run 'make test' ;)  
  7.   
  8.     INSTALL install  
  9.     INSTALL install  
  10.     INSTALL install  
  11.     INSTALL install  
  12.     INSTALL install  
  13. make[1]: 離開目錄“/usr/local/redis-3.2.8/src”  
  14. [root@bogon redis-3.2.8]#   

 

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

 

[html]  view plain  copy
 
  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.   
  5. Please select the redis port for this instance: [6379] 6379^H^H^C  
我開始以為提示我輸入6379 我輸入了一下,但是打回車,刪也刪不掉,只好Ctrl+c退出,

 

后來重新執行:./utils/install_server.sh

 

[html]  view plain  copy
 
  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.   
  5. Please select the redis port for this instance: [6379]   
  6. Selecting default: 6379  
  7. Please select the redis config file name [/etc/redis/6379.conf]   
  8. Selected default - /etc/redis/6379.conf  
  9. Please select the redis log file name [/var/log/redis_6379.log]   
  10. 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>  
  11. Please select the data directory for this instance [/var/lib/redis/6379]   
  12. Selected default - /var/lib/redis/6379  
  13. Please select the redis executable path [/usr/local/bin/redis-server]   
  14. Selected config:  
  15. Port           : 6379  
  16. Config file    : /etc/redis/6379.conf  
[html]  view plain  copy
 
  1. <span style="color:#ff0000;">---這個Config file 位置的6379.conf文件是你將來修改遠程連接時的文件位置,,設置密碼,遠程連接都需要來這里</span>  
[html]  view plain  copy
 
  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    
[html]  view plain  copy
 
  1. <span style="color:#ff0000;">---->記住這個路徑,如果上面改名以后服務名沒有改變的時候可以到這里修改文件名 並且進入文件 將里面帶有redis_6379 文件名改掉,我只改了兩三個地方</span>  
[html]  view plain  copy
 
  1.   
[html]  view plain  copy
 
  1. Installing service...  
  2. Successfully added to chkconfig!  
  3. Successfully added to runlevels 345!  
  4. Starting Redis server...  
  5. Installation successful!  

發現原來是 [6379] 是提示的默認值 直接敲回車會繼續執行,也就是說 每一次卡住 都是提示是否修改默認值,

 

我都是默認的 回車繼續

 

[html]  view plain  copy
 
  1. Starting Redis server...  
執行成功!!

 

到這里redis基本上已經安裝成功了,

但是以我嚴謹的態度,我決定查看一下到底安裝成功有什么體現!

接下來 查看開機啟動列表里面 有沒有redis服務

 

[html]  view plain  copy
 
  1. [root@bogon redis-3.2.8]# chkconfig --list  
  2.   
  3. 注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。   
  4.       如果您想列出 systemd 服務,請執行 'systemctl list-unit-files'。  
  5.       欲查看對特定 target 啟用的服務請執行  
  6.       'systemctl list-dependencies [target]'。  
  7.   
  8. jexec           0:關 1:開 2:開 3:開 4:開 5:開 6:關  
  9. netconsole      0:關 1:關 2:關 3:關 4:關 5:關 6:關  
  10. network         0:關 1:關 2:開 3:開 4:開 5:開 6:關  
  11. redis_6379      0:關 1:關 2:開 3:開 4:開 5:開 6:關  
1-6這幾項都代表什么可以去百度一下 ,如果有人懂得 希望可以評論解釋下 我反正不知道 委屈

 

好了開機列表有了

查看一下進程中有沒有redis,並且停止服務看一下剩下什么

(停止redis的進程 可以用kill+28679 結束pid停用服務)

 

[html]  view plain  copy
 
  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服務,並且查看進程

 

 

[html]  view plain  copy
 
  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

 

[html]  view plain  copy
 
  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配置文件 修改里面的三個地方即可

 

[html]  view plain  copy
 
  1. Config file    : /etc/redis/6379.conf  

 

 

------

修改密碼時可以試試來這里 配置文件的這個位置   # requirepass 

打開注釋,后面設置密碼

 

[html]  view plain  copy
 
  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所在目錄下 啟動

 

[html]  view plain  copy
 
  1. ./redis-server redis.conf  
這是需要配置文件的時候 這樣啟動,配置文件就會生效了 但是我不喜歡手動啟動 之后需要重新開一個窗口,所以我讓他開機自啟了

 

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

按照上面修改以后如果不能啟動服務了

 

[html]  view plain  copy
 
  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 /]#   

執行
[html]  view plain  copy
 
  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.   
  13. #大致瀏覽下該啟動腳本,發現redis習慣性用監聽的端口名作為配置文件等命名,我們后面也遵循這個約定。  
  14. #redis服務器監聽的端口  
  15. REDISPORT=6379  
  16. #服務端所處位置,在make install后默認存放與`/usr/local/bin/redis-server`,如果未make install則需要修改該路徑,下同。  
  17. EXEC=/usr/local/bin/redis-server  
  18. #客戶端位置  
  19. CLIEXEC=/usr/local/bin/redis-cli  
  20. #Redis的PID文件位置  
  21. PIDFILE=/var/run/redis_${REDISPORT}.pid  
  22. #配置文件位置,需要修改  
  23. CONF="/etc/redis/${REDISPORT}.conf"  
  24. 配置環境  
  25. 1. 根據啟動腳本要求,將修改好的配置文件以端口為名復制一份到指定目錄。需使用root用戶。  
  26.   
  27. mkdir /etc/redis  
  28. cp redis.conf /etc/redis/6379.conf  
  29.  2. 將啟動腳本復制到/etc/init.d目錄下,本例將啟動腳本命名為redisd(通常都以d結尾表示是后台自啟動服務)。  
  30.   
  31. cp redis_init_script /etc/init.d/redisd  
  32.  3.  設置為開機自啟動  
  33.   
  34. 此處直接配置開啟自啟動 chkconfig redisd on 將報錯誤: service redisd does not support chkconfig   
  35. 參照 此篇文章 ,在啟動腳本開頭添加如下兩行注釋以修改其運行級別:  
  36.   
  37. #!/bin/sh  
  38. # chkconfig:   2345 90 10  
  39. # description:  Redis is a persistent key-value database  
  40. #  
  41.  再設置即可成功。  
  42.   
  43. #設置為開機自啟動服務器  
  44. chkconfig redisd on  
  45. #打開服務  
  46. service redisd start  
  47. #關閉服務  
  48. service redisd stop</pre>地址是:http://blog.csdn.net/duerbin3/article/details/45313461   
  49. <p></p>  
  50. <p>共同學習!!<br>  
  51. <br>  
  52. </p>  
  53. <p><span style="font-family:Microsoft YaHei; color:#666666"><span style="font-size:15px"><br>  
  54. </span></span><br>  
  55. </p>  
  56. <p><br>  
  57. <br>  
  58. </p>  
  59. <p><br>  
  60. <br>  
  61. <br>  
  62. <br>  
  63. <br>  
  64. </p>  
  65. <p><br>  
  66. <br>  
  67. <br>  
  68. </p>  
  69.      
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM