نصب و پیکربندی Redis
سرور کش Redis را نصب میکند، پیکربندی میکند و تنظیمات امنیتی را اعمال میکند.
منتشر شده: 2024/04/15
کد
#!/bin/bash
# Redis Installation Script
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
echo "Installing Redis..."
apt-get update
apt-get install -y redis-server
sed -i "s/bind 127.0.0.1/bind 127.0.0.1/" /etc/redis/redis.conf
sed -i "s/# requirepass foobared/requirepass $(openssl rand -base64 32)/" /etc/redis/redis.conf
sed -i "s/# maxmemory <bytes>/maxmemory 256mb/" /etc/redis/redis.conf
sed -i "s/# maxmemory-policy noeviction/maxmemory-policy allkeys-lru/" /etc/redis/redis.conf
systemctl enable redis-server
systemctl restart redis-server
PASSWORD=$(grep "^requirepass" /etc/redis/redis.conf | cut -d" " -f2)
echo "✓ Redis installed and configured!"
echo ""
echo "Password: $PASSWORD"
echo ""
echo "Test connection:"
echo "redis-cli -a $PASSWORD ping"
نحوه استفاده
sudo chmod +x redis_install.sh
sudo ./redis_install.sh
# Test connection
redis-cli -a <password> ping