1

安装

yum install epel-release
yum install redis

如果要安装最新的redis,需要安装Remi的软件源,官网地址:http://rpms.famillecollet.com/
CentOS7.x:
yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Rocky Linux 9.4:
yum install -y http://rpms.remirepo.net/enterprise/remi-release-9.rpm

然后可以使用下面的命令安装最新版本的redis:
yum --enablerepo=remi install redis -y

安装完毕后,即可使用下面的命令启动redis服务
systemctl restart redis

Redis客户端
redis-cli

允许远程访问
vim /etc/redis.conf

# bind 127.0.0.1 ::1
bind 0.0.0.0
# daemonize是守护进程的意思, 改成yes
daemonize yes

设置密码

requirepass HtiL9h661DQspm

设置开机自动
systemctl enable redis.service

Redis启动警告解决方案

警告1:

WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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.

解决方案: echo 1 > /proc/sys/vm/overcommit_memory

0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2, 表示内核允许分配超过所有物理内存和交换空间总和的内存

警告2

WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

解决方案:
vim /etc/sysctl.conf

# 添加配置
net.core.somaxconn = 1024
net.ipv4.conf.default.accept_source_route = 1

查看配置是否成功: sysctl -p

警告3:

WARNING Your system is configured to use the 'xen' clocksource which might lead to degraded performance. Check the result of the [slow-clocksource] system check: run 'redis-server --check-system' to check if the system's clocksource isn't degrading performance.

执行redis-server --check-system命令, 提示:

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').
翻译:
警告:您的内核中启用了透明的大页面(THP)支持。这将创建与redis的延迟和内存使用问题。若要修复此问题,请以root身份运行命令“echo never > /sys/kernel/mm/transparent_hugepage/enabled”,并将其添加到您的/etc/rc.local,以便在重新启动后保留设置。在禁用THP之后,必须重新启动redis

解决方案:

echo madvise > /sys/kernel/mm/transparent_hugepage/enabled

# 重启redis
systemctl restart redis

# 如果警告依然存在,需要重启服务器
reboot

YYGP
25 声望11 粉丝

写BUG