Redis安装

Redis 安装及连接
 
官方下载地址:http://download.redis.io/releases/
 
查看yum仓库redis版本
CentOS 8 由系统源提供
[root@centos8 ~]#dnf info redis
 
CentOS 7 由epel源提供
[root@centos7 ~]#yum info redis
 
yum安装 redis
[root@localhost ~]# dnf install redis -y

[root@localhost ~]# pstree -p|grep redis
|-redis-server(1423)-+-{redis-server}(1424)
| |-{redis-server}(1425)
| `-{redis-server}(1426)
[root@localhost ~]# ss -ntl

State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:6379 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*

[root@localhost ~]# redis-cli
127.0.0.1:6379> info
# Server
redis_version:5.0.3
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:9529b692c0384fb7
redis_mode:standalone
os:Linux 4.18.0-240.el8.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:8.4.1

127.0.0.1:6379> ping
PONG

编译安装 redis 
#Centos7环境
wget http://download.redis.io/releases/redis-6.2.4.tar.gz
yum  -y install gcc jemalloc-devel systemd-devel
tar xf redis-6.2.4.tar.gz
cd redis-6.2.4
make -j 4 USE_SYSTEMD=yes PREFIX=/apps/redis/ install
#准备相关目录和配置文件 
mkdir /apps/redis/{etc,log,data,run}
cp redis.conf /apps/redis/etc/
ln -s /apps/redis/bin/redis-server /usr/bin/
sed -i -e 's/bind 127.0.0.1.*/bind 0.0.0.0/'  -e "/# requirepass/a requirepass 123456"  -e "/^dir .*/c dir /apps/redis/data/"  -e "/logfile .*/c logfile /apps/redis/log/redis-6379.log"  -e  "/^pidfile .*/c  pidfile /apps/redis/run/redis_6379.pid" /apps/redis/etc/redis.conf
 
 
解决启动时的三个警告提示
tcp-backlog

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
#sysctl -p 

 vm.overcommit_memory
 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.

 
0、表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内
存申请失败,并把错误返回给应用进程。
1、表示内核允许分配所有的物理内存,而不管当前的内存状态如何
2、表示内核允许分配超过所有物理内存和交换空间总和的内存 
#vim /etc/sysctl.conf
vm.overcommit_memory = 1
#sysctl -p
transparent hugepage 
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.
警告:您在内核中启用了透明大页面(THP,不同于一般内存页的4k为2M)支持。 这将在Redis中造成延迟和
内存使用问题。 要解决此问题,请以root 用户身份运行命令“echo never>
/sys/kernel/mm/transparent_hugepage/enabled”,并将其添加到您的/etc/rc.local中,以便在
重启后保留设置。禁用THP后,必须重新启动Redis。
[root@centos7 ~]#echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled'
>> /etc/rc.d/rc.local
[root@centos7 ~]#cat /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@centos7 ~]#chmod +x /etc/rc.d/rc.local 
 
 
posted @   低调的泅渡者  阅读(35)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示