Sunucu İzleme Araçları: Grafana, Prometheus ve Netdata
Prometheus + Grafana stack kurulumu, Netdata, node_exporter, alert kuralları, dashboard oluşturma ve sunucu metrik izleme.
Squid forward proxy, HAProxy load balancer, SSL termination, ACL kuralları, caching, health check ve yüksek erişilebilirlik.
Proxy sunucular, ağ trafiğini yönetmek, güvenliği artırmak ve yük dengeleme sağlamak için kritik bileşenlerdir. Bu rehberde Squid forward proxy ve HAProxy load balancer kurulumunu detaylı olarak ele alacağız.
Squid, en yaygın kullanılan açık kaynaklı forward proxy ve caching sunucusudur. Web trafiğini önbelleğe alarak bant genişliği tasarrufu sağlar ve erişim kontrolü kurallarıyla ağ güvenliğini artırır.
Squid'in temel özellikleri:
# Ubuntu/Debian
sudo apt update
sudo apt install squid -y
# CentOS/RHEL
sudo dnf install squid -y
# Servis durumu
sudo systemctl enable --now squid
sudo systemctl status squid
# docker-compose.yml
version: '3.8'
services:
squid:
image: ubuntu/squid:latest
container_name: squid-proxy
restart: unless-stopped
ports:
- "3128:3128"
volumes:
- ./squid.conf:/etc/squid/squid.conf
- squid_cache:/var/spool/squid
- squid_logs:/var/log/squid
volumes:
squid_cache:
squid_logs:
# /etc/squid/squid.conf
# Ağ tanımları
acl localnet src 10.0.0.0/8
acl localnet src 172.16.0.0/12
acl localnet src 192.168.0.0/16
# Port tanımları
acl SSL_ports port 443
acl Safe_ports port 80 # HTTP
acl Safe_ports port 443 # HTTPS
acl Safe_ports port 21 # FTP
acl Safe_ports port 1025-65535 # Yüksek portlar
acl CONNECT method CONNECT
# Erişim kuralları
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localnet
http_access allow localhost
http_access deny all
# Proxy portu
http_port 3128
# Cache ayarları
cache_mem 256 MB
maximum_object_size_in_memory 512 KB
cache_dir ufs /var/spool/squid 10000 16 256
maximum_object_size 100 MB
minimum_object_size 0 KB
# Log ayarları
access_log /var/log/squid/access.log squid
cache_log /var/log/squid/cache.log
# DNS ayarları
dns_nameservers 8.8.8.8 8.8.4.4
# Gizlilik
forwarded_for off
request_header_access Via deny all
request_header_access X-Forwarded-For deny all
# Belirli siteleri engelle
acl blocked_sites dstdomain .facebook.com .twitter.com .instagram.com
http_access deny blocked_sites
# Belirli dosya türlerini engelle
acl blocked_extensions urlpath_regex -i \.(mp3|mp4|avi|mkv)$
http_access deny blocked_extensions
# Çalışma saatleri dışında erişimi kısıtla
acl work_hours time MTWHF 08:00-18:00
acl social_media dstdomain .youtube.com .reddit.com
http_access deny social_media !work_hours
# IP bazlı erişim
acl admin_ips src 192.168.1.100 192.168.1.101
http_access allow admin_ips
# Bant genişliği sınırlama
delay_pools 1
delay_class 1 2
delay_parameters 1 1000000/1000000 500000/500000
delay_access 1 allow localnet
# NCSA (htpasswd) kimlik doğrulama
sudo apt install apache2-utils -y
sudo htpasswd -c /etc/squid/passwords kullanici1
sudo htpasswd /etc/squid/passwords kullanici2
# squid.conf'a ekle
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwords
auth_param basic realm Proxy Kimlik Dogrulama
auth_param basic credentialsttl 2 hours
acl authenticated proxy_auth REQUIRED
http_access allow authenticated
http_access deny all
HAProxy (High Availability Proxy), yüksek performanslı bir TCP/HTTP load balancer ve proxy sunucusudur. Milyonlarca eşzamanlı bağlantıyı yönetebilir ve kurumsal düzeyde yük dengeleme sağlar.
HAProxy'nin temel özellikleri:
# Ubuntu/Debian
sudo apt update
sudo apt install haproxy -y
# Versiyon kontrolü
haproxy -v
# Servis başlat
sudo systemctl enable --now haproxy
# docker-compose.yml
version: '3.8'
services:
haproxy:
image: haproxy:latest
container_name: haproxy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- "8404:8404"
volumes:
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
- ./certs:/etc/haproxy/certs:ro
sysctls:
- net.ipv4.ip_unprivileged_port_start=0
# /etc/haproxy/haproxy.cfg
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
# SSL ayarları
ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256
ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384
ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
tune.ssl.default-dh-param 2048
defaults
log global
mode http
option httplog
option dontlognull
option forwardfor
option http-server-close
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
# İstatistik paneli
listen stats
bind *:8404
stats enable
stats uri /stats
stats refresh 10s
stats admin if LOCALHOST
stats auth admin:GucluSifre123
# HTTP → HTTPS yönlendirme
frontend http_front
bind *:80
redirect scheme https code 301 if !{ ssl_fc }
# HTTPS frontend
frontend https_front
bind *:443 ssl crt /etc/haproxy/certs/example.com.pem
# ACL kuralları
acl is_api path_beg /api
acl is_static path_end .css .js .png .jpg .gif .ico
# Backend yönlendirme
use_backend api_servers if is_api
use_backend static_servers if is_static
default_backend web_servers
# Web sunucuları backend
backend web_servers
balance roundrobin
option httpchk GET /health
http-check expect status 200
cookie SERVERID insert indirect nocache
server web1 192.168.1.10:8080 check cookie web1 weight 100
server web2 192.168.1.11:8080 check cookie web2 weight 100
server web3 192.168.1.12:8080 check cookie web3 weight 50 backup
# API sunucuları backend
backend api_servers
balance leastconn
option httpchk GET /health
server api1 192.168.1.20:3000 check
server api2 192.168.1.21:3000 check
# Statik dosya sunucuları
backend static_servers
balance uri
server static1 192.168.1.30:80 check
server static2 192.168.1.31:80 check
# Let's Encrypt sertifikası ile HAProxy
# PEM dosyası oluştur (cert + key birleşik)
sudo cat /etc/letsencrypt/live/example.com/fullchain.pem \
/etc/letsencrypt/live/example.com/privkey.pem \
> /etc/haproxy/certs/example.com.pem
# Sertifika yenileme hook'u
sudo tee /etc/letsencrypt/renewal-hooks/post/haproxy.sh > /dev/null <<'EOF'
#!/bin/bash
cat /etc/letsencrypt/live/example.com/fullchain.pem \
/etc/letsencrypt/live/example.com/privkey.pem \
> /etc/haproxy/certs/example.com.pem
systemctl reload haproxy
EOF
sudo chmod +x /etc/letsencrypt/renewal-hooks/post/haproxy.sh
# Gelişmiş health check
backend web_servers
option httpchk
http-check connect
http-check send meth GET uri /health ver HTTP/1.1 hdr Host example.com
http-check expect status 200
# Health check aralıkları
server web1 192.168.1.10:8080 check inter 5s fall 3 rise 2
server web2 192.168.1.11:8080 check inter 5s fall 3 rise 2
frontend https_front
bind *:443 ssl crt /etc/haproxy/certs/example.com.pem
# Rate limiting - IP başına saniyede 20 istek
stick-table type ip size 100k expire 30s store http_req_rate(10s)
http-request track-sc0 src
http-request deny deny_status 429 if { sc_http_req_rate(0) gt 200 }
# DDoS koruması
stick-table type ip size 100k expire 30s store conn_cur
http-request deny deny_status 429 if { src_conn_cur ge 50 }
Keepalived ile HAProxy HA kurulumu:
# Keepalived kurulumu
sudo apt install keepalived -y
# /etc/keepalived/keepalived.conf (Master)
vrrp_script check_haproxy {
script "/usr/bin/killall -0 haproxy"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass GucluSifre
}
virtual_ipaddress {
192.168.1.100/24
}
track_script {
check_haproxy
}
}
# Squid yapılandırma kontrolü
squid -k parse
squid -k reconfigure
# HAProxy yapılandırma kontrolü
haproxy -c -f /etc/haproxy/haproxy.cfg
# Proxy testi
curl -x http://proxy-ip:3128 http://example.com
curl -x https://proxy-ip:3128 https://example.com
# HAProxy stats
curl http://localhost:8404/stats
# HAProxy log izleme
tail -f /var/log/haproxy.log
REXE sunucularınızda Squid ile güvenli internet erişimi ve HAProxy ile yüksek erişilebilir yük dengeleme kurabilirsiniz. SSL termination ve health check özellikleri ile kurumsal düzeyde altyapı oluşturabilirsiniz.
Squid yapılandırmasında SSL_ports ACL'inin 443 portunu içerdiğinden ve 'http_access deny CONNECT !SSL_ports' kuralının doğru sırada olduğundan emin olun. HTTPS trafiği CONNECT metodu kullanır. Firewall'da 3128 portunun açık olduğunu kontrol edin. İstemci tarafında proxy ayarlarının doğru yapılandırıldığını doğrulayın.
Health check endpoint'inin (/health) backend sunucularda çalıştığını doğrulayın. 'http-check expect status 200' ayarını kontrol edin. Backend sunuculara HAProxy'den erişilebildiğini test edin: 'curl http://192.168.1.10:8080/health'. HAProxy loglarını inceleyin: 'tail -f /var/log/haproxy.log'. Health check aralığını ve fall/rise değerlerini ayarlayın.
Let's Encrypt sertifikasını PEM formatına dönüştürün: 'cat fullchain.pem privkey.pem > example.com.pem'. HAProxy frontend'inde 'bind *:443 ssl crt /etc/haproxy/certs/example.com.pem' şeklinde tanımlayın. Sertifika yenileme için renewal hook scripti oluşturun. Birden fazla domain için SNI kullanabilirsiniz.
cache_mem değerini artırın (512 MB veya daha fazla). cache_dir boyutunu disk kapasitesine göre ayarlayın. maximum_object_size değerini büyük dosyalar için artırın. SSD disk kullanın. refresh_pattern kurallarıyla cache süresini optimize edin. Cache hit oranını 'squidclient mgr:info' ile izleyin.
Backend tanımında 'cookie SERVERID insert indirect nocache' ekleyin ve her server satırına 'cookie sunucu_adi' parametresi verin. HAProxy, istemciye bir cookie gönderir ve sonraki istekleri aynı backend sunucuya yönlendirir. Alternatif olarak 'stick-table' ile IP bazlı yapışkanlık da kullanabilirsiniz.
HAProxy özellikle load balancing için tasarlanmıştır ve bu alanda daha gelişmiş özellikler sunar: detaylı health check, gelişmiş algoritma seçenekleri (leastconn, uri, hdr), gerçek zamanlı stats dashboard ve daha düşük gecikme. Nginx ise web sunucu + reverse proxy olarak daha çok yönlüdür. Yüksek trafikli ortamlarda HAProxy genellikle tercih edilir.
Prometheus + Grafana stack kurulumu, Netdata, node_exporter, alert kuralları, dashboard oluşturma ve sunucu metrik izleme.
Nginx Proxy Manager Docker kurulumu, SSL sertifikası otomatik yenileme, proxy host ekleme, access list, redirect, stream ve custom location.
CrowdSec kurulumu, bouncer yapılandırması, saldırı algılama, IP engelleme, dashboard, koleksiyon ve senaryo yönetimi.