CentOS 7系统Redis安装步骤

发表时间:2018-11-19 10:43 | 分类:数据库运维 | 浏览:1,247 次

REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统。Redis是一个开源的使用ANSI C语言编写、遵守BSD协议、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。它通常被称为数据结构服务器,因为值(value)可以是 字符串(String), 哈希(Map), 列表(list), 集合(sets) 和 有序集合(sorted sets)等类型。Redis安装比较简单,下面就在CentOS 7 中安装,步骤如下。

下载

mkdir -pv /root/softbak
wget http://download.redis.io/releases/redis-4.0.11.tar.gz -O redis-4.0.11.tar.gz
cd /root/softbak

新建用户

groupadd redis
useradd -g redis redis

安装

# 创建目录
mkdir -pv /usr/local/redis
mkdir -pv /usr/local/redis/bin
mkdir -pv /usr/local/redis/conf
mkdir -pv /usr/local/redis/logs
chown -R redis:redis /usr/local/redis

# 解压安装
yum install gcc make
cd /root/softbak
tar zxf redis-4.0.11.tar.gz
cd redis-4.0.11/
make MALLOC=libc

# 复制
cd src
cp redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server redis-sentinel redis-trib.rb /usr/local/redis/bin
cd ..
cp redis.conf /usr/local/redis/conf

配置

# 环境变量
cat >>/etc/profile<<eof
export PATH=/usr/local/redis/bin:\$PATH
eof
source /etc/profile

# 修改 redis.conf
sed -i "s@bind 127.0.0.1@bind 0.0.0.0@g" /usr/local/redis/conf/redis.conf
sed -i "s@daemonize no@daemonize yes@g" /usr/local/redis/conf/redis.conf
sed -i "s@redis_6379.pid@redis.pid@g" /usr/local/redis/conf/redis.conf
sed -i "s@logfile \"\"@logfile \"/usr/local/redis/logs/redis.log\"@g" /usr/local/redis/conf/redis.conf
sed -i "s@dir ./@dir /usr/local/redis@g" /usr/local/redis/conf/redis.conf

优化

1、somaxconn

该内核参数默认值一般是128(定义了系统中每一个端口最大的监听队列的长度),对于负载很大的服务程序来说大大的不够。一般会将它修改为2048或者更大。

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

修改:net.core.somaxconn=2048

2、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.

修改:vm.overcommit_memory=1

3、THP

# 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.

修改:/etc/rc.local,增加 echo never > /sys/kernel/mm/transparent_hugepage/enabled 。

性能参数的参考网址: https://www.techandme.se/performance-tips-for-redis-cache-server/

Systemd启动

最后上个systemd启动的配置文件。

[Unit]
Description=Redis Server
After=syslog.target network.target
 
[Service]
Type=notify
PIDFile=/usr/local/redis/var/redis.pid
KillMode=process
User=redis
Group=redis
LimitNOFILE=65000
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf --supervised systemd
ExecStop=/bin/kill -SIGTERM $MAINPID
 
[Install]
WantedBy=multi-user.target

本文标签:

本文链接:https://www.sijitao.net/2931.html

欢迎您在本博客中留下评论,如需转载原创文章请注明出处,谢谢!

一键脚本 博客历程 留言联系 文章归档 网站地图 谷歌地图
Copyright © 2010-2024 章郎虫博客 All Rights Reserved.