Skip to content

Instantly share code, notes, and snippets.

@faryx
Created September 27, 2025 05:24
Show Gist options
  • Select an option

  • Save faryx/f4246d0f7009a991ce7447f2a60d8e83 to your computer and use it in GitHub Desktop.

Select an option

Save faryx/f4246d0f7009a991ce7447f2a60d8e83 to your computer and use it in GitHub Desktop.
install-n8n.sh
#!/bin/bash
# Script Instalasi n8n untuk Ubuntu 22.04
# Dibuat untuk pemula - dengan penjelasan bahasa Indonesia
echo "=========================================="
echo " INSTALASI n8n DI UBUNTU 22.04"
echo " Script Otomatis untuk Pemula"
echo "=========================================="
echo ""
# Warna untuk output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Fungsi untuk print dengan warna
print_success() {
echo -e "${GREEN}βœ… $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
print_info() {
echo -e "${YELLOW}ℹ️ $1${NC}"
}
# Cek apakah running sebagai root
if [ "$EUID" -ne 0 ]; then
print_error "Script ini harus dijalankan sebagai root!"
echo "Gunakan: sudo bash install-n8n.sh"
exit 1
fi
print_info "Memulai instalasi n8n..."
echo ""
# Step 1: Update sistem
print_info "Step 1: Update sistem Ubuntu..."
apt update && apt upgrade -y
if [ $? -eq 0 ]; then
print_success "Sistem berhasil diupdate!"
else
print_error "Gagal update sistem. Cek koneksi internet."
exit 1
fi
echo ""
# Step 2: Install dependencies
print_info "Step 2: Install dependencies yang dibutuhkan..."
apt install -y curl wget git build-essential
if [ $? -eq 0 ]; then
print_success "Dependencies berhasil diinstall!"
else
print_error "Gagal install dependencies."
exit 1
fi
echo ""
# Step 3: Install Node.js 18
print_info "Step 3: Install Node.js versi 18..."
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt install -y nodejs
if [ $? -eq 0 ]; then
print_success "Node.js berhasil diinstall!"
echo "Node.js version: $(node --version)"
echo "npm version: $(npm --version)"
else
print_error "Gagal install Node.js."
exit 1
fi
echo ""
# Step 4: Install n8n
print_info "Step 4: Install n8n (ini mungkin memakan waktu beberapa menit)..."
npm install -g n8n
if [ $? -eq 0 ]; then
print_success "n8n berhasil diinstall!"
echo "n8n version: $(n8n --version)"
else
print_error "Gagal install n8n."
exit 1
fi
echo ""
# Step 5: Install PM2
print_info "Step 5: Install PM2 untuk menjalankan n8n di background..."
npm install -g pm2
if [ $? -eq 0 ]; then
print_success "PM2 berhasil diinstall!"
else
print_error "Gagal install PM2."
exit 1
fi
echo ""
# Step 6: Buat folder konfigurasi
print_info "Step 6: Membuat folder dan file konfigurasi..."
mkdir -p /root/.n8n
# Ambil IP publik VPS
PUBLIC_IP=$(curl -s ifconfig.me)
print_info "IP Publik VPS Anda: $PUBLIC_IP"
# Minta user untuk set password
echo ""
echo "=========================================="
echo " KONFIGURASI KEAMANAN n8n"
echo "=========================================="
echo ""
print_info "Anda perlu membuat username dan password untuk akses n8n"
echo ""
read -p "Masukkan username untuk n8n (default: admin): " N8N_USER
N8N_USER=${N8N_USER:-admin}
while true; do
read -s -p "Masukkan password untuk n8n (minimal 8 karakter): " N8N_PASS
echo ""
if [ ${#N8N_PASS} -ge 8 ]; then
read -s -p "Konfirmasi password: " N8N_PASS_CONFIRM
echo ""
if [ "$N8N_PASS" = "$N8N_PASS_CONFIRM" ]; then
break
else
print_error "Password tidak cocok! Coba lagi."
fi
else
print_error "Password harus minimal 8 karakter!"
fi
done
print_success "Username dan password berhasil dikonfigurasi!"
echo ""
# Buat file environment
cat > /root/.n8n/n8n-env.sh << EOF
#!/bin/bash
# Konfigurasi n8n
export N8N_HOST=0.0.0.0
export N8N_PORT=5678
export N8N_PROTOCOL=http
export WEBHOOK_URL=http://$PUBLIC_IP:5678/
export N8N_BASIC_AUTH_ACTIVE=true
export N8N_BASIC_AUTH_USER=$N8N_USER
export N8N_BASIC_AUTH_PASSWORD=$N8N_PASS
export EXECUTIONS_PROCESS=main
export N8N_LOG_LEVEL=info
EOF
chmod +x /root/.n8n/n8n-env.sh
print_success "File konfigurasi berhasil dibuat!"
echo ""
# Step 7: Buat script starter
print_info "Step 7: Membuat script untuk menjalankan n8n..."
cat > /root/start-n8n.sh << 'EOF'
#!/bin/bash
source /root/.n8n/n8n-env.sh
n8n start
EOF
chmod +x /root/start-n8n.sh
print_success "Script starter berhasil dibuat!"
echo ""
# Step 8: Jalankan n8n dengan PM2
print_info "Step 8: Menjalankan n8n dengan PM2..."
pm2 start /root/start-n8n.sh --name n8n
pm2 save
pm2 startup systemd -u root --hp /root
systemctl enable pm2-root
print_success "n8n berhasil dijalankan dengan PM2!"
echo ""
# Step 9: Konfigurasi firewall
print_info "Step 9: Konfigurasi firewall..."
ufw allow 22/tcp
ufw allow 5678/tcp
ufw --force enable
print_success "Firewall berhasil dikonfigurasi!"
echo ""
# Step 10: Buat script helper
print_info "Step 10: Membuat script helper untuk management n8n..."
# Script untuk restart n8n
cat > /usr/local/bin/n8n-restart << 'EOF'
#!/bin/bash
echo "Restarting n8n..."
pm2 restart n8n
echo "n8n berhasil direstart!"
EOF
chmod +x /usr/local/bin/n8n-restart
# Script untuk stop n8n
cat > /usr/local/bin/n8n-stop << 'EOF'
#!/bin/bash
echo "Stopping n8n..."
pm2 stop n8n
echo "n8n berhasil distop!"
EOF
chmod +x /usr/local/bin/n8n-stop
# Script untuk start n8n
cat > /usr/local/bin/n8n-start << 'EOF'
#!/bin/bash
echo "Starting n8n..."
pm2 start n8n
echo "n8n berhasil distart!"
EOF
chmod +x /usr/local/bin/n8n-start
# Script untuk melihat log
cat > /usr/local/bin/n8n-logs << 'EOF'
#!/bin/bash
pm2 logs n8n --lines 50
EOF
chmod +x /usr/local/bin/n8n-logs
# Script untuk melihat status
cat > /usr/local/bin/n8n-status << 'EOF'
#!/bin/bash
pm2 status n8n
EOF
chmod +x /usr/local/bin/n8n-status
print_success "Script helper berhasil dibuat!"
echo ""
# Tampilkan informasi akses
echo ""
echo "=========================================="
echo -e "${GREEN} βœ… INSTALASI BERHASIL!${NC}"
echo "=========================================="
echo ""
echo "πŸ“Œ INFORMASI AKSES n8n:"
echo "------------------------"
echo "URL: http://$PUBLIC_IP:5678"
echo "Username: $N8N_USER"
echo "Password: [password yang Anda buat]"
echo ""
echo "πŸ“ PERINTAH MANAGEMENT n8n:"
echo "------------------------"
echo "β€’ Restart n8n: n8n-restart"
echo "β€’ Stop n8n: n8n-stop"
echo "β€’ Start n8n: n8n-start"
echo "β€’ Lihat log: n8n-logs"
echo "β€’ Cek status: n8n-status"
echo ""
echo "πŸ” VERIFIKASI:"
echo "------------------------"
pm2 status
echo ""
echo "=========================================="
echo "Silakan buka browser dan akses:"
echo "http://$PUBLIC_IP:5678"
echo "=========================================="
echo ""
print_info "Script instalasi selesai! πŸŽ‰"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment