Inspired from
and made with chat gpt
If you need custom subdomain make with duckdns and use domain & token otherwise you can remove that part asking AI.
#!/bin/bash
# Update system and install necessary packages
sudo apt update && sudo apt upgrade -y
sudo apt install -y redis-server curl net-tools stunnel4 certbot
# Configure Redis to require a default password
REDIS_PASSWORD="dnxapps123"
sudo sed -i "s/# requirepass foobared/requirepass $REDIS_PASSWORD/" /etc/redis/redis.conf
# Allow Redis to listen on all interfaces (IPv4 and IPv6)
sudo sed -i "s/^bind 127.0.0.1 ::1/# bind 127.0.0.1 ::1/" /etc/redis/redis.conf
sudo sed -i "s/protected-mode yes/protected-mode no/" /etc/redis/redis.conf
# Restart Redis server and enable it at startup
sudo systemctl restart redis-server.service
sudo systemctl enable redis-server.service
# Install DuckDNS client and configure with domain and token
DUCKDNS_DIR=~/duckdns
mkdir -p $DUCKDNS_DIR
echo "neekheel" > $DUCKDNS_DIR/domains
echo "YOUR TOKEN" > $DUCKDNS_DIR/token
# Create the DuckDNS update script
cat << EOF > $DUCKDNS_DIR/duckdns.sh
#!/bin/bash
curl -s "https://www.duckdns.org/update?domains=\$(cat ~/duckdns/domains)&token=\$(cat ~/duckdns/token)&ip=" > ~/duckdns/duck.log
EOF
# Make the script executable
chmod +x $DUCKDNS_DIR/duckdns.sh
# Set up a cron job to run the DuckDNS update every 5 minutes
(crontab -l 2>/dev/null; echo "*/5 * * * * ~/duckdns/duckdns.sh >/dev/null 2>&1") | crontab -
# Install Let's Encrypt SSL certificate with Certbot
sudo apt install -y certbot
sudo certbot certonly --standalone -d neekheel.duckdns.org --agree-tos --no-eff-email -m admin@neekheel.duckdns.org
# Define certificate path variables
CERT_PATH="/etc/letsencrypt/live/neekheel.duckdns.org/fullchain.pem"
KEY_PATH="/etc/letsencrypt/live/neekheel.duckdns.org/privkey.pem"
# Configure Stunnel for Redis SSL tunneling using Let's Encrypt certificates
STUNNEL_CONFIG="/etc/stunnel/stunnel.conf"
sudo bash -c "cat > $STUNNEL_CONFIG" <<EOF
pid = /var/run/stunnel.pid
output = /var/log/stunnel.log
[redis-server]
client = no
accept = 6380
connect = 127.0.0.1:6379
cert = $CERT_PATH
key = $KEY_PATH
EOF
# Enable and start Stunnel
sudo systemctl enable stunnel4
sudo systemctl restart stunnel4
# Display Redis server details
echo -e "\nRedis Server Details (SSL Configured with Let's Encrypt):"
echo "=========================================================="
echo "Redis SSL Server: neekheel.duckdns.org"
echo "Redis SSL Port: 6380"
echo "Redis Password: $REDIS_PASSWORD"
# Check if Redis (via Stunnel) is listening on port 6380
echo -e "\nChecking if Redis SSL is listening on port 6380..."
sudo netstat -tulnp | grep 6380
echo -e "\nSetup complete! Your Redis server is now running with Let's Encrypt SSL."
# Schedule auto-renewal of SSL certificate with a cron job
(crontab -l 2>/dev/null; echo "0 3 * * * sudo certbot renew --quiet && sudo systemctl restart stunnel4") | crontab -
Just replace all neekheel with your subdomain and YOURTOKEN with actual token.