<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Carlos André Ferrari</title>
	<atom:link href="http://ferrari.eti.br/feed/" rel="self" type="application/rss+xml" />
	<link>http://ferrari.eti.br</link>
	<description>php, python, xhtml, html5, css, javascript, jquery, webstandards, linux, nginx</description>
	<lastBuildDate>Thu, 21 Jul 2011 12:42:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Usando MongoDB como storage de arquivos #2</title>
		<link>http://ferrari.eti.br/usando-mongodb-como-storage-de-arquivos-2/</link>
		<comments>http://ferrari.eti.br/usando-mongodb-como-storage-de-arquivos-2/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 12:42:59 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[Sem categoria]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=160</guid>
		<description><![CDATA[No post anterior foi mostrado como montar um replicaSet para guardarmos nossos arquivos, aqui vou mostrar como configurar o servidor de aplicação e uma instância do MongoDB como arbitro. Minha aplicação vai rodar também em uma maquina Ubuntu Server 11.04, com o PHP5.3, vamos configurar isso tudo de uma vez! Instalação do PHP Vamos precisar [...]]]></description>
			<content:encoded><![CDATA[<p>No <a href="http://ferrari.eti.br/usando-mongodb-como-storage-de-arquivos-1/">post anterior</a> foi mostrado como montar um replicaSet para guardarmos nossos arquivos, aqui vou mostrar como configurar o servidor de aplicação e uma instância do MongoDB como <a href="http://www.mongodb.org/display/DOCS/Replica+Sets+-+Voting">arbitro</a>.</p>
<p>Minha aplicação vai rodar também em uma maquina Ubuntu Server 11.04, com o PHP5.3, vamos configurar isso tudo de uma vez!</p>
<h2>Instalação do PHP</h2>
<p>Vamos precisar instalar alguns pacotes para tudo funcionar, comece instalando o mongodb, da mesma forma que foi feito no item &#8220;instalação&#8221; do post anterior, depois vamos precisar de mais alguns pacotes:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">sudo aptitude install libapache2-mod-php5 php-apc php-pear php5-dev build-essential</pre></div></div>

<ul>
<li><strong>libapache2-mod-php5</strong>: Instala o apache2, o php5 e claro, o modulo do apache</li>
<li><strong>php-apc</strong>: Modulo de cache de opcode do php, para performance =)</li>
<li><strong>php-pear</strong>: Vamos precisar paixar o modulo do mongo para o php</li>
<li><strong>php5-dev</strong> e <strong>build-essential</strong>: Para que o modulo possa ser compilado</li>
</ul>
<p>Depois de tudo instalado, vamos configurar o php para poder acessar o mongo e reiniciar o apache</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">sudo pecl install mongo
sudo sh -c 'echo &quot;extension=mongo.so&quot; &amp;gt; /etc/php5/apache2/conf.d/mongodb.ini'
sudo service apache2 restart</pre></div></div>

<h2>Configuração do Arbitro</h2>
<p>Como disse no post anterior, o Arbitro é uma instancia do mongo que existe apenas para decidir qual dos membros do replicaSet será o novo Master caso algum venha a falhar de alguma forma.</p>
<p>Primeiro edite todos os arquivos /etc/hosts das maquinas do replicaSet e adicione o IP do arbitro (que no meu caso é o IP do servidor de aplicação) e também adicione estas entradas no servidor de aplicação</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">192.168.0.100      arquivo1a 
192.168.0.101      arquivo1b
192.168.0.102      arquivo1bkp
192.168.0.99       arquivo1arbiter</pre></div></div>

<p>Depois disso, faça login no servidor que é o seu nó Master do replicaSet, verifique quem é acessando:</p>
<p>http://192.168.0.101:28017/_replSet</p>
<p>e vamos configurar, acesse a administração do mongo:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">mongo admin</pre></div></div>

<p>e adicione o arbitro ao replicaSet:</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">rs.addArb(&quot;arquivo1arbiter&quot;)</pre></div></div>

<p>feito isso, de ctrl+c e confira o status do seu replicaSet (http://192.168.0.101:28017/_replSet):<br />
<a href="http://ferrari.eti.br/wp-content/uploads/2011/07/replica2.jpg"><img class="aligncenter" title="replica2" src="http://ferrari.eti.br/wp-content/uploads/2011/07/replica2.jpg" alt="" width="500" height="175" /></a></p>
<p>Com isso nosso replicaSet está pronto para receber nossa aplicação, faça testes desligando o processo de seus clientes e veja como um outro assume, neste caso, se o servidor arquivo1a e arquivo1b caírem, a aplicação para, mas é muito simples adicionar novos nós para aumentar essa segurança,  o mínimo para um replicaSet de produção são 3 instâncias para armazenamento, uma de backup e um arbitro.</p>
<p>até a próxima parte.</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/usando-mongodb-como-storage-de-arquivos-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Usando MongoDB como storage de arquivos #1</title>
		<link>http://ferrari.eti.br/usando-mongodb-como-storage-de-arquivos-1/</link>
		<comments>http://ferrari.eti.br/usando-mongodb-como-storage-de-arquivos-1/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 12:42:14 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[Sem categoria]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=152</guid>
		<description><![CDATA[Estou envolvido em um projeto que vai necessitar armazenar muitos arquivos, e precisava de uma solução que fosse tolerante a falhas e escalasse muito bem, tanto verticalmente (Mais disco) quanto horizontalmente (Mais servidores). Depois de olhar algumas soluções existentes como MogileFS, Cassandra, entre outros, eu gostei bastante do GridFS do MongoDB, pela simplicidade de configuração [...]]]></description>
			<content:encoded><![CDATA[<p>Estou envolvido em um projeto que vai necessitar armazenar muitos arquivos, e precisava de uma solução que fosse tolerante a falhas e escalasse muito bem, tanto verticalmente (Mais disco) quanto horizontalmente (Mais servidores).</p>
<p>Depois de olhar algumas soluções existentes como <a href="http://danga.com/mogilefs/">MogileFS</a>, <a href="http://cassandra.apache.org/">Cassandra</a>, entre outros, eu gostei bastante do <a href="http://www.mongodb.org/display/DOCS/GridFS">GridFS</a> do <a href="http://www.mongodb.org/">MongoDB</a>, pela simplicidade de configuração e principalmente pelo sistema de eleição de um novo servidor mestre caso o ativo venha a falhar em um determinado <a href="http://www.mongodb.org/display/DOCS/Replica+Sets">replicaSet</a>.</p>
<p>Minha configuração inicial dessa estrutura consiste em dois servidores de Storage (Ubuntu Server 11.04 64bits rodando em VMs vmware em discos diferentes) e uma terceira maquina simples e remota que será um backup onde será configurado meu primeiro ReplicaSet. No servidor de aplicação vou ter o MongoDB rodando como arbitro (sem armazenar dados) apenas para determinar qual o servidor é o mestre caso algum venha a falhar.</p>
<h2>Instalação:</h2>
<p>Considerando que nos servidores foi instalado o ubuntu server, sem nada, vamos a configuração:</p>
<p>primeiro vamos adicionar a linha na configuração do APT para podermos baixar o <a href="http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages">pacote oficial</a> do MongoDB, mantido pela <a href="http://www.10gen.com/">10-gen</a>, crie o arquivo: /etc/apt/sources.list.d/mongo.list e adicione a linha:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen</pre></div></div>

<p>depois de salvar o arquivo, adicione a chave do repositorio:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10</pre></div></div>

<p>e finalmente instale o mongodb:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">sudo aptitude update
sudo aptitude install mongodb-10gen</pre></div></div>

<p>repita este processo em todas as maquinas de seu replicaSet.</p>
<h2>Configuração do MongoDB</h2>
<p>Primeiro vamos criar a pasta de armazenamento dos dados e definir as permissões:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">sudo mkdir /dados
sudo chown mongodb:mongodb /dados/
sudo chmod 700 mongodb -Rf</pre></div></div>

<p>Em todos os servidores vamos editar a configuração do MongoDB em /etc/mongodb.conf, aqui ficou assim:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">dbpath</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/dados/</span>
<span style="color: #000099;">logpath</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/var/log/mongodb/mongodb.log</span>
<span style="color: #000099;">logappend</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">true</span>
<span style="color: #000099;">replSet</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> arquivo1</span>
<span style="color: #000099;">rest</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">true</span></pre></div></div>

<p>* o parâmetro rest, faz com o que o servidor crie uma página para monitoramento dos status.</p>
<p>Depois de configurar todos os membros do replicaSet, reinicie o processo em todas as maquinas:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">sudo service mongodb restart</pre></div></div>

<p>Agora temos os servidores prontos para configurar a parte mais simples, o replicaset</p>
<h2>Configuração do ReplicaSet</h2>
<p>Para facilitar, configure nomes para seus membros do replicaSet no seu servidor de DNS interno ou, edite o arquivo /etc/hosts e adicione as maquinas que serão membro do replicaSet:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">192.168.0.100      arquivo1a 
192.168.0.101      arquivo1b
192.168.0.102      arquivo1bkp</pre></div></div>

<p>* Ajuste os IPs de acordo com sua rede.</p>
<p>Agora, em um servidor qualquer, acesse o console de administração do Mongo:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">mongo admin</pre></div></div>

<p>e crie a configuração do replicaSet:</p>

<div class="wp_syntax"><div class="code"><pre class="json" style="font-family:monospace;">conf = { _id : 'arquivo1',                    
... members : [
... {_id: 0, host: 'arquivo1a'}, 
... {_id: 1, host: 'arquivo1b'},
... {_id: 2, host: 'arquivo1bkp', priority: 0}
... ]}</pre></div></div>

<p>* Note que o servidor de backup tem prioridade zero, isto faz com que este servidor nunca seja eleito como servidor Mestre.<br />
confira se está tudo ok:</p>

<div class="wp_syntax"><div class="code"><pre class="json" style="font-family:monospace;">{
	&quot;_id&quot; : &quot;arquivo1&quot;,
	&quot;members&quot; : [
		{
			&quot;_id&quot; : 0,
			&quot;host&quot; : &quot;arquivo1a&quot;
		},
		{
			&quot;_id&quot; : 1,
			&quot;host&quot; : &quot;arquivo1b&quot;
		},
		{
			&quot;_id&quot; : 2,
			&quot;host&quot; : &quot;arquivo1bkp&quot;,
			&quot;priority&quot; : 0
		}
	]
}</pre></div></div>

<p>se estiver ok, ainda no console do Mongo, inicialize o replicaset:</p>

<div class="wp_syntax"><div class="code"><pre class="json" style="font-family:monospace;">rs.initiate(conf)</pre></div></div>

<p>em 10 segundos o seu replicaSet deverá estar rodando e pronto para receber dados, veja como está pelo navegador, acessando:</p>

<div class="wp_syntax"><div class="code"><pre class="url" style="font-family:monospace;">http://192.168.0.100:28017/_replSet</pre></div></div>

<p>Você verá uma tela com o status de todos os membros do replicaSet:<br />
<a href="http://ferrari.eti.br/wp-content/uploads/2011/07/replica.jpg"><img class="aligncenter" title="replica" src="http://ferrari.eti.br/wp-content/uploads/2011/07/replica.jpg" alt="" width="500" height="154" /></a></p>
<p>Bom, é isso, no próximo post vou explicar como configurar o php e efetivamente armazenar arquivos no GridFS, Abraços</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/usando-mongodb-como-storage-de-arquivos-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Flash Plugin 11 beta no Ubuntu 64</title>
		<link>http://ferrari.eti.br/flash-plugi-11-beta-no-ubuntu-64/</link>
		<comments>http://ferrari.eti.br/flash-plugi-11-beta-no-ubuntu-64/#comments</comments>
		<pubDate>Sat, 16 Jul 2011 11:12:01 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[diversos]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=136</guid>
		<description><![CDATA[Saiu recentemente a versão beta do pugin do flash 11, e esta versão está funcionando muito melhor no Ubuntu 64bits, para instalar é bem simples: wget http://download.macromedia.com/pub/labs/flashplatformruntimes/flashplayer11/flashplayer11_b1_install_lin_64_071311.tar.gz tar -zxvf flashplayer11_b1_install_lin_64_071311.tar.gz sudo cp usr / -Rfv sudo cp libflashplayer.so /usr/lib/flashplugin-installer/ /etc/alternatives/firefox-flashplugin Depois é só reiniciar seu firefox e conseguir ver aquelas apresentações legais no slideshare.]]></description>
			<content:encoded><![CDATA[<p>Saiu recentemente a versão beta do pugin do flash 11, e esta versão está funcionando muito melhor no Ubuntu 64bits, para instalar é bem simples:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>download.macromedia.com<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>labs<span style="color: #000000; font-weight: bold;">/</span>flashplatformruntimes<span style="color: #000000; font-weight: bold;">/</span>flashplayer11<span style="color: #000000; font-weight: bold;">/</span>flashplayer11_b1_install_lin_64_071311.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxvf</span> flashplayer11_b1_install_lin_64_071311.tar.gz
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> usr <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-Rfv</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> libflashplayer.so <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>flashplugin-installer<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>alternatives<span style="color: #000000; font-weight: bold;">/</span>firefox-flashplugin</pre></div></div>

<p>Depois é só reiniciar seu firefox e conseguir ver aquelas apresentações legais no slideshare.</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/flash-plugi-11-beta-no-ubuntu-64/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pegando a temperatura de qualquer cidade</title>
		<link>http://ferrari.eti.br/pegando-a-temperatura-de-qualquer-cidade/</link>
		<comments>http://ferrari.eti.br/pegando-a-temperatura-de-qualquer-cidade/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 09:36:38 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[codigo]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[temperatura]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=126</guid>
		<description><![CDATA[Me surgiu um trabalho aqui pelo qual preciso exibir a temperatura atual da cidade, e como estava com insônia decidi brincar um pouco e criar uma solução para isso, fui para o google e pesquisei por &#8220;Previsão do Tempo&#8220;, me surgiram alguns resultados, porém, gostei mais do UOL. Depois disso foi correr para a criação [...]]]></description>
			<content:encoded><![CDATA[<p>Me surgiu um trabalho aqui pelo qual preciso exibir a <strong>temperatura</strong> atual da cidade, e como estava com insônia decidi brincar um pouco e criar uma solução para isso, fui para o google e pesquisei por &#8220;<strong>Previsão do Tempo</strong>&#8220;, me surgiram alguns resultados, porém, gostei mais do <a href="http://tempoagora.uol.com.br/previsaodotempo.html/brasil/Palmas-TO/">UOL</a>.</p>
<p>Depois disso foi correr para a criação do script para ler o HTML e retornar um objeto contendo as informações da temperatura no momento, segue o código escrito em <strong>php</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> loadTemp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cidade</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'Palmas-TO'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// variavel para dados de retorno</span>
	<span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;http://tempoagora.uol.com.br/previsaodotempo.html/brasil/<span style="color: #006699; font-weight: bold;">$cidade</span>/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// carrega o html do tempoagora</span>
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Pegamos apenas a parte que interessa do html</span>
	<span style="color: #000088;">$iniflag</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;!-- Insere dados Atuais de AeroPortos ou Est. Meteorologica --&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$fimflag</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;!-- FIM Insere dados Atuais de AeroPortos ou Est. Meteorologica --&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ini</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #000088;">$iniflag</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iniflag</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$fim</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fimflag</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ini</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ini</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fim</span><span style="color: #339933;">-</span><span style="color: #000088;">$ini</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// pegamos a url do icone</span>
	<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@&lt;img src=&quot;/(imagens/icones/[a-zA-Z\-]+.gif)&quot;@'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mat</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'icone'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://tempoagora.uol.com.br/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$mat</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Limpa o código html</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;nbsp;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// quebra o que sobrou em um vetor</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// limpa espaços e linhas em branco</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$v</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #339933;">===</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// pega horário da verificação</span>
	<span style="color: #000088;">$lin</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@[0-9]{1,2}:[0-9]{1,2}@'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lin</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mat</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'verificado'</span><span style="color: #009900;">&#93;</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$mat</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// pega insidência de nuvens</span>
	<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nuvens'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// define nomes melhores para as próximas propriedades</span>
	<span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'temperatura'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sensacao'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'vento'</span><span style="color: #339933;">,</span> 
			<span style="color: #0000ff;">'pressao'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'umidade'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'visibilidade'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// reseta as chaves do vetor</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_unique</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// percorre chaves impares e aplica as propriedades definidas acima</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">&lt;=</span><span style="color: #cc66cc;">11</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">=</span><span style="color: #000088;">$x</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keys</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// retorna os dados como um objeto</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span><span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Analisando o site deles, notei que a <strong>temperatura</strong> é atualizada de hora em hora, então a melhor forma de utilizar essa solução é utilizando o <strong>crontab</strong>, que executa a cada hora, eu escolhi executar no quinto minuto de cada hora cheia (5:05, 6:05, etc).</p>
<p>segue o código <strong>php</strong> que o <strong>crontab</strong> executa:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'loadTemp.php'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// define nome do arquivo de cache</span>
<span style="color: #000088;">$cache_file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sys_get_temp_dir</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/temp'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// carrega a temperatura</span>
<span style="color: #000088;">$temp</span> <span style="color: #339933;">=</span> loadTemp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// salva em cache</span>
<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache_file</span><span style="color: #339933;">,</span> <span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$temp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>E para exibir no sistema eu fiz uma funçãozinha:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> temp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$cache_file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sys_get_temp_dir</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/temp'</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// se o cache existe, retorna o objeto</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// senão cria o cache e retorna =)</span>
	<span style="color: #000088;">$temp</span> <span style="color: #339933;">=</span> loadTemp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache_file</span><span style="color: #339933;">,</span> <span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$temp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>depois, no local específico, ficou algo mais ou menos assim:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$temp</span> <span style="color: #339933;">=</span> temp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">icone</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; alt=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nuvens</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&lt;span&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">temperatura</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> (&lt;a rel=&quot;external&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;saiba mais&lt;/a&gt;)&lt;/span&gt;</pre></div></div>

<p>Minha forma de pagar por esse uso é manter um link para o <a href="http://tempoagora.uol.com.br/">Tempoagora</a>, o que é bastante interessante, pois meu visitante pode querer obter mais informações</p>
<p>É isso ai, abraço a todos</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/pegando-a-temperatura-de-qualquer-cidade/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Classe, WebService e RSS para rastreamento de encomendas nos Correios em PHP</title>
		<link>http://ferrari.eti.br/classe-api-webservice-para-rastreamento-de-encomendas-nos-correios-em-php/</link>
		<comments>http://ferrari.eti.br/classe-api-webservice-para-rastreamento-de-encomendas-nos-correios-em-php/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 10:25:32 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[github]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[opensource]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=117</guid>
		<description><![CDATA[Olá, depois de meses sem escrever estou voltando com uma classe muito útil e simples que nunca vi em lugar nenhum. É uma classe para rastrear encomendas nos correios que eu escrevi em PHP, que retorna um vetor com cada modificação de status lá. Vamos direto ao ponto, confira o exemplo: http://ferrari.eti.br/correios/samples/class.php E para deixar [...]]]></description>
			<content:encoded><![CDATA[<p>Olá, depois de meses sem escrever estou voltando com uma <strong>classe</strong> muito útil e simples que nunca vi em lugar nenhum. É uma classe para rastrear encomendas nos <strong>correios</strong> que eu escrevi em <strong>PHP</strong>, que retorna um vetor com cada modificação de status lá.</p>
<p>Vamos direto ao ponto, confira o exemplo:</p>
<p><a href="http://ferrari.eti.br/correios/samples/class.php">http://ferrari.eti.br/correios/samples/class.php</a></p>
<p>E para deixar a brincadeira mais divertida, fiz também um <strong>webservice</strong> com suporte a <strong>Json</strong> (padrão), <strong>phpserialize</strong>, <strong>XML</strong> e um modo dump, para visualização:</p>
<p><a href="http://ferrari.eti.br/correios/webservice/?q=PB151832535BR">http://ferrari.eti.br/correios/webservice/?q=PB151832535BR</a><br />
<a href="http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;f=dump">http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;f=dump</a><br />
<a href="http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;f=serial">http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;f=serial</a><br />
<a href="http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;f=xml">http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;f=xml</a><br />
e claro, para quem usa <strong>Ajax</strong>:<br />
<a href="http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;callback=minhaFuncJs">http://ferrari.eti.br/correios/webservice/?q=PB151832535BR&amp;callback=minhaFuncJs</a></p>
<p>Disponibilizei tanto a classe quanto o código do webservice (que tem suporte a <strong>caching</strong>!) &#8220;de grátis&#8221; e com licença BSD no <strong>github</strong>:</p>
<p><a href="http://github.com/caferrari/correios/">http://github.com/caferrari/correios/</a></p>
<p><strong>*UPDATE* </strong>Adicionado um gerador de RSS, assim é possível usar o proprio agregador para fazer o tracking!<strong></strong></p>
<p><a href="http://ferrari.eti.br/correios/rss/?PB151832535BR">http://ferrari.eti.br/correios/rss/?PB151832535BR</a></p>
<p>e em homenagem aos atendentes de telemarketing: Estarei esperando forks e colaborações para a classe, além de comentários!.</p>
<p>Até a próxima.</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/classe-api-webservice-para-rastreamento-de-encomendas-nos-correios-em-php/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>PHP 5.3, PHP-FPM, XCache, Nginx no Debian Lenny &#8211; Performance extrema</title>
		<link>http://ferrari.eti.br/php-5-3-php-fpm-xcache-nginx-no-debian-lenny-performance-extrema/</link>
		<comments>http://ferrari.eti.br/php-5-3-php-fpm-xcache-nginx-no-debian-lenny-performance-extrema/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 14:36:08 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[webserver]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php-fpm]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[xcache]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=112</guid>
		<description><![CDATA[Neste post vou exemplificar os passos para configurar um Webserver que consome poucos recursos e é extremamente rápido no Debian Lenny. PHP-FPM: é um gerenciador de processos CGI do php, similar ao Phpcgi, porém com várias vantagens como: Gerenciador de Processos muito eficiente, com capacidade de parar e iniciar seus deamons caso necessário Possibilidade de [...]]]></description>
			<content:encoded><![CDATA[<p>Neste post vou exemplificar os passos para configurar um Webserver que consome poucos recursos e é extremamente rápido no <a href="http://www.debian.org/">Debian Lenny</a>.</p>
<p><a href="http://php-fpm.org/">PHP-FPM</a>: é um gerenciador de processos CGI do php, similar ao Phpcgi, porém com várias vantagens como:</p>
<ul>
<li>Gerenciador de Processos muito eficiente, com capacidade de parar e iniciar seus <a href="http://en.wikipedia.org/wiki/Daemon">deamons</a> caso necessário</li>
<li>Possibilidade de Iniciar processos com usuários diferentes e com arquivos php.ini diferentes</li>
<li>Uploads otimizados</li>
<li>Capacidade de reinicializar processos caso ocorra algum problema</li>
<li>Escalabilidade de processos, ele pode criar mais processos de acordo com a demanda</li>
<li>e muito mais.</li>
</ul>
<p><a href="http://xcache.lighttpd.net/">XCache</a>: é um gerenciador de cache, que armazena os scripts php em <a href="http://en.wikipedia.org/wiki/Opcode">opcode</a> para uso futuro, é extremamente rápido e muito usado no mundo em servidores com alta demanda.</p>
<p><a href="http://nginx.org">Nginx</a>: Conheci este webserver lendo o <a href="http://www.boo-box.com/blog/br/2009/nova-infraestrutura-de-servidores-web-do-sistema-boo-box/">blog da boo-box</a>, ele é um Servidor web e proxy reverso extremamente veloz e que vem ganhando mercado nos últimos meses devido a sua facilidade de uso e capacidade de carga.</p>
<p style="text-align: center;"><a href="http://royal.pingdom.com/2010/01/22/internet-2009-in-numbers/"><img class="aligncenter" title="Market Share de navegadores no final de 2009" src="http://farm5.static.flickr.com/4022/4295546152_b8e094e8cc_o.png" alt="Market Share de navegadores no final de 2009" width="580" height="300" /></a></p>
<p>Para agilizar a configuração, vamos usar alguns pacotes (php5.3, php-fpm) pré compilados e mantidos <a href="http://www.dotdeb.org/">www.dotdeb.org.</a> os testes que eu realzei usando estes pacotes tiveram um ganho de performance enorme.</p>
<h3>Instalação:</h3>
<p>Vamos começar adicionado os repositórios do dotdeb no /etc/apt/sources.list:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">deb http:<span style="color: #000000; font-weight: bold;">//</span>php53.dotdeb.org stable all
deb-src http:<span style="color: #000000; font-weight: bold;">//</span>php53.dotdeb.org stable all</pre></div></div>

<p>Vamos instalar os pacotes e algumas dependências para o nginx:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> update
<span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-fpm php5-xcache php5-gd php5-curl \
php5-mysql php5-pgsql libssl-dev libpcre3-dev build-essential <span style="color: #660033;">-y</span></pre></div></div>

<p>Agora temos o php instalado, vamos compilar o nginx:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> src
<span style="color: #7a0874; font-weight: bold;">cd</span> src
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>nginx.org<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>nginx-0.7.64.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zxvf</span> nginx-0.7.64.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> nginx-0.7.64
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx <span style="color: #660033;">--user</span>=www-data <span style="color: #660033;">--group</span>=www-data \
    --without-mail_pop3_module --without-mail_imap_module \
    --without-mail_smtp_module --with-http_stub_status_module \
    --with-http_ssl_module <span style="color: #660033;">--http-log-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>access.log \
    <span style="color: #660033;">--conf-path</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>nginx.conf  <span style="color: #660033;">--pid-path</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>nginx.pid
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>Se tudo ocorreu bem, você já tem o nginx instalado, vamos apenas coloca-lo para inicializar automáticamente, crie o arquivo /etc/init.d/nginx e coloque o conteúdo:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">### BEGIN INIT INFO</span>
<span style="color: #666666; font-style: italic;"># Provides:          nginx</span>
<span style="color: #666666; font-style: italic;"># Required-Start:    $all</span>
<span style="color: #666666; font-style: italic;"># Required-Stop:     $all</span>
<span style="color: #666666; font-style: italic;"># Default-Start:     2 3 4 5</span>
<span style="color: #666666; font-style: italic;"># Default-Stop:      0 1 6</span>
<span style="color: #666666; font-style: italic;"># Short-Description: starts the nginx web server</span>
<span style="color: #666666; font-style: italic;"># Description:       starts nginx using start-stop-daemon</span>
<span style="color: #666666; font-style: italic;">### END INIT INFO</span>
&nbsp;
<span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span>
<span style="color: #007800;">DAEMON</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>nginx
<span style="color: #007800;">NAME</span>=nginx
<span style="color: #007800;">DESC</span>=nginx
&nbsp;
<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-x</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Include nginx defaults if available</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>default<span style="color: #000000; font-weight: bold;">/</span>nginx <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
        . <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>default<span style="color: #000000; font-weight: bold;">/</span>nginx
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-e</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
  start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting <span style="color: #007800;">$DESC</span>: &quot;</span>
        start-stop-daemon <span style="color: #660033;">--start</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid \
                <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$DAEMON_OPTS</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NAME</span>.&quot;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Stopping <span style="color: #007800;">$DESC</span>: &quot;</span>
        start-stop-daemon <span style="color: #660033;">--stop</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid \
                <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NAME</span>.&quot;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  restart<span style="color: #000000; font-weight: bold;">|</span>force-reload<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Restarting <span style="color: #007800;">$DESC</span>: &quot;</span>
        start-stop-daemon <span style="color: #660033;">--stop</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> \
                <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
        <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
        start-stop-daemon <span style="color: #660033;">--start</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> \
                <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$DAEMON_OPTS</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NAME</span>.&quot;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  reload<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Reloading <span style="color: #007800;">$DESC</span> configuration: &quot;</span>
        start-stop-daemon <span style="color: #660033;">--stop</span> <span style="color: #660033;">--signal</span> HUP <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$NAME</span>.pid \
            <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NAME</span>.&quot;</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  configtest<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Testing <span style="color: #007800;">$DESC</span> configuration: &quot;</span>
        <span style="color: #000000; font-weight: bold;">if</span> nginx <span style="color: #660033;">-t</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">then</span>
          <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NAME</span>.&quot;</span>
        <span style="color: #000000; font-weight: bold;">else</span>
          <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$?</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: <span style="color: #007800;">$NAME</span> {start|stop|restart|reload|force-reload|configtest}&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>depois vamos torna-lo executável e atualizar o rc.d:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx
update-rc.d nginx defaults</pre></div></div>

<p>Com isso o processo de instalação está concluído, vamos configurar!</p>
<h3>Configuração do XCache</h3>
<p>Coloque a seguinte configuração no arquivo /etc/php5/fpm/conf.d/xcache.ini:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">; configuration for php xcache module</span>
<span style="color: #000099;">extension</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">xcache.so</span>
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>xcache.admin<span style="">&#93;</span></span>
xcache.admin.user <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;secom&quot;</span>
<span style="color: #666666; font-style: italic;">; xcache.admin.pass = md5($your_password)</span>
xcache.admin.pass <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;&quot;</span>
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>xcache<span style="">&#93;</span></span>
<span style="color: #666666; font-style: italic;">; ini only settings, all the values here is default unless explained</span>
<span style="color: #666666; font-style: italic;">; select low level shm/allocator scheme implemenation</span>
xcache.shm_scheme <span style="color: #000066; font-weight:bold;">=</span>        <span style="color: #933;">&quot;mmap&quot;</span>
<span style="color: #666666; font-style: italic;">; to disable: xcache.size=0</span>
<span style="color: #666666; font-style: italic;">; to enable : xcache.size=64M etc (any size &gt; 0) and your system mmap allows</span>
xcache.size  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">                64M</span>
<span style="color: #666666; font-style: italic;">; set to cpu count (cat /proc/cpuinfo |grep -c processor)</span>
xcache.count <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">                 1</span>
<span style="color: #666666; font-style: italic;">; just a hash hints, you can always store count(items) &gt; slots</span>
xcache.slots <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">                8K</span>
<span style="color: #666666; font-style: italic;">; ttl of the cache item, 0=forever</span>
xcache.ttl   <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">                 0</span>
<span style="color: #666666; font-style: italic;">; interval of gc scanning expired items, 0=no scan, other values is in seconds</span>
xcache.gc_interval <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">           0</span>
<span style="color: #666666; font-style: italic;">; same as aboves but for variable cache</span>
xcache.var_size  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">            64M</span>
xcache.var_count <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">             1</span>
xcache.var_slots <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">            8K</span>
<span style="color: #666666; font-style: italic;">; default ttl</span>
xcache.var_ttl   <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">             0</span>
xcache.var_maxttl   <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">          0</span>
xcache.var_gc_interval <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">     300</span>
xcache.test <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">                Off</span>
<span style="color: #666666; font-style: italic;">; N/A for /dev/zero</span>
xcache.readonly_protection <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> Off</span>
<span style="color: #666666; font-style: italic;">; for *nix, xcache.mmap_path is a file path, not directory.</span>
<span style="color: #666666; font-style: italic;">; Use something like &quot;/tmp/xcache&quot; if you want to turn on ReadonlyProtection</span>
<span style="color: #666666; font-style: italic;">; 2 group of php won't share the same /tmp/xcache</span>
<span style="color: #666666; font-style: italic;">; for win32, xcache.mmap_path=anonymous map name, not file path</span>
xcache.mmap_path <span style="color: #000066; font-weight:bold;">=</span>    <span style="color: #933;">&quot;/dev/zero&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">; leave it blank(disabled) or &quot;/tmp/phpcore/&quot;</span>
<span style="color: #666666; font-style: italic;">; make sure it's writable by php (without checking open_basedir)</span>
xcache.coredump_directory <span style="color: #000066; font-weight:bold;">=</span>   <span style="color: #933;">&quot;&quot;</span>
<span style="color: #666666; font-style: italic;">; per request settings</span>
xcache.cacher <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">               On</span>
xcache.stat   <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">               On</span>
xcache.optimizer <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">            On</span>
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>xcache.coverager<span style="">&#93;</span></span>
<span style="color: #666666; font-style: italic;">; per request settings</span>
<span style="color: #666666; font-style: italic;">; enable coverage data collecting for xcache.coveragedump_directory and xcache_coverager_start/stop/get/clean() functions (will hurt executing performance)</span>
xcache.coverager <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">          Off</span>
<span style="color: #666666; font-style: italic;">; ini only settings</span>
<span style="color: #666666; font-style: italic;">; make sure it's readable (care open_basedir) by coverage viewer script</span>
<span style="color: #666666; font-style: italic;">; requires xcache.coverager=On</span>
xcache.coveragedump_directory <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;&quot;</span></pre></div></div>

<h3>Configuração do Nginx</h3>
<p>Edite o arquivo em /etc/nginx/nginx.conf:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user  www-data;
&nbsp;
<span style="color: #666666; font-style: italic;">#Coloque quantos processos simultaneos, o ideal é um para cada nucleo do sistema:</span>
worker_processes  <span style="color: #000000;">4</span>;
&nbsp;
error_log  <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>error.log;
&nbsp;
events <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #666666; font-style: italic;"># numero de conexões simultaneas por worker</span>
    worker_connections  <span style="color: #000000;">1024</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
http <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    include       mime.types;
    default_type  application<span style="color: #000000; font-weight: bold;">/</span>octet-stream;
&nbsp;
    access_log  <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>access.log;
    sendfile        on;
    <span style="color: #666666; font-style: italic;"># isso é interessante, dá um ganho enorme na navegação, e o nginx aguenta tranquilamente</span>
    keepalive_timeout  <span style="color: #000000;">60</span>;
    tcp_nodelay        on;
&nbsp;
    <span style="color: #666666; font-style: italic;">## Compressão</span>
    <span style="color: #c20cb9; font-weight: bold;">gzip</span> on;
    gzip_http_version <span style="color: #000000;">1.0</span>;
    gzip_comp_level <span style="color: #000000;">2</span>;
    gzip_proxied any;
    gzip_min_length  <span style="color: #000000;">1100</span>;
    gzip_buffers <span style="color: #000000;">16</span> 8k;
    <span style="color: #666666; font-style: italic;"># mime types para zipar e adicionar header de cache</span>
    gzip_types text<span style="color: #000000; font-weight: bold;">/</span>plain text<span style="color: #000000; font-weight: bold;">/</span>css application<span style="color: #000000; font-weight: bold;">/</span>x-javascript text<span style="color: #000000; font-weight: bold;">/</span>xml application<span style="color: #000000; font-weight: bold;">/</span>xml application<span style="color: #000000; font-weight: bold;">/</span>xml+rss text<span style="color: #000000; font-weight: bold;">/</span>javascript image<span style="color: #000000; font-weight: bold;">/</span>gif image<span style="color: #000000; font-weight: bold;">/</span>jpeg image<span style="color: #000000; font-weight: bold;">/</span>png;
    <span style="color: #666666; font-style: italic;"># Desabilita compressão em algumas versões do IE6</span>
    gzip_disable <span style="color: #ff0000;">&quot;MSIE [1-6].(?!.*SV1)&quot;</span>;
    <span style="color: #666666; font-style: italic;"># Impede que servidores proxy mandem versões em gzip do arquivo para os IE6</span>
    gzip_vary on;
&nbsp;
    server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	root  <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>;
	server_name     localhost;
	listen          <span style="color: #000000;">80</span>;
	location <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		index  index.php index.html index.htm;
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">#error_page  404  /404.html;</span>
	<span style="color: #666666; font-style: italic;"># redirect server error pages to the static page /50x.html</span>
	error_page   <span style="color: #000000;">500</span> <span style="color: #000000;">502</span> <span style="color: #000000;">503</span> <span style="color: #000000;">504</span>  <span style="color: #000000; font-weight: bold;">/</span>50x.html;
	location = <span style="color: #000000; font-weight: bold;">/</span>50x.html <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		root   <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>nginx-default;
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;"># Joga requisições para arquivos .php para o php-fpm</span>
	location ~ \.php$ <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		fastcgi_pass   127.0.0.1:<span style="color: #000000;">9000</span>;
		fastcgi_index  index.php;
		include fastcgi_params;
        	fastcgi_param SCRIPT_FILENAME <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$fastcgi_script_name</span>;
        	fastcgi_param SERVER_NAME <span style="color: #007800;">$http_host</span>;
        	fastcgi_ignore_client_abort on;
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<h3>Configuração do php-fpm</h3>
<p>Edite o arquivo: /etc/php5/fpm/php5-fpm.conf e faça os ajustes que você achar interessante, aqui eu só aumento os max_childrens (Numero de clientes CGI) de 5 para 50, esta configuração depende do seu hardware.</p>
<h3>Configuração do Logrotate</h3>
<p>Vamos configurar agora o logrotate para não enchermos os discos com logs do nginx, edite o arquivo /etc/logrotate.d/nginx:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/*</span>.log <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        daily
        missingok
        rotate <span style="color: #000000;">7</span>
        compress
        delaycompress
        notifempty
        create <span style="color: #000000;">640</span> root adm
        sharedscripts
        postrotate
                <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>nginx.pid <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-USR1</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>nginx.p$
        endscript
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<h3>Finalizando</h3>
<p>Agora que está tudo configurado, vamos reinicalizar os serviços:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>php5-fpm restart
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx restart</pre></div></div>

<p>crie um arquivo /var/www/index.php e vamos testar o php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
e acesse<span style="color: #339933;">:</span> http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//ip_do_servidor/</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/php-5-3-php-fpm-xcache-nginx-no-debian-lenny-performance-extrema/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>GVT, Vivendi, Internet, TV Digital e o Futuro</title>
		<link>http://ferrari.eti.br/gvt-vivendi-internet-tv-digital-e-o-futuro/</link>
		<comments>http://ferrari.eti.br/gvt-vivendi-internet-tv-digital-e-o-futuro/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 13:37:10 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[diversos]]></category>
		<category><![CDATA[inovação]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[tendências]]></category>
		<category><![CDATA[tv digital]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=106</guid>
		<description><![CDATA[Nos últimos meses estou acompanhando notícias sobre a venda da GVT, no inicio a Vivendi fez uma oferta muito boa para a aquisição, porém a Telecômica Telefônica apareceu com uma oferta bem maior e quando tudo parecia perdido foi anunciada a compra de 57,5% das ações da GVT pela Vivendi! A GVT é conhecida como [...]]]></description>
			<content:encoded><![CDATA[<p>Nos últimos meses estou acompanhando notícias sobre a venda da <a href="http://pt.wikipedia.org/wiki/Global_Village_Telecom">GVT</a>, no inicio a <a href="http://pt.wikipedia.org/wiki/Vivendi">Vivendi</a> fez uma oferta muito boa para a aquisição, porém a <del>Telecômica</del> Telefônica apareceu com uma oferta bem maior e quando tudo parecia perdido foi anunciada a <a href="http://forumpcs.com.br/viewtopic.php?t=261188">compra de 57,5% das ações da GVT pela Vivendi</a>!</p>
<p>A GVT é conhecida como a melhor (realmente muito melhor) operadora de telefônia, que nasceu e atua no Brasil, e ela é melhor em todos os aspectos (atendimento, preço, qualidade de serviço e qualidade de banda larga) enquanto a <a href="http://www.reclameaqui.com.br/indices/1956/telefonica-speedy">Telefônica</a> compete com a <a href="http://www.reclameaqui.com.br/indices/?id=1492">Oi</a> pelo maior numero de clientes insatisfeitos.</p>
<p>A Vivendi é uma empresa francesa que atua no setor de mídia e comunicação com atividades na música, televisão, cinema, editoração, telecomunicações e Internet. (por: Wikipedia)</p>
<div id="attachment_107" class="wp-caption aligncenter" style="width: 610px"><img class="size-full wp-image-107" title="vivendi" src="http://ferrari.eti.br/wp-content/uploads/2009/11/vivendi.jpg" alt="Areas de atuação da Vivendi" width="600" height="357" /><p class="wp-caption-text">Areas de atuação da Vivendi</p></div>
<p>Bom, mas o que isso significa&#8230;</p>
<p>Vamos considerar os seguintes pontos:</p>
<ul>
<li>Governo investindo em inclusão digital</li>
<li>Qualidade dos serviços e atendimento da GVT</li>
<li>O know-how em mídias e o dinheiro da Vivendi</li>
</ul>
<p>E juntamos isso com o fato de que a mídia da forma que conhecemos está definhando devido a Internet (RSS, Twitter, Orkut, Facebook, etc).</p>
<p>Com apenas isso já é possível se concluir o óbvio. A Vivendi está vindo para, além de nos prover acesso a internet com qualidade e chutar a Oi e Telefônica de vez, nos prover um serviço que pode em pouco tempo engolir também a nossa TV Digital. <a href="http://www.iptv-news.com/iptv_news/september_09_3/vivendi_plans_iptv_for_brazils_gvt">Ela vem para criar aqui um sistema de IPTV</a></p>
<p>Se pararmos para analisar, a TV Digital do mundo todo irá evoluir para <a href="http://pt.wikipedia.org/wiki/IPTV">IPTV</a>, pois, todas as qualidades da TV Digital (<a href="http://pt.wikipedia.org/wiki/1080p">FullHD</a>, <a href="http://pt.wikipedia.org/wiki/Som_surround">Som Surround</a> e <a href="http://pt.wikipedia.org/wiki/Interatividade">Interatividade</a>) podem ser superadas pela Internet.</p>
<p>Daí pega outro ponto: Infraestrutura, porém, para vocês terem uma ideia, no Japão um link de 100Mb por <a href="http://pt.wikipedia.org/wiki/Fibra_%C3%B3ptica">fibra ótica</a> custa o equivalente a 60 reais por mês. Mas acredito que a Vivendi tem cacife suficiente para engolir <span style="text-decoration: line-through;">os lixos</span> as empresas em que somos obrigados a depender e pagar 100 reais por meros 2mb de banda com <a href="http://conexaoto.com.br/noticia/operadora-oi-pode-estar-praticando--traffic-shaping-no-tocantins/6726">Traffic Shaping</a> e finalmente nos prover um serviço de “primeiro mundo”.</p>
<p>As questões que ficam são:</p>
<p>Irá no final das contas a TV digital sobreviver? Ou veremos nossas mães e irmãs assistindo as novelas e discutindo com amigas em tempo real pela TV ou pelo Computador?</p>
<p>Após escrever essa pergunta me surgiram outras questões:</p>
<ul>
<li>Quanto tempo a <a href="http://pt.wikipedia.org/wiki/Televis%C3%A3o_digital_no_Brasil">TV Digital Brasileira</a> irá sobreviver?</li>
<li>Quanto tempo vai levar até a Globo, Record ou outra emissora começar a transmitir suas programações ao vivo e em tempo real pela internet?</li>
<li>Quanto tempo irá levar para todas as <a href="http://barbusci.com.br/blog2/?p=9">mídias de massa</a> se <a href="http://mundoconectado.blogspot.com/2006/08/mas-afinal-o-que-convergncia-digital.html">convergirem</a> na Internet?</li>
</ul>
<p>No final de tudo uma certeza eu tenho: Quem resistir vai ser engolido.</p>
<p>Até!</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/gvt-vivendi-internet-tv-digital-e-o-futuro/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Trabalhando em Grupo em um mesmo branch no git</title>
		<link>http://ferrari.eti.br/trabalhando-em-grupo-em-um-mesmo-branch-no-gi/</link>
		<comments>http://ferrari.eti.br/trabalhando-em-grupo-em-um-mesmo-branch-no-gi/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 19:58:29 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=96</guid>
		<description><![CDATA[Problema: Trabalhar em grupo em um branch que não seja o master usando git. Solução: Considerando que o repositório já está ok, e você já está conectado no remote: Aqui estão os passos para criar o branch que a equipe vai trabalhar # criar o branch git checkout -b meu_branch # enviar o branch para [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problema:</strong> Trabalhar em grupo em um branch que não seja o master usando git.</p>
<p><strong>Solução:</strong><br />
Considerando que o repositório já está ok, e você já está conectado no remote:</p>
<p>Aqui estão os passos para criar o branch que a equipe vai trabalhar</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># criar o branch</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> checkout <span style="color: #660033;">-b</span> meu_branch
<span style="color: #666666; font-style: italic;"># enviar o branch para a origem</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> push origin meu_branch
<span style="color: #666666; font-style: italic;"># vamos apagar esse branch local agora</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> checkout master
<span style="color: #c20cb9; font-weight: bold;">git</span> branch <span style="color: #660033;">-D</span> meu_branch</pre></div></div>

<p>Agora cada um que vai trabalhar com este branch pode adicioná-lo assim:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> checkout <span style="color: #660033;">--track</span> <span style="color: #660033;">-b</span> meu_branch origin<span style="color: #000000; font-weight: bold;">/</span>meu_branch</pre></div></div>

<p>Agora todo mundo da equipe pode trabalhar no &#8220;meu_branch&#8221; como se estivesse no master.</p>
<p>e para excluir o branch da origem faça:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> push origin :meu_branch</pre></div></div>

<p>Até a proxima</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/trabalhando-em-grupo-em-um-mesmo-branch-no-gi/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Backup automático do postgres + rsync para outra máquina</title>
		<link>http://ferrari.eti.br/backup-automatico-do-postgres-usando-rsync/</link>
		<comments>http://ferrari.eti.br/backup-automatico-do-postgres-usando-rsync/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 19:16:33 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=91</guid>
		<description><![CDATA[Aqui vou exemplificar a solução que usamos para fazer backup diário dos nossos bancos de dados, este backup é armazenado em um servidor fora do país. para fazer a sincronia, usamos o rsync. 1) Configurando login automático via chaves digitais no nosso servidor de armazenamento Primeiro você tem que gerar as chaves no seu servidor [...]]]></description>
			<content:encoded><![CDATA[<p>Aqui vou exemplificar a solução que usamos para fazer backup diário dos nossos bancos de dados, este backup é armazenado em um servidor fora do país. para fazer a sincronia, usamos o <a href="http://samba.anu.edu.au/rsync/">rsync</a>.</p>
<h2>1) Configurando login automático via chaves digitais no nosso servidor de armazenamento</h2>
<p>Primeiro você tem que gerar as chaves no seu servidor de banco, com o usuário do banco de dados, no meu caso é o usuário &#8220;postgres&#8221;.</p>
<p>Você será perguntado por uma senha, deixe em branco e confirme:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">su</span> postgres
$ <span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> dsa</pre></div></div>

<p>Agora você terá sua chave, copie-a para seu servidor que irá armazenar o backup</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">scp</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_dsa.pub user<span style="color: #000000; font-weight: bold;">@</span>server_bkp:~<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Agora acesse seu servidor via ssh e adicione a chave pública na lista de chaves autorizadas do ssh</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> user<span style="color: #000000; font-weight: bold;">@</span>server_bkp
$ <span style="color: #c20cb9; font-weight: bold;">cat</span> ~<span style="color: #000000; font-weight: bold;">/</span>id_dsa.pub <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>authorized_keys</pre></div></div>

<p>Volte para o seu servidor de banco no usuario do postgres e teste:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> user<span style="color: #000000; font-weight: bold;">@</span>server_bkp</pre></div></div>

<p>Se você conseguiu acessar o server de backup sem digitar senha, continue no passo 2, senão, de uma revisada. qualquer dúvida comente!.</p>
<h2>2) Instalando o rsync e script de backup</h2>
<p>Para instalar o rsync no debian é bem simples:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> rsync</pre></div></div>

<p>No nosso banco de dados os backups são feitos diariamente as 19 horas, e usamos a pasta /backup para armazena-los:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>backup
$ <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>backup.sh
$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>backup.sh
$ <span style="color: #c20cb9; font-weight: bold;">chown</span> postgres:postgres <span style="color: #000000; font-weight: bold;">/</span>backup <span style="color: #660033;">-R</span></pre></div></div>

<p>Agora, edite o arquivo backup.sh e coloque o conteúdo:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">PASTA</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">DATA</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">DIA</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$PASTA</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$PASTA</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DIA</span>
&nbsp;
<span style="color: #007800;">LIST</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>psql <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $1}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-vE</span> <span style="color: #ff0000;">'^-|^\(|^List|^N[o|a]me|template[0|1]'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">for</span> d <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$LIST</span>
<span style="color: #000000; font-weight: bold;">do</span>
        pg_dump <span style="color: #660033;">-i</span> <span style="color: #660033;">-h</span> 127.0.0.1 <span style="color: #660033;">-p</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">-U</span> postgres <span style="color: #660033;">-F</span> t <span style="color: #660033;">-b</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;/backup/<span style="color: #007800;">$DATA</span>-<span style="color: #007800;">$d</span>.backup&quot;</span> <span style="color: #007800;">$d</span>
        <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zcf</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$PASTA</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DIA</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DATA</span>-<span style="color: #007800;">$d</span>.tar.gz <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DATA</span>-<span style="color: #007800;">$d</span>.backup
        <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DATA</span>-<span style="color: #007800;">$d</span>.backup
        <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rsync <span style="color: #660033;">-avzh</span> <span style="color: #660033;">--delete</span> <span style="color: #660033;">--progress</span> <span style="color: #660033;">--update</span> <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span> user<span style="color: #000000; font-weight: bold;">@</span>server_bkp:~<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>faça um teste e rode o script com o user do postgres:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">su</span> postgres
$ <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>backup.sh</pre></div></div>

<p>Se tudo ocorrer bem, é só adicionar no crontab para executar quando você quiser:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">su</span>
$ pico <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>crontab</pre></div></div>

<p>e adicionar:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">0</span> <span style="color: #000000;">19</span>    <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span>   postgres    <span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>backup.sh</pre></div></div>

<p>Reinicie o cron e o backup será feito todos os dias as 19 horas.</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/backup-automatico-do-postgres-usando-rsync/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>nginx &#8211; webserver, proxy reverso e perfeito!</title>
		<link>http://ferrari.eti.br/nginx-webserver-proxy-reverso-e-perfeito/</link>
		<comments>http://ferrari.eti.br/nginx-webserver-proxy-reverso-e-perfeito/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 13:00:25 +0000</pubDate>
		<dc:creator>caferrari</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[webserver]]></category>

		<guid isPermaLink="false">http://ferrari.eti.br/?p=85</guid>
		<description><![CDATA[Nosso departamento é responsável por manter a identidade visual dos sites do Governo do Estado e ainda fazemos os sites dos orgãos que não possuem um. No trabalho sempre tivemos um constante problema para hospedar nossos sites: hardware!. Contamos hoje com dois incríveis servidores IBM Pentium4 3Ghz com 2gb de memória e HDs scsi, um [...]]]></description>
			<content:encoded><![CDATA[<p>Nosso <a href="http://web.secom.to.gov.br">departamento</a> é responsável por manter a identidade visual dos sites do <a href="http://to.gov.br">Governo do Estado</a> e ainda fazemos os sites dos orgãos que não possuem um.</p>
<p>No trabalho sempre tivemos um constante problema para hospedar nossos sites: hardware!. Contamos hoje com dois incríveis servidores IBM Pentium4 3Ghz com 2gb de memória e HDs scsi, um para hospedar mais de 40 sites e o outro onde fica postgres com os bancos de dados desses sites.</p>
<p>Ultimamente nosso problema tem crescido bastante, pois, a demanda por sites aumentou e ao mesmo tempo o número de visitas veio aumentando e, como não conseguimos de forma alguma (até agora) investimento em equipamento novo estavamos chegando em uma situação crítica, nosso servidor começava a <del datetime="2009-10-15T12:28:06+00:00">sentar</del> morrer com 200 conexões simultaneas!</p>
<p>Lembrei-me de um <a href="http://www.boo-box.com/blog/br/2009/a-infraestrutura-de-servidores-web-do-sistema-boo-box/">post do boo-box</a> onde vi um servidor web chamado <a href="http://nginx.net">nginx</a> (lê-se engineX) e decidi pesquisar mais e fazer testes em casa onde rodando um servidor e servindo uma página php com um usleep de meio segundo consegui mais de 2000 conexões simultaneas! uau!..</p>
<p style="text-align: center;"><img class="aligncenter" title="nginx_performance" src="../wp-content/uploads/2009/10/nginx_performance.jpg" alt="nginx_performance" width="500" height="331" /></p>
<p>Na segunda feira seguinte, sem pensar muito, fui para o nosso servidor de produção e apliquei a seguinte política de funcionamento:</p>
<ul>
<li>nginx recebe todas as conexões pela porta 80</li>
<li>nginx faz proxy para o apache (que roda em outra porta) se a solicitação for para uma página php</li>
<li>nginx resolve sozinho usando php-cgi caso a requisição seja para:
<ul>
<li>uma fotografia</li>
<li>um arquivo</li>
<li>uma requisição para o webservice</li>
<li>um download do diário oficial</li>
<li>um banner do Governo</li>
<li>a barra padrão do Estado</li>
<li>ou um arquivo na nossa lib</li>
</ul>
</li>
</ul>
<p><del datetime="2009-11-15T10:54:02+00:00">Como resultado da experiência, nossos sites continuam morrendo, porém, aguentando 700 conexões simultaneas e esse valor só é alcançado quando tem muita pesquisa no banco de dados (Dias que sai algo sobre algum concurso público ou muita demissão no Diário Oficial) logo, fica claro, que o problema não é mais do webserver e sim do nosso servidor de Banco. Bom, o nosso webserver atualmente mal chega a 5% de uso, mesmo com as 700 conexões. Só espero conseguir uma maquina nova e mais eficiente para os nossos Bancos de Dados logo!.</del></p>
<p>Update:<br />
Fomos atendidos, estamos com um Xeon Quad Core com 4Gb de memória para o Banco de dados, e, associado com uma otimização do cache do webservice alcançamos mais de 1000 conexões simultâneas sem nenhuma degradação na performance. Detalhe que o webserver ainda é um P4 3ghz com 1gb de memória em que a utilização de processamento não passa de 5%.</p>
]]></content:encoded>
			<wfw:commentRss>http://ferrari.eti.br/nginx-webserver-proxy-reverso-e-perfeito/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

