Files
download/redis/install.sh
耗子 758e1c8799
All checks were successful
Generate Checksums / checksums (push) Successful in 46s
feat: 清理提交
2026-01-31 07:03:45 +08:00

99 lines
3.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
source <(curl -f -s --connect-timeout 10 --retry 3 https://dl.acepanel.net/public.sh)
if [ $? -ne 0 ]; then
echo "Download public.sh failed, please check the network or try again later."
exit 1
fi
channel=${1}
version=${2}
redis_path="${setup_path}/server/redis"
if ! id -u "redis" >/dev/null 2>&1; then
groupadd redis
useradd -s /sbin/nologin -g redis redis
fi
# 安装依赖
if [ ${OS} == "rhel" ]; then
dnf makecache -y
dnf groupinstall "Development Tools" -y
dnf install systemd-devel openssl-devel -y
elif [ ${OS} == "debian" ] || [ ${OS} == "ubuntu" ]; then
apt-get update
# Debian 13+ 及 Ubuntu 25+ 需要单独安装 systemd-dev旧版系统不能安装否则会出现严重问题
if { [ ${OS} == "debian" ] && [ ${VERSION} -ge 13 ]; } || { [ ${OS} == "ubuntu" ] && [ ${VERSION} -ge 25 ]; }; then
apt-get install systemd-dev -y
fi
apt-get install build-essential libsystemd-dev libssl-dev -y
else
error "Unsupported operating system"
fi
if [ "$?" != "0" ]; then
error "Failed to install dependencies"
fi
# 准备目录
rm -rf ${redis_path}
mkdir -p ${redis_path}
cd ${redis_path}
# 下载源码
dl "${redis_path}" "/redis/redis-${version}.zip"
unzip -o redis-${version}.zip
rm -f redis-${version}.zip
mv redis-${version}/* ./ && rm -rf redis-${version}
mkdir -p ${redis_path}/bin
make BUILD_TLS=yes USE_SYSTEMD=yes -j${CORES}
if [ "$?" != "0" ]; then
rm -rf ${redis_path}
error "Compilation failed"
fi
make PREFIX=${redis_path} install
if [ ! -f "${redis_path}/bin/redis-server" ]; then
rm -rf ${redis_path}
error "Installation failed"
fi
# 设置软链接
ln -sf ${redis_path}/bin/* /usr/local/bin/
sed -i "s|dir \./|dir ${redis_path}/|g" ${redis_path}/redis.conf
sed -i 's/# supervised.*/supervised systemd/g' ${redis_path}/redis.conf
sed -i 's/# maxmemory-policy.*/maxmemory-policy volatile-lfu/g' ${redis_path}/redis.conf
sed -i 's|pidfile.*|pidfile ${redis_path}/redis.pid|g' ${redis_path}/redis.conf
if [ ${ARCH} == "aarch64" ]; then
echo "ignore-warnings ARM64-COW-BUG" >>${redis_path}/redis.conf
fi
chown -R redis:redis ${redis_path}
chmod -R 700 ${redis_path}
# 设置服务
\cp -f utils/systemd-redis_server.service /etc/systemd/system/redis.service
sed -i "s!ExecStart=.*!ExecStart=${redis_path}/bin/redis-server ${redis_path}/redis.conf!g" /etc/systemd/system/redis.service
sed -i "s!#User=.*!User=redis!g" /etc/systemd/system/redis.service
sed -i "s!#Group=.*!Group=redis!g" /etc/systemd/system/redis.service
sed -i "s!#WorkingDirectory=.*!WorkingDirectory=${redis_path}!g" /etc/systemd/system/redis.service
sed -i "s!TimeoutStartSec=.*!TimeoutStartSec=30s!g" /etc/systemd/system/redis.service
sed -i "s!TimeoutStopSec=.*!TimeoutStopSec=30s!g" /etc/systemd/system/redis.service
chmod 644 /etc/systemd/system/redis.service
systemctl daemon-reload
systemctl enable --now redis
if [ "$?" != "0" ]; then
error "Failed to start"
fi
acepanel app write redis ${channel} ${version}
echo -e $HR
echo "Installation successful"
echo -e $HR