<?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>Communauté Magento francophone &#187; memcached magento</title>
	<atom:link href="http://www.wikigento.com/tag/memcached-magento/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wikigento.com</link>
	<description>Optimisation de sites E-commerce</description>
	<lastBuildDate>Wed, 01 Sep 2010 14:08:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Construire son infrastructure Magento, partie 1/3 : firewall / RProxy / load balancer</title>
		<link>http://www.wikigento.com/optimisation-systeme-reseau/construire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer/</link>
		<comments>http://www.wikigento.com/optimisation-systeme-reseau/construire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer/#comments</comments>
		<pubDate>Fri, 22 May 2009 12:55:35 +0000</pubDate>
		<dc:creator>Philippe Humeau</dc:creator>
				<category><![CDATA[Optimisation LAMP/Zend/Magento]]></category>
		<category><![CDATA[Optimisation Système & Réseau]]></category>
		<category><![CDATA[admin système & réseau]]></category>
		<category><![CDATA[sécurité]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[firewall magento]]></category>
		<category><![CDATA[firewall reverse proxy load balancer]]></category>
		<category><![CDATA[load balancer]]></category>
		<category><![CDATA[load balancer magento]]></category>
		<category><![CDATA[memcached magento]]></category>
		<category><![CDATA[reverse proxy]]></category>
		<category><![CDATA[reverse proxy magento]]></category>
		<category><![CDATA[squid magento]]></category>

		<guid isPermaLink="false">http://www.wikigento.com/?p=656</guid>
		<description><![CDATA[Installation et paramétrage d'un Firewall / Reverse Proxy / load balancer pour une infrastructure Magento.]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p><BR></p>
<p style="text-align: justify">Cet article est le premier d&#8217;une série de 3 sur la configuration d&#8217;un infrastructure Magento complète, comprenant pour l&#8217;exemple un serveur qui sera Firewall/Reverse proxy/Load Balancer, deux autres qui seront des Serveur Web frontaux et un quatrième qui sera en  charge de la base de données.</p>
<h2>Plan des posts<span style="text-decoration: underline;"> </span></h2>
<p style="text-align: justify">1/3 : Configuration du firewall, du load balancer et du Rproxy<br />
2/3 : Configuration des serveurs Web (APC / Apache / PHP)<br />
3/3 : Configuration de la base de données  (Mysql)<br />
<span style="text-decoration: underline;"><br />
</span></p>
<h2><span style="text-decoration: underline;"> </span>Le setup de l&#8217;infrastructure Magento</h2>
<p style="text-align: justify"><a rel="attachment wp-att-789" href="http://www.wikigento.com/?attachment_id=789"><img class="alignleft size-medium wp-image-789" title="archi de base" src="http://www.wikigento.com/wp-content/uploads/2009/05/schema1-305x500.jpg" alt="archi de base" width="305" height="500" /></a>Internet, routeurs et hop, on tombe sur quoi ?</p>
<p style="text-align: justify">Le Firewall, reverse proxy, load balancer.</p>
<p style="text-align: justify">Le premier élément réellement intelligent et puissant sur  lequel on va pouvoir travailler, le premier serveur quoi. Parfois l&#8217;élément Firewall est séparé et repose sur une appliance en amont mais dans le principe, si vous faites dans le full opensource, vous aimez netfilter et donc le firewall de Linux.</p>
<p style="text-align: justify">C&#8217;est par ailleurs un excellent Firewall, je vais donc l&#8217;intégrer à ce petit tuto et même démarrer par là !</p>
<p style="text-align: justify">Pour cet exemple et le paramétrage des fichiers de configuration, le firewall/RP/LB est en 192.168.1.1, les serveurs Web sont en 192.168.1.2 et .3 et la DB est en 192.168.1.4 et le magasin &#8220;virtuel&#8221; s&#8217;appel www.demostore.fr.</p>
<p style="text-align: justify">Enfin, cote ip publique, j&#8217;ai utilisé 33.44.55.66 comme étant celle de demostore.fr et 88.77.111.222 comme étant celle des admins. Vous trouverez ces paramètres dans les fichiers de configuration du firewall, du reverse proxy et du load balancer, il faudra les modifier pour vos besoins.</p>
<p style="text-align: justify">
<p><BR><br />
<BR></p>
<h2>Points non couverts dans ces 3 articles</h2>
<p style="text-align: justify">Je vais me la jouer un peu à la Ruquier, donc ce soir, on ne recevra pas, euh pardon, dans cette série de 3 articles, on ne verra pas :</p>
<ul>
<li>Comment faire de la redondance mutli datacenter avec BGP et les synchros de sites &amp; de DB</li>
<li>Comment séparer les flux de bases de données en écriture &amp; lecture sur deux DB</li>
<li>Comment faire du Master/Master Master/Slave ou du Cluster en Mysql</li>
<li>Comment isoler le backoffice en terme de performances sur les serveurs frontaux</li>
<li>Comment isoler le backoffice en terme d&#8217;accès aux bases de données</li>
</ul>
<p style="text-align: justify;"><span style="text-decoration: underline;">On ne verra pas tout cela car :</span><br />
D&#8217;une part parce que cela serait très long et très complexe à expliquer et que les compétences nécessaires pour faire le tour du sujet sont très vastes. D&#8217;autre part parce que ca va déjà faire un bon volume à rédiger et donc que ca va prendre du temps. Et enfin parce que ces points sont très critiques sur le terrain commercial et qu&#8217;ils sont actuellement des avantages en faveur de ma société vis à vis de ses concurrents.</p>
<p style="text-align: justify">Vu que la concurrence dans le milieu de l&#8217;infogérance Magento est assez active, ma société <a title="NBS System, infogérance Magento" href="http://www.nbs-system.com/hebergement" target="_blank">NBS System</a> ne peux pas se permettre de révéler ses tous derniers tricks ou ses toutes dernières optimisations pour l&#8217;infogérance ou l&#8217;hébergemnt de Magento, mais ce qui sera décrit dans les 5 articles correspond à ce que nous utilisions fin décembre 2008, donc des configurations tout à fait décentes et efficaces.</p>
<p style="text-align: justify;">
En plus mes collègues bossent en ce moment même avec Zend pour faire un papier très complet sur les performances et l&#8217;optimisation avec ZAS (Zend Application Server), je ne vais donc pas dévoiler de secrets avant la publication officielle au <a title="Bargento 2" href="http://www.bargento.fr" target="_blank">Bargento 2</a>.</p>
<h2>Préambule sur GRSEC/PAX</h2>
<p style="text-align: justify;">
Autre point, c&#8217;est peu décrit dans cet article mais plus dans un autre dont je donne le lien et aussi sur le net : <strong><span style="text-decoration: underline;">GRSEC + PAX c&#8217;est l&#8217;assurance vie de vos serveurs</span></strong>. Ce n&#8217;est pas une option : c&#8217;est un pré-requis. Grsec/Pax impose de recompiler le kernel, tache un peu complexe quand on a pas l&#8217;habitude mais le couple vous protège à 99,999% contre tous les overflow, les off by one et autres cochonneries de ce genre. Que ce soit apache, mysql, php, squid, memcached, apc etc&#8230; tous ces applicatifs peuvent avoir un jour une faille de sécurité. Grsec c&#8217;est l&#8217;assurance que même si ca se produit (et ca se produira), vos serveurs ne seront pas compromis.</p>
<h1>Le Firewall</h1>
<p><BR></p>
<h2>Configuration simple</h2>
<p style="text-align: justify">J&#8217;ai réalisé, il y a (très) longtemps de cela, <a title="Iptables et netfilter" href="http://www.nbs-system.com/dossiers/howto-iptables.html" target="_blank">un petit tutoriel pour prendre Iptables &amp; Netfilter en main</a>. Il est incomplet, très vieux, contient des erreurs ou des abbérations que je n&#8217;ai pas eu le temps de corriger dans les scripts mais les explications et schémas sont corrects. <em>Vous remarquerez au passage ma maîtrise considérable dans la création de page Web, celle-ci à faillit avoir de nombreuses récompenses pour l&#8217;utilisation audacieuse des CSS, mais finalement le jury a préféré un autre site (curieusement).</em></p>
<p><span style="text-decoration: underline;">Ceci étant, ce que l&#8217;on souhaite faire ici est assez simple :<br />
</span>- Interdire tout par défaut (comme tout firewall décent)<br />
- Authoriser spécifiquement les connexions d&#8217;administration depuis  nos IP<br />
- Permettre d&#8217;accéder directement aux serveurs derrière également depuis nos IP</p>
<p style="text-align: justify">Attention, il existe de très nombreux tricks à mettre en place pour avoir le top du top, dans le /proc/sys/net/ipv4, afin d&#8217;ajouter des règles anti DOS,  d&#8217;ajuster la stack IP pour la gestion des connexions demi ouvertes, gérer la réduction des timeouts, et puis aussi par des règles pour loger les attaques, ajouter des systèmes de sondes/IDS etc&#8230;</p>
<p>C&#8217;est un firewall assez basique que je vais exposer ici. Pour de très fortes charges, il faudra également vérifier les capacités de NAT de la machine qui repose sur un système de buckets, lui même calculé en fonction de la RAM de la machine. Il faudra également redonder la machine, etc&#8230; <em>(Mais avant que vous en soyez là, vous pourrez largement vous payer les services de personnes qui voient très bien de quoi je parles)<br />
</em></p>
<p><span style="text-decoration: underline;">Préparation du Kernel :</span></p>
<ol>
<li>On télécharge les patchs de GRSEC <a title="GRSEC patch" href="http://www.grsecurity.net/grsecurity-2.1.12-2.6.27.10-200812271347.patch.gz" target="_blank">ici</a>,<a title="GRadmin" href="gradm-2.1.12-200812271437.tar.gz"> ici</a> (et en option le patch pour iptables <a title="GRSEC patch iptables" href="http://www.grsecurity.net/grsecurity-iptables-1.4.0.patch">ici</a>)</li>
<li>On télécharge le kernel qui va avec la version de grsec <a title="Kernel 2.6.27.10" href="http://www.kernel.org/pub/linux/kernel/v2.6/patch-2.6.27.10.bz2">ici</a></li>
<li>On détar/dézip les archives et on applique les patchs (<strong>bzip2 -d kernel*; tar xvf grsec*;patch -p0 &lt; gr*.patch</strong>)</li>
<li>On ajoute deux ou trois tools qui risque de manquer : <strong>install libncurses-dev ncurses-dev make gcc paxtest gradm2 chpax</strong></li>
<li>On configure le kernel (make menuconfig), voici l&#8217;ultra minimum :<br />
- Pas de support des modules, tout en statique (ca évite l&#8217;insertion de backdoor)<br />
- networking/networking options/netfilter/ip:netfilter configuration/activer la majorité des options<br />
- Security options / Grsec: activez tout sauf dans kernel auditing juste les relocations et forks, dans Pax mettez tout.</li>
</ol>
<p style="text-align: justify">C&#8217;est une config <u>ultra</u> minimaliste. Pour plus d&#8217;info de nombreux sites parle de la compilation du noyau, le <a title="howto iptables" href="http://www.nbs-system.com/dossiers/howto-iptables.html" target="_blank">howto iptables</a> est un peu plus précis aussi mais c&#8217;est trop long à expliquer pour avoir une place ici. Après, de nombreuses petites ou grands optimisations peuvent être effectuées au niveau du noyau, les  résultats, du coté performances, comme du coté sécurité s&#8217;en ressentiront. Disons que si vous avez correctement configuré votre kernel avec pax et grsec, normalement les autres options par défaut sont rarement débiles.</p>
<p><span style="text-decoration: underline;">Pour le firewall à proprement parler, on va faire simple dans un premier temps :</span></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p656code1'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6561"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
</pre></td><td class="code" id="p656code1"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># short, simple, incomplete, not really commented iptables script for Debianed firewalls/rproxy/load balancers by Philippe Humeau (c) 2009 NBS System, lord Rusty forgive me, amen</span>
&nbsp;
<span style="color: #007800;">IPTABLES</span>=<span style="color: #ff0000;">&quot;/sbin/iptables&quot;</span> 
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
start<span style="color: #7a0874; font-weight: bold;">&#41;</span> 
&nbsp;
<span style="color: #007800;">date</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">'%b %d %k:%M:%S'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">ADMIN_IP</span>=<span style="color: #ff0000;">&quot;88.77.111.222&quot;</span> <span style="color: #666666; font-style: italic;"># &amp;lt;-------------- Change me !</span>
<span style="color: #007800;">SERVERS_IP</span>=<span style="color: #ff0000;">&quot;192.168.1.0/24&quot;</span>
<span style="color: #007800;">SERVERS_WEB1</span>=<span style="color: #ff0000;">&quot;192.168.1.2&quot;</span>
<span style="color: #007800;">SERVERS_WEB2</span>=<span style="color: #ff0000;">&quot;192.168.1.3&quot;</span>
<span style="color: #007800;">SERVERS_DB</span>=<span style="color: #ff0000;">&quot;192.168.1.4&quot;</span>
<span style="color: #007800;">INET</span>=<span style="color: #ff0000;">&quot;eth0&quot;</span>
<span style="color: #007800;">SERVERS</span>=<span style="color: #ff0000;">&quot;eth1&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$date</span> -- Starting Firewall --&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>kern.log
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;31mSetting Default Policies to DROP \033[0m &amp;lt;-&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> INPUT DROP
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> OUTPUT DROP
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-P</span> FORWARD DROP 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;33mFlushing all rules &amp;amp; tables \033[0m &amp;lt;-&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-X</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-Z</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> INPUT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> OUTPUT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> FORWARD
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-F</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-Z</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-X</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> LOG_DROP
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> LOG_DROP <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">6</span><span style="color: #000000; font-weight: bold;">/</span>h <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-tcp-options</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">'Dropped: '</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> LOG_DROP <span style="color: #660033;">-j</span> DROP
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> syn-flood
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> syn-flood <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">10</span><span style="color: #000000; font-weight: bold;">/</span>s <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">10</span> <span style="color: #660033;">-j</span> RETURN
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> syn-flood <span style="color: #660033;">-j</span> DROP 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;34m Set kernel networking tweaks \033[0m &amp;lt;-&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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_dynaddr
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>conf<span style="color: #000000; font-weight: bold;">/</span>all<span style="color: #000000; font-weight: bold;">/</span>accept_source_route
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>tcp_timestamps
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>tcp_syncookies
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>conf<span style="color: #000000; font-weight: bold;">/</span>all<span style="color: #000000; font-weight: bold;">/</span>accept_redirects
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>conf<span style="color: #000000; font-weight: bold;">/</span>all<span style="color: #000000; font-weight: bold;">/</span>rp_filter
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>icmp_ignore_bogus_error_responses
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">16384</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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_conntrack_max
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>conf<span style="color: #000000; font-weight: bold;">/</span>all<span style="color: #000000; font-weight: bold;">/</span>log_martians
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">30</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>tcp_fin_timeout
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">2400</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>tcp_keepalive_time
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>kernel<span style="color: #000000; font-weight: bold;">/</span>printk
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1800</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>tcp_keepalive_time
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>tcp_window_scaling
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>tcp_sack
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">64</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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_default_ttl
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">2048</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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_queue_maxlen
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>icmp_ignore_bogus_error_responses
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>icmp_echo_ignore_broadcasts
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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>tcp_ecn
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;33m INPUT RULING \033[0m &amp;lt;-&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> all <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED,RELATED <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-s</span> <span style="color: #007800;">$ADMIN_IP</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">11211</span> <span style="color: #660033;">-j</span> ACCEPT <span style="color: #666666; font-style: italic;"># memcached</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">-s</span> <span style="color: #007800;">$SERVERS_IP</span> <span style="color: #660033;">-j</span> ACCEPT        <span style="color: #666666; font-style: italic;"># accept très (trop) générique pour les requêtes des serveurs au rp/lb/fw</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> ICMP <span style="color: #660033;">-i</span> SERVERS <span style="color: #660033;">-s</span> <span style="color: #007800;">$SERVERS_IP</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> ICMP <span style="color: #660033;">-i</span> lo <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-s</span> <span style="color: #007800;">$SERVERS_IP</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Spoofed packet: &quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-f</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Frag packet: &quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-p</span> icmp <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">12</span><span style="color: #000000; font-weight: bold;">/</span>hour <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;ICMP: &quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">2</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;SSH loggin attempt&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL FIN,URG,PSH <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Stealth XMAS scan&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL SYN,RST,ACK,FIN,URG <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;Stealth XMAS-PSH scan&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL ALL <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Stealth XMAS-ALL scan&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL FIN <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Stealth FIN scan&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,RST SYN,RST <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Stealth SYN/RST scan&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,FIN SYN,FIN <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Stealth SYN/FIN scan(?)&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL NONE <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>m <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Stealth Null scan&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">0</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">6</span><span style="color: #000000; font-weight: bold;">/</span>h <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Port 0 OS fingerprint&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--dport</span> <span style="color: #000000;">0</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">6</span><span style="color: #000000; font-weight: bold;">/</span>h <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;UDP port 0 OS fingerprint&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #000000;">0</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">6</span><span style="color: #000000; font-weight: bold;">/</span>h <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;TCP source port 0&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> udp <span style="color: #660033;">--sport</span> <span style="color: #000000;">0</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">6</span><span style="color: #000000; font-weight: bold;">/</span>h <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> LOG_DRop <span style="color: #666666; font-style: italic;"># &quot;UDP source port 0&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> multiport <span style="color: #660033;">--sports</span> <span style="color: #000000;">20</span>,<span style="color: #000000;">21</span>,<span style="color: #000000;">22</span>,<span style="color: #000000;">23</span>,<span style="color: #000000;">80</span>,<span style="color: #000000;">110</span>,<span style="color: #000000;">143</span>,<span style="color: #000000;">443</span>,<span style="color: #000000;">993</span>,<span style="color: #000000;">995</span> <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">6</span><span style="color: #000000; font-weight: bold;">/</span>h <span style="color: #660033;">--limit-burst</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-j</span> LOG_DROP <span style="color: #666666; font-style: italic;"># &quot;Napta/smurfing/Drd/Dos&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-p</span> tcp <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">--syn</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> DROP <span style="color: #666666; font-style: italic;"># &quot;drop TCP connexion wich doesn't start by a syn&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> INVALID <span style="color: #660033;">-j</span> DROP
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--syn</span> <span style="color: #660033;">-j</span> syn-flood 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;32m FORWARD RULING \033[0m &amp;lt;-&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> INVALID <span style="color: #660033;">-j</span> DROP
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-p</span> all <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED,RELATED <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-o</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">20</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-o</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">21</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-o</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-o</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">25</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-o</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-o</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-i</span> <span style="color: #007800;">$SERVERS</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> ACCEPT 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;32m OUTPUT RULING \033[0m &amp;lt;-&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> all <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED,RELATED <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> ICMP <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--dport</span> <span style="color: #000000;">20</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--dport</span> <span style="color: #000000;">21</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--dport</span> <span style="color: #000000;">22</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--dport</span> <span style="color: #000000;">25</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> UDP <span style="color: #660033;">--dport</span> <span style="color: #000000;">53</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <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> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> UDP <span style="color: #660033;">--dport</span> <span style="color: #000000;">123</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--dport</span> <span style="color: #000000;">123</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">--dport</span> <span style="color: #000000;">443</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;33m Masquerading \033[0m &amp;lt;-&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> POSTROUTING <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,RST SYN <span style="color: #660033;">-j</span> TCPMSS <span style="color: #660033;">--clamp-mss-to-pmtu</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> POSTROUTING <span style="color: #660033;">-i</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">$INET</span> <span style="color: #660033;">-j</span> MASQUERADE
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;-&amp;gt; \033[40m\033[1;32m Firewall Setup complete, activating Forward \033[0m &amp;lt;-&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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 
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;------------------------&amp;gt; \033[40m\033[1;32mEOF : End of Firewall \033[0m&amp;lt;-----------------------&quot;</span>
<span style="color: #000000; font-weight: bold;">;;</span> 
&nbsp;
stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;\033[40m\033[1;31m----------------------&amp;gt; Shutting down Firewall ! &amp;lt;----------------------\033[0m&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; &quot;</span>
<span style="color: #007800;">IPTABLES</span>=<span style="color: #ff0000;">&quot;/sbin/iptables&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-X</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-Z</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> INPUT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> OUTPUT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> FORWARD
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-F</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-Z</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-X</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <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
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-&amp;gt; DONE ! &amp;lt;-&quot;</span>
<span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: /etc/init.d/firewall {start|stop}&quot;</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></td></tr></table></div>

<p><BR></p>
<p style="text-align: justify"><span style="text-decoration: underline;">Quelques points :<br />
</span>- N&#8217;oubliez pas de durcir tous vos noyaux de serveurs, tout spécialement celui-ci, avec le patch GRSEC pour le kernel Linux. (ca doit aussi être décrit dans le howto de mémoire).</p>
<p style="text-align: justify;">- Si on veut être plus méchant, au lieu de DROP on peut utiliser TARPIT si on a compilé iptables avec, ca fait un bel effet sur la machine attaquante !</p>
<p style="text-align: justify;">- Si le scipt ne charge pas c&#8217;est que j&#8217;ai fais un faute de frappe quelque part, corrigez là <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Si il ne charge pas parcequ&#8217;il manque des target, ajoutez les dans le noyau au moment de sa compilation.</p>
<h1>Le Reverse Proxy</h1>
<p><BR></p>
<h2>Introduction</h2>
<p style="text-align: justify">
<p style="text-align: justify">Le Firewall est une fonction en soit est très peu consommatrice car, sur un noyau linux, c&#8217;est embarqué. Netfilter et son application de pilotage iptables  sont des outils très puissants et très économes.</p>
<p style="text-align: justify">Dans le cas qui nous préoccupe, c&#8217;est d&#8217;autant plus vrai qu&#8217;on va filtrer très peu de chose, ce n&#8217;est pas non plus le firewall du pentagone, on va juste protéger les accès d&#8217;administration. Sur notre beau serveur, on a dépensé 0,000001% de la capacité CPU, que faire du reste ?</p>
<p style="text-align: justify">Hummmmm du folding@home, du calcul de Pi, un serveur Quake 3, du Seti project : non !</p>
<p>On va faire un reverse proxy et un load balancer qui eux peuvent commencer à occuper un peu la machine sur ses 99,999999 % de temps CPU restant.</p>
<p style="text-align: justify;">Le reverse proxy, c&#8217;est une histoire un peu plus complexe. Si on part sur une solution simple, Squid est très capable. Pour de la dentelle, qui nécessite aussi une optimisation du code pour en tirer le plein partit, Varnish est une solution plus costaud mais réellement plus longue à mettre en place. On va donc ici s&#8217;atteler à concevoir un Squid correcte.</p>
<h2>Rôle<span style="text-decoration: underline;"><br />
</span></h2>
<p><span style="text-decoration: underline;">Le rôle du reverse proxy c&#8217;est ca :</span><br />
<a rel="attachment wp-att-681" href="http://www.wikigento.com/?attachment_id=681"><img class="alignnone size-full wp-image-681" title="rp stats" src="http://www.wikigento.com/wp-content/uploads/2009/04/rp.jpg" alt="rp stats" width="394" height="358" /></a></p>
<p>Réduire les accès aux serveurs Web en les allégeants de tout ce qui n&#8217;a pas de valeur ajouté, tout ce qui n&#8217;est pas généré.  J&#8217;ai pris volontairement une page très lourde pour la démonstration.</p>
<p><span style="text-decoration: underline;">En l&#8217;occurence on va cacher :</span></p>
<ul>
<li>Le HTML</li>
<li>Les CSS</li>
<li>Les images</li>
<li>Les fichiers Javascript</li>
</ul>
<p style="text-align: justify">et forcément, le serveur Web, ca lui fait du bien. En résumé, il se concentre sur les requêtes Ajax et le PHP, il laisse les transferts &#8220;de base&#8221; au Rproxy. Evidemment, un tour de magie de ce type, ca consomme un maximum en RAM car il faut tout stocker en RAM pour aller vite. Si on doit charger chaque éléments depuis le disque dur, c&#8217;est plutôt lent. Un bon reverse proxy a donc beaucoup de RAM et un processeur correct, sans plus puisque la charge processeur est faible.</p>
<p style="text-align: justify">Au final, même si l&#8217;exemple ici, un peu exagéré, montre un gain de 97%, on gagne quand même en général au minimum 75% de trafic en moins vers le ou les serveurs Web. Donc qu&#8217;on ait un serveur Web ou plusieurs, le reverse proxy est <span style="text-decoration: underline;">in-dis-pen-sable</span>.</p>
<p style="text-align: justify;">Une autre optimisation intelligente sur ce point est à faire au niveau du code. Un fichier JS, un fichier CSS et pas des millions, ca change des choses. Du coup, concaténer tout cela intelligemment, c&#8217;est un plus non négligeable. Un gars s&#8217;est pris la tête à faire le boulot pour vous et encore mieux, il en a fait un plugin Magento, que demande le peuple ? Au fait ca s&#8217;appel <a title="Fooman speedster Module" href="http://www.magentocommerce.com/extension/457/fooman-speedster" target="_blank">Fooman speedster module</a> et, depuis l&#8217;invention de la fénéantise, c&#8217;est un des outils les plus indispensable pour optimiser sans se fatiguer.</p>
<h2>Installation de Squid</h2>
<p style="text-align: justify">
Vous êtes des gens biens, vous avez une Debian.</p>
<p>Vous pouvez aussi être des gens bien et ne pas avoir de Debian mais dans ce cas vous savez installer une tarball ou un package. Il y a même des gens bien qui travaillent avec OpenBSD par exemple, ils ont toute ma considération mais je ne ferai pas de howto pour <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  (Il n&#8217;y a plus de gens bien sous HPUX rassurez moi ?)</p>
<p>Le coté &#8220;à la main&#8221;, je sais faire aussi mais, personnellement, j&#8217;adore APT et DPKG <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span style="text-decoration: underline;">Attention, on se concentre, installer Squid ce n&#8217;est pas simple sous debian :</span></p>
<p>~&gt; su   (on passe root car on est <span style="text-decoration: underline;">jamais</span> loggé en root par défaut)<br />
~&gt; apt-get install squid</p>
<p>Ok on respire, on a fait le plus dur. Un petit café pour se récompenser s&#8217;impose, bravo, vous avez bien bossé ! (merci aux gars de Gnu aussi). Ca c&#8217;est fait, Squid est installé, on souffle, on respire, c&#8217;était dur mais la vie est dure parfois.</p>
<h2>Configuration de squid en reverse proxy Magento</h2>
<p style="text-align: justify;">Phase 2, on essaye de faire croire aux patrons qu&#8217;on est payé à faire quelque chose de balaise et incompréhensible, qui mérite probablement une augmentation énorme mais qu&#8217;on va se contenter de 10% et une voiture de fonction : on édite le fichier de configuration.</p>
<p style="text-align: justify;">Bon Squid c&#8217;est un proxy et un reverse proxy. En gros ca permet dans un cas comme dans l&#8217;autre de gérer un cache pour que les fichiers régulièrement demandés soient dans un cache rapide, mémoire de préférence, plutot que redemandés voir ré interprétés par le serveurs Web. Ca allège énormément les serveurs dans le cas du reverse proxy. Le proxy cache les réponses des serveurs Web aux browsers http pour les acheminer au client sans les redemander. Le reverse proxy lui fait l&#8217;inverse (d&#8217;où le reverse), il stocke les réponses les plus souvent envoyées par le serveurs aux clients afin de servir ceux-ci sans demander quoique ce soit aux serveurs Web.</p>
<p style="text-align: justify;">Bref Squid c&#8217;est complexe, énorme, un fichier de conf de base ca fait dans les 7000 lignes avec les commentaires, je vous livre donc ici une version expurgée des commentaires, juste préparer pour du reverse proxy et dont toutes les fonctions ne sont pas activées, juste les principales. Encore une précision, quand vous utilisez un reverse proxy, n&#8217;oubliez pas que votre serveur Web ne verra plus toutes les requêtes&#8230; Eh oui, c&#8217;est bien le but d&#8217;ailleurs. Donc ce qui est intercepté doit être minutieusement loggé pour pouvoir avoir des stats et compléter celles des serveurs Web sous Apache.</p>
<p><span style="text-decoration: underline;">Allez, voici la configuration :</span></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p656code2'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6562"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
</pre></td><td class="code" id="p656code2"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Squid sooooo basic configuration for Magento, by Philippe Humeau &amp;amp; Adrien Urban (c) 2009 NBS System</span>
acl manager proto cache_object
acl localhost src 127.0.0.1<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span>
acl to_localhost dst 127.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span>
acl SSL_ports port <span style="color: #000000;">443</span>
acl Safe_ports port <span style="color: #000000;">80</span>		<span style="color: #666666; font-style: italic;"># http</span>
acl Safe_ports port <span style="color: #000000;">443</span>		<span style="color: #666666; font-style: italic;"># https</span>
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny <span style="color: #000000; font-weight: bold;">!</span>Safe_ports
http_access deny CONNECT <span style="color: #000000; font-weight: bold;">!</span>SSL_ports
icp_access deny all
htcp_access deny all
&nbsp;
http_port 192.168.1.1:<span style="color: #000000;">80</span> transparent <span style="color: #007800;">name</span>=proxy_int_IP
http_port 33.44.55.66:<span style="color: #000000;">80</span> transparent <span style="color: #007800;">name</span>=ip_demostore
hierarchy_stoplist cgi-bin ?
&nbsp;
cache_mem <span style="color: #000000;">6144</span> MB
maximum_object_size_in_memory <span style="color: #000000;">8</span> MB
memory_replacement_policy heap lfuda
cache_dir null <span style="color: #000000; font-weight: bold;">/</span>tmp
&nbsp;
&nbsp;
access_log <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>squid3<span style="color: #000000; font-weight: bold;">/</span>access.log squid
access_log <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>squid3<span style="color: #000000; font-weight: bold;">/</span>access-apache.log combined
refresh_pattern <span style="color: #7a0874; font-weight: bold;">&#40;</span>cgi-bin<span style="color: #000000; font-weight: bold;">|</span>\?<span style="color: #7a0874; font-weight: bold;">&#41;</span>	<span style="color: #000000;">0</span>	<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span>	<span style="color: #000000;">0</span>
refresh_pattern .		<span style="color: #000000;">0</span>	<span style="color: #000000;">20</span><span style="color: #000000; font-weight: bold;">%</span>	<span style="color: #000000;">4320</span>
icp_port <span style="color: #000000;">3130</span>
&nbsp;
acl localhost src 127.0.0.1<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span>
acl localnet src 192.168.1.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span>
&nbsp;
acl debianUpdate dstdomain ftp.fr.debian.org              <span style="color: #666666; font-style: italic;"># pour les updates Debian</span>
acl debianUpdate dstdomain security.debian.org          <span style="color: #666666; font-style: italic;"># pour les updates Debian</span>
acl dstOutAllowed dstdomain ws.mperf.com                <span style="color: #666666; font-style: italic;"># pour le mailing, remplacer mailperf par votre fournisseur</span>
acl dstOutAllowed dstdomain chart.apis.google.com      <span style="color: #666666; font-style: italic;"># pour les beaux graphs à la google style</span>
acl dstOutAllowed dstdomain www.magentocommerce.com     <span style="color: #666666; font-style: italic;"># devinez</span>
acl dstOutAllowed dstdomain connect.magentocommerce.com <span style="color: #666666; font-style: italic;"># devinez v2.0</span>
acl dstOutAllowed dstdomain pear.php.net                           <span style="color: #666666; font-style: italic;"># devinez v3.0</span>
acl dstOutAllowed dstdomain schemas.xmlsoap.org                <span style="color: #666666; font-style: italic;"># pour les wsdl, soaperie et autres webservices</span>
&nbsp;
http_access allow localnet debianUpdate
http_access allow localnet dstOutAllowed
&nbsp;
acl IpInternal myportname proxy_int_IP
acl IpExternal myportname ip_demostore
acl dstdemostore dstdomain www.demostore.fr
acl dstdemostore dstdomain demostore.fr
never_direct allow dstdemostore
&nbsp;
<span style="color: #666666; font-style: italic;"># demostore</span>
cache_peer 192.168.1.2 parent <span style="color: #000000;">80</span> <span style="color: #000000;">0</span> no-query round-robin sourcehash
cache_peer 192.168.1.3 parent <span style="color: #000000;">80</span> <span style="color: #000000;">0</span> no-query round-robin sourcehash
cache_peer_access 192.168.1.2 allow dstdemostore
cache_peer_access 192.168.1.3 allow dstdemostore
&nbsp;
cache_peer_access 192.168.1.2 deny all
cache_peer_access 192.168.1.3 deny all
&nbsp;
http_access allow dstdemostore
&nbsp;
http_access deny all
&nbsp;
access_log <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>squid3<span style="color: #000000; font-weight: bold;">/</span>demostore-squid.log squid demostore
access_log <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>squid3<span style="color: #000000; font-weight: bold;">/</span>demostore-apache.log combined demostore</pre></td></tr></table></div>

<p style="text-align: justify">Dans cet exemple, votre serveur dispose de 8 Go de Ram et on en prend 6 pour le cache de squid. C&#8217;est évidemment à ajuster en fonction de votre configuration. (cache_mem 6144 MB) On a aussi une taille maximal de fichier à 8 Mo pour cacher les gros objets et on interdit le cache sur disque pour ne pas gréver les performances. On a paramétré le service Squid pour gérer www.demostore.fr et demostore.fr et donné l&#8217;accès aux serveurs vers d&#8217;autres hosts comme Magento connect ou les updates de Debian.</p>
<h2>Le load balancer</h2>
<p style="text-align: justify">Bonne nouvelle : c&#8217;est déjà fait !</p>
<p>Eh oui en donnant deux peers vous avez dit à Squid qu&#8217;il avait deux serveurs Web dont il devait s&#8217;occuper. Vous pourriez vouloir donner un poids différent (ici dans l&#8217;exemple c&#8217;est du 50/50) si vous avez des serveurs de puissance différentes. Il faudra alors ajouter Weight comme directive dans la déclaration des peers.</p>
<p>Le piège serait de faire du load balancing IP. Netfilter sait le faire, c&#8217;est même assez simple à mettre en oeuvre et pour tout vous dire c&#8217;est ce qu&#8217;on faisait à NBS System avant. Mais cela posait des problèmes quand le client arrivait d&#8217;une IP qui changeait en cour de session (gros firewall corporate qui nat par une autre connexion ou même simplement une adsl en ip variable). Du coup il vaut mieux passer par cette solution qui est plus propre.</p>
<h1>Memcached</h1>
<p><BR></p>
<h2>Introduction</h2>
<p style="text-align: justify">Nous y voila, la fin de l&#8217;aventure Firewall / Load Balancer / Reverse Proxy est proche&#8230;</p>
<p>Si je finis par ce point c&#8217;est aussi parce que c&#8217;est le plus facile quelque part.</p>
<p>On peut mettre memcached un peu partout dans l&#8217;infrastructure, sur le proxy, sur les serveurs Web ou même sur les serveurs de base de données. L&#8217;idée c&#8217;est de garder les sessions des surfers non pas en fichiers mais en mémoire. D&#8217;un point de vue performance, c&#8217;est très préférable et c&#8217;est simple à réaliser alors pourquoi s&#8217;en passer&#8230;</p>
<h2>Installation</h2>
<p style="text-align: justify">
On peut le mettre dans plusieurs endroit ce fameux memcached mais je préconise un serveur qui est unique et accédé / accessible par tous comme la base de données (si on a qu&#8217;un serveur de DB) ou le reverse proxy mais, si possible, pas sur les serveurs Web. En effet si l&#8217;un tombe, autant que l&#8217;autre puisse bosser et reprendre ses sessions. Evidemment, il vaut mieux que le dit serveur soit redondant ou bien costaud pour ne pas tomber sinon c&#8217;est toutes les sessions qu&#8217;on perd mais vu que le site tombera avec, ca sera un moindre problème <img src='http://www.wikigento.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</p>
<p><u>Oui, je sais, toujours un peu douleureuse cette phase sous Debian : </u><br />
~&gt; su   (on passe root car on est <span style="text-decoration: underline;">plus</span> loggé en root, normal)<br />
~&gt; apt-get install memcached php5-memcached</p>
<p>Allez, ca va aller, c&#8217;est finit&#8230; On respire lentement, le rythme cardiaque redescend !</p>
<h2>Configuration</h2>
<p>Dans le fichier local.xml de Magento, vous devriez pouvoir ajouter :</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p656code3'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6563"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p656code3"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;backend<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>memcached<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/backend<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;memcached<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;compression</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache_dir</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hashed_directory_level</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hashed_directory_umask</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;file_name_prefix</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
             <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;host<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>192.168.1.1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/host<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;port<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>11211<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/port<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
             <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;persistent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/persistent<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
           <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/memcached<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cache<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;session_save<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[memcache]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/session_save<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;session_save_path<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #339933;">&lt;![CDATA[tcp://192.168.1.1:11211?persistent=1]]&gt;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/session_save_path<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>On peut aussi mettre memcached en dehors de Magento et de sa configuration, tout simplement en installant le démon avec une configuration dans le /etc/memcached.conf :</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p656code4'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6564"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p656code4"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># memcached ultra simplistic config file by philippe Humeau (c) 2009 NBS System</span>
<span style="color: #660033;">-d</span>
logfile <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>memcached.log
<span style="color: #660033;">-m</span> <span style="color: #000000;">1024</span>
<span style="color: #660033;">-p</span> <span style="color: #000000;">11211</span> 
<span style="color: #660033;">-u</span> nobody
<span style="color: #660033;">-l</span> 192.168.1.1</pre></td></tr></table></div>

<p><BR></p>
<h1>Conclusion</h1>
<p><BR></p>
<ol>
<li>Vous méritez un café après tout ce travail</li>
<li>Je mérite un café après ce travail de rédaction</li>
<li>Il est incompréhensible que les producteurs de café soient pauvres</li>
<li>La personne qui monte un site Magento entièrement dédié au café, il va se faire du blé</li>
</ol>
<p style="text-align: justify">Oui&#8230; Je sais&#8230; J&#8217;ai toujours un petit soucis sur les conclusions mais bon, vous commencez à être habitués depuis le temps et puis je me soigne.</p>
<p>Prochain exercice de style, l&#8217;article 2/3 : Configuration d&#8217;un serveur Web pour Magento !</p>
<p style="text-align: justify">
PS : N&#8217;oubliez pas de vous inscrire pour Bargento 2, il reste encore quelques places et après on est complet, ce qui implique que même en arrivant à l&#8217;improviste sur place, on ne pourra pas vous faire rentrer pour rester dans les capacités d&#8217;accueil de la salle.</p>
<p>De plus, le papier sur Zend Application Server et les performances de Magento devrait apporter un jour nouveau et pas mal de complément sur ce mini tuto / howto.</p>
<p>Par manque de temps, je n&#8217;ai pas eu le temps de tout tester sur un serveur donc si il y a des boulettes dans les fichiers de configuration, n&#8217;hésitez pas à me les signaler, je modifierai l&#8217;article.</p>



Partager cet article :


	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F&amp;title=Construire%20son%20infrastructure%20Magento%2C%20partie%201%2F3%20%3A%20firewall%20%2F%20RProxy%20%2F%20load%20balancer&amp;bodytext=Installation%20et%20param%C3%A9trage%20d%27un%20Firewall%20%2F%20Reverse%20Proxy%20%2F%20load%20balancer%20pour%20une%20infrastructure%20Magento." title="Digg"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F&amp;title=Construire%20son%20infrastructure%20Magento%2C%20partie%201%2F3%20%3A%20firewall%20%2F%20RProxy%20%2F%20load%20balancer&amp;notes=Installation%20et%20param%C3%A9trage%20d%27un%20Firewall%20%2F%20Reverse%20Proxy%20%2F%20load%20balancer%20pour%20une%20infrastructure%20Magento." title="del.icio.us"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F&amp;t=Construire%20son%20infrastructure%20Magento%2C%20partie%201%2F3%20%3A%20firewall%20%2F%20RProxy%20%2F%20load%20balancer" title="Facebook"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F&amp;title=Construire%20son%20infrastructure%20Magento%2C%20partie%201%2F3%20%3A%20firewall%20%2F%20RProxy%20%2F%20load%20balancer&amp;annotation=Installation%20et%20param%C3%A9trage%20d%27un%20Firewall%20%2F%20Reverse%20Proxy%20%2F%20load%20balancer%20pour%20une%20infrastructure%20Magento." title="Google Bookmarks"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Construire%20son%20infrastructure%20Magento%2C%20partie%201%2F3%20%3A%20firewall%20%2F%20RProxy%20%2F%20load%20balancer&amp;url=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F" title="Slashdot"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.wikio.fr/vote?url=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F" title="Wikio FR"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/wikio.png" title="Wikio FR" alt="Wikio FR" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=Construire%20son%20infrastructure%20Magento%2C%20partie%201%2F3%20%3A%20firewall%20%2F%20RProxy%20%2F%20load%20balancer&amp;body=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F" title="email"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F&amp;title=Construire%20son%20infrastructure%20Magento%2C%20partie%201%2F3%20%3A%20firewall%20%2F%20RProxy%20%2F%20load%20balancer&amp;source=Communaut%C3%A9+Magento+francophone+Optimisation+de+sites+E-commerce&amp;summary=Installation%20et%20param%C3%A9trage%20d%27un%20Firewall%20%2F%20Reverse%20Proxy%20%2F%20load%20balancer%20pour%20une%20infrastructure%20Magento." title="LinkedIn"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F&amp;title=Construire%20son%20infrastructure%20Magento%2C%20partie%201%2F3%20%3A%20firewall%20%2F%20RProxy%20%2F%20load%20balancer" title="Live"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.myspace.com/Modules/PostTo/Pages/?u=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F&amp;t=Construire%20son%20infrastructure%20Magento%2C%20partie%201%2F3%20%3A%20firewall%20%2F%20RProxy%20%2F%20load%20balancer" title="MySpace"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/myspace.png" title="MySpace" alt="MySpace" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F" title="Technorati"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F&amp;title=Construire%20son%20infrastructure%20Magento%2C%20partie%201%2F3%20%3A%20firewall%20%2F%20RProxy%20%2F%20load%20balancer" title="blogmarks"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/blogmarks.png" title="blogmarks" alt="blogmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F&amp;partner=sociable" title="Print"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.wikigento.com/feed/" title="RSS"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Construire%20son%20infrastructure%20Magento%2C%20partie%201%2F3%20%3A%20firewall%20%2F%20RProxy%20%2F%20load%20balancer%20-%20http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F" title="Twitter"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.viadeo.com/shareit/share/?url=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F&title=Construire%20son%20infrastructure%20Magento%2C%20partie%201%2F3%20%3A%20firewall%20%2F%20RProxy%20%2F%20load%20balancer&urllanguage=fr" title="viadeo FR"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/viadeo.png" title="viadeo FR" alt="viadeo FR" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.wikio.com/vote?url=http%3A%2F%2Fwww.wikigento.com%2Foptimisation-systeme-reseau%2Fconstruire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer%2F" title="Wikio"><img src="http://www.wikigento.com/wp-content/plugins/sociable/images/wikio.png" title="Wikio" alt="Wikio" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.wikigento.com/optimisation-systeme-reseau/construire-son-infrastructure-magento-partie-13-firewall-rproxy-load-balancer/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
