不败君

前端萌新&初级后端攻城狮

Centos编译安装Redis

Centos编译安装Redis

2020-10-21 13:27:42

围观(2204)

访问 Redis 官网的下载栏目:https://redis.io/download

获取到最新稳定版的下载地址:https://download.redis.io/releases/redis-6.0.8.tar.gz

在 Centos 下载源码:

wget https://download.redis.io/releases/redis-6.0.8.tar.gz

下载完成后,解压:

tar -xzf redis-6.0.8.tar.gz

进入刚解压的目录并执行编译:

make

执行完后进入 src 目录并执行命令开启 Redis:

./redis-server

如果返回则说明成功开启 Redis:

[root@localhost src]# ./redis-server
9841:C 21 Oct 2020 13:17:28.966 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9841:C 21 Oct 2020 13:17:28.966 # Redis version=6.0.8, bits=64, commit=00000000, modified=0, pid=9841, just started
9841:C 21 Oct 2020 13:17:28.966 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
9841:M 21 Oct 2020 13:17:28.967 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 6.0.8 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 9841
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

9841:M 21 Oct 2020 13:17:28.969 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
9841:M 21 Oct 2020 13:17:28.969 # Server initialized
9841:M 21 Oct 2020 13:17:28.969 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
9841:M 21 Oct 2020 13:17:28.969 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo madvise > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled (set to 'madvise' or 'never').
9841:M 21 Oct 2020 13:17:28.984 * Ready to accept connections

关闭当前的窗口,再另外进行 ssh 连接服务器进入到 redis 的 src 并执行:

./redis-cli

则可以使用 Redis 的客户端模式。


常见错误

如果报错:

make[3]: cc:命令未找到
make[3]: *** [net.o] 错误 127
make[3]: 离开目录“/root/redis-6.0.8/deps/hiredis”
make[2]: *** [hiredis] 错误 2
make[2]: 离开目录“/root/redis-6.0.8/deps”
make[1]: [persist-settings] 错误 2 (忽略)
    CC adlist.o
/bin/sh: cc: 未找到命令
make[1]: *** [adlist.o] 错误 127
make[1]: 离开目录“/root/redis-6.0.8/src”
make: *** [all] 错误 2

则需要安装 gcc:

yum install gcc-c++


如果报错:

server.c:5304:176: 错误:‘struct redisServer’没有名为‘maxmemory’的成员
         serverLog(LL_WARNING,"WARNING: You specified a maxmemory value that is less than 1MB (current value is %llu bytes). Are you sure this is what you really want?", server.maxmemory);

                                           ^
server.c:5307:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员
     redisSetCpuAffinity(server.server_cpulist);
                               ^
server.c: 在函数‘hasActiveChildProcess’中:
server.c:1480:1: 警告:在有返回值的函数中,控制流程到达函数尾 [-Wreturn-type]
 }
 ^
server.c: 在函数‘allPersistenceDisabled’中:
server.c:1486:1: 警告:在有返回值的函数中,控制流程到达函数尾 [-Wreturn-type]
 }
 ^
server.c: 在函数‘writeCommandsDeniedByDiskError’中:
server.c:3897:1: 警告:在有返回值的函数中,控制流程到达函数尾 [-Wreturn-type]
 }
 ^
server.c: 在函数‘iAmMaster’中:
server.c:5094:1: 警告:在有返回值的函数中,控制流程到达函数尾 [-Wreturn-type]
 }
 ^
make[1]: *** [server.o] 错误 1
make[1]: 离开目录“/root/redis-6.0.8/src”
make: *** [all] 错误 2

需要更新版本(依次执行命令):

yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash


每次报错安装好了依赖之后可以清空上次编译失败的文件再继续执行:

make distclean


本文地址 : bubaijun.com/page.php?id=212

版权声明 : 未经允许禁止转载!

上一篇文章: Laravel 批量插入数据并去重

下一篇文章: PHP使用Redis实现队列

评论:我要评论
发布评论:
Copyright © 不败君 粤ICP备18102917号-1

不败君

首 页 作 品 微 语