Linux下Redis服务器搭建

一、系统环境

  • 操作系统:CentOS 6.9
  • redis版本:redis-4.0.2

二、安装步骤

1. 安装预环境

运行以下命令安装预环境。

[root@redis02 redis-4.0.2]# yum -y install gcc make

2. 下载redis源代码文件并解压缩

下载完redis源代码后,运行以下命令进行解压缩。

[root@redis02 softwares]# tar -xzf redis-4.0.2.tar.gz

3. redis编译

运行make命令进行编译。

make命令执行完成编译后,会在src目录下生成6个可执行文件,分别是redis-server、redis-cli、redis-benchmark、redis-check-aof、redis-check-dump、redis-sentinel。

4. redis安装配置

运行make install命令。

命令执行后会将make编译生成的可执行文件拷贝到/usr/local/bin目录下,如下图。

然后,运行./utils/install_server.sh配置向导来配置redis,并且可以将redis服务加到开机自启动中。【重要】

5. redis服务查看,开启和关闭

此时redis服务已经启动了。可以通过以下命令来操作redis了。

查看redis的运行状态:

[root@redis02 redis-4.0.2]# service redis_6379 status

关闭redis服务:

[root@redis02 redis-4.0.2]# service redis_6379 stop

开启redis服务:

[root@redis02 redis-4.0.2]# service redis_6379 start

最后可以通过redis内置的客户端工具来测试下:

[root@redis02 ~]# redis-cli
127.0.0.1:6379> get name

(nil)

127.0.0.1:6379> set name mcgrady

OK

127.0.0.1:6379> get name

"mcgrady"

127.0.0.1:6379>

可以看到,redis服务已经成功配置好了!

三、注意事项

1. 运行make命令报错?

错误信息如下:

make[3]: gcc: Command not found

/bin/sh: cc: command not found

解决方案:

因为预环境没有安装,运行以下命令安装预环境。

[root@redis02 redis-4.0.2]# yum -y install gcc make

2. 安装完预环境后运行make命令报以下错误?

错误信息:

zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory

zmalloc.h:55:2: error: #error "Newer version of jemalloc required"

解决方案:

运行以下命令。

make MALLOC=libc

3. 运行make test命令报以下错误?

错误信息:

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

解决方案:

运行以下命令安装tcl。

[root@redis02 redis-4.0.2]# yum -y install tcl

4. 调用ConnectionMultiplexer.Connect创建连接的时候报错?

错误信息:

It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. UnableToResolvePhysicalConnection on TIME

解决方案:

1)关闭保护模式,注意默认是打开的。

2)绑定IP,注意默认只绑定了127.0.0.1。

有用命令:

telnet 192.168.1.29 6379,可以直接测试客户端是否能连上服务器,如果通的话,基本上就没有什么问题。

ps -aux | grep redis ,查看redis的进程,看redis是否正常启动。

标签:RedisLinux 发布于:2019-11-04 21:44:11