返回首页

Redis安装配置笔记

注:网站系统为Linux系统,使用systemd。

一、包管理器安装:

yum/apt install redis
systemctl start redis
systemctl enable redis

二、编译安装:

wget http://download.redis.io/releases/redis-6.0.5.tar.gz
tar xvf redis-6.0.5.tar.gz
cd redis-6.0.5
#CentOS7安装5
#wget http://download.redis.io/releases/redis-5.0.9.tar.gz
#tar xvf redis-5.0.9.tar.gz
#cd redis-5.0.9
#CentOS7安装6需要升级gcc并设置为默认gcc(gcc-4.9以上)
#yum install centos-release-scl
#yum install devtoolset-9-gcc
#scl enable devtoolset-9 bash
make
make PREFIX=/data/redis install
cp redis.conf /data/redis/
useradd -U -r -M -s /bin/false redis
cat > /lib/systemd/system/redis.service << "EOF"
[Unit]
Description=Redis persistent key-value database
After=network.target

[Service]
ExecStart=/data/redis/bin/redis-server /data/redis/redis.conf --daemonize no
ExecStop=/data/redis/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown
User=redis
Group=redis
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
EOF
ln -sf /data/redis/bin/* /usr/local/bin/
#Failed opening the RDB file dump.rdb问题
mkdir /data/redis/db
chown redis:redis /data/redis/db -R
sed -i "s/dir .\//dir \/data\/redis\/db\//g" /data/redis/redis.conf
#日志文件
mkdir /data/redis/log
sed -i "s/logfile \"\"/logfile \"\/data\/redis\/log\/redis.log\"/g" /data/redis/redis.conf
touch /data/redis/log/redis.log
chown redis:redis /data/redis/log/redis.log
#The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.问题
echo 511 > /proc/sys/net/core/somaxconn
echo "echo 511 > /proc/sys/net/core/somaxconn" >> /etc/rc.local
#MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk问题
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
sysctl -p
echo 1 > /proc/sys/vm/overcommit_memory
# WARNING you have Transparent Huge Pages (THP) support enabled in your kernel.问题
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local
#注意:使用systemd的发行版,/etc/rc.local或软链接到的/etc/rc.d/rc.local无执行权限,需要处理一下
chmod +x /etc/rc.local
systemctl start redis
systemctl enable redis

返回首页

© 2016-2020 清风的个人笔记