本文介紹了在AWS中redis的下載以及相關(guān)的配置
一.從官網(wǎng)下載redis.
下載文件名為:redis-4.0.9.tar.gz
二.將下載的redis文件上傳AWS.
1.通過SCP上傳redis-4.0.9.tar.gz文件
scp -i /Users/lby/key.pem -r /Users/lby/Desktop/AWS文件/redis-4.0.9.tar.gz ec2-user@123.123.123.1523:/data
以上命令表示:將redis-4.0.9.tar.gz文件上傳至服務(wù)器/data文件夾下.
- 注意:
scp的具體用法可以參考<Java開發(fā)>之AWS jdk下載和配置標(biāo)題二中的講解.
三.解壓redis-4.0.9.tar.gz文件并修改文件名.
解壓文件命令如下:
tar -zxvf redis-4.0.9.tar.gz
此時(shí)當(dāng)前路徑下的文件名為redis-4.0.9.如果需修改文件名,使用以下命令:
mv redis-4.0.9 redis
命令含義為:mv 原文件名 修改后文件名
四.redis配置.
1.進(jìn)入redis文件中.
cd /data/redis
2.執(zhí)行make命令.
make
如果出現(xiàn)以下錯(cuò)誤:
make[3]: Entering directory `/data/installfiles/redis-4.0.9/deps/hiredis'
gcc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c
make[3]: gcc: Command not found
make[3]: *** [net.o] Error 127
make[3]: Leaving directory `/data/installfiles/redis-4.0.9/deps/hiredis'
make[2]: *** [hiredis] Error 2
make[2]: Leaving directory `/data/installfiles/redis-4.0.9/deps'
make[1]: [persist-settings] Error 2 (ignored)
CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/data/installfiles/redis-4.0.9/src'
make: *** [test] Error 2
根據(jù)gcc: Command not found提示可知,缺少gcc,那就安裝gcc.
通過yum安裝gcc的命令:
sudo yum install gcc
執(zhí)行成功后顯示:
Installed:
gcc.noarch 0:4.8.5-1.22.amzn1
Dependency Installed:
cpp48.x86_64 0:4.8.5-28.142.amzn1
gcc48.x86_64 0:4.8.5-28.142.amzn1
glibc-devel.x86_64 0:2.17-222.173.amzn1
glibc-headers.x86_64 0:2.17-222.173.amzn1
kernel-headers.x86_64 0:4.14.33-51.37.amzn1
libgcc48.x86_64 0:4.8.5-28.142.amzn1
libgomp.x86_64 0:6.4.1-1.45.amzn1
libmpc.x86_64 0:1.0.1-3.3.amzn1
mpfr.x86_64 0:3.1.1-4.14.amzn1
Complete!
3.執(zhí)行make test命令.
make test
如果出現(xiàn)以下錯(cuò)誤:
make[1]: Entering directory `/data/installfiles/redis-4.0.9/src'
CC Makefile.dep
make[1]: Leaving directory `/data/installfiles/redis-4.0.9/src'
make[1]: Entering directory `/data/installfiles/redis-4.0.9/src'
CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
#include <jemalloc/jemalloc.h>
^
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/data/installfiles/redis-4.0.9/src’
根據(jù)zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory提示可使用以下命令解決:
make MALLOC=libc
顯示
Hint: It's a good idea to run 'make test' ;)
4.重新執(zhí)行make test命令
make test
5.執(zhí)行make install命令
make install
6.進(jìn)入redis下的src文件.
cd src
7.開啟redis服務(wù)
./redis-server
如果以下信息表示redis服務(wù)開啟成功.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.8 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 39798
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | [http://redis.io](http://redis.io)
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
39798:M 10 Apr 17:21:48.446 # Server initialized
39798:M 10 Apr 17:21:48.447 * Ready to accept connections
8.查看redis是否開啟
./redis-cli
顯示:
127.0.0.1:6379>
輸入
ping
顯示:pong,表示,redis服務(wù)可以使用.
也可以輸入keys *查看redis緩存中的所有key.
keys *
五.redis自啟動(dòng)配置.
1.進(jìn)入redis文件
cd /data/redis
2.將redis.conf文件復(fù)制到etc文件目錄下
cp redis.conf /etc
3.進(jìn)入etc文件
cd /etc
此時(shí),etc文件下已經(jīng)有redis.conf文件.
4.修改redis.conf文件中的daemonize no參數(shù)為daemonize yes.
vim redis.conf
輸入i進(jìn)入編輯狀態(tài).
i
找到daemonize no參數(shù),改為daemonize yes.
強(qiáng)制寫入保存并退出
:wq!
5.使配置生效.
redis-server /etc/redis.conf
最終顯示:
6691:C 23 May 06:59:02.250 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
6691:C 23 May 06:59:02.250 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=6691, just started
6691:C 23 May 06:59:02.250 # Configuration loaded