CentOS 下载:http://mirrors.aliyun.com/centos/
Redis:http://download.redis.io/releases/
CentOS 1908 配置 Redis 5.0.7 集群 二(主从复制)
CentOS 1908 配置 Redis 5.0.7 集群 三(哨兵模式)
- 下载 Redis 5.0.7:
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
- 解压 Redis:
tar -zxvf redis-5.0.7.tar.gz
- 安装 gcc:
如未安装,可能出现如下问题:yum -y install gcc
/bin/sh: cc: command not found
- 安装 tcl:
如未安装,可能出现如下问题:yum -y install tcl
You need tcl 8.5 or newer in order to run the Redis test
- 进入 Redis 文件夹:
[root@192 ~]# cd redis-5.0.7/ [root@192 redis-5.0.7]#
- 编译:
编译时如果出现:make
使用以下命令编译:zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory #include <jemalloc/jemalloc.h>
make MALLOC=libc
- 编译测试:
make test
- 测试安装没有问题后,进行编译安装:
make install
- 启动 Redis:
Ctrl + C 停止。[root@192 redis-5.0.7]# src/redis-server redis.conf 57110:C 13 Jan 2020 21:31:05.240 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 57110:C 13 Jan 2020 21:31:05.240 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=57110, just started 57110:C 13 Jan 2020 21:31:05.240 # Configuration loaded 57110:M 13 Jan 2020 21:31:05.241 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 5.0.7 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 57110 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 57110:M 13 Jan 2020 21:31:05.243 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 57110:M 13 Jan 2020 21:31:05.243 # Server initialized 57110:M 13 Jan 2020 21:31:05.243 # 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. 57110:M 13 Jan 2020 21:31:05.243 # 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. 57110:M 13 Jan 2020 21:31:05.244 * Ready to accept connections
- 打开 CentOS 的 Redis 端口:
firewall-cmd --zone=public --add-port=6379/tcp --permanent
- 重新加载防火墙:
firewall-cmd --reload
- 查看已开放的端口和服务:
firewall-cmd --list-all
[root@192 ~]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: ens33 ens34 sources: services: dhcpv6-client ssh ports: 6379/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: [root@192 ~]#
- 开放远程连接:
修改 redis.conf:
修改完成,重启 Redis。# 注释 bind,如下: # bind 127.0.0.1 # 修改 protected-mode 为 no,如下: protected-mode no
- 远程连接:
- 如要开启后台运行,需要在 redis.conf 中将 daemonize 设置为 yes。