Redis6.2 源码编译和部署
源码编译
下载源码
下载地址:https://download.redis.io/releases/
检查是否安装gcc
[root@redis240 src]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
检查是否安装jemalloc
Redis 内存碎片自动清理功能必须配置jemalloc
没安装参考:https://199604.com/3161
(二进制安装),https://pkgs.org/download/jemalloc
(rpm)
[root@redis240 src]# ldconfig -p | grep jemalloc
libjemalloc.so.2 (libc6,x86-64) => /usr/local/lib/libjemalloc.so.2
libjemalloc.so (libc6,x86-64) => /usr/local/lib/libjemalloc.so
编译源码
# -j 指定cpu个数提升编译速度,MALLOC 指定内存分配器
make -j 4 MALLOC=jemalloc
# PREFIX指定二进制安装路径,默认安装/usr/local/bin
make PREFIX=/work_app/redis install
#cd /work_app/redis && ls
操作系统调整
调整vm.overcommit_memory
调整vm.overcommit_memory避免内存不足时导致 Redis fork 失败
# 1 表示内核允许超量使用内存直到用完为止
echo 1 > /proc/sys/vm/overcommit_memory
# 持久化参数
echo "vm.overcommit_memory=1" >>/etc/sysctl.conf
sysctl -p
禁用Transparent Huge Pages
避免降低 Redis fork 速度和写速度
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local
chmod +x /etc/rc.local
echo 2048 > /proc/sys/net/core/somaxconn
#echo 2048 >> /proc/sys/net/ipv4/tcp_max_syn_backlog
echo "net.core.somaxconn= 1024" >>/etc/sysctl.conf
#echo "net.ipv4.tcp_max_syn_backlog = 2048" >>/etc/sysctl.conf
sysctl -p
适当调整ulimit
cat /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
* soft nproc 65565
* hard nproc 65565
参数文件设置
mdkir -p /work_app/redis/conf/
mkdir -p /work_app/redis/logs/
cp /usr/local/src/redis-6.2.16/redis.conf /work_app/redis/conf/
# redis.conf 我这边修改了一下参数
daemonize yes
logfile "/work_app/redis/logs/redis.log"
dir /work_app/redis/
# 密码
requirepass xxxx
maxclients 10000
# 50gb
# 最大内存
maxmemory 53687091200
#无差别随机删
maxmemory-policy allkeys-random
# RDB 持久化
save 900 1
save 300 10
save 60 10000
启动 Redis脚本
[root@redis78 redis]# cat start-redis.sh
cd /work_app/redis && ./bin/redis-server /work_app/redis/conf/redis.conf