<?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>Everlinux's Blog &#187; Scripts</title>
	<atom:link href="http://everlinux.com/blog/category/scripts/feed" rel="self" type="application/rss+xml" />
	<link>http://everlinux.com/blog</link>
	<description>Sempre vivendo, aprendendo e blogando... :)</description>
	<lastBuildDate>Fri, 30 Jul 2010 18:13:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>OpenVPN com os clientes na mesma rede</title>
		<link>http://everlinux.com/blog/2009/07/18/openvpn-com-os-clientes-na-mesma-rede</link>
		<comments>http://everlinux.com/blog/2009/07/18/openvpn-com-os-clientes-na-mesma-rede#comments</comments>
		<pubDate>Sat, 18 Jul 2009 19:27:36 +0000</pubDate>
		<dc:creator>Tiago Cruz</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Segurança]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[VPN]]></category>

		<guid isPermaLink="false">http://everlinux.com/blog/?p=524</guid>
		<description><![CDATA[Um tempo atrás escrevi um artigo sobre VPNs que abordava as vantagens e desvantagens do PPTP, e também um passo-a-passo para subir um OpenVPN autenticando com certificados e etc. O artigo ainda está disponível na Web, e chama-se Implementando soluções de VPN. O que eu não sabia era que, embora o artigo seja meio antigo [...]]]></description>
			<content:encoded><![CDATA[<p>Um tempo atrás escrevi um artigo sobre VPNs que abordava as vantagens e desvantagens do PPTP, e também um passo-a-passo para subir um OpenVPN autenticando com certificados e etc.</p>
<p>O artigo ainda está disponível na Web, e chama-se <a href="http://everlinux.com/artigos/openvpn.html">Implementando soluções de VPN</a>. O que eu não sabia era que, embora o artigo seja meio antigo (Março de 2006) ele ainda continua funcional! Eu fui seguindo-o passo-a-passo, copiando e colando os comandos e em 15 minutos eu estava conectado à uma VPN usando roteamento com o device <strong>&#8220;tun&#8221;</strong>!</p>
<p>O modo de como esta VPN funciona é bem bacana, pois separa a sua rede &#8220;servidora&#8221; (ex: 192.168.0.x) da rede do cliente conectado via OpenVPN, criando uma rede como inválida qualquer como 10.8.0.x. O acesso de uma rede para a outra é feita via roteamento, descantando toda aquela nhaca de broadcast, netbios e etc.</p>
<p>Porém, desta vez a necessidade era diferente. Eu precisava realmente estar dentro da rede servidora, pois de dentro da rede era possível o acesso à uma outra rede, no caso uma LP com o México. A lambança era mais ou menos assim:</p>
<p>Rede_Mexico   = 10.95.0.0/16<br />
Rede_Servidor = 10.10.10.0/24<br />
Rede_VPN = 10.8.0.0/24</p>
<p>Utilizando o device <strong>&#8220;tun&#8221;</strong> a rede VPN até chegava na rede do Servidor, porém, não chegava até a rede do México. Não duvido que seja possível de ser feito usando alguns roteamentos malucos, porém consegui resolver o problema apelando para bridges no Linux, usando o device <strong>&#8220;tap&#8221;</strong>.</p>
<p>O Carlos Morimoto havia postado um artigo chamado <a href="http://www.guiadohardware.net/tutoriais/openvpn_2/pagina6.html">Criando bridges no OpenVPN</a> do qual me foi muito útil, pois assim o OpenVPN conectava diretamente na rede 10.10.10.0/24 me enviando um IP que eu mesmo posso escolher via DHCP:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">server-bridge 10.10.10.200 255.255.255.0 10.10.10.210 10.10.10.220</pre></div></div>

<p>No exemplo acima, 10.10.10.200/24 será o IP do servidor, e 10.10.10.210 até 10.10.10.220 será o range oferecido aos clientes remotos que conectarem usando o OpenVPN.</p>
<p>Porém, para que tudo funcione a contento é necessário criar uma Bridge entre as interfaces eth0 e tap0, para que todo mundo se converse e se enxergue:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># brctl show</span>
bridge name	bridge <span style="color: #c20cb9; font-weight: bold;">id</span>		STP enabled	interfaces
br0		8000.00188be16805	no		eth0
							tap0</pre></div></div>

<p>Neste caso, o IP não ficará nem na eth0 e nem na tap0, mas sim na br0:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ifconfig </span>
br0       Link encap:Ethernet  HWaddr 00:<span style="color: #000000;">28</span>:0b:ef:<span style="color: #000000;">58</span>:<span style="color: #000000;">75</span>  
          inet addr:10.10.10.2  Bcast:10.10.10.255  Mask:255.255.255.0
          inet6 addr: fe80::<span style="color: #000000;">218</span>:8bff:fee1:<span style="color: #000000;">6805</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">64</span> Scope:Link</pre></div></div>

<p>Bom, chega de teoria. Os links acima possuem todo o background necessário para que você entenda a coisa passo-a-passo. Vamos logo para o que interessa: Os arquivos de configuração:</p>
<p>Arquivo openvpn.conf no servidor?</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># /etc/openvpn/openvpn.conf</span>
<span style="color: #666666; font-style: italic;"># Objetivo: Clientes remotos conectarem no mesmo range da LAN local sem roteamento</span>
proto udp
port <span style="color: #000000;">1194</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># bridge utiliza a interface &quot;tap&quot; em vez da &quot;tun&quot;</span>
<span style="color: #666666; font-style: italic;"># (o tap transmite pacotes de broadcast e o tun não)</span>
dev tap0
&nbsp;
<span style="color: #666666; font-style: italic;"># Faixa de IPs para os clientes</span>
server-bridge 10.10.10.200 255.255.255.0 10.10.10.210 10.10.10.220
&nbsp;
<span style="color: #666666; font-style: italic;"># No cliente eh necessário um</span>
<span style="color: #666666; font-style: italic;"># route add -net 10.95.0.0 netmask 255.255.0.0 gw 10.10.10.1 tap0</span>
<span style="color: #666666; font-style: italic;"># para acessar a LP no Mexico 10.95.x.x</span>
push <span style="color: #ff0000;">&quot;route 10.95.0.0 255.255.0.0 10.10.10.1&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Compressão e persistência</span>
comp-lzo
keepalive <span style="color: #000000;">10</span> <span style="color: #000000;">120</span>
ifconfig-pool-persist <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>ipp.txt
&nbsp;
<span style="color: #666666; font-style: italic;"># Certificados</span>
tls-server
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
&nbsp;
<span style="color: #666666; font-style: italic;"># Logs e etc</span>
status      <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>openvpn-status.log
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>openvpn.log
log-append  <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>openvpn.log
verb <span style="color: #000000;">3</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Bridges para simular um mesmo switch entre a tap0 e a eth0</span>
up <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>bridge-start
down <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>bridge-stop</pre></div></div>

<p>Arquivo bridge-start:</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>
<span style="color: #666666; font-style: italic;"># /etc/openvpn/bridge-start</span>
&nbsp;
<span style="color: #007800;">br</span>=<span style="color: #ff0000;">&quot;br0&quot;</span>
<span style="color: #007800;">tap</span>=<span style="color: #ff0000;">&quot;tap0&quot;</span>
<span style="color: #007800;">eth</span>=<span style="color: #ff0000;">&quot;eth0&quot;</span>
<span style="color: #007800;">eth_ip</span>=<span style="color: #ff0000;">&quot;10.10.10.2&quot;</span>
<span style="color: #007800;">eth_gw</span>=<span style="color: #ff0000;">&quot;10.10.10.1&quot;</span>
<span style="color: #007800;">eth_netmask</span>=<span style="color: #ff0000;">&quot;255.255.255.0&quot;</span>
<span style="color: #007800;">eth_broadcast</span>=<span style="color: #ff0000;">&quot;10.10.10.255&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> t <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$tap</span>; <span style="color: #000000; font-weight: bold;">do</span>
openvpn <span style="color: #660033;">--mktun</span> <span style="color: #660033;">--dev</span> <span style="color: #007800;">$t</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
brctl addbr <span style="color: #007800;">$br</span>
brctl addif <span style="color: #007800;">$br</span> <span style="color: #007800;">$eth</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> t <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$tap</span>; <span style="color: #000000; font-weight: bold;">do</span>
brctl addif <span style="color: #007800;">$br</span> <span style="color: #007800;">$t</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> t <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$tap</span>; <span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$t</span> 0.0.0.0 promisc up
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$eth</span> 0.0.0.0 promisc up
<span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$br</span> <span style="color: #007800;">$eth_ip</span> netmask <span style="color: #007800;">$eth_netmask</span> broadcast <span style="color: #007800;">$eth_broadcast</span>
<span style="color: #666666; font-style: italic;">#route add default gw $eth_gw dev $br</span>
route add <span style="color: #660033;">-net</span> 10.95.0.0 netmask 255.255.0.0 gw 10.10.10.1 br0
&nbsp;
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> tap0 <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> br0 <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-i</span> br0 <span style="color: #660033;">-j</span> ACCEPT</pre></div></div>

<p>Arquivo bridge-stop:</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>
<span style="color: #666666; font-style: italic;"># /etc/openvpn/bridge-stop</span>
&nbsp;
<span style="color: #007800;">br</span>=<span style="color: #ff0000;">&quot;br0&quot;</span>
<span style="color: #007800;">tap</span>=<span style="color: #ff0000;">&quot;tap0&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$br</span> down
brctl delbr <span style="color: #007800;">$br</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> t <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$tap</span>; <span style="color: #000000; font-weight: bold;">do</span>
openvpn <span style="color: #660033;">--rmtun</span> <span style="color: #660033;">--dev</span> <span style="color: #007800;">$t</span>
<span style="color: #000000; font-weight: bold;">done</span> 
&nbsp;
route del <span style="color: #660033;">-net</span> 10.95.0.0 netmask 255.255.0.0 gw 10.10.10.1 br0
ifdown eth0
ifup eth0
route add <span style="color: #660033;">-net</span> 10.95.0.0 netmask 255.255.0.0 gw 10.10.10.1 eth0</pre></div></div>

<p>Arquivo no cliente:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Cliente pode ser Linux ou Windows</span>
remote 200.200.200.100
proto udp
port <span style="color: #000000;">1194</span>
client
pull
dev tap
comp-lzo
keepalive <span style="color: #000000;">10</span> <span style="color: #000000;">120</span>
tls-client
ca ca.crt
cert tiagocruz.crt
key tiagocruz.key
ns-cert-type server 
verb <span style="color: #000000;">3</span></pre></div></div>

<p>O resultado pode ser visto nos screnshoots abaixo:</p>
<p><img src="http://everlinux.com/blog/wp-content/uploads/2009/07/openvpn.png" alt="openvpn" title="openvpn" width="634" height="620" class="aligncenter size-full wp-image-537" /></p>
<p>Como você deve ter percebido, apenas alguns ajustes foram necessários nos scripts que iniciam e derrubam as bridges. A parte mais chata foi automatizar a criação de rotas estáticas nos clientes, para que não fosse necessário usar o &#8220;route add&#8221; em toda a conexão. A linha do &#8220;push&#8221; resolveu este problema, inclusive apontando a rota para um host que diferente do servidor de VPN, que é o padrão.</p>
<p>Segue uma screnshoot mostrando o antes, o durante e o depois do super device tap <img src='http://everlinux.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><img src="http://everlinux.com/blog/wp-content/uploads/2009/07/openvpn-rotas.png" alt="openvpn-rotas" title="openvpn-rotas" width="647" height="531" class="aligncenter size-full wp-image-540" /></p>
<p>Nos testes foram utilizadas as versões OpenVPN 2.1_rc7 x86_64-pc-linux-gnu no servidor rodando Ubuntu 8.04.3 LTS e o cliente OpenVPN 2.1_rc11 i486-pc-linux-gnu em um Ubuntu 9.04.</p>
<p>Também foi possível conectar usando a <a href="http://openvpn.se/">GUI do OpenVPN</a> para Windows.</p>
<p>Abraços e até o próximo post! <img src='http://everlinux.com/blog/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://everlinux.com/blog/2009/07/18/openvpn-com-os-clientes-na-mesma-rede/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Squid Autenticando em um Active Directory</title>
		<link>http://everlinux.com/blog/2009/05/06/squid-autenticando-em-um-active-directory</link>
		<comments>http://everlinux.com/blog/2009/05/06/squid-autenticando-em-um-active-directory#comments</comments>
		<pubDate>Thu, 07 May 2009 00:31:08 +0000</pubDate>
		<dc:creator>Tiago Cruz</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[AD]]></category>

		<guid isPermaLink="false">http://everlinux.com/blog/?p=418</guid>
		<description><![CDATA[Dica rápida, sem muitas novidades. Apenas uma forma rápida de colocar um Squid 2.6.18 rodando em um Ubuntu 8.04 LTS para autenticar em um Windows 2003 Server, sem usar samba+winbind, dar join no domínio, usar ntp e etc. A idéia é documentar uma árvore LDAP padrão do Windows, para servir como base para futuras implementações, [...]]]></description>
			<content:encoded><![CDATA[<p>Dica rápida, sem muitas novidades. Apenas uma forma rápida de colocar um Squid 2.6.18 rodando em um Ubuntu 8.04 LTS para autenticar em um Windows 2003 Server, sem usar samba+winbind, dar join no domínio, usar ntp e etc.</p>
<p>A idéia é documentar uma árvore LDAP padrão do Windows, para servir como base para futuras implementações, visto que muitos admins de AD desconhecem esta informação <img src='http://everlinux.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>No squid.conf, ficaria mais ou menos assim (o &#8220;\&#8221; é uma quebra de linha, porém o comando deve ficar em uma linha única):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">...
acl diretoria src 10.10.10.9<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span>
http_access allow diretoria
&nbsp;
<span style="color: #666666; font-style: italic;"># Autenticacao AD Windows</span>
auth_param basic program <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>squid<span style="color: #000000; font-weight: bold;">/</span>ldap_auth <span style="color: #660033;">-R</span> <span style="color: #660033;">-b</span> <span style="color: #ff0000;">&quot;dc=dominio&quot;</span> <span style="color: #660033;">-D</span> <span style="color: #ff0000;">&quot;cn=tiago <span style="color: #000099; font-weight: bold;">\
</span>cruz,cn=users,dc=dominio&quot;</span> <span style="color: #660033;">-w</span> <span style="color: #ff0000;">&quot;senha&quot;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">sAMAccountName</span>=<span style="color: #000000; font-weight: bold;">%</span>s <span style="color: #660033;">-h</span> 10.10.10.10
auth_param basic children <span style="color: #000000;">5</span>
auth_param basic realm Autenticacao
auth_param basic credentialsttl <span style="color: #000000;">5</span> minutes
acl ldapauth proxy_auth REQUIRED
http_access allow ldapauth
&nbsp;
<span style="color: #666666; font-style: italic;"># White List</span>
acl liberados dstdom_regex <span style="color: #660033;">-i</span> <span style="color: #ff0000;">&quot;/etc/squid/unblock.txt&quot;</span>
http_access allow liberados
...
<span style="color: #666666; font-style: italic;"># Rede Local LAN</span>
acl rede_local src 10.10.10.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span>
http_access allow rede_local</pre></div></div>

<p>Caso <strong>não funcione</strong> &#8220;de prima&#8221;, recomendo estes comandos para <strong>debugar</strong> o problema:</p>
<p>1-) Usando o LDAPSearch para ver se retorna OK:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ ldapsearch <span style="color: #660033;">-LLL</span> <span style="color: #660033;">-h</span> 10.10.10.10 <span style="color: #660033;">-P</span> <span style="color: #000000;">3</span> <span style="color: #660033;">-x</span> <span style="color: #660033;">-D</span> <span style="color: #ff0000;">&quot;CN=Tiago Cruz,CN=Users,DC=Dominio&quot;</span> \
<span style="color: #660033;">-W</span> <span style="color: #660033;">-b</span> <span style="color: #ff0000;">&quot;DC=Dominio&quot;</span> <span style="color: #ff0000;">&quot;(&amp;(&amp;(objectClass=User)(objectCategory=Person))(sAMAccountName=tcruz))&quot;</span>
Enter LDAP Password: 
dn: <span style="color: #007800;">CN</span>=Tiago Cruz,<span style="color: #007800;">CN</span>=Users,<span style="color: #007800;">DC</span>=dominio
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
cn: Tiago Cruz
sn: Cruz
givenName: Tiago
initials: ti
distinguishedName: <span style="color: #007800;">CN</span>=Tiago Cruz,<span style="color: #007800;">CN</span>=Users,<span style="color: #007800;">DC</span>=dominio
instanceType: <span style="color: #000000;">4</span>
whenCreated: 20090427110042.0Z
whenChanged: 20090427190603.0Z
displayName: Tiago Cruz
uSNCreated: <span style="color: #000000;">555987</span>
....</pre></div></div>

<p>2-) Simulando o LDAP_AUTH do Squid na mão, passando na mesma linha usuário e senha desejado para ver se funciona bem:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <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>squid<span style="color: #000000; font-weight: bold;">/</span>ldap_auth <span style="color: #660033;">-R</span> <span style="color: #660033;">-b</span> <span style="color: #ff0000;">&quot;dc=dominio&quot;</span> <span style="color: #660033;">-D</span> <span style="color: #ff0000;">&quot;cn=tiago <span style="color: #000099; font-weight: bold;">\
</span>cruz,cn=users,dc=dominio&quot;</span> <span style="color: #660033;">-w</span> <span style="color: #ff0000;">&quot;senha&quot;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">sAMAccountName</span>=tcruz <span style="color: #660033;">-h</span> 10.10.10.10
tcruz senhacorreta
OK
tcruz senhaerrada
ERR Success</pre></div></div>

<p>Lembrando que se você estiver usando <strong>Proxy Transparente</strong>, você deverá configurar o endereço do Proxy diretamente no navegador do usuário pois a autenticação não funcionará.</p>
<p>Se você não sabe se usa Proxy Transparente, seria algo mais ou menos assim:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># No squid:</span>
http_port <span style="color: #000000;">3128</span> transparent
&nbsp;
<span style="color: #666666; font-style: italic;"># No firewall:</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>net<span style="color: #000000; font-weight: bold;">/</span>ipv4<span style="color: #000000; font-weight: bold;">/</span>ip_forward
iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> POSTROUTING <span style="color: #660033;">-o</span> eth1 <span style="color: #660033;">-j</span> MASQUERADE
iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> PREROUTING <span style="color: #660033;">-s</span> 10.10.10.0<span style="color: #000000; font-weight: bold;">/</span>255.255.255.0 <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> REDIRECT <span style="color: #660033;">--to-port</span> <span style="color: #000000;">3128</span></pre></div></div>

<p>A idéia é pegar todo o tráfego que vem da sua rede local com destino à porta 80/tcp e encaminhar para o squid na porta 3128/tcp, de forma transparente. Funciona muito bem, mas caso você queira autenticação será necessário mexer no browser no cliente.</p>
<p>Para fazer uma configuração <strong>automática</strong>, sugiro a utilização de um <strong>Script de Logon</strong> mais ou menos como este arquivo &#8220;todos.bat&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">echo</span> off
net use f: \\server\shared
net use h: <span style="color: #000000; font-weight: bold;">/</span>home
regedit <span style="color: #000000; font-weight: bold;">/</span>s \\server\netlogon\proxy.reg</pre></div></div>

<p>Sendo que o <strong>proxy.reg</strong> seria algo mais ou menos assim:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">REGEDIT4
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #ff0000;">&quot;ProxyServer&quot;</span>=<span style="color: #ff0000;">&quot;10.10.10.1:3128&quot;</span>
<span style="color: #ff0000;">&quot;ProxyEnable&quot;</span>=dword:00000001
<span style="color: #ff0000;">&quot;EnableAutodial&quot;</span>=dword:00000000
<span style="color: #ff0000;">&quot;NoNetAutodial&quot;</span>=dword:00000000
<span style="color: #ff0000;">&quot;MigrateProxy&quot;</span>=dword:00000001</pre></div></div>

<p>Mais informações:<br />
- <a href="http://www.papercut.com/kb/Main/ConfiguringSquidProxyToAuthenticateWithActiveDirectory">Configuring Squid on Linux to authenticate with Active Directory</a><br />
- <a href="http://wiki.squid-cache.org/ConfigExamples/Authenticate/WindowsActiveDirectory">Configuring a Squid Server to authenticate off Active Directory</a><br />
- <a href="http://www.vivaolinux.com.br/artigo/Squid-autenticado-no-Active-Directory-com-Winbind/">Squid autenticado no Active Directory com Winbind</a><br />
- <a href="http://www.linuxman.pro.br/autenticando_o_squid_no_ad_via_ntlm.pdf">Autenticando o SQUID no Active Directory via NTLM</a><br />
- <a href="http://everlinux.com/artigos/samba3.html">SaMBa 3.x -> Tudo o que você precisa saber (e não tinha para quem perguntar <img src='http://everlinux.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </a></p>
<p>Abraços e até a próxima! <img src='http://everlinux.com/blog/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://everlinux.com/blog/2009/05/06/squid-autenticando-em-um-active-directory/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cluster com VMware ESX + GFS</title>
		<link>http://everlinux.com/blog/2009/01/06/cluster-com-vmware-esx-gfs</link>
		<comments>http://everlinux.com/blog/2009/01/06/cluster-com-vmware-esx-gfs#comments</comments>
		<pubDate>Tue, 06 Jan 2009 23:26:47 +0000</pubDate>
		<dc:creator>Tiago Cruz</dc:creator>
				<category><![CDATA[Cluster]]></category>
		<category><![CDATA[Dicas]]></category>
		<category><![CDATA[ESX]]></category>
		<category><![CDATA[High Availability]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Storage]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[Virtualização]]></category>
		<category><![CDATA[GFS]]></category>

		<guid isPermaLink="false">http://www.everlinux.com/blog/2009/01/06/cluster-com-vmware-esx-gfs/</guid>
		<description><![CDATA[Já escrevemos bastante sobre Virtualização usando Xen e Cluster aqui no Blog. Desta vez, para começar bem 2009 eu irei apenas citar alguns testes que fiz usando VMware ESX com GFS, em um Storage compartilhado, usando tecnologia Red Hat 5.2 x86_64 com um Fence_VMWare Tech Preview do RHEL 5.3 beta. O Problema Eu já o [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.everlinux.com/blog/wp-content/uploads/2009/01/teste_esx_gfs_ever.png' title='Teste_ESX_GFS_Ever'><img src='http://www.everlinux.com/blog/wp-content/uploads/2009/01/teste_esx_gfs_ever.thumbnail.png' alt='Teste_ESX_GFS_Ever' /></a></p>
<p>Já escrevemos bastante sobre <a href="http://www.everlinux.com/blog/category/virtualizacao/">Virtualização </a>usando <a href="http://www.everlinux.com/blog/category/xen/">Xen</a> e <a href="http://www.everlinux.com/blog/category/cluster/">Cluster</a> aqui no Blog. </p>
<p>Desta vez, para começar bem 2009 eu irei apenas citar alguns testes que fiz usando VMware ESX com GFS, em um <a href="http://www.everlinux.com/blog/category/storage/">Storage</a> compartilhado, usando tecnologia Red Hat 5.2 x86_64 com um Fence_VMWare Tech Preview do RHEL 5.3 beta.</p>
<p><strong>O Problema</strong></p>
<p>Eu já o utilizava o GFS com Xen ou até mesmo com <a href="http://www.everlinux.com/blog/2008/06/16/usando-drbd-com-gfs-e-fencing-manual/">DRBD em Muti-Master</a>, porém o grande problema é que não existia um fence para vmware que funcionasse a contento.</p>
<p>O <a href="http://sources.redhat.com/cgi-bin/cvsweb.cgi/cluster/fence/agents/vmware/fence_vmware.pl?cvsroot=cluster">fence_vmware</a>, escrito em perl parou no tempo em Agosto de 2007 e fora que a <a href="http://www.vmware.com/download/sdk/api.html">VMware Perl API</a> necessária não compila em 64 bits.</p>
<p>A Red Hat pretende lançar agora no RHEL 5.3 um <a href="http://sources.redhat.com/cluster/wiki/VMware_FencingConfig">fence_vmware re-escrito em Python</a>, porém ele ainda não trabalha com Cluster, pois conecta-se direto na máquina física, e não no VMCenter.</p>
<p><strong>A Solução</strong></p>
<p>A solução é utilizar o vmware_fence_vi, também da Red Hat que está em fase de desenvolvimento atualmente, que conecta no Virtual Center e não na máquina física que pode estar morta <img src='http://everlinux.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Segue o /etc/cluster/cluster.conf utilizado nos testes:</p>
<p><strong>Configuração do Cluster</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>cluster <span style="color: #007800;"><span style="color: #7a0874; font-weight: bold;">alias</span></span>=<span style="color: #ff0000;">&quot;Cluster_GFS&quot;</span> <span style="color: #007800;">config_version</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;Cluster_GFS&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>fence_daemon <span style="color: #007800;">clean_start</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #007800;">post_fail_delay</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #007800;">post_join_delay</span>=<span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>cman<span style="color: #000000; font-weight: bold;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;</span>multicast <span style="color: #007800;">addr</span>=<span style="color: #ff0000;">&quot;224.0.0.1&quot;</span> <span style="color: #007800;">interface</span>=<span style="color: #ff0000;">&quot;eth1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>cman<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>clusternodes<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>clusternode <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;cluster-01-node-01&quot;</span> <span style="color: #007800;">nodeid</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #007800;">votes</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;</span>multicast <span style="color: #007800;">addr</span>=<span style="color: #ff0000;">&quot;224.0.0.1&quot;</span> <span style="color: #007800;">interface</span>=<span style="color: #ff0000;">&quot;eth1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
	           <span style="color: #000000; font-weight: bold;">&lt;</span>fence<span style="color: #000000; font-weight: bold;">&gt;</span>
        	        <span style="color: #000000; font-weight: bold;">&lt;</span>method <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;single&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                	        <span style="color: #000000; font-weight: bold;">&lt;</span>device <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;node-01&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
	                <span style="color: #000000; font-weight: bold;">&lt;/</span>method<span style="color: #000000; font-weight: bold;">&gt;</span>
	           <span style="color: #000000; font-weight: bold;">&lt;/</span>fence<span style="color: #000000; font-weight: bold;">&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;/</span>clusternode<span style="color: #000000; font-weight: bold;">&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;</span>clusternode <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;cluster-01-node-02&quot;</span> <span style="color: #007800;">nodeid</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #007800;">votes</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;</span>multicast <span style="color: #007800;">addr</span>=<span style="color: #ff0000;">&quot;224.0.0.1&quot;</span> <span style="color: #007800;">interface</span>=<span style="color: #ff0000;">&quot;eth1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
                   <span style="color: #000000; font-weight: bold;">&lt;</span>fence<span style="color: #000000; font-weight: bold;">&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>method <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;single&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                                <span style="color: #000000; font-weight: bold;">&lt;</span>device <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;node-02&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;/</span>method<span style="color: #000000; font-weight: bold;">&gt;</span>
                   <span style="color: #000000; font-weight: bold;">&lt;/</span>fence<span style="color: #000000; font-weight: bold;">&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;/</span>clusternode<span style="color: #000000; font-weight: bold;">&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;</span>clusternode <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;cluster-01-node-03&quot;</span> <span style="color: #007800;">nodeid</span>=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #007800;">votes</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;</span>multicast <span style="color: #007800;">addr</span>=<span style="color: #ff0000;">&quot;224.0.0.1&quot;</span> <span style="color: #007800;">interface</span>=<span style="color: #ff0000;">&quot;eth1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
                   <span style="color: #000000; font-weight: bold;">&lt;</span>fence<span style="color: #000000; font-weight: bold;">&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>method <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;single&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                                <span style="color: #000000; font-weight: bold;">&lt;</span>device <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;node-03&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;/</span>method<span style="color: #000000; font-weight: bold;">&gt;</span>
                   <span style="color: #000000; font-weight: bold;">&lt;/</span>fence<span style="color: #000000; font-weight: bold;">&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;/</span>clusternode<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>clusternodes<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>fencedevices<span style="color: #000000; font-weight: bold;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>fencedevice <span style="color: #007800;">agent</span>=<span style="color: #ff0000;">&quot;fence_vmware_vi&quot;</span> <span style="color: #007800;">ipaddr</span>=<span style="color: #ff0000;">&quot;10.107.113.2&quot;</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">login</span></span>=<span style="color: #ff0000;">&quot;user&quot;</span> <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;node-01&quot;</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">passwd</span></span>=<span style="color: #ff0000;">&quot;xxxxx&quot;</span> <span style="color: #007800;">port</span>=<span style="color: #ff0000;">&quot;Cluster_01_Node_01&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>fencedevice <span style="color: #007800;">agent</span>=<span style="color: #ff0000;">&quot;fence_vmware_vi&quot;</span> <span style="color: #007800;">ipaddr</span>=<span style="color: #ff0000;">&quot;10.107.113.2&quot;</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">login</span></span>=<span style="color: #ff0000;">&quot;user&quot;</span> <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;node-02&quot;</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">passwd</span></span>=<span style="color: #ff0000;">&quot;xxxxx&quot;</span> <span style="color: #007800;">port</span>=<span style="color: #ff0000;">&quot;Cluster_01_Node_02&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;</span>fencedevice <span style="color: #007800;">agent</span>=<span style="color: #ff0000;">&quot;fence_vmware_vi&quot;</span> <span style="color: #007800;">ipaddr</span>=<span style="color: #ff0000;">&quot;10.107.113.2&quot;</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">login</span></span>=<span style="color: #ff0000;">&quot;user&quot;</span> <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;node-03&quot;</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">passwd</span></span>=<span style="color: #ff0000;">&quot;xxxxx&quot;</span> <span style="color: #007800;">port</span>=<span style="color: #ff0000;">&quot;Cluster_01_Node_03&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>fencedevices<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>cluster<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Notas: </p>
<p>1-) Troque parênteses por sinal de maior/ menor (maldito wordpress!) <img src='http://everlinux.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>2-) O IP 10.107.113.2 é o IP do Virtual Center. Ele sempre sabe onde a máquina virtual se encontra, mesmo que ela for migrada para outro host físico.</p>
<p>3-) Forçamos o MultiCast pela eth1, que é uma interface dedicada para o heartbeat do Cluster. Algumas vezes o multicast tentava sair pela interface de loopback e cada máquina achava que estava sozinha no cluster <img src='http://everlinux.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>/etc/hosts dos servidores:</p>
<p><code>10.0.0.1	cluster-01-node-01<br />
10.0.0.2	cluster-01-node-02<br />
10.0.0.3	cluster-01-node-03<br />
10.0.1.1	node-01<br />
10.0.1.2	node-02<br />
10.0.1.3	node-03</code></p>
<p><strong>Script de escrita</strong></p>
<p>Foi utilizado um script para escrever no storage compartilhado a cada segundo com o nome da máquina e a hora exata (minuto, segundo) da escrita.</p>
<p><code># for i in `seq 1 1000`; do a=`echo $RANDOM | cut -c1-2`; dd if=/dev/zero of=/teste/`hostname -s`-`date +%H_%M_%S` bs=512k count=$a; sleep 1; done</code></p>
<p><strong>Nós do Cluster</strong></p>
<p><code>[root@cluster-01-node-02 ~]# cman_tool nodes<br />
Node  Sts   Inc   Joined               Name<br />
   1   M     60   2009-01-06 19:46:11  cluster-01-node-01<br />
   2   M     56   2009-01-06 19:46:11  cluster-01-node-02<br />
   3   M     68   2009-01-06 19:56:35  cluster-01-node-03</code></p>
<p><strong>Fence Device</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>fence_vmware_vi - DEVEL.1229423489
&nbsp;
<span style="color: #666666; font-style: italic;"># The Following agent has been tested on:</span>
<span style="color: #666666; font-style: italic;"># VI Perl API 1.6 against:</span>
<span style="color: #666666; font-style: italic;">#       VMware ESX 3.5</span>
<span style="color: #666666; font-style: italic;">#       VMware ESXi 3.5 update 2</span>
<span style="color: #666666; font-style: italic;">#       VMware Virtual Center 2.5</span>
<span style="color: #666666; font-style: italic;">#&lt;/code&gt;</span></pre></div></div>

<p>Com a seguinte modificação na linha 13:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#sys.path.append(&quot;@FENCEAGENTSLIBDIR@&quot;)</span>
sys.path.append<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;/usr/lib/fence&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p><strong>Desligar máquina VIRTUAL</strong></p>
<p>Teste: Desligar máquina VIRTUAL cluster-01-node-03</p>
<p>Resultado: GFS congelado por ~1 minuto</p>
<p>O que ocorreu: O fence_vmware_vi conectou no vmcenter e tirou a máquina do Cluster, liberando assim o I/O.</p>
<p><strong>Desligar máquina FISICA normalmente</strong></p>
<p>Teste: Desligar com reboot máquina FISICA 01 (que tinha a cluster-01-node-03)</p>
<p>Resultado: GFS congelado por ~2 minutos</p>
<p>O que ocorreu: Máquinas física iniciou o processo de reboot, a máquina virtual cluster-01-node-03 morreu e foi migrada e reiniciada em outro host físico.</p>
<p>PS: A máquina virtual não retornou ao seu host de origem quando a máquina física voltou</p>
<p><code>-rw-r--r-- 1 root root 44040192 Jan  6  2009 cluster-01-node-01-19_50_52<br />
-rw-r--r-- 1 root root 15204352 Jan  6  2009 cluster-01-node-01-19_50_53<br />
-rw-r--r-- 1 root root 10485760 Jan  6  2009 cluster-01-node-01-19_50_54<br />
-rw-r--r-- 1 root root 41418752 Jan  6  2009 cluster-01-node-01-19_52_57<br />
-rw-r--r-- 1 root root 17825792 Jan  6  2009 cluster-01-node-01-19_52_58<br />
-rw-r--r-- 1 root root 23068672 Jan  6  2009 cluster-01-node-01-19_52_59<br />
-rw-r--r-- 1 root root  6815744 Jan  6  2009 cluster-01-node-01-19_53_00<br />
-rw-r--r-- 1 root root 49807360 Jan  6  2009 cluster-01-node-01-19_53_01<br />
-rw-r--r-- 1 root root 10485760 Jan  6  2009 cluster-01-node-01-19_53_03<br />
</code></p>
<p><strong>Desligar máquina FISICA brutalmente</strong></p>
<p>Desligar com RESET (via RSA) máquina FISICA 02 (que tinha a cluster-01-node-03)</p>
<p>Resultado: GFS congelado por ~3 minutos</p>
<p>O que ocorreu: Máquinas física foi brutalmente desligada, a máquina virtual cluster-01-node-03 morreu e foi migrada e reiniciada em outro host físico.</p>
<p>O fence_vmware_vi tentou várias vezes tirar a máquina do cluster com falhas consecutivas pois a máquina não mais existia e o ESX demorou um pouco para entender o que estava acontecendo.</p>
<p>PS: A máquina virtual não retornou ao seu host de origem quando a máquina física voltou</p>
<p><code>-rw-r--r-- 1 root root 12058624 Jan  6 20:17 cluster-01-node-01-20_17_57<br />
-rw-r--r-- 1 root root 11534336 Jan  6 20:17 cluster-01-node-01-20_17_58<br />
-rw-r--r-- 1 root root 10485760 Jan  6 20:17 cluster-01-node-01-20_17_59<br />
-rw-r--r-- 1 root root  5242880 Jan  6 20:18 cluster-01-node-01-20_18_00<br />
-rw-r--r-- 1 root root  5767168 Jan  6 20:20 cluster-01-node-01-20_18_01<br />
-rw-r--r-- 1 root root  6291456 Jan  6 20:21 cluster-01-node-01-20_21_00<br />
-rw-r--r-- 1 root root 37748736 Jan  6 20:21 cluster-01-node-01-20_21_02<br />
-rw-r--r-- 1 root root 17825792 Jan  6 20:21 cluster-01-node-01-20_21_03<br />
-rw-r--r-- 1 root root 12582912 Jan  6 20:21 cluster-01-node-01-20_21_04<br />
-rw-r--r-- 1 root root 34603008 Jan  6 20:21 cluster-01-node-01-20_21_05<br />
-rw-r--r-- 1 root root  5242880 Jan  6 20:21 cluster-01-node-01-20_21_06<br />
-rw-r--r-- 1 root root 12582912 Jan  6 20:21 cluster-01-node-01-20_21_07<br />
-rw-r--r-- 1 root root 12582912 Jan  6 20:21 cluster-01-node-01-20_21_08</code></p>
<p><strong>Trechos de logs</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">10</span> cluster-01-node-01 openais<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2646</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #7a0874; font-weight: bold;">&#91;</span>TOTEM<span style="color: #7a0874; font-weight: bold;">&#93;</span> The token was lost <span style="color: #000000; font-weight: bold;">in</span> the OPERATIONAL state. 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">10</span> cluster-01-node-01 openais<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2646</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #7a0874; font-weight: bold;">&#91;</span>TOTEM<span style="color: #7a0874; font-weight: bold;">&#93;</span> Receive multicast socket recv buffer <span style="color: #c20cb9; font-weight: bold;">size</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">288000</span> bytes<span style="color: #7a0874; font-weight: bold;">&#41;</span>. 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">10</span> cluster-01-node-01 openais<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2646</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #7a0874; font-weight: bold;">&#91;</span>TOTEM<span style="color: #7a0874; font-weight: bold;">&#93;</span> Transmit multicast socket send buffer <span style="color: #c20cb9; font-weight: bold;">size</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">262142</span> bytes<span style="color: #7a0874; font-weight: bold;">&#41;</span>. 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">10</span> cluster-01-node-01 openais<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2646</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #7a0874; font-weight: bold;">&#91;</span>TOTEM<span style="color: #7a0874; font-weight: bold;">&#93;</span> entering GATHER state from 2. 
&nbsp;
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">15</span> cluster-01-node-01 openais<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2646</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #7a0874; font-weight: bold;">&#91;</span>CLM  <span style="color: #7a0874; font-weight: bold;">&#93;</span> CLM CONFIGURATION CHANGE 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">15</span> cluster-01-node-01 openais<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2646</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #7a0874; font-weight: bold;">&#91;</span>CLM  <span style="color: #7a0874; font-weight: bold;">&#93;</span> New Configuration: 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">15</span> cluster-01-node-01 openais<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2646</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #7a0874; font-weight: bold;">&#91;</span>CLM  <span style="color: #7a0874; font-weight: bold;">&#93;</span> 	r<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> ip<span style="color: #7a0874; font-weight: bold;">&#40;</span>10.0.0.1<span style="color: #7a0874; font-weight: bold;">&#41;</span>  
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">15</span> cluster-01-node-01 openais<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2646</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #7a0874; font-weight: bold;">&#91;</span>CLM  <span style="color: #7a0874; font-weight: bold;">&#93;</span> 	r<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> ip<span style="color: #7a0874; font-weight: bold;">&#40;</span>10.0.0.2<span style="color: #7a0874; font-weight: bold;">&#41;</span>  
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">15</span> cluster-01-node-01 openais<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2646</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #7a0874; font-weight: bold;">&#91;</span>CLM  <span style="color: #7a0874; font-weight: bold;">&#93;</span> Members Left: 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">15</span> cluster-01-node-01 fenced<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2666</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: cluster-01-node-03 not a cluster member after <span style="color: #000000;">0</span> sec post_fail_delay
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">15</span> cluster-01-node-01 openais<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2646</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #7a0874; font-weight: bold;">&#91;</span>CLM  <span style="color: #7a0874; font-weight: bold;">&#93;</span> 	r<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> ip<span style="color: #7a0874; font-weight: bold;">&#40;</span>10.0.0.3<span style="color: #7a0874; font-weight: bold;">&#41;</span>  
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">15</span> cluster-01-node-01 fenced<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2666</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: fencing node <span style="color: #ff0000;">&quot;cluster-01-node-03&quot;</span>
&nbsp;
  Please use <span style="color: #ff0000;">'-h'</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #007800;">usagcation</span>=HASH<span style="color: #7a0874; font-weight: bold;">&#40;</span>0x1df33bd0<span style="color: #7a0874; font-weight: bold;">&#41;</span>ing with the remote host.eports: vmware_helper returned Cannot power off vm Cluster_01_Node_03<span style="color: #000000; font-weight: bold;">!</span>
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">47</span> cluster-01-node-01 fenced<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2666</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: agent <span style="color: #ff0000;">&quot;fence_vmware_vi&quot;</span> reports: e 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">47</span> cluster-01-node-01 ccsd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2636</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: Attempt to close an unopened CCS descriptor <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">44880</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>. 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">47</span> cluster-01-node-01 ccsd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2636</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: Error <span style="color: #000000; font-weight: bold;">while</span> processing disconnect: Invalid request descriptor 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">47</span> cluster-01-node-01 fenced<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2666</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: fence <span style="color: #ff0000;">&quot;cluster-01-node-03&quot;</span> failed
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">18</span>:<span style="color: #000000;">52</span> cluster-01-node-01 fenced<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2666</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: fencing node <span style="color: #ff0000;">&quot;cluster-01-node&quot;</span>
&nbsp;
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">19</span>:<span style="color: #000000;">28</span> cluster-01-node-01 fenced<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2666</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: agent <span style="color: #ff0000;">&quot;fence_vmware_vi&quot;</span> reports: Connection timed out 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">19</span>:<span style="color: #000000;">28</span> cluster-01-node-01 ccsd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2636</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: Attempt to close an unopened CCS descriptor <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">45600</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>. 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">19</span>:<span style="color: #000000;">28</span> cluster-01-node-01 ccsd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2636</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: Error <span style="color: #000000; font-weight: bold;">while</span> processing disconnect: Invalid request descriptor 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">19</span>:<span style="color: #000000;">28</span> cluster-01-node-01 fenced<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2666</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: fence <span style="color: #ff0000;">&quot;cluster-01-node-03&quot;</span> failed
&nbsp;
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">19</span>:<span style="color: #000000;">33</span> cluster-01-node-01 fenced<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2666</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: fencing node <span style="color: #ff0000;">&quot;cluster-01-node-03&quot;</span>
  Please use <span style="color: #ff0000;">'-h'</span> <span style="color: #007800;">tNotConnected</span>=HASH<span style="color: #7a0874; font-weight: bold;">&#40;</span>0x19bb0090<span style="color: #7a0874; font-weight: bold;">&#41;</span>mote host, since it is disconnected.ware_helper returned Cannot power on vm Cluster_01_Node_03<span style="color: #000000; font-weight: bold;">!</span>
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">19</span>:<span style="color: #000000;">46</span> cluster-01-node-01 fenced<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2666</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: agent <span style="color: #ff0000;">&quot;fence_vmware_vi&quot;</span> reports: <span style="color: #000000; font-weight: bold;">for</span> usage 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">19</span>:<span style="color: #000000;">46</span> cluster-01-node-01 fenced<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2666</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: fence <span style="color: #ff0000;">&quot;cluster-01-node-03&quot;</span> failed
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">19</span>:<span style="color: #000000;">51</span> cluster-01-node-01 fenced<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2666</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: fencing node <span style="color: #ff0000;">&quot;cluster-01-node-03&quot;</span>
&nbsp;
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">20</span>:<span style="color: #000000;">59</span> cluster-01-node-01 ccsd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2636</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: Attempt to close an unopened CCS descriptor <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">46710</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>. 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">20</span>:<span style="color: #000000;">59</span> cluster-01-node-01 ccsd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2636</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: Error <span style="color: #000000; font-weight: bold;">while</span> processing disconnect: Invalid request descriptor 
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">20</span>:<span style="color: #000000;">59</span> cluster-01-node-01 fenced<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2666</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: fence <span style="color: #ff0000;">&quot;cluster-01-node-03.ig.com.br&quot;</span> success
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">20</span>:<span style="color: #000000;">59</span> cluster-01-node-01 kernel: GFS: <span style="color: #007800;">fsid</span>=Cluster_GFS:gfs.0: <span style="color: #007800;">jid</span>=<span style="color: #000000;">2</span>: Trying to acquire journal lock...
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">20</span>:<span style="color: #000000;">59</span> cluster-01-node-01 kernel: GFS: <span style="color: #007800;">fsid</span>=Cluster_GFS:gfs.0: <span style="color: #007800;">jid</span>=<span style="color: #000000;">2</span>: Looking at journal...
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">20</span>:<span style="color: #000000;">59</span> cluster-01-node-01 kernel: GFS: <span style="color: #007800;">fsid</span>=Cluster_GFS:gfs.0: <span style="color: #007800;">jid</span>=<span style="color: #000000;">2</span>: Acquiring the transaction lock...
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">20</span>:<span style="color: #000000;">59</span> cluster-01-node-01 kernel: GFS: <span style="color: #007800;">fsid</span>=Cluster_GFS:gfs.0: <span style="color: #007800;">jid</span>=<span style="color: #000000;">2</span>: Replaying journal...
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">20</span>:<span style="color: #000000;">59</span> cluster-01-node-01 kernel: GFS: <span style="color: #007800;">fsid</span>=Cluster_GFS:gfs.0: <span style="color: #007800;">jid</span>=<span style="color: #000000;">2</span>: Replayed <span style="color: #000000;">79</span> of <span style="color: #000000;">93</span> blocks
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">20</span>:<span style="color: #000000;">59</span> cluster-01-node-01 kernel: GFS: <span style="color: #007800;">fsid</span>=Cluster_GFS:gfs.0: <span style="color: #007800;">jid</span>=<span style="color: #000000;">2</span>: replays = <span style="color: #000000;">79</span>, skips = <span style="color: #000000;">13</span>, sames = <span style="color: #000000;">1</span>
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">20</span>:<span style="color: #000000;">59</span> cluster-01-node-01 kernel: GFS: <span style="color: #007800;">fsid</span>=Cluster_GFS:gfs.0: <span style="color: #007800;">jid</span>=<span style="color: #000000;">2</span>: Journal replayed <span style="color: #000000; font-weight: bold;">in</span> 1s
Jan  <span style="color: #000000;">6</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">20</span>:<span style="color: #000000;">59</span> cluster-01-node-01 kernel: GFS: <span style="color: #007800;">fsid</span>=Cluster_GFS:gfs.0: <span style="color: #007800;">jid</span>=<span style="color: #000000;">2</span>: Done</pre></div></div>

<p><strong>Conclusão</strong></p>
<p>Estes testes foram realizados buscando alternativas que reduzam o downtime dos serviços e/ou aplicações contidos em um servidor, chegando a manter sua disponibilidade próxima dos 99,999%.</p>
<p>Como você pôde perceber, esta estrutura permite chegarmos a este número, mas até o momento em que está sendo escrito este post, a versão usada ainda não está homologada, usando pacotes ainda em desenvolvimento (cman+fence_vmware). </p>
<p>Num futuro próximo, já devemos ter algum retorno das empresas desenvolvedoras, pois focam em uma fatia do merdado muito forte e competitiva ($$$).</p>
]]></content:encoded>
			<wfw:commentRss>http://everlinux.com/blog/2009/01/06/cluster-com-vmware-esx-gfs/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Usando DRBD com GFS e Fencing Manual</title>
		<link>http://everlinux.com/blog/2008/06/16/usando-drbd-com-gfs-e-fencing-manual</link>
		<comments>http://everlinux.com/blog/2008/06/16/usando-drbd-com-gfs-e-fencing-manual#comments</comments>
		<pubDate>Mon, 16 Jun 2008 19:42:02 +0000</pubDate>
		<dc:creator>Tiago Cruz</dc:creator>
				<category><![CDATA[Cluster]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Red Hat]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.everlinux.com/blog/2008/06/16/usando-drbd-com-gfs-e-fencing-manual/</guid>
		<description><![CDATA[* DRBD 8.x DBRD é a acrônimo para o nome inglês Distributed Replicated Block Device. O DRBD consiste num módulo para o kernel de Linux que, juntamente com alguns scripts, oferece um dispositivo de bloco projetado para disponibilizar dispositivos de armazenamento distribuídos, geralmente utilizado em clusters de alta disponibilidade. Isto é feito espelhando conjuntos de [...]]]></description>
			<content:encoded><![CDATA[<p><strong>* DRBD 8.x </strong></p>
<p>DBRD é a acrônimo para o nome inglês <em>Distributed Replicated Block Device</em>. O DRBD consiste num módulo para o kernel de Linux que, juntamente com alguns scripts, oferece um dispositivo de bloco projetado para disponibilizar dispositivos de armazenamento distribuídos, geralmente utilizado em clusters de alta disponibilidade. Isto é feito espelhando conjuntos de blocos via rede (dedicada). O DRBD funciona, portanto, como um sistema RAID baseado em rede.</p>
<p>Referência: <a href="http://pt.wikipedia.org/wiki/DRBD">http://pt.wikipedia.org/wiki/DRBD</a></p>
<p><strong>* GFS 1.x </strong></p>
<p>O &#8220;<em>Red Hat Global File System</em>&#8221; é um Sistema de Arquivos para Cluster, que permite que vários nós leiam e escrevam dados simultaneamente em um dispositivo compartilhado.</p>
<p>O GFS suporta ACL&#8217;s e atributos extendidos, diferente se seu concorrente direto, o OCFS (Oracle Cluster File System)</p>
<p>Vale observar que a versão 2.0 do GFS ainda é considerado &#8220;Technology Preview&#8221; e não deve ser usado em produção.</p>
<p>Porém, o GFS congela todo o I/O se ele perde um nó (cliente), e fica congelado até o que o nó retorne ou que o mesmo seja &#8220;fenced&#8221;.</p>
<p>Referência: <a href="http://www.redhat.com/gfs/">http://www.redhat.com/gfs/</a><br />
<a href="http://en.wikipedia.org/wiki/Comparison_of_file_systems">http://en.wikipedia.org/wiki/Comparison_of_file_systems</a></p>
<p><strong>* Fence Devices </strong></p>
<p>Fence é algo difícil de traduzir para a nossa língua, assim como a palavra &#8220;proxy&#8221; O Babylon sugere &#8220;grade; muro; cercar; proteger&#8221; enquanto o Google Translator sugere &#8220;vedação&#8221;.</p>
<p>Enfim, é algo nesse sentido: Se um nó do cluster apresenta problemas, para evitar que esse cara escreva algo no FileSystem? e acabe por corromper o mesmo, é necessário que o mesmo seja &#8220;fenceado&#8221;, ou seja, tirado da jogada. As formas comuns se se fazer isso são:</p>
<p>- Desligando a alimentação de energia deles;<br />
- Desligando a porta do switch;<br />
- Reiniciando a máquina usando DRAC/RSA/ILO (Dell, IBM e HP respectivamente);<br />
- Manualmente;</p>
<p>Utilizaremos a forma menos recomendada (manual) devido a falta de infra-estrutura para utilizarmos as demais. Um script do modificado do DRBD irá tornar o fencing_manual em um fencing automatizado <img src='http://everlinux.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
<p>Referência: <a href="http://www.everlinux.com/blog/2008/04/22/redhat-enterprise-linux-51-cluster-suite/">http://www.everlinux.com/blog/2008/04/22/redhat-enterprise-linux-51-cluster-suite/</a></p>
<p><strong>* LVM </strong></p>
<p>Usaremos LVM para garantir flexibilidade da solução:</p>
<p>Criar volumes LV nas duas máquinas</p>
<p># pvcreate /dev/sda9<br />
# vgcreate vol0 /dev/sda9<br />
# lvcreate -L 105.94G -n lvm vol0</p>
<p><strong> &#8211; Configurando o DRBD</strong></p>
<p>Configurar o /etc/hosts para conter todas as maquinas, principalmente o hostname no IP principal e um nome para os IPs da rede de sincronismo: </p>
<p>127.0.0.1        localhost.localdomain localhost<br />
10.10.10.1     hotsite-1.com.br<br />
10.10.10.2     hotsite-2.com.br<br />
192.168.0.3     drbd_hotsite-1 drdb_hotsite-1.com.br<br />
192.168.0.4     drdb_hotsite-2 drdb_hotsite-2.com.br</p>
<p>Configurar o /etc/drbd.conf no master e slave</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># DRDB Configuration</span>
global <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        usage-count no;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
resource hotsite <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        protocol C;
&nbsp;
        startup <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                wfc-timeout <span style="color: #000000;">0</span>;
                degr-wfc-timeout <span style="color: #000000;">120</span>;
                become-primary-on both;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
        disk    <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                fencing resource-and-stonith;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
       handlers <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                outdate-peer <span style="color: #ff0000;">&quot;/sbin/obliterate&quot;</span>;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
        net     <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                cram-hmac-alg sha1;
                shared-secret <span style="color: #ff0000;">&quot;senha_secreta&quot;</span>;
                timeout <span style="color: #000000;">60</span>;
                connect-int <span style="color: #000000;">10</span>;
                ping-int <span style="color: #000000;">10</span>;
                max-buffers <span style="color: #000000;">2048</span>;
                max-epoch-size <span style="color: #000000;">2048</span>;
                allow-two-primaries;
                after-sb-0pri discard-zero-changes;
                after-sb-1pri discard-secondary;
                after-sb-2pri disconnect;
                rr-conflict violently;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
        syncer  <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                rate 650M;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
        on hotsite-1.com.br <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                device    <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>drbd0;
                disk      <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>vol0<span style="color: #000000; font-weight: bold;">/</span>lvm;
                address   192.168.0.3:<span style="color: #000000;">7789</span>;
                flexible-meta-disk internal;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
        on hotsite-2.com.br <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                device    <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>drbd0;
                disk      <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>vol0<span style="color: #000000; font-weight: bold;">/</span>lvm;
                address   192.168.0.4:<span style="color: #000000;">7789</span>;
                flexible-meta-disk internal;
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Inicializar as partições para o drbd no master e slave </p>
<p><code># drbdadm create-md hotsite  |<br />
# drbdadm attach hotsite     |  drbdadm up hotsite<br />
# drbdadm connect hotsite    |</p>
<p># drbdadm -- --overwrite-data-of-peer primary hotsite<br />
# watch -n1 cat /proc/drbd<br />
# drbdadm primary hotsite<br />
</code></p>
<p>Obs: Caso de erro de carga de modulo inicie o drbd com &#8220;service drbd start&#8221; mesmo acusando erro, isso fará com que carregue o modulo corretamente.</p>
<p>Inicializar o drbd no master e slave </p>
<p><code># service drbd start</code></p>
<p><strong>- Configurando o cluster para o GFS</strong></p>
<p>* Crie o arquivo de configuração do cluster (/etc/cluster/cluster.conf) para o gfs, em todas as maquinas: </p>
<p>Vou colocar ele em um arquivo separado pois o wordpress não está(va) gostando as tags do mesmo: <a href='http://www.everlinux.com/blog/wp-content/uploads/2008/06/clusterconf.txt' title='cluster.conf'>cluster.conf</a></p>
<p>Update:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;</span>?xml <span style="color: #007800;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span>?<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>cluster <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;hotsite&quot;</span> <span style="color: #007800;">config_version</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>cman <span style="color: #007800;">two_node</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #007800;">expected_votes</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>fence_daemon <span style="color: #007800;">post_join_delay</span>=<span style="color: #ff0000;">&quot;60&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>fence_daemon<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>clusternodes<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>clusternode <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;drdb_hotsite-1&quot;</span> <span style="color: #007800;">nodeid</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>fence<span style="color: #000000; font-weight: bold;">&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;</span>method <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;single&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>device <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;node1&quot;</span> <span style="color: #007800;">ipaddr</span>=<span style="color: #ff0000;">&quot;192.168.0.3&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;/</span>method<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;/</span>fence<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>clusternode<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>clusternode <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;drdb_hotsite-2&quot;</span> <span style="color: #007800;">nodeid</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>fence<span style="color: #000000; font-weight: bold;">&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;</span>method <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;single&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
                        <span style="color: #000000; font-weight: bold;">&lt;</span>device <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;node2&quot;</span> <span style="color: #007800;">ipaddr</span>=<span style="color: #ff0000;">&quot;192.168.0.4&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;/</span>method<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;/</span>fence<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>clusternode<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>clusternodes<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>fencedevices<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">&lt;</span>fencedevice <span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;manual&quot;</span> <span style="color: #007800;">agent</span>=<span style="color: #ff0000;">&quot;fence_manual&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>fencedevices<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>cluster<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p><strong>Formatar a partição DRBD com GFS</strong></p>
<p><code># gfs_mkfs -t hotsite:gfs-00 -p lock_dlm -j 2 /dev/drbd0</code></p>
<p>Com isto ele irá iniciar o sincronismo com slave, pode ser observado executando o comando:</p>
<p><code># watch -n 1 cat /proc/drbd</code></p>
<p><strong>Inicie o serviços de cluster: </strong></p>
<p># service cman start</p>
<p><strong>Testando</strong></p>
<p><code># mount -v /dev/drbd0 /data<br />
# for i in `seq 1 10`; do a=`echo $RANDOM`; dd if=/dev/zero of=/data/$a bs=1k count=$a; sleep 1; done<br />
# ls -ltrk /data</code></p>
<p><strong>Forçando um reboot:</strong><br />
<code># echo 1 > /proc/sys/kernel/sysrq<br />
# echo b > /proc/sysrq-trigger<br />
</code></p>
<p>Para forçar o sincronismo de uma máquina<br />
(faça somente se souber o que está fazendo)<br />
<code># drbdsetup /dev/drbd0 primary -o</code></p>
<p><strong>Ordem dos scripts:</strong></p>
<p>Essa deverá ser a ordem para init level 0 e 6, pois durante o reboot/ shutdown da máquina o procedimento é o seguinte:<br />
- Desmonta a partição<br />
- Tira a máquina do Cluster<br />
- Para o DRBD</p>
<p><code>[root@hotsite-2 /etc/rc0.d]# ll | egrep '(partition|drbd|cman)'<br />
lrwxrwxrwx 1 root root 12 Jun 13 11:57 K80partition -> ../init.d/partition<br />
lrwxrwxrwx 1 root root 14 Jun 13 11:47 K81cman -> ../init.d/cman<br />
lrwxrwxrwx 1 root root 14 Jun 13 11:57 K82drbd -> ../init.d/drbd</code></p>
<p>Para os init level 3, 4 e 5 deverá ser:<br />
- Coloca a máquina do Cluster<br />
- Inicia o DRBD<br />
- Monta a partição do drbd (pois o mesmo irá falhar durante a inicialização)</p>
<p><code>[root@hotsite-2 /etc/rc3.d]# ll | egrep '(partition|drbd|cman)'<br />
lrwxrwxrwx 1 root root 14 Jun 13 11:55 S21cman -> ../init.d/cman<br />
lrwxrwxrwx 1 root root 14 Jun 13 11:55 S70drbd -> ../init.d/drbd<br />
lrwxrwxrwx 1 root root 12 Jun 13 11:55 S91partition -> ../init.d/partition</code></p>
<p><strong>O Script obliterate</strong></p>
<p>O script Obliterate foi escrito pelo Lon Hohberger e está disponível <a href="http://people.redhat.com/lhh/obliterate">aqui</a>.</p>
<p>Eu alterei as últimas linhas pois o fence_manual precisa que o comando fence_ack_manual seja executado, senão o GFS não vai liberar o I/O do cluster enquanto o outro nó não retornar com sucesso&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#</span>
fence_node <span style="color: #007800;">$REMOTE</span>
fence_ack_manual <span style="color: #660033;">-O</span> <span style="color: #660033;">-e</span> <span style="color: #660033;">-n</span> <span style="color: #007800;">$REMOTE</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #666666; font-style: italic;"># Reference:</span>
	<span style="color: #666666; font-style: italic;"># http://osdir.com/ml/linux.kernel.drbd.devel/2006-11/msg00005.html</span>
	<span style="color: #666666; font-style: italic;"># 7 = node got blown away.  </span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">7</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Fencing failed?!</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span></pre></div></div>

<p>Referência: <a href="http://sources.redhat.com/cluster/wiki/DRBD_Cookbook">http://sources.redhat.com/cluster/wiki/DRBD_Cookbook</a></p>
]]></content:encoded>
			<wfw:commentRss>http://everlinux.com/blog/2008/06/16/usando-drbd-com-gfs-e-fencing-manual/feed</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Fazendo backup das suas VM’s do Xen: Atualizado</title>
		<link>http://everlinux.com/blog/2008/05/12/fazendo-backup-das-suas-vm%e2%80%99s-do-xen-atualizado</link>
		<comments>http://everlinux.com/blog/2008/05/12/fazendo-backup-das-suas-vm%e2%80%99s-do-xen-atualizado#comments</comments>
		<pubDate>Mon, 12 May 2008 19:44:21 +0000</pubDate>
		<dc:creator>Tiago Cruz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Virtualização]]></category>
		<category><![CDATA[Xen]]></category>

		<guid isPermaLink="false">http://www.everlinux.com/blog/2008/05/12/fazendo-backup-das-suas-vm%e2%80%99s-do-xen-atualizado/</guid>
		<description><![CDATA[O script anterior foi atualizado contando com algumas melhorias sugeridas pelos seus usuários, como: - Agora ele é escrito em Inglês, para maior portabilidade com outros usuários do xen ao redor do mundo; - Você pode fazer backup de somente uma máquina específica, não é mais necessário esperar todo o laço terminar para ver o [...]]]></description>
			<content:encoded><![CDATA[<p>O <a href="http://www.everlinux.com/blog/2008/04/03/fazendo-backup-das-suas-vms-do-xen/">script anterior</a> foi atualizado contando com algumas melhorias sugeridas pelos seus usuários, como:</p>
<p>- Agora ele é escrito em Inglês, para maior portabilidade com outros usuários do xen ao redor do mundo;</p>
<p>- Você pode fazer backup de somente uma máquina específica, não é mais necessário esperar todo o laço terminar para ver o resultado do mesmo;</p>
<p>- Script parametrizado e funcões sub-divididas e</p>
<p>- Pequenos problemas corrigidos.</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>
<span style="color: #666666; font-style: italic;"># Backup of Xen VM's</span>
<span style="color: #666666; font-style: italic;"># Tiago Cruz - tiagocruz@everlinux.com</span>
<span style="color: #666666; font-style: italic;"># v 1.0	Mar/2008 - Initial version, just backup all VM's</span>
<span style="color: #666666; font-style: italic;"># v 1.1 May/2008 - Now we have functions and parameters</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<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: #007800;">BACK</span>=<span style="color: #ff0000;">&quot;_snap&quot;</span>
<span style="color: #007800;">LOG</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>backup.<span style="color: #000000; font-weight: bold;">`</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: #000000; font-weight: bold;">`</span>
<span style="color: #666666; font-style: italic;"># root partition to backup (&quot;/&quot;)</span>
<span style="color: #666666; font-style: italic;"># usually the second it's swap</span>
<span style="color: #007800;">ROOT</span>=<span style="color: #ff0000;">&quot;1&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;/mnt/back&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span>  <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;/data/backup&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span>  <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>backup
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> showHelp<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; &quot;</span>        
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Use the following parameters: &quot;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;          help   = Show this help&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;          all    = Backup of all VM's&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;          list   = List all VM's from this domain&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;          &lt;vm&gt;   = Backup one specific VM&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; &quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;ex: back_xen.sh tomcat_shop&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; &quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> listVM<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;List of VM's avaliables:&quot;</span>
	<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>xm list <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;">egrep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'(Name|Domain-0)'</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; &quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> backXen <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backuping machine <span style="color: #007800;">$i</span>...&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please, look the progress on <span style="color: #007800;">$LOG</span>&quot;</span>
	listVM <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Machine <span style="color: #007800;">$i</span> does not exist, aborting!&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">2</span>
	<span style="color: #000000; font-weight: bold;">fi</span>	
	backup
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup of <span style="color: #007800;">$i</span> completed successfully!!!&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup finalized on <span style="color: #780078;">`date`</span> with load <span style="color: #780078;">`cat /proc/loadavg | cut -c 1-14`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;==============================================&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;==============================================&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> backAll <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #007800;">VMS</span>=<span style="color: #000000; font-weight: bold;">`</span>xm list <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;">egrep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'(Name|Domain-0)'</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$VMS</span>; <span style="color: #000000; font-weight: bold;">do</span>
		backup
	<span style="color: #000000; font-weight: bold;">done</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup finalized on <span style="color: #780078;">`date`</span> with load <span style="color: #780078;">`cat /proc/loadavg | cut -c 1-14`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;==============================================&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;==============================================&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> backup <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;==============================================&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup <span style="color: #007800;">$i</span> started on <span style="color: #780078;">`date`</span> with load <span style="color: #780078;">`cat /proc/loadavg | cut -c 1-14`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
	<span style="color: #007800;">DEVICE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> ^disk <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>xen<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;Vol_LVM&quot;</span> <span style="color: #ff0000;">'{print $2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span> , <span style="color: #660033;">-f</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Virtual Machine <span style="color: #007800;">$i</span> uses <span style="color: #007800;">$DEVICE</span> as storage device&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
&nbsp;
	lvcreate <span style="color: #660033;">--snapshot</span> <span style="color: #660033;">-L</span> 15G <span style="color: #660033;">-n</span> <span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>Vol_LVM<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DEVICE</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error <span style="color: #007800;">$i</span>: creating LVM <span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span> 
&nbsp;
	kpartx <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>Vol_LVM-<span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
	<span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>Vol_LVM-<span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span><span style="color: #007800;">$ROOT</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error <span style="color: #007800;">$i</span>: mounting <span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span><span style="color: #007800;">$ROOT</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span> 
&nbsp;
	<span style="color: #007800;">SIZE1</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">df</span> <span style="color: #660033;">-hP</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> Used<span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #007800;">SIZE2</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">df</span> <span style="color: #660033;">-hP</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> Size<span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup of /dev/mapper/Vol_LVM-<span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span><span style="color: #007800;">$ROOT</span> - <span style="color: #007800;">$SIZE1</span> of <span style="color: #007800;">$SIZE2</span> used&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
	<span style="color: #c20cb9; font-weight: bold;">tar</span> zcf <span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$i</span>-xen.tar.gz <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error <span style="color: #007800;">$i</span>: creating /LVM/backup/<span style="color: #007800;">$i</span>.tar.gz&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span> 
&nbsp;
	<span style="color: #007800;">SIZE3</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-lh</span> <span style="color: #000000; font-weight: bold;">/</span>LVM<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$i</span>-xen.tar.gz  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $5}'</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Created /LVM/backup/<span style="color: #007800;">$i</span>-xen.tar.gz with <span style="color: #007800;">$SIZE3</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
&nbsp;
	<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
	<span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error <span style="color: #007800;">$i</span>: umounting <span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span> 
	kpartx <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>Vol_LVM-<span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error <span style="color: #007800;">$i</span>: deleting partition mappings <span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span> 
&nbsp;
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Removing snapshot already backuped <span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
	lvremove <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>Vol_LVM<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$#&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	showHelp
&nbsp;
<span style="color: #000000; font-weight: bold;">fi</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> 
	list<span style="color: #7a0874; font-weight: bold;">&#41;</span>	listVM	<span style="color: #000000; font-weight: bold;">;;</span>
	all <span style="color: #7a0874; font-weight: bold;">&#41;</span>	backAll	<span style="color: #000000; font-weight: bold;">;;</span>
	<span style="color: #7a0874; font-weight: bold;">help</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>	showHelp <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: #007800;">i</span>=$<span style="color: #000000;">1</span>; backXen <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span></pre></div></div>

<p>Caso tenha problemas com o copy-past, você pode pegar o mesmo aqui: <a href="http://www.everlinux.com/tiago/shell/back_xen.sh.txt">back_xen.sh.txt</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://everlinux.com/blog/2008/05/12/fazendo-backup-das-suas-vm%e2%80%99s-do-xen-atualizado/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Fazendo backup das suas VM&#8217;s do Xen</title>
		<link>http://everlinux.com/blog/2008/04/03/fazendo-backup-das-suas-vms-do-xen</link>
		<comments>http://everlinux.com/blog/2008/04/03/fazendo-backup-das-suas-vms-do-xen#comments</comments>
		<pubDate>Thu, 03 Apr 2008 14:06:51 +0000</pubDate>
		<dc:creator>Tiago Cruz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Virtualização]]></category>
		<category><![CDATA[Xen]]></category>

		<guid isPermaLink="false">http://www.everlinux.com/blog/2008/04/03/fazendo-backup-das-suas-vms-do-xen/</guid>
		<description><![CDATA[Se você usa o Xen, usa Storage Devices sob LVM, e acha importante ter um backup das mesmas, você pode utilizar/ adaptar este pequeno script que tira um snapshot e em seguida faz um &#8220;tar.gz&#8221; de todo o &#8220;/&#8221; da sua VM, e a guarda em um local para que você possa restaura-lo caso necessário. [...]]]></description>
			<content:encoded><![CDATA[<p>Se você usa o Xen, usa Storage Devices sob LVM, e acha importante ter um backup das mesmas, você pode utilizar/ adaptar este pequeno script que tira um snapshot e em seguida faz um &#8220;tar.gz&#8221; de todo o &#8220;/&#8221; da sua VM, e a guarda em um local para que você possa restaura-lo caso necessário. <img src='http://everlinux.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </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>
<span style="color: #666666; font-style: italic;"># Backup das VM's do Xen</span>
<span style="color: #666666; font-style: italic;"># Tiago Cruz - tiagocruz@everlinux.com</span>
<span style="color: #666666; font-style: italic;"># Mar/2008</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<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
&nbsp;
<span style="color: #007800;">VMS</span>=<span style="color: #000000; font-weight: bold;">`</span>xm list <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;">egrep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'(Name|Domain-0)'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">BACK</span>=<span style="color: #ff0000;">&quot;_snap&quot;</span>
<span style="color: #007800;">LOG</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>backup
<span style="color: #666666; font-style: italic;"># Particao root, geralmente a segunda eh swap</span>
<span style="color: #007800;">ROOT</span>=<span style="color: #ff0000;">&quot;1&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;/mnt/back&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span>  <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;/dados/backup&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span>  <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>dados<span style="color: #000000; font-weight: bold;">/</span>backup
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$VMS</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;=================================================================&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup <span style="color: #007800;">$i</span> iniciado em <span style="color: #780078;">`date`</span> com load de <span style="color: #780078;">`cat /proc/loadavg`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
        <span style="color: #007800;">DEVICE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> disk <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>xen<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;Vol_LVM&quot;</span> <span style="color: #ff0000;">'{print $2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span> , <span style="color: #660033;">-f</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Maquina Virtual <span style="color: #007800;">$i</span> usa <span style="color: #007800;">$DEVICE</span> como storage device&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
&nbsp;
        lvcreate <span style="color: #660033;">--snapshot</span> <span style="color: #660033;">-L</span> 15G <span style="color: #660033;">-n</span> <span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>Vol_LVM<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$DEVICE</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
        <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Erro <span style="color: #007800;">$i</span>: criando LVM <span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
&nbsp;
        kpartx <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>Vol_LVM-<span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
        <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>Vol_LVM-<span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span><span style="color: #007800;">$ROOT</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
        <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Erro <span style="color: #007800;">$i</span>: montando <span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span><span style="color: #007800;">$ROOT</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
&nbsp;
        <span style="color: #007800;">SIZE1</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">df</span> <span style="color: #660033;">-hP</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> Used<span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #007800;">SIZE2</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">df</span> <span style="color: #660033;">-hP</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> Size<span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup de /dev/mapper/Vol_LVM-<span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span><span style="color: #007800;">$ROOT</span> - <span style="color: #007800;">$SIZE1</span> de <span style="color: #007800;">$SIZE2</span> usados&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
        <span style="color: #c20cb9; font-weight: bold;">tar</span> zcf <span style="color: #000000; font-weight: bold;">/</span>dados<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$i</span>-xen.tar.gz <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
        <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Erro <span style="color: #007800;">$i</span>: criando /dados/backup/<span style="color: #007800;">$i</span>.tar.gz&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
&nbsp;
        <span style="color: #007800;">SIZE3</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-lh</span> <span style="color: #000000; font-weight: bold;">/</span>dados<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$i</span>-xen.tar.gz  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $5}'</span><span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Criado /dados/backup/<span style="color: #007800;">$i</span>-xen.tar.gz com <span style="color: #007800;">$SIZE3</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
&nbsp;
        <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>back<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
        <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Erro <span style="color: #007800;">$i</span>: desmontando <span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
        kpartx <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>Vol_LVM-<span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
        <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Erro <span style="color: #007800;">$i</span>: desmapeando <span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
&nbsp;
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Removendo snapshot ja backupeado <span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
        lvremove <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>Vol_LVM<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$i</span><span style="color: #007800;">$BACK</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backup finalizado em <span style="color: #780078;">`date`</span> com load de <span style="color: #780078;">`cat /proc/loadavg`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;=================================================================&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;=================================================================&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOG</span></pre></div></div>

<p>Trecho do log:</p>
<blockquote><p>Backup ora_busca iniciado em Fri Mar 28 05:02:53 BRT 2008 com load de 1.31 1.33 1.21<br />
Maquina Virtual ora_busca usa ora_busca como storage device<br />
  Logical volume &#8220;ora_busca_snap&#8221; created<br />
Backup de /dev/mapper/Vol_LVM-ora_busca_snap1 &#8211; 16G de 95G usados<br />
Criado /dados/backup/ora_busca-xen.tar.gz com 4.9G<br />
Removendo snapshot ja backupeado ora_busca_snap<br />
  Logical volume &#8220;ora_busca_snap&#8221; successfully removed
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://everlinux.com/blog/2008/04/03/fazendo-backup-das-suas-vms-do-xen/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Clonando VM&#8217;s no XEN</title>
		<link>http://everlinux.com/blog/2008/02/07/clonando-vms-no-xen</link>
		<comments>http://everlinux.com/blog/2008/02/07/clonando-vms-no-xen#comments</comments>
		<pubDate>Thu, 07 Feb 2008 18:16:48 +0000</pubDate>
		<dc:creator>Tiago Cruz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Virtualização]]></category>
		<category><![CDATA[Xen]]></category>

		<guid isPermaLink="false">http://www.everlinux.com/blog/2008/02/07/clonando-vms-no-xen/</guid>
		<description><![CDATA[1-) Estou armazenando as VMs no LVM: # lvcreate -Ay -L 60G -n vm00 Vol_LVM # lvcreate -Ay -L 60G -n vm01 Vol_LVM # lvcreate -Ay -L 60G -n vm02 Vol_LVM 2-) Estou usando o &#8220;partimage-0.6.7_beta2.tar.bz2&#8243;, pois a versão stable não funciona bem em 64 bits: 3-) A primeira VM deve ser instalada/ configurada manualmente/normalmente. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>1-)</strong> Estou armazenando as VMs no LVM:</p>
<p><code>	# lvcreate -Ay -L 60G -n vm00 Vol_LVM<br />
	# lvcreate -Ay -L 60G -n vm01 Vol_LVM<br />
	# lvcreate -Ay -L 60G -n vm02 Vol_LVM<br />
</code><br />
<strong>2-)</strong> Estou usando o &#8220;partimage-0.6.7_beta2.tar.bz2&#8243;, pois a versão stable não funciona bem em 64 bits:</p>
<p><strong>3-)</strong> A primeira VM deve ser instalada/ configurada manualmente/normalmente. Depois você pode tirar uma cópia dela:</p>
<p><code>	# kpartx -a /dev/mapper/Vol_LVM-vm01<br />
	# partimage -z1 save /dev/mapper/Vol_LVM-vm01p1 /LVM/vm01p1.partimg.gz</code><br />
ou<br />
<code>	# partimage -z0 -c -d -f0 save /dev/mapper/Vol_LVM-vm01p1 /LVM/vm01p1.partimg<br />
	# kpartx -d /dev/mapper/Vol_LVM-vm01</code></p>
<p>PS: Note que se você usar compressão (-z1) a geração da imagem vai demorar mais para ser criado, porém com o tamanho bem menor (515M vs 3.7GB) . A restauração da mesma também será mais lenta.</p>
<p><strong>4-)</strong> Com base na primeira VM:</p>
<p><code># fdisk -l /dev/mapper/Vol_LVM-vm00<br />
Disk /dev/mapper/Vol_LVM-vm00: 64.4 GB, 64424509440 bytes<br />
255 heads, 63 sectors/track, 7832 cylinders<br />
Units = cylinders of 16065 * 512 = 8225280 bytes</p>
<p>                   Device Boot      Start         End      Blocks   Id  System<br />
/dev/mapper/Vol_LVM-vm00p1   *           2        7395    59392305   83  Linux<br />
/dev/mapper/Vol_LVM-vm00p2            7396        7832     3510202+  82  Linux swap / Solaris<br />
</code></p>
<p>Você poderá preparar um arquivo, por exemplo, /tmp/parttable, com as especificações das demais partições.<br />
1,7394,83,*<br />
7395,,82,-</p>
<p>Estou usando uma partição primária para o raiz &#8220;/&#8221; (tipo 83) com ~ 60 GB e o restante para swap (tipo 82).</p>
<p>Você poderá usar o sfdisk e especificar os dados em: sectors, blocks, cylinders ou megabytes.</p>
<p><strong>5-)</strong> Crie as partições para a segunda VM:</p>
<p><code>	# dd if=/dev/zero of=/dev/mapper/Vol_LVM-vm01 count=1 bs=512<br />
	# sfdisk -uC /dev/mapper/Vol_LVM-vm01 < /tmp/parttable</code></p>
<p>Se preferir, simplesmente faça o processo manualmente:<br />
# fdisk /dev/mapper/Vol_LVM-vm01</p>
<p><strong>6-)</strong> Crie a SWAP para o segundo device:</p>
<p>Será necessário usar o "kpartx" para "mapear" as partições que existem dentro do device LVM:</p>
<p><code>	# kpartx -a /dev/mapper/Vol_LVM-vm01<br />
	# ll /dev/mapper/Vol_LVM-vm01*<br />
	# mkswap /dev/mapper/Vol_LVM-vm01p2<br />
</code><br />
<strong>7-)</strong> Restaure a imagem da primeira VM:</p>
<p>- Restauração com GZIP:</p>
<blockquote><p>	# partimage restore /dev/mapper/Vol_LVM-vm02p1 /LVM/vm01p1.partimg.gz<br />
        Time elapsed: 10m:59sec<br />
        Speed: 5.16 GiB/min<br />
        Data copied: 56.64 GiB</p></blockquote>
<p>- Restauração sem GZIP:</p>
<blockquote><p>	# partimage restore /dev/mapper/Vol_LVM-vm03p1 /LVM/vm01p1.partimg.000<br />
        Time elapsed:  1m:15sec<br />
        Speed: 2.90 GiB/min<br />
        Data copied: 3.62 GiB</p></blockquote>
<p><strong> <img src='http://everlinux.com/blog/wp-includes/images/smilies/icon_cool.gif' alt='8-)' class='wp-smiley' /> </strong> Monte a VM e troque endereços de IP, hostname e MAC Address:<br />
<code>	# mount /dev/mapper/Vol_LVM-vm01p1 /mnt/xen/<br />
        # vi /mnt/xen/etc/sysconfig/network-scripts/ifcfg-eth0<br />
        # vi /mnt/xen/etc/sysconfig/network<br />
        # vi /mnt/xen/etc/hosts</code></p>
<p>PS: Use o macgen.py para alterar o MAC address:</p>
<blockquote><p>$ cat macgen.py<br />
	#! /usr/bin/python<br />
	# macgen.py script generates a MAC address for Xen guests<br />
	#<br />
	import random<br />
	mac = [ 0x00, 0x16, 0x3e,<br />
	random.randint(0x00, 0x7f),<br />
	random.randint(0x00, 0xff),<br />
	random.randint(0x00, 0xff) ]<br />
	print ':'.join(map(lambda x: "%02x" % x, mac))</p></blockquote>
<p><strong>9-) </strong>Desmonte a partição, e arrume seu /etc/xen/vm02:</p>
<p><code>	# umount /mnt/xen<br />
	# kpartx -d /dev/mapper/Vol_LVM-vm02<br />
</code></p>
<p>Utilize o "uuidgen" para gerar um novo UUID para sua VM.<br />
Não esqueça de trocar também o MAC no campo "vif" e o device LVM, ex:</p>
<blockquote><p>name = "vm02"<br />
uuid = "82f89076-487e-4de5-ab4a-99ce07c586eb"<br />
maxmem = 1000<br />
memory = 800<br />
vcpus = 1<br />
bootloader = "/usr/bin/pygrub"<br />
on_poweroff = "destroy"<br />
on_reboot = "restart"<br />
on_crash = "restart"<br />
vfb = [ "type=vnc,vncunused=1,keymap=en-us" ]<br />
disk = [ "phy:/dev/Vol_LVM/vm01,xvda,w" ]<br />
vif = [ "mac=00:16:3e:5a:02:a6,bridge=xenbr0" ]
</p></blockquote>
<p><strong>10-) </strong>Inicie a VM e corra para o abraço:</p>
<p>	<code># xm create vm02 -c</code></p>
<p>Em caso de problemas, consulte este artigo: <a href="http://www.everlinux.com/blog/2007/12/04/xen-dicas-rapidas-e-problemas-resolvidos/">Xen: Dicas rápidas e problemas resolvidos</a></p>
]]></content:encoded>
			<wfw:commentRss>http://everlinux.com/blog/2008/02/07/clonando-vms-no-xen/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Verificando a quantidade de memória utilizada pelo apache</title>
		<link>http://everlinux.com/blog/2008/01/08/verificando-a-quantidade-de-memoria-utilizada-pelo-apache</link>
		<comments>http://everlinux.com/blog/2008/01/08/verificando-a-quantidade-de-memoria-utilizada-pelo-apache#comments</comments>
		<pubDate>Tue, 08 Jan 2008 16:40:55 +0000</pubDate>
		<dc:creator>Tiago Cruz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.everlinux.com/blog/2008/01/08/verificando-a-quantidade-de-memoria-utilizada-pelo-apache/</guid>
		<description><![CDATA[Caso você precise saber quanta memória seus processos do apache estão utilizando do seu SO, pode utilizar este script no crontab: #!/bin/bash LOG="/var/log/apache_memoria.log" PROC=`ps -eLf &#124; grep apache &#124; wc -l` rm -f /tmp/http.txt for i in `ps -ylC httpd --sort:rss &#124; awk '{print $8}'`; do echo $i &#124; grep -v RSS >> /tmp/http.txt ; [...]]]></description>
			<content:encoded><![CDATA[<p>Caso você precise saber quanta memória seus processos do apache estão utilizando do seu SO, pode utilizar este script no crontab:</p>
<p><code>#!/bin/bash<br />
LOG="/var/log/apache_memoria.log"<br />
PROC=`ps -eLf | grep apache | wc -l`<br />
rm -f /tmp/http.txt<br />
for i in `ps -ylC httpd --sort:rss | awk '{print $8}'`; do echo $i | grep -v RSS >> /tmp/http.txt ; done<br />
MEM=$(echo "scale=2; (`cat /tmp/http.txt | tr '\n' +`0"\)/1024 | bc)<br />
echo "`date` -- $MEM MB utilizados pelo httpd com $PROC processos" >> $LOG</p>
<p>Os resultados me parecem bem interessantes... <img src='http://everlinux.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<blockquote><p>...<br />
Tue Jan  8 12:45:01 BRST 2008 -- 765.91 MB utilizados pelo httpd<br />
Tue Jan  8 13:00:01 BRST 2008 -- 903.92 MB utilizados pelo httpd<br />
Tue Jan  8 13:15:01 BRST 2008 -- 689.61 MB utilizados pelo httpd<br />
Tue Jan  8 13:30:01 BRST 2008 -- 629.17 MB utilizados pelo httpd<br />
...</p></blockquote>
<p>A quantidade pode variar bastante, caso seu apache seja estático ou dinâmico (com PHP por exemplo) e MPM's de prefork e worker também apresentam resultados diferentes.</p>
]]></content:encoded>
			<wfw:commentRss>http://everlinux.com/blog/2008/01/08/verificando-a-quantidade-de-memoria-utilizada-pelo-apache/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>check_raid.sh para o Nagios</title>
		<link>http://everlinux.com/blog/2007/06/14/check_raidsh-para-o-nagios</link>
		<comments>http://everlinux.com/blog/2007/06/14/check_raidsh-para-o-nagios#comments</comments>
		<pubDate>Thu, 14 Jun 2007 17:45:16 +0000</pubDate>
		<dc:creator>Tiago Cruz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.everlinux.com/blog/2007/06/14/check_raidsh-para-o-nagios/</guid>
		<description><![CDATA[Estou passando aqui somente para compartilhar um shell script para verificar o estado atual da sua controladora RAID, pois redundância é bom mas se você não trocar os discos não adianta muita coisa O script atualmente suporta: - Controladoras da LSI Megaraid e as mais novas MegaraidSAS, usando o megarc e o MegaCli respectivamente; - [...]]]></description>
			<content:encoded><![CDATA[<p>Estou passando aqui somente para compartilhar um shell script para verificar o estado atual da sua controladora RAID, pois redundância é bom mas se você não trocar os discos não adianta muita coisa <img src='http://everlinux.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
<p>O script atualmente suporta:</p>
<p>- Controladoras da LSI Megaraid e as mais novas MegaraidSAS, usando o <a href="http://www.lsi.com/files/support/rsa/utilities/megaconf/ut_linux_megarc_1.11.zip">megarc</a> e o <a href="http://www.lsilogic.com/files/support/rsa/MR_SAS_1.0/Linux_MegaCli_1.01.09.zip">MegaCli</a> respectivamente;<br />
- Contoladoras ServerRAID da IBM (só o modelo novo que não funciona ainda no <strong>ipssend</strong>, o &#8220;<em>IBM ServeRAID 8k/8k-l8</em>&#8221; e eu não entendo o motivo.);<br />
- Controladora Mylex e RAID por Software;<br />
- É capaz de detectar sua controladora e configurar o nrpe localmente;<br />
- Dá permissão para o usuário do nagios usar SUID para rodar os aplicativos;</p>
<blockquote><p>
Utilize os seguintes parâmetros:<br />
check_raid.sh detecta       &#8211; Para tentar detectar sua controladora e instalar os pacotes necessários<br />
check_raid.sh nrpe          &#8211; Para configurar o daemon do nrpe para a sua controladora</p>
<p>check_raid.sh megaraid      &#8211; Para controladoras MegaRAID (geralmente nas Dell&#8217;s Poweredge 18xx, 28xx ou mais antigas)<br />
check_raid.sh megaraid_sas  &#8211; Para controladoras MegaRAD SAS (geralmente nas Dell&#8217;s Poweredge 19xx, 29xx ou mais novas)<br />
check_raid.sh serveraid     &#8211; Para controladoras geralmente presente em máquinas IBM&#8217;s<br />
check_raid.sh mylex         &#8211; Para a controladora Mylex<br />
check_raid.sh software      &#8211; Para RAID via software </p>
<p>Exemplos:<br />
check_raid.sh nrpe<br />
check_raid.sh megaraid_sas</p></blockquote>
<p>O script está meio bagunçado, não reconhece todas as controladoras mas é um adianto na hora de chegar centenas ou milhares de RAID&#8217;s diferentes. Caso tenha alguma contribuição, favor entrar em contato comigo (tiagocruz AT everlinux.com).</p>
<p>Download aqui: <a href="http://everlinux.com/raid/check_raid.sh">http://everlinux.com/raid/check_raid.sh</a></p>
<p>PS: Não enviei ao <a href="http://www.nagiosexchange.org/">NagioExchange</a> porque fiz a me*** de escreve-lo todo em Português do Brasil&#8230; <img src='http://everlinux.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://everlinux.com/blog/2007/06/14/check_raidsh-para-o-nagios/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  everlinux.com/blog/category/scripts/feed ) in 2.24432 seconds, on Jul 30th, 2010 at 8:56 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Jul 30th, 2010 at 9:56 pm UTC -->