segurança e performance em serviços web - lamp
DESCRIPTION
Palestra sobre performance e segurança webTRANSCRIPT
Performance&
Segurança Servidores WEB
Toronto Garcez
Performance – Load Balance e Cache
Proxy reverso Squid / Varnish Round-robin Peso (weight) Cache Escalabilidade Disponibilidade
Performance – Load Balance e Cache
SQUID Suporte SSL Suporte para Antivirus Cache em disco
Performance – Load Balance e Cache
Varnish Feito para CMS lentos Cache em RAM Round-robin / random Compressão (gzip) Security.VCL(Uma camada a mais, não substitui o modsec!!!!!)
Performance – Varnish x Squid
Performance – Elementos web
Estáticos HTML CSS JavaScript Imagens (jpg, png, gif...) Vídeos XML SWF (Flash)
Dinâmicos PHP, ASP, ...
Não é preciso carregar o PHP e seus módulos para entregar objetos estáticos!Consumo desnecessário de memória
Performance – Separação de requisições
Lighttpd
CSS, JS, PNG, JPEG, HMTL ...
if ( req.http.host && req.request == "GET" && req.url ~ "\.(gif|jpg|jpeg|bmp|png|tiff|tif|ico|img|tga|wmf|html|js|swf|css)$")
{ set req.backend = servidor_lighttpd; }
Performance – Mod_cache Apache
Cache Cache Cache
Mod_cache mod_disk_cache<IfModule mod_disk_cache.c> CacheRoot /var/cache/apache2/mod_disk_cache CacheEnable disk / CacheDirLevels 5 CacheDirLength 3</IfModule>
mod_mem_cache
<IfModule mod_mem_cache.c> CacheEnable mem / MCacheSize 4096 MCacheMaxObjectCount 100 MCacheMinObjectSize 1 MCacheMaxObjectSize 2048</IfModule>
Performance – Memcached
Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
Users
● Wikipedia
● Flickr
● Youtube
● WordPress.com
Performance – Memcachedbom vamos a um exemplo
$mem = new Memcache;
$mem->addServer("localhost:11211");
$mem->set("chave01", $array, TRUE, 60);
No exemplo acima, eu estou armazenando na chave01 meu array por 60 segundos.
Agora para pegar esse conteúdo, você deve usar a função get. Vamos ao exemplo.
$mem = new Memcache;
$mem->addServer("localhost:11211");
$resp = $mem->get("chave01");
print_r($resp);
Performance – MySQL
Cache
/etc/my.cnfquery_cache_type=1 # Habilita o cachequery_cache_limit=10M # Tamanho máximo por consultaquery_cache_size=100M # Tamanho do cache
Temporary Tables
/etc/my.cnftmpdir = /disco2 #Disco rápido
Performance – Geração de HTMLs
SCRIPT PHP – Colocar no cronphp -f /scripts/gera_html.php
<?php // Portal $vHtml = file_get_contents('http://www.site.com/index.php?'.rand(0,1000000)); if(!empty($vHtml)) file_put_contents('/var/www/html/index.html', $vHtml); ?>
Apache<VirtualHost *:80> ... DirectoryIndex index.html index.php</VirtualHost>
Performance – CDN
30% tráfego da internet
● Akamai ● Ananke CDN● Azion● CDNetworks● CDN77● EdgeCast Networks● Limelight Networks
Segurança – WAF
Perguntas?
Contato: [email protected]
Obg! :)