> 数据库 > Redis >

CentOS安装Redis单机版

概述
每次安装总是会忘记一些命令或遇到问题,考虑到每次搜索然后看到不那么靠谱的文章导致浪费不少时间,故有此文,仅仅是记录一下,持续更新。

单机版
Linux
注:此文Linux版本为CentOS 8。

先去Redis官网下载压缩包,如redis-5.0.9.tar.gz,然后上传到root用户的默认目录:/root,解压到/usr/local目录:
tar zxvf redis-5.0.9.tar.gz -C /usr/local
重命名:
mv redis-5.0.9/ redis
进入redis目录:
cd redis
执行make,然后执行make install,至此安装成功。
pwd查看当前目录,输出:
/usr/local/redis
ll查看所有文件,输出:

total 284
-rw-rw-r--.  1 root root 119270 Apr 17  2020 00-RELEASENOTES
-rw-rw-r--.  1 root root     53 Apr 17  2020 BUGS
-rw-rw-r--.  1 root root   2381 Apr 17  2020 CONTRIBUTING
-rw-rw-r--.  1 root root   1487 Apr 17  2020 COPYING
drwxrwxr-x.  6 root root    192 Feb 19 01:50 deps
-rw-r--r--.  1 root root     92 Feb 19 02:58 dump.rdb
-rw-rw-r--.  1 root root     11 Apr 17  2020 INSTALL
-rw-rw-r--.  1 root root    151 Apr 17  2020 Makefile
-rw-rw-r--.  1 root root   6888 Apr 17  2020 MANIFESTO
-rw-rw-r--.  1 root root  20555 Apr 17  2020 README.md
-rw-rw-r--.  1 root root  61819 Feb 19 03:12 redis.conf
-rwxrwxr-x.  1 root root    275 Apr 17  2020 runtest
-rwxrwxr-x.  1 root root    280 Apr 17  2020 runtest-cluster
-rwxrwxr-x.  1 root root    373 Apr 17  2020 runtest-moduleapi
-rwxrwxr-x.  1 root root    281 Apr 17  2020 runtest-sentinel
-rw-rw-r--.  1 root root   9710 Apr 17  2020 sentinel.conf
drwxrwxr-x.  3 root root   8192 Feb 19 01:51 src
drwxrwxr-x. 11 root root    182 Apr 17  2020 tests
drwxrwxr-x.  8 root root   4096 Apr 17  2020 utils

启动Redis:
/usr/local/redis/src/redis-server /usr/local/redis/redis.conf

36705:C 19 Feb 2021 02:57:50.909 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
36705:C 19 Feb 2021 02:57:50.909 # Redis version=5.0.9, bits=64, commit=00000000, modified=0, pid=36705, just started
36705:C 19 Feb 2021 02:57:50.909 # Configuration loaded
36705:M 19 Feb 2021 02:57:50.910 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 5.0.9 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
(    '      ,       .-`  | `,    )     Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
|    `-._   `._    /     _.-'    |     PID: 36705
  `-._    `-._  `-./  _.-'    _.-'
|`-._`-._    `-.__.-'    _.-'_.-'|
|    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
|`-._`-._    `-.__.-'    _.-'_.-'|
|    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

36705:M 19 Feb 2021 02:57:50.910 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
36705:M 19 Feb 2021 02:57:50.910 # Server initialized
36705:M 19 Feb 2021 02:57:50.910 # 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.
36705:M 19 Feb 2021 02:57:50.911 # 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 never > /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.
36705:M 19 Feb 2021 02:57:50.911 * Ready to accept connections

但是这种方式是前台启动,不方便。修改配置文件:
vim /usr/local/redis/redis.conf
设置为daemonize yes
命令太长不方便,创建软链接:
ln -s /usr/local/redis/src/redis-server /usr/bin/redis-server
启动:
redis-server /usr/local/redis/redis.conf

现在已经成功安装并启动,如何通过客户端,如RedisPlus连接。
修改配置文件:
vim /usr/local/redis/redis.conf
更新配置:
protected-mode no
仅仅修改如上配置并不行。
还需要修改bind 127.0.0.1为bind 192.168.20.149。
当然,这种方式是配置无密码。

如果执行make最后输出:
Hint: It's a good idea to run 'make test' ;)
一般是没有完全安装成功,执行命令:
make test
根据报错信息来安装相应的包。

遇到的问题:

make test输出You need tcl 8.5 or newer in order to run the Redis test
解决方法:
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
tar xzvf tcl8.6.1-src.tar.gz
cd tcl8.6.1/unix/
./configure
make
make install

make test报错:I/O error reading reply while executing
解决方案也是安装tcl。
Windows
集群版 (责任编辑:IT)