java开发之AWS redis下载和配置

本文介绍了在AWS中redis的下载以及相关的配置

一.从官网下载redis.

下载文件名为:redis-4.0.9.tar.gz

二.将下载的redis文件上传AWS.

1.通过SCP上传redis-4.0.9.tar.gz文件

1
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文件上传至服务器/data文件夹下.

三.解压redis-4.0.9.tar.gz文件并修改文件名.

解压文件命令如下:

1
tar -zxvf redis-4.0.9.tar.gz

此时当前路径下的文件名为redis-4.0.9.如果需修改文件名,使用以下命令:

1
mv redis-4.0.9 redis

命令含义为:mv 原文件名 修改后文件名

四.redis配置.

1.进入redis文件中.

1
cd /data/redis

2.执行make命令.

1
make

如果出现以下错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
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

根据gcc: Command not found提示可知,缺少gcc,那就安装gcc.
通过yum安装gcc的命令:

1
sudo yum install gcc

执行成功后显示:

1
2
3
4
5
6
7
8
9
10
11
12
13
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.执行make test命令.

1
make test

如果出现以下错误:

1
2
3
4
5
6
7
8
9
10
11
12
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’

根据zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory提示可使用以下命令解决:

1
make MALLOC=libc

显示

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

4.重新执行make test命令

1
make test

5.执行make install命令

1
make install

6.进入redis下的src文件.

1
cd src

7.开启redis服务

1
./redis-server

如果以下信息表示redis服务开启成功.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
                _._                                                 
           _.-``__ ''-._                                            
      _.-``    `.  `_.  ''-._           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是否开启

1
./redis-cli

显示:

1
127.0.0.1:6379>

输入

1
ping

显示:pong,表示,redis服务可以使用.
也可以输入keys *查看redis缓存中的所有key.

1
keys *

五.redis自启动配置.

1.进入redis文件

1
cd /data/redis

2.将redis.conf文件复制到etc文件目录下

1
cp redis.conf /etc

3.进入etc文件

1
cd /etc

此时,etc文件下已经有redis.conf文件.

4.修改redis.conf文件中的daemonize no参数为daemonize yes.

1
vim redis.conf

输入i进入编辑状态.

1
i

找到daemonize no参数,改为daemonize yes.
强制写入保存并退出

1
:wq!

5.使配置生效.

1
redis-server /etc/redis.conf

最终显示:

1
2
3
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

总结:到此,AWS中的redis配置就告一段落.


CSDN

Java开发之AWS redis下载和配置