分類:
版權聲明:本文為博主原創文章,未經博主允許不得轉載。
1.下載Redis-3.2.8.tar.gz 壓縮包
解壓 :
- # tar zxf redis-3.2.8.tar.gz
- [root@bogon local]# cd redis-3.2.8
- [root@bogon redis-3.2.8]# ll
編譯命令是make
- [root@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”
- 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
這時候只要安裝編譯器即可
- [root@bogon redis-3.2.8]# yum install -y gcc g++ gcc-c++ make
安裝完成提示
- 已安裝:
- 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
- 完畢!
------------------------------
編譯器安裝完成之后再redis-3.2.8目錄下執行make命令
- [root@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
又出現錯誤,上網查了之后說是
- 原因分析
- 在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 出錯。
這時候在編譯過程時增加一個參數
- [root@bogon redis-3.2.8]# make MALLOC=libc
其中出現了兩個警告
- 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);
- liblua.a(loslib.o):在函數‘os_tmpname’中:
- loslib.c:(.text+0x28c): 警告:the use of `tmpnam' is dangerous, better use `mkstemp'
說實在的 由於時間關系,警告沒有考慮是怎么回事,如果有人願意分享一下不勝感激!
===============
現在redis可以說能用了,執行命令啟動redis后 還需要再打開一個窗口執行server-cli測試
- [root@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
這樣太麻煩,我想有沒有別的辦法讓他后台運行呢?
我試過幾個命令
- [root@bogon src]# ./redis-server -d
- [root@bogon src]# ./redis-server redis.conf
- [root@bogon src]# $redis-server
- [root@bogon src]# $redis-server$
- bash: -server$: 未找到命令...
- [root@bogon src]# $redis-server$
- bash: -server$: 未找到命令...
- [root@bogon src]# $redis-server $
- bash: -server: 未找到命令...
- [root@bogon src]# ./redis-server $
- 28241:C 24 Feb 14:07:23.503 # Fatal error, can't open config file '$'
- [root@bogon src]# ps -ef|grep redis
- root 28244 4439 0 14:07 pts/0 00:00:00 grep --color=auto redis
- [root@bogon src]# ./redis-cli
- Could not connect to Redis at 127.0.0.1:6379: Connection refused
- not connected> exit
- [root@bogon src]# redis-server ./redis.conf
- bash: redis-server: 未找到命令...
- [root@bogon src]# $redis-server ./redis.conf
- bash: -server: 未找到命令...
- [root@bogon src]# $ redis-server ./redis.conf
- bash: $: 未找到命令...
- [root@bogon src]# $ redis-server redis.conf
都不可以,只能繼續上網搜
網上搜索了一下發現百度經驗的一片分享:
http://jingyan.baidu.com/article/6dad507510ea07a123e36e95.html
設置如何開機啟動我就照做了:(主要是記錄自己的操作和總結經驗 以下拷貝的會比較多)
首先是 執行make install。會將make編譯生成的可執行文件拷貝到/usr/local/bin目錄下;
- [root@bogon src]# cd ../
- [root@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”
- [root@bogon redis-3.2.8]#
接下來 懵了,不知道怎么回事卡住了
- [root@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
后來重新執行:./utils/install_server.sh
- [root@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
- <span style="color:#ff0000;">---這個Config file 位置的6379.conf文件是你將來修改遠程連接時的文件位置,,設置密碼,遠程連接都需要來這里</span>
- 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
- <span style="color:#ff0000;">---->記住這個路徑,如果上面改名以后服務名沒有改變的時候可以到這里修改文件名 並且進入文件 將里面帶有redis_6379 文件名改掉,我只改了兩三個地方</span>
- Installing service...
- Successfully added to chkconfig!
- Successfully added to runlevels 345!
- Starting Redis server...
- Installation successful!
發現原來是 [6379] 是提示的默認值 直接敲回車會繼續執行,也就是說 每一次卡住 都是提示是否修改默認值,
我都是默認的 回車繼續
- Starting Redis server...
到這里redis基本上已經安裝成功了,
但是以我嚴謹的態度,我決定查看一下到底安裝成功有什么體現!
接下來 查看開機啟動列表里面 有沒有redis服務
- [root@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:關
好了開機列表有了
查看一下進程中有沒有redis,並且停止服務看一下剩下什么
(停止redis的進程 可以用kill+28679 結束pid停用服務)
- [root@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
- [root@bogon redis-3.2.8]# service redis_6379 stop
- Stopping ...
- Waiting for Redis to shutdown ...
- Redis stopped
- [root@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服務,並且查看進程
- [root@bogon redis-3.2.8]# service redis_6379 start
- Starting Redis server...
- [root@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
- [root@bogon redis-3.2.8]# ./src/redis-cli
- 127.0.0.1:6379> keys *
- (empty list or set)
剩下的就是redis的操作了 ,不多說了 Linux安裝完成!
=============================
最后 設置允許遠程訪問:
找到上面的6379.conf配置文件 修改里面的三個地方即可
- Config file : /etc/redis/6379.conf
------
修改密碼時可以試試來這里 配置文件的這個位置 # requirepass
打開注釋,后面設置密碼
- requirepass 123456
-----
1 bind :127.0.0.1 默認是沒有注釋掉的 ,給他注釋掉
2 redis3.2后新增protected-mode配置,默認是yesprotected-mode 設置為no 關閉保護
3 daemonize 默認是yes 如果被注釋了就打開注釋 並且設置為no
開啟這三個就可以實現遠程訪問
注意:在設置 .conf文件時 如果是手動啟動 需要到redis根目錄的redis.conf所在目錄下 啟動
- ./redis-server redis.conf
-------------
按照上面修改以后如果不能啟動服務了
- [root@bogon log]# systemctl start redisd
- Warning: redisd.service changed on disk. Run 'systemctl daemon-reload' to reload units.
- [root@bogon log]# cd /
- [root@bogon /]# systemctl daemon-reload
- [root@bogon /]# systemctl start redisd
- [root@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
- [root@bogon /]#
執行
- <pre name="code" class="html">[root@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>
