Installation
Installation
Grafana installation On Ubuntu/Debian
- Use the following commands for installation of Grafana
sudo apt-get install -y software-properties-common
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
sudo apt-get update
sudo apt-get install grafana
Grafana-Installation Prerequisites
-
Linux-based system (Ubuntu 20.04+ recommended)
-
Docker and Docker Compose
-
Minimum 2GB RAM, 2 CPU cores
-
20GB+ available disk space
-
Network access to data sources
Installation Steps
- Environment Setup
bash
# Update system packages
sudo apt update && sudo apt upgrade -y
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER
# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Create directory structure
mkdir -p /opt/grafana/{data,config,logs,plugins}
- Database Setup
bash
# Create PostgreSQL database
docker run --name grafana-db -d \
-e POSTGRES_DB=grafana \
-e POSTGRES_USER=grafana \
-e POSTGRES_PASSWORD=secure_password \
-v postgres_data:/var/lib/postgresql/data \
postgres:14
# Initialize database
docker exec grafana-db psql -U grafana -d grafana -c "CREATE EXTENSION IF NOT EXISTS pg_stat_statements;"
- Docker Compose Configuration
yaml
# docker-compose.yml
version: '3.8'
services:
grafana:
image: grafana/grafana:12.0.2
container_name: grafana
ports:
- "3000:3000"
environment:
- GF_DATABASE_TYPE=postgres
- GF_DATABASE_HOST=postgres:5432
- GF_DATABASE_NAME=grafana
- GF_DATABASE_USER=grafana
- GF_DATABASE_PASSWORD=secure_password
- GF_SECURITY_ADMIN_PASSWORD=admin_password
- GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource
volumes:
- grafana_data:/var/lib/grafana
- ./config:/etc/grafana
- ./logs:/var/log/grafana
depends_on:
- postgres
restart: unless-stopped
postgres:
image: postgres:14
container_name: grafana-db
environment:
- POSTGRES_DB=grafana
- POSTGRES_USER=grafana
- POSTGRES_PASSWORD=secure_password
volumes:
- postgres_data:/var/lib/postgresql/data
restart: unless-stopped
volumes:
grafana_data:
postgres_data:
- Initial Configuration
bash
# Create configuration file
cat > config/grafana.ini << 'EOF'
[paths]
data = /var/lib/grafana
logs = /var/log/grafana
plugins = /var/lib/grafana/plugins
[server]
http_port = 3000
domain = grafana.yourdomain.com
root_url = https://grafana.yourdomain.com
[database]
type = postgres
host = postgres:5432
name = grafana
user = grafana
password = secure_password
[security]
admin_user = admin
admin_password = admin_password
secret_key = your_secret_key_here
cookie_secure = true
cookie_samesite = strict
[users]
allow_sign_up = false
allow_org_create = false
auto_assign_org = true
auto_assign_org_role = Viewer
[auth]
disable_login_form = false
disable_signout_menu = false
[unified_alerting]
enabled = true
EOF
- Deploy Services
bash
# Start services
docker-compose up -d
# Check status
docker-compose ps
docker-compose logs -f grafana
# Wait for initialization
sleep 30
# Access Grafana
curl -I http://localhost:3000
Initial Setup Verification bash
# Test login
curl -c cookies.txt -X POST \
-H "Content-Type: application/json" \
-d '{"user":"admin","password":"admin_password"}' \
http://localhost:3000/login
# Check health
curl -b cookies.txt http://localhost:3000/api/health
# List data sources
curl -b cookies.txt http://localhost:3000/api/datasources