Redis安装(Windows、Linux、单机、分布式)

概述

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

单机版

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:M 19 Feb 2021 02:57:50.910 * Increased maximum number of open files to 10032 (it was originally set to 1024).
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,设置为daemonize yes
命令太长不方便,创建软链接:
ln -s /usr/local/redis/src/redis-server /usr/bin/redis-server
启动:
redis-server /usr/local/redis/redis.conf

问题

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

遇到的问题:

  1. make test报错You need tcl 8.5 or newer in order to run the Redis test
    解决方法就是下载安装tcl
    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
    
  2. make test报错:I/O error reading reply while executing
    解决方案也是安装tcl。

客户端连接

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

Windows

下载地址

注册为本地服务:
./redis-server.exe --service-install redis.windows.conf --service-name redis --port 6379
打开 任务管理器-服务列表,即可看到Redis服务,右键打开服务,打开服务管理器,右键属性,可以设置启动类型,默认即为自动:
在这里插入图片描述
使用一段时间后,发现Redis服务已停止
在这里插入图片描述
不能启动,在服务管理器启动时的报错信息为 本地计算机上的Redis服务启动后停止
在这里插入图片描述
卸载重新安装:
./redis-server.exe --service-uninstall redis.windows.conf --service-name redis --port 6379
安装时需要追加参数--maxmemory 200m,即完整命令为:
./redis-server.exe --service-install redis.windows.conf --service-name redis --port 6379 --maxmemory 200m

集群版

猜你喜欢

转载自blog.csdn.net/lonelymanontheway/article/details/113394034
今日推荐