Centos7 下Redis4.0.6版本的安装及常见问题。

1、     下载redis压缩包

redis-4.0.6.tar.gz

2、     上传并解压

1 [[email protected]]# tar -zxvf redis-4.0.6.tar.gz

3、     编译测试

跳转到解压目录

1 [[email protected]]# cd redis-4.0.6

编译(可直接使用make命令进行编译)

1 [[email protected] redis-4.0.6]# make MALLOC=libc

编译最后显示

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

安装测试,执行make test命令。

1[[email protected] redis-4.0.6]# cd src

2[[email protected] src]# make test

3All tests passed without errors

出现“All tests passed without errors”说明无误。

4、     安装

1[[email protected] redis-4.0.6]# cd src && make installl

出现类似如下图,安装成功。

Redis安装(Linux)

安装完成后可以将没用的源文件删掉

1[[email protected] src]# rm *.c

2[[email protected] src]# rm *.o

3[[email protected] src]# rm *.h

5、     配置

redis的很多配置都通过配置文件进行调整,配置文件为解压目录下的redis.conf文件。

通过vim命令修改:

1[[email protected] redis-4.0.6]# vim redis.conf

1.  修改后台启动

修改配置文件:

daemonize no

修改为:

daemonize yes

如图

Redis安装(Linux)

2.  修改保护模式

当前场景没有使用保护模式,通过配置文件关闭。

关闭保护模式,注释掉ip绑定。

修改配置文件:

将:

bind127.0.0.1

protected-mode yes

修改为:

#bind 127.0.0.1

protected-mode no

如图

Redis安装(Linux)

6、     启动redis

1.  指定配置文件启动(推荐)

前面配置文件中如果修改了后台启动,即:

daemonize yes

可以后通过指定配置文件的方式启动(一般以该方式启动,推荐使用)。

指定redis.conf文件启动,命令如下:

1[[email protected] src]# ./redis-server /usr/local/redis-4.0.6/redis.conf

出现类似如下信息,启动成功。

114337:C 29 Jun 14:06:26.693 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

214337:C 29 Jun 14:06:26.693 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=14337, just started

3 14337:C 29 Jun 14:06:26.693 # Configuration loaded

2.  前台启动

执行下执行

1[[email protected] src]# ./redis-server

如图,说明redis启动成功:

该方式是前台启动,这种启动方式绑定终端,需要一直打开窗口,不能进行其他操作,不太方便。不建议使用。

Redis安装(Linux)

建议通过指定配置文件进行后台启动。

7、     测试

 1#首先连接客户端

 2[[email protected] src]# ./redis-cli

 3#检查网络是否可以

 4127.0.0.1:6379> ping

 5PONG

 6#设置一个键值对

 7127.0.0.1:6379> set hello world

 8OK

 9#获取刚刚设置的键值对

10127.0.0.1:6379> get hello

11"world"

12#查看所有的键

13127.0.0.1:6379> keys *

141)"hello"

15#删除name这个键

16127.0.0.1:6379> del hello

17(integer)1

18127.0.0.1:6379> keys *

19(empty list or set)

20127.0.0.1:6379> 

8、     关闭redis进程

1.  启动终端关闭

如果是前台启动方式,可以通过在启动终端按ctrl + c可以退出。

2.  客户端命令关闭

1[[email protected] src]# redis-cli shutdown [save|nosave]

或则

1[[email protected] src]# redis-cli

2127.0.0.1:6379> shutdown [save|nosave]

shutdown有一个参数,代表关闭redis服务前是否生产持久化文件

shutdown save|nosave

3.  系统命令关闭进程

因为Redis可以妥善处理SIGTERM信号,所以直接kill也是可以的。

首先使用ps -aux | grep redis或者(ps -ef | grep redis)查看redis进程。

1[[email protected] src]# ps -aux | grep redis

2root 14338 0.0 0.1 43612 11320 ? Ssl 14:06 0:00 ./src/redis-server *:6379

3root 14347 0.0 0.0 9256 1552 pts/0 S+ 14:08  0:00 grep --color=auto redis

使用kill命令杀死进程。

1[[email protected] src]# kill 14338

注意:

尽量不要使用Kill 9方式关闭redis进程,这样redis不会进行持久化操作,除此之外,还会造成缓冲区等资源不能优雅关闭,极端情况下会造成AOF和复制丢失数据的情况

另外pkill redis-server命令可以关闭所有redis相关服务(例如哨兵)。

9、     常见问题

1.     缺少依赖包TCL

 测试安装环节,执行下面命令时

1[[email protected] src]# make test

如果出现如下错误

1You need tcl 8.5 or newer in order to run the Redis test

2make: *** [test]Error 1

则按照下面步骤处理

TCL(Tool Command Language)工具脚本语言,是Linux内的一种语言包。,这里需要先安装tcl。

1、先去这里下载:

http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz

2、然后将其拷贝至服务器

3、然后解压对于.tar.gz的后缀文件可以使用tar zxvf *.tar.gz解压

1[[email protected] local]# tar zxvf tcl8.6.1-src.tar.gz

4、安装Tcl

为编译Tcl 做准备:

1[[email protected] local]# cd tcl8.6.1/

2[[email protected] tcl8.6.1]# cd unix/

3[[email protected] unix]# ./configure

编译软件包:

1[[email protected] unix]# make

安装软件包:

1[[email protected] unix]# make install

再次回到redis相应目录中重新测试make test,当各项检查都显示ok时,出现如下提示说明无误。

1All tests passed without errors

欢迎关注公众号:

零点小时光

lingdianxiaoshiguang

Redis安装(Linux)

相关文章:

  • 2021-05-10
猜你喜欢
  • 2021-11-24
  • 2022-01-17
  • 2021-11-05
  • 2021-10-31
  • 2021-05-05
相关资源
相似解决方案