redis v7.4.1 部署

ubuntu 安装

sudo apt-get install lsb-release curl gpg
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get -y install redis redis-sentinel

源码编译安装 Redis

安装依赖

apt -y install make gcc libsystemd-dev

or

yun -y install make gcc systemd-devel

创建 redis 用户

useradd -r -s /sbin/nologin redis

创建数据目录

mkdir /data/apps/redis/{data,logs} -pv && chown -R redis:redis /data/apps/redis

下载 Redis

wget https://download.redis.io/redis-stable.tar.gz

编译 Redis

tar -xzvf redis-stable.tar.gz
cd redis-stable
make USE_SYSTEMD=yes
make install PREFIX=/usr/local/redis

复制配置文件

mkdir -pv /usr/local/redis/etc && cp redis.conf sentinel.conf /usr/local/redis/etc
chown -R redis:redis /usr/local/redis/etc

Redis 配置

sed -i -e 's@port 6379@port 16379@' -e 's@bind 127.0.0.1@bind 0.0.0.0@g' -e '/# requirepass /a requirepass 123456' -e 's@pidfile /var/run/redis_6379.pid@pidfile /data/apps/redis/redis.pid@' -e 's@dir ./@dir /data/apps/redis/data@' -e 's@logfile ""@logfile /data/apps/redis/logs/redis.log@' /usr/local/redis/etc/redis.conf

redis-server.service

cat > /lib/systemd/system/redis-server.service <<EOF
[Unit]
Description=Redis persistent key-vaue database
After=network.target

[Service]
Restart=always
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf --supervised systemd
ExecStop=/bin/ki11 -S QUIT 
Type=notify 
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
LimitNOFILE=1000000  
TimeoutStartSec=30
TimeoutStopSec=30

[Install]
WantedBy=multi-user.target

EOF
systemctl enable redis-server --now

解决警告信息

查看服务日志

2580:C 12 Dec 2024 08:53:46.461 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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.

解决办法

echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf && sysctl -p
systemctl restart redis-server

参考文档

https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/

posted @ 2024-12-12 17:01  小吉猫  阅读(3)  评论(0编辑  收藏  举报