104 lines
3.4 KiB (Stored with Git LFS)
Bash
104 lines
3.4 KiB (Stored with Git LFS)
Bash
#!/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.cdn.haozi.net/panel/public.sh)
|
|
if [ $? -ne 0 ]; then
|
|
echo "下载 public.sh 失败,请检查网络或稍后重试。"
|
|
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
|
|
[ ${OS} == "debian" ] && apt-get install systemd-dev -y # Debian 13+
|
|
apt-get install build-essential libsystemd-dev libssl-dev -y
|
|
else
|
|
error "不支持的操作系统"
|
|
fi
|
|
if [ "$?" != "0" ]; then
|
|
error "安装依赖软件失败"
|
|
fi
|
|
|
|
# 准备目录
|
|
rm -rf ${redis_path}
|
|
mkdir -p ${redis_path}
|
|
cd ${redis_path}
|
|
|
|
# 下载源码
|
|
wget --retry-connrefused --retry-on-host-error --retry-on-http-error=429,500,502,503,504 -t 10 -T 120 -O ${redis_path}/redis-${version}.tar.gz ${download_url}/redis/redis-${version}.tar.gz
|
|
wget --retry-connrefused --retry-on-host-error --retry-on-http-error=429,500,502,503,504 -t 10 -T 120 -O ${redis_path}/redis-${version}.tar.gz.sha256 ${download_url}/redis/redis-${version}.tar.gz.sha256
|
|
|
|
if ! sha256sum --status -c redis-${version}.tar.gz.sha256; then
|
|
rm -rf ${redis_path}
|
|
error "Redis 校验失败"
|
|
fi
|
|
|
|
tar -zxvf redis-${version}.tar.gz
|
|
rm -f redis-${version}.tar.gz
|
|
rm -f redis-${version}.tar.gz.sha256
|
|
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 "Redis 编译失败"
|
|
fi
|
|
make PREFIX=${redis_path} install
|
|
if [ ! -f "${redis_path}/bin/redis-server" ]; then
|
|
rm -rf ${redis_path}
|
|
error "Redis 安装失败"
|
|
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 allkeys-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 -r 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 "启动失败"
|
|
fi
|
|
|
|
panel-cli app write redis ${channel} ${version}
|
|
|
|
echo -e $HR
|
|
echo "安装完成"
|
|
echo -e $HR
|