返回首页

Redis安装配置笔记

一、Linux下安装说明

1、包管理器安装:

yum/apt install redis
systemctl start redis
systemctl enable redis

2、编译安装:

wget http://download.redis.io/releases/redis-7.4.1.tar.gz
tar xvf redis-7.4.1.tar.gz
cd redis-7.4.1
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/
#linux中以unix socket运行redis,提升连接速度
sed -i "s/# unixsocket \/run\/redis.sock/unixsocket \/tmp\/redis.sock/g" /data/redis/redis.conf
sed -i "s/# unixsocketperm 700/unixsocketperm 666/g" /data/redis/redis.conf
#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
#设置密码(如:redis123)
sed -i "s/# requirepass foobared/requirepass redis123/g" /data/redis/redis.conf

二、Windows下安装说明

1、下载地址:https://github.com/zkteco-home/redis-windows

最新版本为:redis-7.4.1

2、解压,命令行进入当前目录,运行“redis-server.exe redis.conf”

返回首页

© 2016-2024 清风的个人笔记