<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wiki.sdnog.sd/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Manhal.Mohamed</id>
	<title>SdNOG wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.sdnog.sd/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Manhal.Mohamed"/>
	<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php/Special:Contributions/Manhal.Mohamed"/>
	<updated>2026-05-27T21:16:05Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.32.0</generator>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=ASKLY_moodle_platform&amp;diff=2356</id>
		<title>ASKLY moodle platform</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=ASKLY_moodle_platform&amp;diff=2356"/>
		<updated>2026-02-17T12:38:10Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: Created page with &amp;quot;center&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:Askly-ramadan.png|thumb|center]]&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=File:Askly-ramadan.png&amp;diff=2355</id>
		<title>File:Askly-ramadan.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=File:Askly-ramadan.png&amp;diff=2355"/>
		<updated>2026-02-17T12:37:54Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;askly&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=Documentations&amp;diff=2354</id>
		<title>Documentations</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=Documentations&amp;diff=2354"/>
		<updated>2026-02-17T12:15:21Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:SdNOG]]&lt;br /&gt;
[[Category:SdNOG_KnowBase]]&lt;br /&gt;
Welcome to the SDNOG documentation page. This resource provides comprehensive details about our infrastructure and services. Here, you'll find information on how SDNOG's systems are designed, built, and maintained, including various how-to articles and technical documentation. Our goal is to offer clear and detailed insights into the operations and management of SDNOG services.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pages ==&lt;br /&gt;
* [[sdnog Infrasturcture]] &amp;lt;span style=&amp;quot;background:#00FF00&amp;quot;&amp;gt; Done&amp;lt;/span&amp;gt;&lt;br /&gt;
* [[sdnog Services]]    &amp;lt;span style=&amp;quot;background:#00FF00&amp;quot;&amp;gt; Done&amp;lt;/span&amp;gt;&lt;br /&gt;
* [[Business Model Canvas for SDNOG]]&amp;lt;span style=&amp;quot;background:#00FF00&amp;quot;&amp;gt; Done&amp;lt;/span&amp;gt;&lt;br /&gt;
* DMARC and DKIM records for mail.sdnog.sd &lt;br /&gt;
* [[Verify sdnog.sd domain with google Postmaster Tools]]    &amp;lt;span style=&amp;quot;background:#00FF00&amp;quot;&amp;gt; Done&amp;lt;/span&amp;gt;&lt;br /&gt;
* [[SdNOG DNS infrastructure]] &amp;lt;span style=&amp;quot;background:#00FF00&amp;quot;&amp;gt; Done&amp;lt;/span&amp;gt;&lt;br /&gt;
* [[SdNOG Users creation Ansible code ]]     &amp;lt;span style=&amp;quot;background:#00FF00&amp;quot;&amp;gt; Done&amp;lt;/span&amp;gt;&lt;br /&gt;
* [[Using Algo VPN to Access SDNOG Infrastructure ]] &amp;lt;span style=&amp;quot;background:#00FF00&amp;quot;&amp;gt; Done&amp;lt;/span&amp;gt;&lt;br /&gt;
* [[Install and Configure NetBox IPAM on Ubuntu ]]&amp;lt;span style=&amp;quot;background:#00FF00&amp;quot;&amp;gt; Done&amp;lt;/span&amp;gt;&lt;br /&gt;
* [[ IPv6 subnetting for sdnog]]&lt;br /&gt;
* [[ ASKLY moodle platform ]]&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=High_Availability_Cluster_with_Pacemaker,_Chronyd&amp;diff=2353</id>
		<title>High Availability Cluster with Pacemaker, Chronyd</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=High_Availability_Cluster_with_Pacemaker,_Chronyd&amp;diff=2353"/>
		<updated>2025-07-22T09:38:02Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* 1. DNS Update Script (/usr/local/bin/update_dns.sh) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
This guide documents the setup of a 4-node high availability cluster using:&lt;br /&gt;
* '''Pacemaker/Corosync''' for cluster management&lt;br /&gt;
* '''HAProxy''' for load balancing&lt;br /&gt;
* '''Chronyd''' for time synchronization&lt;br /&gt;
* '''Automated DNS updates''' during failover scenarios&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
* 4 identical Debian servers (≥ 2GB RAM, ≥ 2 CPU cores recommended)&lt;br /&gt;
* Network interfaces:&lt;br /&gt;
** Primary: 1Gbps (for client traffic)&lt;br /&gt;
** Secondary: 100Mbps minimum (for heartbeat)&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
* Debian 10/11 (tested on both)&lt;br /&gt;
* Root access to all nodes&lt;br /&gt;
* DNS server supporting dynamic updates&lt;br /&gt;
&lt;br /&gt;
=== Network Requirements ===&lt;br /&gt;
* Static IP assignments for all nodes&lt;br /&gt;
* Fully qualified domain names for each node&lt;br /&gt;
* Unrestricted communication on ports:&lt;br /&gt;
** 2224 (pcsd)&lt;br /&gt;
** 5404-5405 (corosync)&lt;br /&gt;
** 80/443 (HAProxy)&lt;br /&gt;
&lt;br /&gt;
== Initial Node Setup ==&lt;br /&gt;
=== 1. System Preparation ===&lt;br /&gt;
On all nodes (node1-node4):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update &amp;amp;&amp;amp; sudo apt upgrade -y&lt;br /&gt;
&lt;br /&gt;
sudo apt install -y \&lt;br /&gt;
    pacemaker \&lt;br /&gt;
    pcs \&lt;br /&gt;
    corosync \&lt;br /&gt;
    crmsh \&lt;br /&gt;
    haproxy \&lt;br /&gt;
    chrony \&lt;br /&gt;
    bind9utils \&lt;br /&gt;
    mailutils \&lt;br /&gt;
    vim&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Hosts File Configuration ===&lt;br /&gt;
Add to &amp;lt;code&amp;gt;/etc/hosts&amp;lt;/code&amp;gt; on every node:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
192.168.1.101 node1.cluster.local node1&lt;br /&gt;
192.168.1.102 node2.cluster.local node2&lt;br /&gt;
192.168.1.103 node3.cluster.local node3&lt;br /&gt;
192.168.1.104 node4.cluster.local node4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Firewall Configuration ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install -y ufw&lt;br /&gt;
sudo ufw allow from 192.168.1.0/24&lt;br /&gt;
sudo ufw enable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cluster Configuration ==&lt;br /&gt;
=== 1. Initialize Cluster Services ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl enable --now pcsd corosync pacemaker&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Set hacluster Password ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;hacluster:SecureP@ssw0rd123&amp;quot; | sudo chpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 3. Authenticate Nodes (from node1) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster auth \&lt;br /&gt;
    node1.cluster.local \&lt;br /&gt;
    node2.cluster.local \&lt;br /&gt;
    node3.cluster.local \&lt;br /&gt;
    node4.cluster.local \&lt;br /&gt;
    -u hacluster \&lt;br /&gt;
    -p SecureP@ssw0rd123 \&lt;br /&gt;
    --force&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 4. Create Cluster ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster setup \&lt;br /&gt;
    --name haproxy_cluster \&lt;br /&gt;
    node1.cluster.local \&lt;br /&gt;
    node2.cluster.local \&lt;br /&gt;
    node3.cluster.local \&lt;br /&gt;
    node4.cluster.local \&lt;br /&gt;
    --force&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 5. Start Cluster ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster start --all&lt;br /&gt;
sudo pcs cluster enable --all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 6. Verify Status ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Expected output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cluster name: haproxy_cluster&lt;br /&gt;
Stack: corosync&lt;br /&gt;
Current DC: node1.cluster.local (version x.x.x-x) &lt;br /&gt;
4 nodes configured&lt;br /&gt;
0 resources configured&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Setup ==&lt;br /&gt;
=== 1. Install HAProxy on All Nodes ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install -y haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Configuration Template (/etc/haproxy/haproxy.cfg) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log /dev/log local0&lt;br /&gt;
    log /dev/log local1 notice&lt;br /&gt;
    chroot /var/lib/haproxy&lt;br /&gt;
    stats socket /run/haproxy/admin.sock mode 660 level admin&lt;br /&gt;
    stats timeout 30s&lt;br /&gt;
    user haproxy&lt;br /&gt;
    group haproxy&lt;br /&gt;
    daemon&lt;br /&gt;
    maxconn 4000&lt;br /&gt;
    tune.ssl.default-dh-param 2048&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    log global&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    option dontlognull&lt;br /&gt;
    timeout connect 5s&lt;br /&gt;
    timeout client 50s&lt;br /&gt;
    timeout server 50s&lt;br /&gt;
    option forwardfor&lt;br /&gt;
    option http-server-close&lt;br /&gt;
&lt;br /&gt;
frontend http_front&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/ssl/private/example.com.pem&lt;br /&gt;
    http-request set-header X-Forwarded-Port %[dst_port]&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    default_backend http_back&lt;br /&gt;
&lt;br /&gt;
backend http_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server webserver1 192.168.1.201:80 check cookie s1&lt;br /&gt;
    server webserver2 192.168.1.202:80 check cookie s2&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind *:1936&lt;br /&gt;
    stats enable&lt;br /&gt;
    stats uri /&lt;br /&gt;
    stats hide-version&lt;br /&gt;
    stats auth admin:SecureStatsP@ss&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Add as Cluster Resource ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs resource create haproxy systemd:haproxy \&lt;br /&gt;
    op monitor interval=10s timeout=20s \&lt;br /&gt;
    op start interval=0s timeout=30s \&lt;br /&gt;
    op stop interval=0s timeout=30s \&lt;br /&gt;
    --group haproxy_group&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Time Synchronization ==&lt;br /&gt;
=== 1. Configure Chronyd (/etc/chrony/chrony.conf) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pool 0.debian.pool.ntp.org iburst&lt;br /&gt;
pool 1.debian.pool.ntp.org iburst&lt;br /&gt;
pool 2.debian.pool.ntp.org iburst&lt;br /&gt;
pool 3.debian.pool.ntp.org iburst&lt;br /&gt;
&lt;br /&gt;
allow 192.168.1.0/24&lt;br /&gt;
leapsectz right/UTC&lt;br /&gt;
makestep 1.0 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Verify Time Sync ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart chronyd&lt;br /&gt;
sudo chronyc tracking&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Failover Automation ==&lt;br /&gt;
=== 1. DNS Update Script (/usr/local/bin/update_dns.sh) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
CLUSTER_NAME=&amp;quot;haproxy_cluster&amp;quot;&lt;br /&gt;
DNS_RECORD=&amp;quot;haproxy.example.com&amp;quot;&lt;br /&gt;
DNS_SERVER=&amp;quot;ns1.example.com&amp;quot;&lt;br /&gt;
DNS_KEY=&amp;quot;/etc/bind/cluster.key&amp;quot;&lt;br /&gt;
TTL=300&lt;br /&gt;
&lt;br /&gt;
# List your cluster node IPs here for reference (optional, not used in script logic)&lt;br /&gt;
NODE_IPS=(&amp;quot;192.168.1.101&amp;quot; &amp;quot;192.168.1.102&amp;quot; &amp;quot;192.168.1.103&amp;quot; &amp;quot;192.168.1.104&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Detect the IP of the current active node (Current DC)&lt;br /&gt;
ACTIVE_NODE=$(sudo pcs status | grep &amp;quot;Current DC:&amp;quot; | awk '{print $4}')&lt;br /&gt;
ACTIVE_NODE_IP=$(getent hosts $ACTIVE_NODE | awk '{ print $1 }')&lt;br /&gt;
&lt;br /&gt;
logger -t haproxy-cluster &amp;quot;Failover detected. Active node: $ACTIVE_NODE ($ACTIVE_NODE_IP)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
nsupdate -k $DNS_KEY &amp;lt;&amp;lt;EOF&lt;br /&gt;
server $DNS_SERVER&lt;br /&gt;
update delete $DNS_RECORD A&lt;br /&gt;
update add $DNS_RECORD $TTL A $ACTIVE_NODE_IP&lt;br /&gt;
send&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
dig +short $DNS_RECORD @$DNS_SERVER&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Make Script Executable ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo chmod 750 /usr/local/bin/update_dns.sh&lt;br /&gt;
sudo chown hacluster:haclient /usr/local/bin/update_dns.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 3. Configure Pacemaker Resource ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs resource create dns_update ocf:pacemaker:ClusterMon \&lt;br /&gt;
    user=hacluster \&lt;br /&gt;
    extra_options=&amp;quot;-e /usr/local/bin/update_dns.sh&amp;quot; \&lt;br /&gt;
    op monitor interval=15s timeout=30s \&lt;br /&gt;
    meta target-role=Started&lt;br /&gt;
&lt;br /&gt;
sudo pcs constraint colocation add dns_update with haproxy_group INFINITY&lt;br /&gt;
sudo pcs constraint order haproxy_group then dns_update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Procedures ==&lt;br /&gt;
=== 1. Manual Failover Test ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs resource move haproxy_group node2.cluster.local&lt;br /&gt;
sudo pcs status | grep -A5 &amp;quot;haproxy_group&amp;quot;&lt;br /&gt;
sudo pcs resource clear haproxy_group&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Simulate Node Failure ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl stop corosync&lt;br /&gt;
sudo pcs status&lt;br /&gt;
watch -n 1 sudo pcs status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 3. Verify DNS Updates ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dig +short haproxy.example.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Maintenance Operations ==&lt;br /&gt;
=== 1. Node Maintenance ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs node standby node3.cluster.local&lt;br /&gt;
sudo pcs node unstandby node3.cluster.local&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Cluster Maintenance ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster standby --all&lt;br /&gt;
sudo pcs cluster unstandby --all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 3. Adding/Removing Nodes ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster node add node5.cluster.local&lt;br /&gt;
sudo pcs cluster node remove node4.cluster.local&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
=== Common Issues ===&lt;br /&gt;
'''Corosync fails to start'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo corosync-cfgtool -s&lt;br /&gt;
sudo corosync-cmapctl | grep members&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''Split-brain scenario'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs property set stonith-enabled=true&lt;br /&gt;
sudo pcs stonith create fence_ipmi fence_ipmilan ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''Resource failures'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs resource debug-start haproxy&lt;br /&gt;
sudo pcs resource failcount show&lt;br /&gt;
sudo pcs resource cleanup haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Log Locations ===&lt;br /&gt;
* '''Corosync''': /var/log/corosync/corosync.log&lt;br /&gt;
* '''Pacemaker''': journalctl -u pacemaker&lt;br /&gt;
* '''HAProxy''': /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
== Appendix ==&lt;br /&gt;
=== Sample DNS Key File (/etc/bind/cluster.key) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
key &amp;quot;cluster-key&amp;quot; {&lt;br /&gt;
    algorithm hmac-sha256;&lt;br /&gt;
    secret &amp;quot;Base64EncodedKeyHere==&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Useful Commands ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs config show&lt;br /&gt;
sudo pcs stonith show&lt;br /&gt;
sudo pcs resource operations haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== References &amp;amp; Further Reading ===&lt;br /&gt;
* [https://clusterlabs.org/pacemaker/doc/ Pacemaker Documentation]&lt;br /&gt;
* [https://www.haproxy.org/download/ HAProxy Configuration Manual]&lt;br /&gt;
* [https://wiki.debian.org/HighAvailability Debian Cluster Suite]&lt;br /&gt;
* [https://corosync.github.io/ Corosync Documentation]&lt;br /&gt;
* [https://chrony.tuxfamily.org/ Chrony Documentation]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''This comprehensive guide includes: step-by-step instructions, configuration examples, automated failover procedures, maintenance and troubleshooting, and a reference appendix.''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=High_Availability_Cluster_with_Pacemaker,_Chronyd&amp;diff=2352</id>
		<title>High Availability Cluster with Pacemaker, Chronyd</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=High_Availability_Cluster_with_Pacemaker,_Chronyd&amp;diff=2352"/>
		<updated>2025-07-22T09:36:13Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* 1. DNS Update Script (/usr/local/bin/update_dns.sh) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
This guide documents the setup of a 4-node high availability cluster using:&lt;br /&gt;
* '''Pacemaker/Corosync''' for cluster management&lt;br /&gt;
* '''HAProxy''' for load balancing&lt;br /&gt;
* '''Chronyd''' for time synchronization&lt;br /&gt;
* '''Automated DNS updates''' during failover scenarios&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
* 4 identical Debian servers (≥ 2GB RAM, ≥ 2 CPU cores recommended)&lt;br /&gt;
* Network interfaces:&lt;br /&gt;
** Primary: 1Gbps (for client traffic)&lt;br /&gt;
** Secondary: 100Mbps minimum (for heartbeat)&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
* Debian 10/11 (tested on both)&lt;br /&gt;
* Root access to all nodes&lt;br /&gt;
* DNS server supporting dynamic updates&lt;br /&gt;
&lt;br /&gt;
=== Network Requirements ===&lt;br /&gt;
* Static IP assignments for all nodes&lt;br /&gt;
* Fully qualified domain names for each node&lt;br /&gt;
* Unrestricted communication on ports:&lt;br /&gt;
** 2224 (pcsd)&lt;br /&gt;
** 5404-5405 (corosync)&lt;br /&gt;
** 80/443 (HAProxy)&lt;br /&gt;
&lt;br /&gt;
== Initial Node Setup ==&lt;br /&gt;
=== 1. System Preparation ===&lt;br /&gt;
On all nodes (node1-node4):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update &amp;amp;&amp;amp; sudo apt upgrade -y&lt;br /&gt;
&lt;br /&gt;
sudo apt install -y \&lt;br /&gt;
    pacemaker \&lt;br /&gt;
    pcs \&lt;br /&gt;
    corosync \&lt;br /&gt;
    crmsh \&lt;br /&gt;
    haproxy \&lt;br /&gt;
    chrony \&lt;br /&gt;
    bind9utils \&lt;br /&gt;
    mailutils \&lt;br /&gt;
    vim&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Hosts File Configuration ===&lt;br /&gt;
Add to &amp;lt;code&amp;gt;/etc/hosts&amp;lt;/code&amp;gt; on every node:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
192.168.1.101 node1.cluster.local node1&lt;br /&gt;
192.168.1.102 node2.cluster.local node2&lt;br /&gt;
192.168.1.103 node3.cluster.local node3&lt;br /&gt;
192.168.1.104 node4.cluster.local node4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Firewall Configuration ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install -y ufw&lt;br /&gt;
sudo ufw allow from 192.168.1.0/24&lt;br /&gt;
sudo ufw enable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cluster Configuration ==&lt;br /&gt;
=== 1. Initialize Cluster Services ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl enable --now pcsd corosync pacemaker&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Set hacluster Password ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;hacluster:SecureP@ssw0rd123&amp;quot; | sudo chpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 3. Authenticate Nodes (from node1) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster auth \&lt;br /&gt;
    node1.cluster.local \&lt;br /&gt;
    node2.cluster.local \&lt;br /&gt;
    node3.cluster.local \&lt;br /&gt;
    node4.cluster.local \&lt;br /&gt;
    -u hacluster \&lt;br /&gt;
    -p SecureP@ssw0rd123 \&lt;br /&gt;
    --force&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 4. Create Cluster ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster setup \&lt;br /&gt;
    --name haproxy_cluster \&lt;br /&gt;
    node1.cluster.local \&lt;br /&gt;
    node2.cluster.local \&lt;br /&gt;
    node3.cluster.local \&lt;br /&gt;
    node4.cluster.local \&lt;br /&gt;
    --force&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 5. Start Cluster ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster start --all&lt;br /&gt;
sudo pcs cluster enable --all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 6. Verify Status ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Expected output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cluster name: haproxy_cluster&lt;br /&gt;
Stack: corosync&lt;br /&gt;
Current DC: node1.cluster.local (version x.x.x-x) &lt;br /&gt;
4 nodes configured&lt;br /&gt;
0 resources configured&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Setup ==&lt;br /&gt;
=== 1. Install HAProxy on All Nodes ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install -y haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Configuration Template (/etc/haproxy/haproxy.cfg) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log /dev/log local0&lt;br /&gt;
    log /dev/log local1 notice&lt;br /&gt;
    chroot /var/lib/haproxy&lt;br /&gt;
    stats socket /run/haproxy/admin.sock mode 660 level admin&lt;br /&gt;
    stats timeout 30s&lt;br /&gt;
    user haproxy&lt;br /&gt;
    group haproxy&lt;br /&gt;
    daemon&lt;br /&gt;
    maxconn 4000&lt;br /&gt;
    tune.ssl.default-dh-param 2048&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    log global&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    option dontlognull&lt;br /&gt;
    timeout connect 5s&lt;br /&gt;
    timeout client 50s&lt;br /&gt;
    timeout server 50s&lt;br /&gt;
    option forwardfor&lt;br /&gt;
    option http-server-close&lt;br /&gt;
&lt;br /&gt;
frontend http_front&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/ssl/private/example.com.pem&lt;br /&gt;
    http-request set-header X-Forwarded-Port %[dst_port]&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    default_backend http_back&lt;br /&gt;
&lt;br /&gt;
backend http_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server webserver1 192.168.1.201:80 check cookie s1&lt;br /&gt;
    server webserver2 192.168.1.202:80 check cookie s2&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind *:1936&lt;br /&gt;
    stats enable&lt;br /&gt;
    stats uri /&lt;br /&gt;
    stats hide-version&lt;br /&gt;
    stats auth admin:SecureStatsP@ss&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Add as Cluster Resource ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs resource create haproxy systemd:haproxy \&lt;br /&gt;
    op monitor interval=10s timeout=20s \&lt;br /&gt;
    op start interval=0s timeout=30s \&lt;br /&gt;
    op stop interval=0s timeout=30s \&lt;br /&gt;
    --group haproxy_group&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Time Synchronization ==&lt;br /&gt;
=== 1. Configure Chronyd (/etc/chrony/chrony.conf) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pool 0.debian.pool.ntp.org iburst&lt;br /&gt;
pool 1.debian.pool.ntp.org iburst&lt;br /&gt;
pool 2.debian.pool.ntp.org iburst&lt;br /&gt;
pool 3.debian.pool.ntp.org iburst&lt;br /&gt;
&lt;br /&gt;
allow 192.168.1.0/24&lt;br /&gt;
leapsectz right/UTC&lt;br /&gt;
makestep 1.0 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Verify Time Sync ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart chronyd&lt;br /&gt;
sudo chronyc tracking&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Failover Automation ==&lt;br /&gt;
=== 1. DNS Update Script (/usr/local/bin/update_dns.sh) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
CLUSTER_NAME=&amp;quot;haproxy_cluster&amp;quot;&lt;br /&gt;
VIP=&amp;quot;192.168.1.100&amp;quot;&lt;br /&gt;
DNS_RECORD=&amp;quot;haproxy.example.com&amp;quot;&lt;br /&gt;
DNS_SERVER=&amp;quot;ns1.example.com&amp;quot;&lt;br /&gt;
DNS_KEY=&amp;quot;/etc/bind/cluster.key&amp;quot;&lt;br /&gt;
TTL=300&lt;br /&gt;
&lt;br /&gt;
ACTIVE_NODE=$(sudo pcs status | grep &amp;quot;Current DC:&amp;quot; | awk '{print $4}' &lt;br /&gt;
logger -t haproxy-cluster &amp;quot;Failover detected. Active node: $ACTIVE_NODE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
nsupdate -k $DNS_KEY &amp;lt;&amp;lt;EOF&lt;br /&gt;
server $DNS_SERVER&lt;br /&gt;
update delete $DNS_RECORD A&lt;br /&gt;
update add $DNS_RECORD $TTL A $VIP&lt;br /&gt;
send&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
dig +short $DNS_RECORD @$DNS_SERVER&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Make Script Executable ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo chmod 750 /usr/local/bin/update_dns.sh&lt;br /&gt;
sudo chown hacluster:haclient /usr/local/bin/update_dns.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 3. Configure Pacemaker Resource ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs resource create dns_update ocf:pacemaker:ClusterMon \&lt;br /&gt;
    user=hacluster \&lt;br /&gt;
    extra_options=&amp;quot;-e /usr/local/bin/update_dns.sh&amp;quot; \&lt;br /&gt;
    op monitor interval=15s timeout=30s \&lt;br /&gt;
    meta target-role=Started&lt;br /&gt;
&lt;br /&gt;
sudo pcs constraint colocation add dns_update with haproxy_group INFINITY&lt;br /&gt;
sudo pcs constraint order haproxy_group then dns_update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Procedures ==&lt;br /&gt;
=== 1. Manual Failover Test ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs resource move haproxy_group node2.cluster.local&lt;br /&gt;
sudo pcs status | grep -A5 &amp;quot;haproxy_group&amp;quot;&lt;br /&gt;
sudo pcs resource clear haproxy_group&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Simulate Node Failure ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl stop corosync&lt;br /&gt;
sudo pcs status&lt;br /&gt;
watch -n 1 sudo pcs status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 3. Verify DNS Updates ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dig +short haproxy.example.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Maintenance Operations ==&lt;br /&gt;
=== 1. Node Maintenance ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs node standby node3.cluster.local&lt;br /&gt;
sudo pcs node unstandby node3.cluster.local&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Cluster Maintenance ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster standby --all&lt;br /&gt;
sudo pcs cluster unstandby --all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 3. Adding/Removing Nodes ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster node add node5.cluster.local&lt;br /&gt;
sudo pcs cluster node remove node4.cluster.local&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
=== Common Issues ===&lt;br /&gt;
'''Corosync fails to start'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo corosync-cfgtool -s&lt;br /&gt;
sudo corosync-cmapctl | grep members&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''Split-brain scenario'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs property set stonith-enabled=true&lt;br /&gt;
sudo pcs stonith create fence_ipmi fence_ipmilan ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''Resource failures'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs resource debug-start haproxy&lt;br /&gt;
sudo pcs resource failcount show&lt;br /&gt;
sudo pcs resource cleanup haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Log Locations ===&lt;br /&gt;
* '''Corosync''': /var/log/corosync/corosync.log&lt;br /&gt;
* '''Pacemaker''': journalctl -u pacemaker&lt;br /&gt;
* '''HAProxy''': /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
== Appendix ==&lt;br /&gt;
=== Sample DNS Key File (/etc/bind/cluster.key) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
key &amp;quot;cluster-key&amp;quot; {&lt;br /&gt;
    algorithm hmac-sha256;&lt;br /&gt;
    secret &amp;quot;Base64EncodedKeyHere==&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Useful Commands ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs config show&lt;br /&gt;
sudo pcs stonith show&lt;br /&gt;
sudo pcs resource operations haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== References &amp;amp; Further Reading ===&lt;br /&gt;
* [https://clusterlabs.org/pacemaker/doc/ Pacemaker Documentation]&lt;br /&gt;
* [https://www.haproxy.org/download/ HAProxy Configuration Manual]&lt;br /&gt;
* [https://wiki.debian.org/HighAvailability Debian Cluster Suite]&lt;br /&gt;
* [https://corosync.github.io/ Corosync Documentation]&lt;br /&gt;
* [https://chrony.tuxfamily.org/ Chrony Documentation]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''This comprehensive guide includes: step-by-step instructions, configuration examples, automated failover procedures, maintenance and troubleshooting, and a reference appendix.''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=High_Availability_Cluster_with_Pacemaker,_Chronyd&amp;diff=2351</id>
		<title>High Availability Cluster with Pacemaker, Chronyd</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=High_Availability_Cluster_with_Pacemaker,_Chronyd&amp;diff=2351"/>
		<updated>2025-07-22T09:34:56Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
This guide documents the setup of a 4-node high availability cluster using:&lt;br /&gt;
* '''Pacemaker/Corosync''' for cluster management&lt;br /&gt;
* '''HAProxy''' for load balancing&lt;br /&gt;
* '''Chronyd''' for time synchronization&lt;br /&gt;
* '''Automated DNS updates''' during failover scenarios&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
* 4 identical Debian servers (≥ 2GB RAM, ≥ 2 CPU cores recommended)&lt;br /&gt;
* Network interfaces:&lt;br /&gt;
** Primary: 1Gbps (for client traffic)&lt;br /&gt;
** Secondary: 100Mbps minimum (for heartbeat)&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
* Debian 10/11 (tested on both)&lt;br /&gt;
* Root access to all nodes&lt;br /&gt;
* DNS server supporting dynamic updates&lt;br /&gt;
&lt;br /&gt;
=== Network Requirements ===&lt;br /&gt;
* Static IP assignments for all nodes&lt;br /&gt;
* Fully qualified domain names for each node&lt;br /&gt;
* Unrestricted communication on ports:&lt;br /&gt;
** 2224 (pcsd)&lt;br /&gt;
** 5404-5405 (corosync)&lt;br /&gt;
** 80/443 (HAProxy)&lt;br /&gt;
&lt;br /&gt;
== Initial Node Setup ==&lt;br /&gt;
=== 1. System Preparation ===&lt;br /&gt;
On all nodes (node1-node4):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update &amp;amp;&amp;amp; sudo apt upgrade -y&lt;br /&gt;
&lt;br /&gt;
sudo apt install -y \&lt;br /&gt;
    pacemaker \&lt;br /&gt;
    pcs \&lt;br /&gt;
    corosync \&lt;br /&gt;
    crmsh \&lt;br /&gt;
    haproxy \&lt;br /&gt;
    chrony \&lt;br /&gt;
    bind9utils \&lt;br /&gt;
    mailutils \&lt;br /&gt;
    vim&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Hosts File Configuration ===&lt;br /&gt;
Add to &amp;lt;code&amp;gt;/etc/hosts&amp;lt;/code&amp;gt; on every node:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
192.168.1.101 node1.cluster.local node1&lt;br /&gt;
192.168.1.102 node2.cluster.local node2&lt;br /&gt;
192.168.1.103 node3.cluster.local node3&lt;br /&gt;
192.168.1.104 node4.cluster.local node4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Firewall Configuration ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install -y ufw&lt;br /&gt;
sudo ufw allow from 192.168.1.0/24&lt;br /&gt;
sudo ufw enable&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cluster Configuration ==&lt;br /&gt;
=== 1. Initialize Cluster Services ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl enable --now pcsd corosync pacemaker&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Set hacluster Password ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;hacluster:SecureP@ssw0rd123&amp;quot; | sudo chpasswd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 3. Authenticate Nodes (from node1) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster auth \&lt;br /&gt;
    node1.cluster.local \&lt;br /&gt;
    node2.cluster.local \&lt;br /&gt;
    node3.cluster.local \&lt;br /&gt;
    node4.cluster.local \&lt;br /&gt;
    -u hacluster \&lt;br /&gt;
    -p SecureP@ssw0rd123 \&lt;br /&gt;
    --force&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 4. Create Cluster ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster setup \&lt;br /&gt;
    --name haproxy_cluster \&lt;br /&gt;
    node1.cluster.local \&lt;br /&gt;
    node2.cluster.local \&lt;br /&gt;
    node3.cluster.local \&lt;br /&gt;
    node4.cluster.local \&lt;br /&gt;
    --force&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 5. Start Cluster ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster start --all&lt;br /&gt;
sudo pcs cluster enable --all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 6. Verify Status ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Expected output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cluster name: haproxy_cluster&lt;br /&gt;
Stack: corosync&lt;br /&gt;
Current DC: node1.cluster.local (version x.x.x-x) &lt;br /&gt;
4 nodes configured&lt;br /&gt;
0 resources configured&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Setup ==&lt;br /&gt;
=== 1. Install HAProxy on All Nodes ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install -y haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Configuration Template (/etc/haproxy/haproxy.cfg) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log /dev/log local0&lt;br /&gt;
    log /dev/log local1 notice&lt;br /&gt;
    chroot /var/lib/haproxy&lt;br /&gt;
    stats socket /run/haproxy/admin.sock mode 660 level admin&lt;br /&gt;
    stats timeout 30s&lt;br /&gt;
    user haproxy&lt;br /&gt;
    group haproxy&lt;br /&gt;
    daemon&lt;br /&gt;
    maxconn 4000&lt;br /&gt;
    tune.ssl.default-dh-param 2048&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    log global&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    option dontlognull&lt;br /&gt;
    timeout connect 5s&lt;br /&gt;
    timeout client 50s&lt;br /&gt;
    timeout server 50s&lt;br /&gt;
    option forwardfor&lt;br /&gt;
    option http-server-close&lt;br /&gt;
&lt;br /&gt;
frontend http_front&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/ssl/private/example.com.pem&lt;br /&gt;
    http-request set-header X-Forwarded-Port %[dst_port]&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    default_backend http_back&lt;br /&gt;
&lt;br /&gt;
backend http_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server webserver1 192.168.1.201:80 check cookie s1&lt;br /&gt;
    server webserver2 192.168.1.202:80 check cookie s2&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind *:1936&lt;br /&gt;
    stats enable&lt;br /&gt;
    stats uri /&lt;br /&gt;
    stats hide-version&lt;br /&gt;
    stats auth admin:SecureStatsP@ss&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Add as Cluster Resource ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs resource create haproxy systemd:haproxy \&lt;br /&gt;
    op monitor interval=10s timeout=20s \&lt;br /&gt;
    op start interval=0s timeout=30s \&lt;br /&gt;
    op stop interval=0s timeout=30s \&lt;br /&gt;
    --group haproxy_group&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Time Synchronization ==&lt;br /&gt;
=== 1. Configure Chronyd (/etc/chrony/chrony.conf) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pool 0.debian.pool.ntp.org iburst&lt;br /&gt;
pool 1.debian.pool.ntp.org iburst&lt;br /&gt;
pool 2.debian.pool.ntp.org iburst&lt;br /&gt;
pool 3.debian.pool.ntp.org iburst&lt;br /&gt;
&lt;br /&gt;
allow 192.168.1.0/24&lt;br /&gt;
leapsectz right/UTC&lt;br /&gt;
makestep 1.0 3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Verify Time Sync ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart chronyd&lt;br /&gt;
sudo chronyc tracking&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Failover Automation ==&lt;br /&gt;
=== 1. DNS Update Script (/usr/local/bin/update_dns.sh) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
CLUSTER_NAME=&amp;quot;haproxy_cluster&amp;quot;&lt;br /&gt;
VIP=&amp;quot;192.168.1.100&amp;quot;&lt;br /&gt;
DNS_RECORD=&amp;quot;haproxy.example.com&amp;quot;&lt;br /&gt;
DNS_SERVER=&amp;quot;ns1.example.com&amp;quot;&lt;br /&gt;
DNS_KEY=&amp;quot;/etc/bind/cluster.key&amp;quot;&lt;br /&gt;
TTL=300&lt;br /&gt;
&lt;br /&gt;
ACTIVE_NODE=$(sudo pcs status | grep &amp;quot;Current DC:&amp;quot; | awk '{print $3}' | cut -d. -f1)&lt;br /&gt;
logger -t haproxy-cluster &amp;quot;Failover detected. Active node: $ACTIVE_NODE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
nsupdate -k $DNS_KEY &amp;lt;&amp;lt;EOF&lt;br /&gt;
server $DNS_SERVER&lt;br /&gt;
update delete $DNS_RECORD A&lt;br /&gt;
update add $DNS_RECORD $TTL A $VIP&lt;br /&gt;
send&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
dig +short $DNS_RECORD @$DNS_SERVER&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Make Script Executable ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo chmod 750 /usr/local/bin/update_dns.sh&lt;br /&gt;
sudo chown hacluster:haclient /usr/local/bin/update_dns.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 3. Configure Pacemaker Resource ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs resource create dns_update ocf:pacemaker:ClusterMon \&lt;br /&gt;
    user=hacluster \&lt;br /&gt;
    extra_options=&amp;quot;-e /usr/local/bin/update_dns.sh&amp;quot; \&lt;br /&gt;
    op monitor interval=15s timeout=30s \&lt;br /&gt;
    meta target-role=Started&lt;br /&gt;
&lt;br /&gt;
sudo pcs constraint colocation add dns_update with haproxy_group INFINITY&lt;br /&gt;
sudo pcs constraint order haproxy_group then dns_update&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Procedures ==&lt;br /&gt;
=== 1. Manual Failover Test ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs resource move haproxy_group node2.cluster.local&lt;br /&gt;
sudo pcs status | grep -A5 &amp;quot;haproxy_group&amp;quot;&lt;br /&gt;
sudo pcs resource clear haproxy_group&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Simulate Node Failure ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl stop corosync&lt;br /&gt;
sudo pcs status&lt;br /&gt;
watch -n 1 sudo pcs status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 3. Verify DNS Updates ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dig +short haproxy.example.com&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Maintenance Operations ==&lt;br /&gt;
=== 1. Node Maintenance ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs node standby node3.cluster.local&lt;br /&gt;
sudo pcs node unstandby node3.cluster.local&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 2. Cluster Maintenance ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster standby --all&lt;br /&gt;
sudo pcs cluster unstandby --all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== 3. Adding/Removing Nodes ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs cluster node add node5.cluster.local&lt;br /&gt;
sudo pcs cluster node remove node4.cluster.local&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
=== Common Issues ===&lt;br /&gt;
'''Corosync fails to start'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo corosync-cfgtool -s&lt;br /&gt;
sudo corosync-cmapctl | grep members&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''Split-brain scenario'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs property set stonith-enabled=true&lt;br /&gt;
sudo pcs stonith create fence_ipmi fence_ipmilan ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
'''Resource failures'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs resource debug-start haproxy&lt;br /&gt;
sudo pcs resource failcount show&lt;br /&gt;
sudo pcs resource cleanup haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Log Locations ===&lt;br /&gt;
* '''Corosync''': /var/log/corosync/corosync.log&lt;br /&gt;
* '''Pacemaker''': journalctl -u pacemaker&lt;br /&gt;
* '''HAProxy''': /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
== Appendix ==&lt;br /&gt;
=== Sample DNS Key File (/etc/bind/cluster.key) ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
key &amp;quot;cluster-key&amp;quot; {&lt;br /&gt;
    algorithm hmac-sha256;&lt;br /&gt;
    secret &amp;quot;Base64EncodedKeyHere==&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Useful Commands ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo pcs config show&lt;br /&gt;
sudo pcs stonith show&lt;br /&gt;
sudo pcs resource operations haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== References &amp;amp; Further Reading ===&lt;br /&gt;
* [https://clusterlabs.org/pacemaker/doc/ Pacemaker Documentation]&lt;br /&gt;
* [https://www.haproxy.org/download/ HAProxy Configuration Manual]&lt;br /&gt;
* [https://wiki.debian.org/HighAvailability Debian Cluster Suite]&lt;br /&gt;
* [https://corosync.github.io/ Corosync Documentation]&lt;br /&gt;
* [https://chrony.tuxfamily.org/ Chrony Documentation]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''This comprehensive guide includes: step-by-step instructions, configuration examples, automated failover procedures, maintenance and troubleshooting, and a reference appendix.''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=High_Availability_Cluster_with_Pacemaker,_Chronyd&amp;diff=2350</id>
		<title>High Availability Cluster with Pacemaker, Chronyd</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=High_Availability_Cluster_with_Pacemaker,_Chronyd&amp;diff=2350"/>
		<updated>2025-07-22T09:31:29Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= High Availability Cluster with Pacemaker, Chronyd, and HAProxy =&lt;br /&gt;
'''A Comprehensive Guide for Debian Systems'''&lt;br /&gt;
&lt;br /&gt;
[[File:haproxy-cluster-diagram.png|center|600px|HA Cluster Diagram]] &amp;lt;!-- Replace with actual diagram --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This guide documents the setup of a 4-node high availability cluster using:&lt;br /&gt;
* '''Pacemaker/Corosync''' for cluster management&lt;br /&gt;
* '''HAProxy''' for load balancing&lt;br /&gt;
* '''Chronyd''' for time synchronization&lt;br /&gt;
* '''Automated DNS updates''' during failover scenarios&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
* 4 identical Debian servers (≥ 2GB RAM, ≥ 2 CPU cores recommended)&lt;br /&gt;
* Network interfaces:&lt;br /&gt;
** Primary: 1Gbps (for client traffic)&lt;br /&gt;
** Secondary: 100Mbps minimum (for heartbeat)&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
* Debian 10/11 (tested on both)&lt;br /&gt;
* Root access to all nodes&lt;br /&gt;
* DNS server supporting dynamic updates&lt;br /&gt;
&lt;br /&gt;
=== Network Requirements ===&lt;br /&gt;
* Static IP assignments for all nodes&lt;br /&gt;
* Fully qualified domain names for each node&lt;br /&gt;
* Unrestricted communication on ports:&lt;br /&gt;
** 2224 (pcsd)&lt;br /&gt;
** 5404-5405 (corosync)&lt;br /&gt;
** 80/443 (HAProxy)&lt;br /&gt;
&lt;br /&gt;
== Initial Node Setup ==&lt;br /&gt;
=== 1. System Preparation ===&lt;br /&gt;
On all nodes (node1-node4):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Update system&lt;br /&gt;
sudo apt update &amp;amp;&amp;amp; sudo apt upgrade -y&lt;br /&gt;
&lt;br /&gt;
# Install base packages&lt;br /&gt;
sudo apt install -y \&lt;br /&gt;
    pacemaker \&lt;br /&gt;
    pcs \&lt;br /&gt;
    corosync \&lt;br /&gt;
    crmsh \&lt;br /&gt;
    haproxy \&lt;br /&gt;
    chrony \&lt;br /&gt;
    bind9utils \&lt;br /&gt;
    mailutils \&lt;br /&gt;
    vim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Hosts File Configuration ===&lt;br /&gt;
Add to '''/etc/hosts''' on every node:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
192.168.1.101 node1.cluster.local node1&lt;br /&gt;
192.168.1.102 node2.cluster.local node2&lt;br /&gt;
192.168.1.103 node3.cluster.local node3&lt;br /&gt;
192.168.1.104 node4.cluster.local node4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Firewall Configuration ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install -y ufw&lt;br /&gt;
sudo ufw allow from 192.168.1.0/24&lt;br /&gt;
sudo ufw enable&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cluster Configuration ==&lt;br /&gt;
=== 1. Initialize Cluster Services ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo systemctl enable --now pcsd corosync pacemaker&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Set hacluster Password ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot;hacluster:SecureP@ssw0rd123&amp;quot; | sudo chpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Authenticate Nodes (from node1) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster auth \&lt;br /&gt;
    node1.cluster.local \&lt;br /&gt;
    node2.cluster.local \&lt;br /&gt;
    node3.cluster.local \&lt;br /&gt;
    node4.cluster.local \&lt;br /&gt;
    -u hacluster \&lt;br /&gt;
    -p SecureP@ssw0rd123 \&lt;br /&gt;
    --force&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 4. Create Cluster ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster setup \&lt;br /&gt;
    --name haproxy_cluster \&lt;br /&gt;
    node1.cluster.local \&lt;br /&gt;
    node2.cluster.local \&lt;br /&gt;
    node3.cluster.local \&lt;br /&gt;
    node4.cluster.local \&lt;br /&gt;
    --force&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 5. Start Cluster ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster start --all&lt;br /&gt;
sudo pcs cluster enable --all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 6. Verify Status ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Expected output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cluster name: haproxy_cluster&lt;br /&gt;
Stack: corosync&lt;br /&gt;
Current DC: node1.cluster.local (version x.x.x-x) &lt;br /&gt;
4 nodes configured&lt;br /&gt;
0 resources configured&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Setup ==&lt;br /&gt;
=== 1. Install HAProxy on All Nodes ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install -y haproxy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Configuration Template (/etc/haproxy/haproxy.cfg) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;conf&amp;quot;&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log /dev/log local0&lt;br /&gt;
    log /dev/log local1 notice&lt;br /&gt;
    chroot /var/lib/haproxy&lt;br /&gt;
    stats socket /run/haproxy/admin.sock mode 660 level admin&lt;br /&gt;
    stats timeout 30s&lt;br /&gt;
    user haproxy&lt;br /&gt;
    group haproxy&lt;br /&gt;
    daemon&lt;br /&gt;
    maxconn 4000&lt;br /&gt;
    tune.ssl.default-dh-param 2048&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    log global&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    option dontlognull&lt;br /&gt;
    timeout connect 5s&lt;br /&gt;
    timeout client 50s&lt;br /&gt;
    timeout server 50s&lt;br /&gt;
    option forwardfor&lt;br /&gt;
    option http-server-close&lt;br /&gt;
&lt;br /&gt;
frontend http_front&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/ssl/private/example.com.pem&lt;br /&gt;
    http-request set-header X-Forwarded-Port %[dst_port]&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    default_backend http_back&lt;br /&gt;
&lt;br /&gt;
backend http_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server webserver1 192.168.1.201:80 check cookie s1&lt;br /&gt;
    server webserver2 192.168.1.202:80 check cookie s2&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind *:1936&lt;br /&gt;
    stats enable&lt;br /&gt;
    stats uri /&lt;br /&gt;
    stats hide-version&lt;br /&gt;
    stats auth admin:SecureStatsP@ss&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Add as Cluster Resource ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs resource create haproxy systemd:haproxy \&lt;br /&gt;
    op monitor interval=10s timeout=20s \&lt;br /&gt;
    op start interval=0s timeout=30s \&lt;br /&gt;
    op stop interval=0s timeout=30s \&lt;br /&gt;
    --group haproxy_group&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Time Synchronization ==&lt;br /&gt;
=== 1. Configure Chronyd (/etc/chrony/chrony.conf) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;conf&amp;quot;&amp;gt;&lt;br /&gt;
pool 0.debian.pool.ntp.org iburst&lt;br /&gt;
pool 1.debian.pool.ntp.org iburst&lt;br /&gt;
pool 2.debian.pool.ntp.org iburst&lt;br /&gt;
pool 3.debian.pool.ntp.org iburst&lt;br /&gt;
&lt;br /&gt;
allow 192.168.1.0/24&lt;br /&gt;
leapsectz right/UTC&lt;br /&gt;
makestep 1.0 3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Verify Time Sync ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo systemctl restart chronyd&lt;br /&gt;
sudo chronyc tracking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Failover Automation ==&lt;br /&gt;
=== 1. DNS Update Script (/usr/local/bin/update_dns.sh) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
CLUSTER_NAME=&amp;quot;haproxy_cluster&amp;quot;&lt;br /&gt;
VIP=&amp;quot;192.168.1.100&amp;quot;&lt;br /&gt;
DNS_RECORD=&amp;quot;haproxy.example.com&amp;quot;&lt;br /&gt;
DNS_SERVER=&amp;quot;ns1.example.com&amp;quot;&lt;br /&gt;
DNS_KEY=&amp;quot;/etc/bind/cluster.key&amp;quot;&lt;br /&gt;
TTL=300&lt;br /&gt;
&lt;br /&gt;
ACTIVE_NODE=$(sudo pcs status | grep &amp;quot;Current DC:&amp;quot; | awk '{print $3}' | cut -d. -f1)&lt;br /&gt;
logger -t haproxy-cluster &amp;quot;Failover detected. Active node: $ACTIVE_NODE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
nsupdate -k $DNS_KEY &amp;lt;&amp;lt;EOF&lt;br /&gt;
server $DNS_SERVER&lt;br /&gt;
update delete $DNS_RECORD A&lt;br /&gt;
update add $DNS_RECORD $TTL A $VIP&lt;br /&gt;
send&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
dig +short $DNS_RECORD @$DNS_SERVER&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Make Script Executable ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo chmod 750 /usr/local/bin/update_dns.sh&lt;br /&gt;
sudo chown hacluster:haclient /usr/local/bin/update_dns.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Configure Pacemaker Resource ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs resource create dns_update ocf:pacemaker:ClusterMon \&lt;br /&gt;
    user=hacluster \&lt;br /&gt;
    extra_options=&amp;quot;-e /usr/local/bin/update_dns.sh&amp;quot; \&lt;br /&gt;
    op monitor interval=15s timeout=30s \&lt;br /&gt;
    meta target-role=Started&lt;br /&gt;
&lt;br /&gt;
sudo pcs constraint colocation add dns_update with haproxy_group INFINITY&lt;br /&gt;
sudo pcs constraint order haproxy_group then dns_update&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Procedures ==&lt;br /&gt;
=== 1. Manual Failover Test ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs resource move haproxy_group node2.cluster.local&lt;br /&gt;
sudo pcs status | grep -A5 &amp;quot;haproxy_group&amp;quot;&lt;br /&gt;
sudo pcs resource clear haproxy_group&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Simulate Node Failure ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo systemctl stop corosync&lt;br /&gt;
sudo pcs status&lt;br /&gt;
watch -n 1 sudo pcs status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Verify DNS Updates ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig +short haproxy.example.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Maintenance Operations ==&lt;br /&gt;
=== 1. Node Maintenance ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs node standby node3.cluster.local&lt;br /&gt;
sudo pcs node unstandby node3.cluster.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Cluster Maintenance ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster standby --all&lt;br /&gt;
sudo pcs cluster unstandby --all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Adding/Removing Nodes ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster node add node5.cluster.local&lt;br /&gt;
sudo pcs cluster node remove node4.cluster.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
=== Common Issues ===&lt;br /&gt;
'''Corosync fails to start'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo corosync-cfgtool -s&lt;br /&gt;
sudo corosync-cmapctl | grep members&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Split-brain scenario'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs property set stonith-enabled=true&lt;br /&gt;
sudo pcs stonith create fence_ipmi fence_ipmilan ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Resource failures'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs resource debug-start haproxy&lt;br /&gt;
sudo pcs resource failcount show&lt;br /&gt;
sudo pcs resource cleanup haproxy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Log Locations ===&lt;br /&gt;
* '''Corosync''': /var/log/corosync/corosync.log&lt;br /&gt;
* '''Pacemaker''': journalctl -u pacemaker&lt;br /&gt;
* '''HAProxy''': /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
== Appendix ==&lt;br /&gt;
=== Sample DNS Key File (/etc/bind/cluster.key) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;conf&amp;quot;&amp;gt;&lt;br /&gt;
key &amp;quot;cluster-key&amp;quot; {&lt;br /&gt;
    algorithm hmac-sha256;&lt;br /&gt;
    secret &amp;quot;Base64EncodedKeyHere==&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Useful Commands ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs config show&lt;br /&gt;
sudo pcs stonith show&lt;br /&gt;
sudo pcs resource operations haproxy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== References &amp;amp; Further Reading ===&lt;br /&gt;
* [https://clusterlabs.org/pacemaker/doc/ Pacemaker Documentation]&lt;br /&gt;
* [https://www.haproxy.org/download/ HAProxy Configuration Manual]&lt;br /&gt;
* [https://wiki.debian.org/HighAvailability Debian Cluster Suite]&lt;br /&gt;
* [https://corosync.github.io/ Corosync Documentation]&lt;br /&gt;
* [https://chrony.tuxfamily.org/ Chrony Documentation]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''This comprehensive guide includes: step-by-step instructions, configuration examples, automated failover procedures, maintenance and troubleshooting, and a reference appendix.''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=High_Availability_Cluster_with_Pacemaker,_Chronyd&amp;diff=2349</id>
		<title>High Availability Cluster with Pacemaker, Chronyd</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=High_Availability_Cluster_with_Pacemaker,_Chronyd&amp;diff=2349"/>
		<updated>2025-07-22T09:30:20Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Sample DNS Key File (/etc/bind/cluster.key) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= High Availability Cluster with Pacemaker, Chronyd, and HAProxy =&lt;br /&gt;
'''A Comprehensive Guide for Debian Systems'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This guide documents the setup of a 4-node high availability cluster using:&lt;br /&gt;
* '''Pacemaker/Corosync''' for cluster management&lt;br /&gt;
* '''HAProxy''' for load balancing&lt;br /&gt;
* '''Chronyd''' for time synchronization&lt;br /&gt;
* '''Automated DNS updates''' during failover scenarios&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
* 4 identical Debian servers (≥ 2GB RAM, ≥ 2 CPU cores recommended)&lt;br /&gt;
* Network interfaces:&lt;br /&gt;
** Primary: 1Gbps (for client traffic)&lt;br /&gt;
** Secondary: 100Mbps minimum (for heartbeat)&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
* Debian 10/11 (tested on both)&lt;br /&gt;
* Root access to all nodes&lt;br /&gt;
* DNS server supporting dynamic updates&lt;br /&gt;
&lt;br /&gt;
=== Network Requirements ===&lt;br /&gt;
* Static IP assignments for all nodes&lt;br /&gt;
* Fully qualified domain names for each node&lt;br /&gt;
* Unrestricted communication on ports:&lt;br /&gt;
** 2224 (pcsd)&lt;br /&gt;
** 5404-5405 (corosync)&lt;br /&gt;
** 80/443 (HAProxy)&lt;br /&gt;
&lt;br /&gt;
== Initial Node Setup ==&lt;br /&gt;
=== 1. System Preparation ===&lt;br /&gt;
On all nodes (node1-node4):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Update system&lt;br /&gt;
sudo apt update &amp;amp;&amp;amp; sudo apt upgrade -y&lt;br /&gt;
&lt;br /&gt;
# Install base packages&lt;br /&gt;
sudo apt install -y \&lt;br /&gt;
    pacemaker \&lt;br /&gt;
    pcs \&lt;br /&gt;
    corosync \&lt;br /&gt;
    crmsh \&lt;br /&gt;
    haproxy \&lt;br /&gt;
    chrony \&lt;br /&gt;
    bind9utils \&lt;br /&gt;
    mailutils \&lt;br /&gt;
    vim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Hosts File Configuration ===&lt;br /&gt;
Add to '''/etc/hosts''' on every node:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
192.168.1.101 node1.cluster.local node1&lt;br /&gt;
192.168.1.102 node2.cluster.local node2&lt;br /&gt;
192.168.1.103 node3.cluster.local node3&lt;br /&gt;
192.168.1.104 node4.cluster.local node4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Firewall Configuration ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install -y ufw&lt;br /&gt;
sudo ufw allow from 192.168.1.0/24&lt;br /&gt;
sudo ufw enable&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cluster Configuration ==&lt;br /&gt;
=== 1. Initialize Cluster Services ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo systemctl enable --now pcsd corosync pacemaker&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Set hacluster Password ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot;hacluster:SecureP@ssw0rd123&amp;quot; | sudo chpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Authenticate Nodes (from node1) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster auth \&lt;br /&gt;
    node1.cluster.local \&lt;br /&gt;
    node2.cluster.local \&lt;br /&gt;
    node3.cluster.local \&lt;br /&gt;
    node4.cluster.local \&lt;br /&gt;
    -u hacluster \&lt;br /&gt;
    -p SecureP@ssw0rd123 \&lt;br /&gt;
    --force&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 4. Create Cluster ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster setup \&lt;br /&gt;
    --name haproxy_cluster \&lt;br /&gt;
    node1.cluster.local \&lt;br /&gt;
    node2.cluster.local \&lt;br /&gt;
    node3.cluster.local \&lt;br /&gt;
    node4.cluster.local \&lt;br /&gt;
    --force&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 5. Start Cluster ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster start --all&lt;br /&gt;
sudo pcs cluster enable --all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 6. Verify Status ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Expected output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cluster name: haproxy_cluster&lt;br /&gt;
Stack: corosync&lt;br /&gt;
Current DC: node1.cluster.local (version x.x.x-x) &lt;br /&gt;
4 nodes configured&lt;br /&gt;
0 resources configured&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Setup ==&lt;br /&gt;
=== 1. Install HAProxy on All Nodes ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install -y haproxy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Configuration Template (/etc/haproxy/haproxy.cfg) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;conf&amp;quot;&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log /dev/log local0&lt;br /&gt;
    log /dev/log local1 notice&lt;br /&gt;
    chroot /var/lib/haproxy&lt;br /&gt;
    stats socket /run/haproxy/admin.sock mode 660 level admin&lt;br /&gt;
    stats timeout 30s&lt;br /&gt;
    user haproxy&lt;br /&gt;
    group haproxy&lt;br /&gt;
    daemon&lt;br /&gt;
    maxconn 4000&lt;br /&gt;
    tune.ssl.default-dh-param 2048&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    log global&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    option dontlognull&lt;br /&gt;
    timeout connect 5s&lt;br /&gt;
    timeout client 50s&lt;br /&gt;
    timeout server 50s&lt;br /&gt;
    option forwardfor&lt;br /&gt;
    option http-server-close&lt;br /&gt;
&lt;br /&gt;
frontend http_front&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/ssl/private/example.com.pem&lt;br /&gt;
    http-request set-header X-Forwarded-Port %[dst_port]&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    default_backend http_back&lt;br /&gt;
&lt;br /&gt;
backend http_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server webserver1 192.168.1.201:80 check cookie s1&lt;br /&gt;
    server webserver2 192.168.1.202:80 check cookie s2&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind *:1936&lt;br /&gt;
    stats enable&lt;br /&gt;
    stats uri /&lt;br /&gt;
    stats hide-version&lt;br /&gt;
    stats auth admin:SecureStatsP@ss&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Add as Cluster Resource ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs resource create haproxy systemd:haproxy \&lt;br /&gt;
    op monitor interval=10s timeout=20s \&lt;br /&gt;
    op start interval=0s timeout=30s \&lt;br /&gt;
    op stop interval=0s timeout=30s \&lt;br /&gt;
    --group haproxy_group&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Time Synchronization ==&lt;br /&gt;
=== 1. Configure Chronyd (/etc/chrony/chrony.conf) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;conf&amp;quot;&amp;gt;&lt;br /&gt;
pool 0.debian.pool.ntp.org iburst&lt;br /&gt;
pool 1.debian.pool.ntp.org iburst&lt;br /&gt;
pool 2.debian.pool.ntp.org iburst&lt;br /&gt;
pool 3.debian.pool.ntp.org iburst&lt;br /&gt;
&lt;br /&gt;
allow 192.168.1.0/24&lt;br /&gt;
leapsectz right/UTC&lt;br /&gt;
makestep 1.0 3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Verify Time Sync ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo systemctl restart chronyd&lt;br /&gt;
sudo chronyc tracking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Failover Automation ==&lt;br /&gt;
=== 1. DNS Update Script (/usr/local/bin/update_dns.sh) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
CLUSTER_NAME=&amp;quot;haproxy_cluster&amp;quot;&lt;br /&gt;
VIP=&amp;quot;192.168.1.100&amp;quot;&lt;br /&gt;
DNS_RECORD=&amp;quot;haproxy.example.com&amp;quot;&lt;br /&gt;
DNS_SERVER=&amp;quot;ns1.example.com&amp;quot;&lt;br /&gt;
DNS_KEY=&amp;quot;/etc/bind/cluster.key&amp;quot;&lt;br /&gt;
TTL=300&lt;br /&gt;
&lt;br /&gt;
ACTIVE_NODE=$(sudo pcs status | grep &amp;quot;Current DC:&amp;quot; | awk '{print $4}' &lt;br /&gt;
logger -t haproxy-cluster &amp;quot;Failover detected. Active node: $ACTIVE_NODE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
nsupdate -k $DNS_KEY &amp;lt;&amp;lt;EOF&lt;br /&gt;
server $DNS_SERVER&lt;br /&gt;
update delete $DNS_RECORD A&lt;br /&gt;
update add $DNS_RECORD $TTL A $VIP&lt;br /&gt;
send&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
dig +short $DNS_RECORD @$DNS_SERVER&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Make Script Executable ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo chmod 750 /usr/local/bin/update_dns.sh&lt;br /&gt;
sudo chown hacluster:haclient /usr/local/bin/update_dns.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Configure Pacemaker Resource ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs resource create dns_update ocf:pacemaker:ClusterMon \&lt;br /&gt;
    user=hacluster \&lt;br /&gt;
    extra_options=&amp;quot;-e /usr/local/bin/update_dns.sh&amp;quot; \&lt;br /&gt;
    op monitor interval=15s timeout=30s \&lt;br /&gt;
    meta target-role=Started&lt;br /&gt;
&lt;br /&gt;
sudo pcs constraint colocation add dns_update with haproxy_group INFINITY&lt;br /&gt;
sudo pcs constraint order haproxy_group then dns_update&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Procedures ==&lt;br /&gt;
=== 1. Manual Failover Test ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs resource move haproxy_group node2.cluster.local&lt;br /&gt;
sudo pcs status | grep -A5 &amp;quot;haproxy_group&amp;quot;&lt;br /&gt;
sudo pcs resource clear haproxy_group&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Simulate Node Failure ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo systemctl stop corosync&lt;br /&gt;
sudo pcs status&lt;br /&gt;
watch -n 1 sudo pcs status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Verify DNS Updates ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig +short haproxy.example.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Maintenance Operations ==&lt;br /&gt;
=== 1. Node Maintenance ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs node standby node3.cluster.local&lt;br /&gt;
sudo pcs node unstandby node3.cluster.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Cluster Maintenance ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster standby --all&lt;br /&gt;
sudo pcs cluster unstandby --all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Adding/Removing Nodes ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster node add node5.cluster.local&lt;br /&gt;
sudo pcs cluster node remove node4.cluster.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
=== Common Issues ===&lt;br /&gt;
'''Corosync fails to start'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo corosync-cfgtool -s&lt;br /&gt;
sudo corosync-cmapctl | grep members&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Split-brain scenario'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs property set stonith-enabled=true&lt;br /&gt;
sudo pcs stonith create fence_ipmi fence_ipmilan ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Resource failures'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs resource debug-start haproxy&lt;br /&gt;
sudo pcs resource failcount show&lt;br /&gt;
sudo pcs resource cleanup haproxy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Log Locations ===&lt;br /&gt;
* '''Corosync''': /var/log/corosync/corosync.log&lt;br /&gt;
* '''Pacemaker''': journalctl -u pacemaker&lt;br /&gt;
* '''HAProxy''': /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
== Appendix ==&lt;br /&gt;
=== Sample DNS Key File (/etc/bind/cluster.key) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;conf&amp;quot;&amp;gt;&lt;br /&gt;
key &amp;quot;cluster-key&amp;quot; {&lt;br /&gt;
    algorithm hmac-sha256;&lt;br /&gt;
    secret &amp;quot;Base64EncodedKeyHere==&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Useful Commands ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs config show&lt;br /&gt;
sudo pcs stonith show&lt;br /&gt;
sudo pcs resource operations haproxy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== References &amp;amp; Further Reading ===&lt;br /&gt;
* [https://clusterlabs.org/pacemaker/doc/ Pacemaker Documentation]&lt;br /&gt;
* [https://www.haproxy.org/download/ HAProxy Configuration Manual]&lt;br /&gt;
* [https://wiki.debian.org/HighAvailability Debian Cluster Suite]&lt;br /&gt;
* [https://corosync.github.io/ Corosync Documentation]&lt;br /&gt;
* [https://chrony.tuxfamily.org/ Chrony Documentation]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''This comprehensive guide includes: step-by-step instructions, configuration examples, automated failover procedures, maintenance and troubleshooting, and a reference appendix.''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=High_Availability_Cluster_with_Pacemaker,_Chronyd&amp;diff=2348</id>
		<title>High Availability Cluster with Pacemaker, Chronyd</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=High_Availability_Cluster_with_Pacemaker,_Chronyd&amp;diff=2348"/>
		<updated>2025-07-22T09:29:39Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: Created page with &amp;quot;= High Availability Cluster with Pacemaker, Chronyd, and HAProxy = '''A Comprehensive Guide for Debian Systems'''   == Introduction == This guide documents the setup of a 4-no...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= High Availability Cluster with Pacemaker, Chronyd, and HAProxy =&lt;br /&gt;
'''A Comprehensive Guide for Debian Systems'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This guide documents the setup of a 4-node high availability cluster using:&lt;br /&gt;
* '''Pacemaker/Corosync''' for cluster management&lt;br /&gt;
* '''HAProxy''' for load balancing&lt;br /&gt;
* '''Chronyd''' for time synchronization&lt;br /&gt;
* '''Automated DNS updates''' during failover scenarios&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
=== Hardware Requirements ===&lt;br /&gt;
* 4 identical Debian servers (≥ 2GB RAM, ≥ 2 CPU cores recommended)&lt;br /&gt;
* Network interfaces:&lt;br /&gt;
** Primary: 1Gbps (for client traffic)&lt;br /&gt;
** Secondary: 100Mbps minimum (for heartbeat)&lt;br /&gt;
&lt;br /&gt;
=== Software Requirements ===&lt;br /&gt;
* Debian 10/11 (tested on both)&lt;br /&gt;
* Root access to all nodes&lt;br /&gt;
* DNS server supporting dynamic updates&lt;br /&gt;
&lt;br /&gt;
=== Network Requirements ===&lt;br /&gt;
* Static IP assignments for all nodes&lt;br /&gt;
* Fully qualified domain names for each node&lt;br /&gt;
* Unrestricted communication on ports:&lt;br /&gt;
** 2224 (pcsd)&lt;br /&gt;
** 5404-5405 (corosync)&lt;br /&gt;
** 80/443 (HAProxy)&lt;br /&gt;
&lt;br /&gt;
== Initial Node Setup ==&lt;br /&gt;
=== 1. System Preparation ===&lt;br /&gt;
On all nodes (node1-node4):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Update system&lt;br /&gt;
sudo apt update &amp;amp;&amp;amp; sudo apt upgrade -y&lt;br /&gt;
&lt;br /&gt;
# Install base packages&lt;br /&gt;
sudo apt install -y \&lt;br /&gt;
    pacemaker \&lt;br /&gt;
    pcs \&lt;br /&gt;
    corosync \&lt;br /&gt;
    crmsh \&lt;br /&gt;
    haproxy \&lt;br /&gt;
    chrony \&lt;br /&gt;
    bind9utils \&lt;br /&gt;
    mailutils \&lt;br /&gt;
    vim&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Hosts File Configuration ===&lt;br /&gt;
Add to '''/etc/hosts''' on every node:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
192.168.1.101 node1.cluster.local node1&lt;br /&gt;
192.168.1.102 node2.cluster.local node2&lt;br /&gt;
192.168.1.103 node3.cluster.local node3&lt;br /&gt;
192.168.1.104 node4.cluster.local node4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Firewall Configuration ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install -y ufw&lt;br /&gt;
sudo ufw allow from 192.168.1.0/24&lt;br /&gt;
sudo ufw enable&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Cluster Configuration ==&lt;br /&gt;
=== 1. Initialize Cluster Services ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo systemctl enable --now pcsd corosync pacemaker&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Set hacluster Password ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot;hacluster:SecureP@ssw0rd123&amp;quot; | sudo chpasswd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Authenticate Nodes (from node1) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster auth \&lt;br /&gt;
    node1.cluster.local \&lt;br /&gt;
    node2.cluster.local \&lt;br /&gt;
    node3.cluster.local \&lt;br /&gt;
    node4.cluster.local \&lt;br /&gt;
    -u hacluster \&lt;br /&gt;
    -p SecureP@ssw0rd123 \&lt;br /&gt;
    --force&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 4. Create Cluster ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster setup \&lt;br /&gt;
    --name haproxy_cluster \&lt;br /&gt;
    node1.cluster.local \&lt;br /&gt;
    node2.cluster.local \&lt;br /&gt;
    node3.cluster.local \&lt;br /&gt;
    node4.cluster.local \&lt;br /&gt;
    --force&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 5. Start Cluster ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster start --all&lt;br /&gt;
sudo pcs cluster enable --all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 6. Verify Status ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Expected output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Cluster name: haproxy_cluster&lt;br /&gt;
Stack: corosync&lt;br /&gt;
Current DC: node1.cluster.local (version x.x.x-x) &lt;br /&gt;
4 nodes configured&lt;br /&gt;
0 resources configured&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Setup ==&lt;br /&gt;
=== 1. Install HAProxy on All Nodes ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install -y haproxy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Configuration Template (/etc/haproxy/haproxy.cfg) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;conf&amp;quot;&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log /dev/log local0&lt;br /&gt;
    log /dev/log local1 notice&lt;br /&gt;
    chroot /var/lib/haproxy&lt;br /&gt;
    stats socket /run/haproxy/admin.sock mode 660 level admin&lt;br /&gt;
    stats timeout 30s&lt;br /&gt;
    user haproxy&lt;br /&gt;
    group haproxy&lt;br /&gt;
    daemon&lt;br /&gt;
    maxconn 4000&lt;br /&gt;
    tune.ssl.default-dh-param 2048&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    log global&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    option dontlognull&lt;br /&gt;
    timeout connect 5s&lt;br /&gt;
    timeout client 50s&lt;br /&gt;
    timeout server 50s&lt;br /&gt;
    option forwardfor&lt;br /&gt;
    option http-server-close&lt;br /&gt;
&lt;br /&gt;
frontend http_front&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/ssl/private/example.com.pem&lt;br /&gt;
    http-request set-header X-Forwarded-Port %[dst_port]&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    default_backend http_back&lt;br /&gt;
&lt;br /&gt;
backend http_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server webserver1 192.168.1.201:80 check cookie s1&lt;br /&gt;
    server webserver2 192.168.1.202:80 check cookie s2&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind *:1936&lt;br /&gt;
    stats enable&lt;br /&gt;
    stats uri /&lt;br /&gt;
    stats hide-version&lt;br /&gt;
    stats auth admin:SecureStatsP@ss&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Add as Cluster Resource ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs resource create haproxy systemd:haproxy \&lt;br /&gt;
    op monitor interval=10s timeout=20s \&lt;br /&gt;
    op start interval=0s timeout=30s \&lt;br /&gt;
    op stop interval=0s timeout=30s \&lt;br /&gt;
    --group haproxy_group&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Time Synchronization ==&lt;br /&gt;
=== 1. Configure Chronyd (/etc/chrony/chrony.conf) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;conf&amp;quot;&amp;gt;&lt;br /&gt;
pool 0.debian.pool.ntp.org iburst&lt;br /&gt;
pool 1.debian.pool.ntp.org iburst&lt;br /&gt;
pool 2.debian.pool.ntp.org iburst&lt;br /&gt;
pool 3.debian.pool.ntp.org iburst&lt;br /&gt;
&lt;br /&gt;
allow 192.168.1.0/24&lt;br /&gt;
leapsectz right/UTC&lt;br /&gt;
makestep 1.0 3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Verify Time Sync ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo systemctl restart chronyd&lt;br /&gt;
sudo chronyc tracking&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Failover Automation ==&lt;br /&gt;
=== 1. DNS Update Script (/usr/local/bin/update_dns.sh) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
CLUSTER_NAME=&amp;quot;haproxy_cluster&amp;quot;&lt;br /&gt;
VIP=&amp;quot;192.168.1.100&amp;quot;&lt;br /&gt;
DNS_RECORD=&amp;quot;haproxy.example.com&amp;quot;&lt;br /&gt;
DNS_SERVER=&amp;quot;ns1.example.com&amp;quot;&lt;br /&gt;
DNS_KEY=&amp;quot;/etc/bind/cluster.key&amp;quot;&lt;br /&gt;
TTL=300&lt;br /&gt;
&lt;br /&gt;
ACTIVE_NODE=$(sudo pcs status | grep &amp;quot;Current DC:&amp;quot; | awk '{print $4}' &lt;br /&gt;
logger -t haproxy-cluster &amp;quot;Failover detected. Active node: $ACTIVE_NODE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
nsupdate -k $DNS_KEY &amp;lt;&amp;lt;EOF&lt;br /&gt;
server $DNS_SERVER&lt;br /&gt;
update delete $DNS_RECORD A&lt;br /&gt;
update add $DNS_RECORD $TTL A $VIP&lt;br /&gt;
send&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
dig +short $DNS_RECORD @$DNS_SERVER&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Make Script Executable ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo chmod 750 /usr/local/bin/update_dns.sh&lt;br /&gt;
sudo chown hacluster:haclient /usr/local/bin/update_dns.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Configure Pacemaker Resource ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs resource create dns_update ocf:pacemaker:ClusterMon \&lt;br /&gt;
    user=hacluster \&lt;br /&gt;
    extra_options=&amp;quot;-e /usr/local/bin/update_dns.sh&amp;quot; \&lt;br /&gt;
    op monitor interval=15s timeout=30s \&lt;br /&gt;
    meta target-role=Started&lt;br /&gt;
&lt;br /&gt;
sudo pcs constraint colocation add dns_update with haproxy_group INFINITY&lt;br /&gt;
sudo pcs constraint order haproxy_group then dns_update&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing Procedures ==&lt;br /&gt;
=== 1. Manual Failover Test ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs resource move haproxy_group node2.cluster.local&lt;br /&gt;
sudo pcs status | grep -A5 &amp;quot;haproxy_group&amp;quot;&lt;br /&gt;
sudo pcs resource clear haproxy_group&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Simulate Node Failure ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo systemctl stop corosync&lt;br /&gt;
sudo pcs status&lt;br /&gt;
watch -n 1 sudo pcs status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Verify DNS Updates ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
dig +short haproxy.example.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Maintenance Operations ==&lt;br /&gt;
=== 1. Node Maintenance ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs node standby node3.cluster.local&lt;br /&gt;
sudo pcs node unstandby node3.cluster.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 2. Cluster Maintenance ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster standby --all&lt;br /&gt;
sudo pcs cluster unstandby --all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 3. Adding/Removing Nodes ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs cluster node add node5.cluster.local&lt;br /&gt;
sudo pcs cluster node remove node4.cluster.local&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
=== Common Issues ===&lt;br /&gt;
'''Corosync fails to start'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo corosync-cfgtool -s&lt;br /&gt;
sudo corosync-cmapctl | grep members&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Split-brain scenario'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs property set stonith-enabled=true&lt;br /&gt;
sudo pcs stonith create fence_ipmi fence_ipmilan ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Resource failures'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs resource debug-start haproxy&lt;br /&gt;
sudo pcs resource failcount show&lt;br /&gt;
sudo pcs resource cleanup haproxy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Log Locations ===&lt;br /&gt;
* '''Corosync''': /var/log/corosync/corosync.log&lt;br /&gt;
* '''Pacemaker''': journalctl -u pacemaker&lt;br /&gt;
* '''HAProxy''': /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
== Appendix ==&lt;br /&gt;
=== Sample DNS Key File (/etc/bind/cluster.key) ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;conf&amp;quot;&amp;gt;&lt;br /&gt;
key &amp;quot;cluster-key&amp;quot; {&lt;br /&gt;
    algorithm hmac-sha256;&lt;br /&gt;
    secret &amp;quot;Base64EncodedKeyHere==&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Useful Commands ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo pcs config show&lt;br /&gt;
sudo pcs stonith show&lt;br /&gt;
sudo pcs resource operations haproxy&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== References &amp;amp; Further Reading ===&lt;br /&gt;
* [https://clusterlabs.org/pacemaker/doc/ Pacemaker Documentation]&lt;br /&gt;
* [https://www.haproxy.org/download/ HAProxy Configuration Manual]&lt;br /&gt;
* [https://wiki.debian.org/HighAvailability Debian Cluster Suite]&lt;br /&gt;
* [https://corosync.github.io/ Corosync Documentation]&lt;br /&gt;
* [https://chrony.tuxfamily.org/ Chrony Documentation]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
''This comprehensive guide includes: step-by-step instructions, configuration examples, automated failover procedures, maintenance and troubleshooting, and a reference appendix.''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2347</id>
		<title>HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition)</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2347"/>
		<updated>2025-07-22T09:28:40Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Appendix: High Availability Cluster with Pacemaker, Chronyd */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition) =&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This guide documents the setup of HAProxy on Ubuntu servers for load balancing web (HTTP/HTTPS) and MySQL database traffic, using the `sdnog.sd` lab domain. The environment includes multiple backend nodes and complete instructions for configuration, testing, and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3+ Ubuntu servers/VMs: 1 for HAProxy (load balancer), at least 2 for web/database backends.&lt;br /&gt;
* Domain names:&lt;br /&gt;
  * `lb.lab.sdnog.sd` (HAProxy/load balancer)&lt;br /&gt;
  * `www.lab.sdnog.sd`, `db.lab.sdnog.sd`, `lb.lab.sdnog.sd` (all pointing to the HAProxy IP)&lt;br /&gt;
  * Backends: `web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`&lt;br /&gt;
* Sudo/root access on all nodes.&lt;br /&gt;
* Ability to update `/etc/hosts` or your DNS zone for lab domains.&lt;br /&gt;
&lt;br /&gt;
== Local Hosts or DNS Configuration ==&lt;br /&gt;
Set the following entries on your local hosts file or DNS server, pointing to your HAProxy IP (`X.X.X.X`):&lt;br /&gt;
&lt;br /&gt;
  X.X.X.X lb.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X www.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X db.lab.sdnog.sd&lt;br /&gt;
&lt;br /&gt;
Backends (`web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`) should resolve to their actual server IPs.&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install HAProxy on Ubuntu ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update&lt;br /&gt;
sudo apt install haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install Web Servers on Backends ==&lt;br /&gt;
On `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`, install Nginx on one and Apache on another:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Nginx (on web01)&lt;br /&gt;
sudo apt install nginx&lt;br /&gt;
echo &amp;quot;This is web01.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&lt;br /&gt;
# Apache (on web02)&lt;br /&gt;
sudo apt install apache2&lt;br /&gt;
echo &amp;quot;This is web02.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install MySQL on Backends ==&lt;br /&gt;
On both `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install mysql-server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 4: Configure MySQL User for HAProxy ==&lt;br /&gt;
On both DB nodes (MySQL prompt):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE USER 'sdnoguser'@'%' IDENTIFIED BY 'StrongPassword';&lt;br /&gt;
GRANT ALL PRIVILEGES ON *.* TO 'sdnoguser'@'%' WITH GRANT OPTION;&lt;br /&gt;
FLUSH PRIVILEGES;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 5: HAProxy Configuration for Web &amp;amp; Database Load Balancing ==&lt;br /&gt;
Edit `/etc/haproxy/haproxy.cfg` on the HAProxy server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log         127.0.0.1:514 local1 info&lt;br /&gt;
    maxconn     4000&lt;br /&gt;
    user        haproxy&lt;br /&gt;
    group       haproxy&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    mode                    http&lt;br /&gt;
    log                     global&lt;br /&gt;
    option                  httplog&lt;br /&gt;
    option                  dontlognull&lt;br /&gt;
    option                  forwardfor except 127.0.0.0/8&lt;br /&gt;
    option                  http-server-close&lt;br /&gt;
    retries                 3&lt;br /&gt;
    timeout http-request    10s&lt;br /&gt;
    timeout queue           1m&lt;br /&gt;
    timeout connect         10s&lt;br /&gt;
    timeout client          1m&lt;br /&gt;
    timeout server          1m&lt;br /&gt;
    timeout http-keep-alive 10s&lt;br /&gt;
    timeout check           10s&lt;br /&gt;
    maxconn                 3000&lt;br /&gt;
&lt;br /&gt;
frontend https-in&lt;br /&gt;
    bind *:443 ssl crt /home/sdnog/lab/cert.pem&lt;br /&gt;
    mode http&lt;br /&gt;
    acl host_lab_sdnog hdr(host) -i www.lab.sdnog.sd&lt;br /&gt;
    use_backend www_back if host_lab_sdnog&lt;br /&gt;
    default_backend www_back&lt;br /&gt;
&lt;br /&gt;
frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
backend www_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server nginx_server web01.lab.sdnog.sd:80 check cookie web01&lt;br /&gt;
    server apache_server web02.lab.sdnog.sd:80 check cookie web02&lt;br /&gt;
&lt;br /&gt;
frontend database_frontend&lt;br /&gt;
    bind *:3306&lt;br /&gt;
    mode tcp&lt;br /&gt;
    default_backend database_backend&lt;br /&gt;
&lt;br /&gt;
backend database_backend&lt;br /&gt;
    mode tcp&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    server db01 web01.lab.sdnog.sd:3306 check&lt;br /&gt;
    server db02 web02.lab.sdnog.sd:3306 check&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind 0.0.0.0:8080&lt;br /&gt;
    bind :::8080&lt;br /&gt;
    mode http&lt;br /&gt;
    stats uri /stats&lt;br /&gt;
    stats realm HAProxy\ Statistics&lt;br /&gt;
    stats auth admin:StrongPassword&lt;br /&gt;
    stats admin if TRUE&lt;br /&gt;
    timeout client 5000&lt;br /&gt;
    timeout connect 4000&lt;br /&gt;
    timeout server 30000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 6: SSL Certificate for HAProxy ==&lt;br /&gt;
Generate or copy your SSL certificate and key as `/home/sdnog/lab/cert.pem` (or another path if you adjust your config).&lt;br /&gt;
&lt;br /&gt;
== Step 7: Restart and Enable HAProxy ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart haproxy&lt;br /&gt;
sudo systemctl enable haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 8: Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Web Load Balancing ===&lt;br /&gt;
Test the round-robin backend selection:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -I https://www.lab.sdnog.sd | grep SERVERID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see alternating results like:&lt;br /&gt;
  set-cookie: SERVERID=web01; path=/&lt;br /&gt;
  set-cookie: SERVERID=web02; path=/&lt;br /&gt;
&lt;br /&gt;
See for example output.&lt;br /&gt;
&lt;br /&gt;
[[File:Web servrs test.png|thumb|center|Web test ]]&lt;br /&gt;
&lt;br /&gt;
=== Database Load Balancing ===&lt;br /&gt;
Test DB backend switching:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql -u sdnoguser -p -h db.lab.sdnog.sd -e &amp;quot;show variables like 'hostname';&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see the hostname alternating between `db01.lab.sdnog.sd` and `db02.lab.sdnog.sd` &lt;br /&gt;
&lt;br /&gt;
[[File:DB loadbalancer test.png|thumb|center|Layer 4 loadbalancing ]]&lt;br /&gt;
&lt;br /&gt;
=== HAProxy Stats Page ===&lt;br /&gt;
Browse to: http://lb.lab.sdnog.sd:8080/stats  &lt;br /&gt;
 for an example:&lt;br /&gt;
&lt;br /&gt;
[[File:Stats page.png|thumb|center]]&lt;br /&gt;
&lt;br /&gt;
== HAProxy Log ==&lt;br /&gt;
&lt;br /&gt;
=== How to Enable HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
To enable and view HAProxy logs, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Edit your HAProxy configuration file (usually &amp;lt;code&amp;gt;/etc/haproxy/haproxy.cfg&amp;lt;/code&amp;gt;) and add the following in the &amp;lt;code&amp;gt;global&amp;lt;/code&amp;gt; and/or &amp;lt;code&amp;gt;defaults&amp;lt;/code&amp;gt; sections:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log 127.0.0.1 local0&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    log     global&lt;br /&gt;
    option  httplog&lt;br /&gt;
    option  dontlognull&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;log 127.0.0.1 local0&amp;lt;/code&amp;gt;: Sends logs to the local syslog server.&lt;br /&gt;
* &amp;lt;code&amp;gt;option httplog&amp;lt;/code&amp;gt;: Enables detailed HTTP log format.&lt;br /&gt;
* &amp;lt;code&amp;gt;option dontlognull&amp;lt;/code&amp;gt;: Avoids logging empty connections.&lt;br /&gt;
&lt;br /&gt;
# Configure your syslog service (such as &amp;lt;code&amp;gt;rsyslog&amp;lt;/code&amp;gt;) to receive HAProxy logs:&lt;br /&gt;
* Add the following to &amp;lt;code&amp;gt;/etc/rsyslog.conf&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/rsyslog.d/haproxy.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ModLoad imudp&lt;br /&gt;
$UDPServerRun 514&lt;br /&gt;
&lt;br /&gt;
local0.*    /var/log/haproxy.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Restart your syslog service:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart rsyslog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Restart HAProxy:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Check your HAProxy log output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo tail -f /var/log/haproxy.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Example Log Line ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
2025-07-18T15:51:04+00:00 localhost haproxy[8400]: 102.117.90.22:57291 [18/Jul/2025:15:51:04.732] https-in~ www_back/nginx_server 0/0/1/1/2 200 210 - - --NI 1/1/0/0/0 0/0 &amp;quot;HEAD https://www.lab.sdnog.sd/ HTTP/2.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Explanation of Fields ===&lt;br /&gt;
&lt;br /&gt;
; '''Timestamp and Host'''&lt;br /&gt;
: &amp;lt;code&amp;gt;2025-07-18T15:51:04+00:00&amp;lt;/code&amp;gt; — Date and time (ISO 8601 format)&lt;br /&gt;
: &amp;lt;code&amp;gt;localhost&amp;lt;/code&amp;gt; — Hostname where HAProxy is running&lt;br /&gt;
: &amp;lt;code&amp;gt;haproxy[8400]&amp;lt;/code&amp;gt; — Process name and PID&lt;br /&gt;
&lt;br /&gt;
; '''Client Info'''&lt;br /&gt;
: &amp;lt;code&amp;gt;102.117.90.22:57291&amp;lt;/code&amp;gt; — Source IP address and port of the client&lt;br /&gt;
&lt;br /&gt;
; '''Accept Date'''&lt;br /&gt;
: &amp;lt;code&amp;gt;[18/Jul/2025:15:51:04.732]&amp;lt;/code&amp;gt; — When HAProxy accepted the connection/request&lt;br /&gt;
&lt;br /&gt;
; '''Frontend, Backend, Server'''&lt;br /&gt;
: &amp;lt;code&amp;gt;https-in~&amp;lt;/code&amp;gt; — HAProxy frontend handling the request&lt;br /&gt;
: &amp;lt;code&amp;gt;www_back/nginx_server&amp;lt;/code&amp;gt; — Backend and backend server that handled the request&lt;br /&gt;
&lt;br /&gt;
; '''Timers (ms)'''&lt;br /&gt;
: &amp;lt;code&amp;gt;0/0/1/1/2&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''Tq''': Time spent waiting in queue&lt;br /&gt;
* '''Tw''': Time waiting for connection to backend server&lt;br /&gt;
* '''Tc''': Time to establish connection to backend&lt;br /&gt;
* '''Tr''': Time to get the full HTTP request from the client&lt;br /&gt;
* '''Tt''': Total time from accept to response&lt;br /&gt;
&lt;br /&gt;
; '''HTTP Status and Bytes'''&lt;br /&gt;
: &amp;lt;code&amp;gt;200&amp;lt;/code&amp;gt; — HTTP status code returned to the client (OK)&lt;br /&gt;
: &amp;lt;code&amp;gt;210&amp;lt;/code&amp;gt; — Number of bytes sent to the client (response size)&lt;br /&gt;
&lt;br /&gt;
; '''Captured Request/Response Cookies'''&lt;br /&gt;
: &amp;lt;code&amp;gt;- -&amp;lt;/code&amp;gt; — (Dashes mean &amp;quot;not captured&amp;quot; or &amp;quot;not set&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
; '''Termination State'''&lt;br /&gt;
: &amp;lt;code&amp;gt;--NI&amp;lt;/code&amp;gt; — How/why the session ended (see [https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#8.2.4 HAProxy documentation] for codes)&lt;br /&gt;
&lt;br /&gt;
; '''Connections (ActConn/FeConn/BeConn/SrvConn/Retry)'''&lt;br /&gt;
: &amp;lt;code&amp;gt;1/1/0/0/0&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''ActConn''': Active connections on the frontend&lt;br /&gt;
* '''FeConn''': Connections on the frontend&lt;br /&gt;
* '''BeConn''': On the backend&lt;br /&gt;
* '''SrvConn''': On the server&lt;br /&gt;
* '''Retry''': Retries&lt;br /&gt;
&lt;br /&gt;
; '''Queues (SrvQueue/BackendQueue)'''&lt;br /&gt;
: &amp;lt;code&amp;gt;0/0&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''SrvQueue''': Number of queued requests on the server&lt;br /&gt;
* '''BackendQueue''': Number of queued requests on the backend&lt;br /&gt;
&lt;br /&gt;
; '''Request Line'''&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;quot;HEAD https://www.lab.sdnog.sd/ HTTP/2.0&amp;quot;&amp;lt;/code&amp;gt; — The HTTP method, URL, and protocol&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Explanation  ==&lt;br /&gt;
&lt;br /&gt;
* Each line is a single request processed by HAProxy.&lt;br /&gt;
* The log shows: when it happened, who connected, what request they made, what server handled it, how long each step took, and what the result was.&lt;br /&gt;
* If you see different backends/servers (like &amp;lt;code&amp;gt;nginx_server&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;apache_server&amp;lt;/code&amp;gt;), it means HAProxy is load balancing between them.&lt;br /&gt;
* '''Status codes''' like &amp;lt;code&amp;gt;200&amp;lt;/code&amp;gt; mean “OK”. If you see &amp;lt;code&amp;gt;500&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;404&amp;lt;/code&amp;gt;, etc., that means there was an error.&lt;br /&gt;
* '''Timings''' help you diagnose where delays are happening (queue, connection, etc.).&lt;br /&gt;
* '''Termination state''' (&amp;lt;code&amp;gt;--NI&amp;lt;/code&amp;gt;) can show if the connection ended normally or with errors/timeouts.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Quick Reference Table ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field                  !! Example Value                   !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| Timestamp              || 2025-07-18T15:51:04+00:00       || When the event happened&lt;br /&gt;
|-&lt;br /&gt;
| Client IP:Port         || 102.117.90.22:57291             || Who made the request&lt;br /&gt;
|-&lt;br /&gt;
| Accept Date            || [18/Jul/2025:15:51:04.732]      || When HAProxy accepted the request&lt;br /&gt;
|-&lt;br /&gt;
| Frontend~              || https-in~                       || Which frontend handled it&lt;br /&gt;
|-&lt;br /&gt;
| Backend/Server         || www_back/nginx_server           || Backend/server chosen&lt;br /&gt;
|-&lt;br /&gt;
| Timers                 || 0/0/1/1/2                       || Time in each HAProxy phase&lt;br /&gt;
|-&lt;br /&gt;
| Status                 || 200                             || HTTP status code&lt;br /&gt;
|-&lt;br /&gt;
| Bytes                  || 210                             || Bytes sent to client&lt;br /&gt;
|-&lt;br /&gt;
| Term. State            || --NI                            || How session ended&lt;br /&gt;
|-&lt;br /&gt;
| Connections            || 1/1/0/0/0                       || Conn. counts (frontend, backend, etc.)&lt;br /&gt;
|-&lt;br /&gt;
| Queues                 || 0/0                             || Queued requests&lt;br /&gt;
|-&lt;br /&gt;
| Request                || &amp;quot;HEAD ... HTTP/2.0&amp;quot;             || HTTP Method, URL, Protocol&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' For more details, see the [https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#8.2.4 HAProxy log format documentation].&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not already in use.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Make sure Apache/Nginx/MySQL are running on their respective servers.&lt;br /&gt;
#* Check firewall rules (UFW, iptables, or cloud security groups) to allow traffic between HAProxy and backend nodes.&lt;br /&gt;
#* Confirm the correct backend IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the certificate and private key path in your HAProxy config.&lt;br /&gt;
#* Ensure your `.pem` file has correct permissions and the combined format (cert + key).&lt;br /&gt;
&lt;br /&gt;
# '''ACLs/routing not working as expected:'''&lt;br /&gt;
#* Verify that your local `/etc/hosts` or DNS is configured for the lab domains.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect HTTP headers if needed.&lt;br /&gt;
&lt;br /&gt;
# '''Stats page not accessible:'''&lt;br /&gt;
#* Confirm the `listen stats` block in your config.&lt;br /&gt;
#* Make sure port 8080 is open on the HAProxy machine and not blocked by a firewall.&lt;br /&gt;
&lt;br /&gt;
# '''MySQL authentication errors:'''&lt;br /&gt;
#* Ensure user/password is the same on all DB nodes.&lt;br /&gt;
#* Make sure MySQL is listening on 0.0.0.0 or the correct interface.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` and `defaults` sections based on your hardware.&lt;br /&gt;
# '''Enable kernel TCP keepalive:'''&lt;br /&gt;
#* Add `option tcpka` in the `defaults` section if needed.&lt;br /&gt;
# '''Enable HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bind *:443 ssl crt /home/sdnog/lab/cert.pem alpn h2,http/1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider using Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
=== Optimal Configuration Options for Web-Based Frontends  ===&lt;br /&gt;
It's crucial to customize the following according to your application's specific requirements.&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    &lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
   &lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    &lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    &lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    &lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    &lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Appendix: Useful Commands ==&lt;br /&gt;
&lt;br /&gt;
* Check HAProxy config: &amp;lt;pre&amp;gt;haproxy -c -f /etc/haproxy/haproxy.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart HAProxy: &amp;lt;pre&amp;gt;sudo systemctl restart haproxy&amp;lt;/pre&amp;gt;&lt;br /&gt;
* View HAProxy logs: &amp;lt;pre&amp;gt;sudo tail -f /var/log/haproxy.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test backend health: &amp;lt;pre&amp;gt;curl http://web01.lab.sdnog.sd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Appendix B :  == &lt;br /&gt;
&lt;br /&gt;
[[High Availability Cluster with Pacemaker, Chronyd  ]]&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
* '''Author''': [[User:Manhal.Mohamed|Manhal Mohamed]] , SdNOG Team&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
''This guide is based on practical deployment, tested with Ubuntu 22.04+. For additional features and advanced security, consult the [https://www.haproxy.org/ HAProxy documentation].''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2346</id>
		<title>HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition)</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2346"/>
		<updated>2025-07-22T09:27:18Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Appendix: Useful Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition) =&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This guide documents the setup of HAProxy on Ubuntu servers for load balancing web (HTTP/HTTPS) and MySQL database traffic, using the `sdnog.sd` lab domain. The environment includes multiple backend nodes and complete instructions for configuration, testing, and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3+ Ubuntu servers/VMs: 1 for HAProxy (load balancer), at least 2 for web/database backends.&lt;br /&gt;
* Domain names:&lt;br /&gt;
  * `lb.lab.sdnog.sd` (HAProxy/load balancer)&lt;br /&gt;
  * `www.lab.sdnog.sd`, `db.lab.sdnog.sd`, `lb.lab.sdnog.sd` (all pointing to the HAProxy IP)&lt;br /&gt;
  * Backends: `web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`&lt;br /&gt;
* Sudo/root access on all nodes.&lt;br /&gt;
* Ability to update `/etc/hosts` or your DNS zone for lab domains.&lt;br /&gt;
&lt;br /&gt;
== Local Hosts or DNS Configuration ==&lt;br /&gt;
Set the following entries on your local hosts file or DNS server, pointing to your HAProxy IP (`X.X.X.X`):&lt;br /&gt;
&lt;br /&gt;
  X.X.X.X lb.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X www.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X db.lab.sdnog.sd&lt;br /&gt;
&lt;br /&gt;
Backends (`web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`) should resolve to their actual server IPs.&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install HAProxy on Ubuntu ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update&lt;br /&gt;
sudo apt install haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install Web Servers on Backends ==&lt;br /&gt;
On `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`, install Nginx on one and Apache on another:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Nginx (on web01)&lt;br /&gt;
sudo apt install nginx&lt;br /&gt;
echo &amp;quot;This is web01.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&lt;br /&gt;
# Apache (on web02)&lt;br /&gt;
sudo apt install apache2&lt;br /&gt;
echo &amp;quot;This is web02.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install MySQL on Backends ==&lt;br /&gt;
On both `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install mysql-server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 4: Configure MySQL User for HAProxy ==&lt;br /&gt;
On both DB nodes (MySQL prompt):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE USER 'sdnoguser'@'%' IDENTIFIED BY 'StrongPassword';&lt;br /&gt;
GRANT ALL PRIVILEGES ON *.* TO 'sdnoguser'@'%' WITH GRANT OPTION;&lt;br /&gt;
FLUSH PRIVILEGES;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 5: HAProxy Configuration for Web &amp;amp; Database Load Balancing ==&lt;br /&gt;
Edit `/etc/haproxy/haproxy.cfg` on the HAProxy server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log         127.0.0.1:514 local1 info&lt;br /&gt;
    maxconn     4000&lt;br /&gt;
    user        haproxy&lt;br /&gt;
    group       haproxy&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    mode                    http&lt;br /&gt;
    log                     global&lt;br /&gt;
    option                  httplog&lt;br /&gt;
    option                  dontlognull&lt;br /&gt;
    option                  forwardfor except 127.0.0.0/8&lt;br /&gt;
    option                  http-server-close&lt;br /&gt;
    retries                 3&lt;br /&gt;
    timeout http-request    10s&lt;br /&gt;
    timeout queue           1m&lt;br /&gt;
    timeout connect         10s&lt;br /&gt;
    timeout client          1m&lt;br /&gt;
    timeout server          1m&lt;br /&gt;
    timeout http-keep-alive 10s&lt;br /&gt;
    timeout check           10s&lt;br /&gt;
    maxconn                 3000&lt;br /&gt;
&lt;br /&gt;
frontend https-in&lt;br /&gt;
    bind *:443 ssl crt /home/sdnog/lab/cert.pem&lt;br /&gt;
    mode http&lt;br /&gt;
    acl host_lab_sdnog hdr(host) -i www.lab.sdnog.sd&lt;br /&gt;
    use_backend www_back if host_lab_sdnog&lt;br /&gt;
    default_backend www_back&lt;br /&gt;
&lt;br /&gt;
frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
backend www_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server nginx_server web01.lab.sdnog.sd:80 check cookie web01&lt;br /&gt;
    server apache_server web02.lab.sdnog.sd:80 check cookie web02&lt;br /&gt;
&lt;br /&gt;
frontend database_frontend&lt;br /&gt;
    bind *:3306&lt;br /&gt;
    mode tcp&lt;br /&gt;
    default_backend database_backend&lt;br /&gt;
&lt;br /&gt;
backend database_backend&lt;br /&gt;
    mode tcp&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    server db01 web01.lab.sdnog.sd:3306 check&lt;br /&gt;
    server db02 web02.lab.sdnog.sd:3306 check&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind 0.0.0.0:8080&lt;br /&gt;
    bind :::8080&lt;br /&gt;
    mode http&lt;br /&gt;
    stats uri /stats&lt;br /&gt;
    stats realm HAProxy\ Statistics&lt;br /&gt;
    stats auth admin:StrongPassword&lt;br /&gt;
    stats admin if TRUE&lt;br /&gt;
    timeout client 5000&lt;br /&gt;
    timeout connect 4000&lt;br /&gt;
    timeout server 30000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 6: SSL Certificate for HAProxy ==&lt;br /&gt;
Generate or copy your SSL certificate and key as `/home/sdnog/lab/cert.pem` (or another path if you adjust your config).&lt;br /&gt;
&lt;br /&gt;
== Step 7: Restart and Enable HAProxy ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart haproxy&lt;br /&gt;
sudo systemctl enable haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 8: Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Web Load Balancing ===&lt;br /&gt;
Test the round-robin backend selection:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -I https://www.lab.sdnog.sd | grep SERVERID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see alternating results like:&lt;br /&gt;
  set-cookie: SERVERID=web01; path=/&lt;br /&gt;
  set-cookie: SERVERID=web02; path=/&lt;br /&gt;
&lt;br /&gt;
See for example output.&lt;br /&gt;
&lt;br /&gt;
[[File:Web servrs test.png|thumb|center|Web test ]]&lt;br /&gt;
&lt;br /&gt;
=== Database Load Balancing ===&lt;br /&gt;
Test DB backend switching:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql -u sdnoguser -p -h db.lab.sdnog.sd -e &amp;quot;show variables like 'hostname';&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see the hostname alternating between `db01.lab.sdnog.sd` and `db02.lab.sdnog.sd` &lt;br /&gt;
&lt;br /&gt;
[[File:DB loadbalancer test.png|thumb|center|Layer 4 loadbalancing ]]&lt;br /&gt;
&lt;br /&gt;
=== HAProxy Stats Page ===&lt;br /&gt;
Browse to: http://lb.lab.sdnog.sd:8080/stats  &lt;br /&gt;
 for an example:&lt;br /&gt;
&lt;br /&gt;
[[File:Stats page.png|thumb|center]]&lt;br /&gt;
&lt;br /&gt;
== HAProxy Log ==&lt;br /&gt;
&lt;br /&gt;
=== How to Enable HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
To enable and view HAProxy logs, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Edit your HAProxy configuration file (usually &amp;lt;code&amp;gt;/etc/haproxy/haproxy.cfg&amp;lt;/code&amp;gt;) and add the following in the &amp;lt;code&amp;gt;global&amp;lt;/code&amp;gt; and/or &amp;lt;code&amp;gt;defaults&amp;lt;/code&amp;gt; sections:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log 127.0.0.1 local0&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    log     global&lt;br /&gt;
    option  httplog&lt;br /&gt;
    option  dontlognull&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;log 127.0.0.1 local0&amp;lt;/code&amp;gt;: Sends logs to the local syslog server.&lt;br /&gt;
* &amp;lt;code&amp;gt;option httplog&amp;lt;/code&amp;gt;: Enables detailed HTTP log format.&lt;br /&gt;
* &amp;lt;code&amp;gt;option dontlognull&amp;lt;/code&amp;gt;: Avoids logging empty connections.&lt;br /&gt;
&lt;br /&gt;
# Configure your syslog service (such as &amp;lt;code&amp;gt;rsyslog&amp;lt;/code&amp;gt;) to receive HAProxy logs:&lt;br /&gt;
* Add the following to &amp;lt;code&amp;gt;/etc/rsyslog.conf&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/rsyslog.d/haproxy.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ModLoad imudp&lt;br /&gt;
$UDPServerRun 514&lt;br /&gt;
&lt;br /&gt;
local0.*    /var/log/haproxy.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Restart your syslog service:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart rsyslog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Restart HAProxy:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Check your HAProxy log output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo tail -f /var/log/haproxy.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Example Log Line ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
2025-07-18T15:51:04+00:00 localhost haproxy[8400]: 102.117.90.22:57291 [18/Jul/2025:15:51:04.732] https-in~ www_back/nginx_server 0/0/1/1/2 200 210 - - --NI 1/1/0/0/0 0/0 &amp;quot;HEAD https://www.lab.sdnog.sd/ HTTP/2.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Explanation of Fields ===&lt;br /&gt;
&lt;br /&gt;
; '''Timestamp and Host'''&lt;br /&gt;
: &amp;lt;code&amp;gt;2025-07-18T15:51:04+00:00&amp;lt;/code&amp;gt; — Date and time (ISO 8601 format)&lt;br /&gt;
: &amp;lt;code&amp;gt;localhost&amp;lt;/code&amp;gt; — Hostname where HAProxy is running&lt;br /&gt;
: &amp;lt;code&amp;gt;haproxy[8400]&amp;lt;/code&amp;gt; — Process name and PID&lt;br /&gt;
&lt;br /&gt;
; '''Client Info'''&lt;br /&gt;
: &amp;lt;code&amp;gt;102.117.90.22:57291&amp;lt;/code&amp;gt; — Source IP address and port of the client&lt;br /&gt;
&lt;br /&gt;
; '''Accept Date'''&lt;br /&gt;
: &amp;lt;code&amp;gt;[18/Jul/2025:15:51:04.732]&amp;lt;/code&amp;gt; — When HAProxy accepted the connection/request&lt;br /&gt;
&lt;br /&gt;
; '''Frontend, Backend, Server'''&lt;br /&gt;
: &amp;lt;code&amp;gt;https-in~&amp;lt;/code&amp;gt; — HAProxy frontend handling the request&lt;br /&gt;
: &amp;lt;code&amp;gt;www_back/nginx_server&amp;lt;/code&amp;gt; — Backend and backend server that handled the request&lt;br /&gt;
&lt;br /&gt;
; '''Timers (ms)'''&lt;br /&gt;
: &amp;lt;code&amp;gt;0/0/1/1/2&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''Tq''': Time spent waiting in queue&lt;br /&gt;
* '''Tw''': Time waiting for connection to backend server&lt;br /&gt;
* '''Tc''': Time to establish connection to backend&lt;br /&gt;
* '''Tr''': Time to get the full HTTP request from the client&lt;br /&gt;
* '''Tt''': Total time from accept to response&lt;br /&gt;
&lt;br /&gt;
; '''HTTP Status and Bytes'''&lt;br /&gt;
: &amp;lt;code&amp;gt;200&amp;lt;/code&amp;gt; — HTTP status code returned to the client (OK)&lt;br /&gt;
: &amp;lt;code&amp;gt;210&amp;lt;/code&amp;gt; — Number of bytes sent to the client (response size)&lt;br /&gt;
&lt;br /&gt;
; '''Captured Request/Response Cookies'''&lt;br /&gt;
: &amp;lt;code&amp;gt;- -&amp;lt;/code&amp;gt; — (Dashes mean &amp;quot;not captured&amp;quot; or &amp;quot;not set&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
; '''Termination State'''&lt;br /&gt;
: &amp;lt;code&amp;gt;--NI&amp;lt;/code&amp;gt; — How/why the session ended (see [https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#8.2.4 HAProxy documentation] for codes)&lt;br /&gt;
&lt;br /&gt;
; '''Connections (ActConn/FeConn/BeConn/SrvConn/Retry)'''&lt;br /&gt;
: &amp;lt;code&amp;gt;1/1/0/0/0&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''ActConn''': Active connections on the frontend&lt;br /&gt;
* '''FeConn''': Connections on the frontend&lt;br /&gt;
* '''BeConn''': On the backend&lt;br /&gt;
* '''SrvConn''': On the server&lt;br /&gt;
* '''Retry''': Retries&lt;br /&gt;
&lt;br /&gt;
; '''Queues (SrvQueue/BackendQueue)'''&lt;br /&gt;
: &amp;lt;code&amp;gt;0/0&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''SrvQueue''': Number of queued requests on the server&lt;br /&gt;
* '''BackendQueue''': Number of queued requests on the backend&lt;br /&gt;
&lt;br /&gt;
; '''Request Line'''&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;quot;HEAD https://www.lab.sdnog.sd/ HTTP/2.0&amp;quot;&amp;lt;/code&amp;gt; — The HTTP method, URL, and protocol&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Explanation  ==&lt;br /&gt;
&lt;br /&gt;
* Each line is a single request processed by HAProxy.&lt;br /&gt;
* The log shows: when it happened, who connected, what request they made, what server handled it, how long each step took, and what the result was.&lt;br /&gt;
* If you see different backends/servers (like &amp;lt;code&amp;gt;nginx_server&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;apache_server&amp;lt;/code&amp;gt;), it means HAProxy is load balancing between them.&lt;br /&gt;
* '''Status codes''' like &amp;lt;code&amp;gt;200&amp;lt;/code&amp;gt; mean “OK”. If you see &amp;lt;code&amp;gt;500&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;404&amp;lt;/code&amp;gt;, etc., that means there was an error.&lt;br /&gt;
* '''Timings''' help you diagnose where delays are happening (queue, connection, etc.).&lt;br /&gt;
* '''Termination state''' (&amp;lt;code&amp;gt;--NI&amp;lt;/code&amp;gt;) can show if the connection ended normally or with errors/timeouts.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Quick Reference Table ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field                  !! Example Value                   !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| Timestamp              || 2025-07-18T15:51:04+00:00       || When the event happened&lt;br /&gt;
|-&lt;br /&gt;
| Client IP:Port         || 102.117.90.22:57291             || Who made the request&lt;br /&gt;
|-&lt;br /&gt;
| Accept Date            || [18/Jul/2025:15:51:04.732]      || When HAProxy accepted the request&lt;br /&gt;
|-&lt;br /&gt;
| Frontend~              || https-in~                       || Which frontend handled it&lt;br /&gt;
|-&lt;br /&gt;
| Backend/Server         || www_back/nginx_server           || Backend/server chosen&lt;br /&gt;
|-&lt;br /&gt;
| Timers                 || 0/0/1/1/2                       || Time in each HAProxy phase&lt;br /&gt;
|-&lt;br /&gt;
| Status                 || 200                             || HTTP status code&lt;br /&gt;
|-&lt;br /&gt;
| Bytes                  || 210                             || Bytes sent to client&lt;br /&gt;
|-&lt;br /&gt;
| Term. State            || --NI                            || How session ended&lt;br /&gt;
|-&lt;br /&gt;
| Connections            || 1/1/0/0/0                       || Conn. counts (frontend, backend, etc.)&lt;br /&gt;
|-&lt;br /&gt;
| Queues                 || 0/0                             || Queued requests&lt;br /&gt;
|-&lt;br /&gt;
| Request                || &amp;quot;HEAD ... HTTP/2.0&amp;quot;             || HTTP Method, URL, Protocol&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' For more details, see the [https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#8.2.4 HAProxy log format documentation].&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not already in use.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Make sure Apache/Nginx/MySQL are running on their respective servers.&lt;br /&gt;
#* Check firewall rules (UFW, iptables, or cloud security groups) to allow traffic between HAProxy and backend nodes.&lt;br /&gt;
#* Confirm the correct backend IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the certificate and private key path in your HAProxy config.&lt;br /&gt;
#* Ensure your `.pem` file has correct permissions and the combined format (cert + key).&lt;br /&gt;
&lt;br /&gt;
# '''ACLs/routing not working as expected:'''&lt;br /&gt;
#* Verify that your local `/etc/hosts` or DNS is configured for the lab domains.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect HTTP headers if needed.&lt;br /&gt;
&lt;br /&gt;
# '''Stats page not accessible:'''&lt;br /&gt;
#* Confirm the `listen stats` block in your config.&lt;br /&gt;
#* Make sure port 8080 is open on the HAProxy machine and not blocked by a firewall.&lt;br /&gt;
&lt;br /&gt;
# '''MySQL authentication errors:'''&lt;br /&gt;
#* Ensure user/password is the same on all DB nodes.&lt;br /&gt;
#* Make sure MySQL is listening on 0.0.0.0 or the correct interface.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` and `defaults` sections based on your hardware.&lt;br /&gt;
# '''Enable kernel TCP keepalive:'''&lt;br /&gt;
#* Add `option tcpka` in the `defaults` section if needed.&lt;br /&gt;
# '''Enable HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bind *:443 ssl crt /home/sdnog/lab/cert.pem alpn h2,http/1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider using Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
=== Optimal Configuration Options for Web-Based Frontends  ===&lt;br /&gt;
It's crucial to customize the following according to your application's specific requirements.&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    &lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
   &lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    &lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    &lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    &lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    &lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Appendix: Useful Commands ==&lt;br /&gt;
&lt;br /&gt;
* Check HAProxy config: &amp;lt;pre&amp;gt;haproxy -c -f /etc/haproxy/haproxy.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart HAProxy: &amp;lt;pre&amp;gt;sudo systemctl restart haproxy&amp;lt;/pre&amp;gt;&lt;br /&gt;
* View HAProxy logs: &amp;lt;pre&amp;gt;sudo tail -f /var/log/haproxy.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test backend health: &amp;lt;pre&amp;gt;curl http://web01.lab.sdnog.sd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Appendix: High Availability Cluster with Pacemaker, Chronyd  ==&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
* '''Author''': [[User:Manhal.Mohamed|Manhal Mohamed]] , SdNOG Team&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
''This guide is based on practical deployment, tested with Ubuntu 22.04+. For additional features and advanced security, consult the [https://www.haproxy.org/ HAProxy documentation].''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2345</id>
		<title>HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition)</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2345"/>
		<updated>2025-07-18T16:11:25Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* HAProxy Log Explanation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition) =&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This guide documents the setup of HAProxy on Ubuntu servers for load balancing web (HTTP/HTTPS) and MySQL database traffic, using the `sdnog.sd` lab domain. The environment includes multiple backend nodes and complete instructions for configuration, testing, and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3+ Ubuntu servers/VMs: 1 for HAProxy (load balancer), at least 2 for web/database backends.&lt;br /&gt;
* Domain names:&lt;br /&gt;
  * `lb.lab.sdnog.sd` (HAProxy/load balancer)&lt;br /&gt;
  * `www.lab.sdnog.sd`, `db.lab.sdnog.sd`, `lb.lab.sdnog.sd` (all pointing to the HAProxy IP)&lt;br /&gt;
  * Backends: `web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`&lt;br /&gt;
* Sudo/root access on all nodes.&lt;br /&gt;
* Ability to update `/etc/hosts` or your DNS zone for lab domains.&lt;br /&gt;
&lt;br /&gt;
== Local Hosts or DNS Configuration ==&lt;br /&gt;
Set the following entries on your local hosts file or DNS server, pointing to your HAProxy IP (`X.X.X.X`):&lt;br /&gt;
&lt;br /&gt;
  X.X.X.X lb.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X www.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X db.lab.sdnog.sd&lt;br /&gt;
&lt;br /&gt;
Backends (`web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`) should resolve to their actual server IPs.&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install HAProxy on Ubuntu ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update&lt;br /&gt;
sudo apt install haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install Web Servers on Backends ==&lt;br /&gt;
On `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`, install Nginx on one and Apache on another:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Nginx (on web01)&lt;br /&gt;
sudo apt install nginx&lt;br /&gt;
echo &amp;quot;This is web01.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&lt;br /&gt;
# Apache (on web02)&lt;br /&gt;
sudo apt install apache2&lt;br /&gt;
echo &amp;quot;This is web02.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install MySQL on Backends ==&lt;br /&gt;
On both `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install mysql-server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 4: Configure MySQL User for HAProxy ==&lt;br /&gt;
On both DB nodes (MySQL prompt):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE USER 'sdnoguser'@'%' IDENTIFIED BY 'StrongPassword';&lt;br /&gt;
GRANT ALL PRIVILEGES ON *.* TO 'sdnoguser'@'%' WITH GRANT OPTION;&lt;br /&gt;
FLUSH PRIVILEGES;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 5: HAProxy Configuration for Web &amp;amp; Database Load Balancing ==&lt;br /&gt;
Edit `/etc/haproxy/haproxy.cfg` on the HAProxy server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log         127.0.0.1:514 local1 info&lt;br /&gt;
    maxconn     4000&lt;br /&gt;
    user        haproxy&lt;br /&gt;
    group       haproxy&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    mode                    http&lt;br /&gt;
    log                     global&lt;br /&gt;
    option                  httplog&lt;br /&gt;
    option                  dontlognull&lt;br /&gt;
    option                  forwardfor except 127.0.0.0/8&lt;br /&gt;
    option                  http-server-close&lt;br /&gt;
    retries                 3&lt;br /&gt;
    timeout http-request    10s&lt;br /&gt;
    timeout queue           1m&lt;br /&gt;
    timeout connect         10s&lt;br /&gt;
    timeout client          1m&lt;br /&gt;
    timeout server          1m&lt;br /&gt;
    timeout http-keep-alive 10s&lt;br /&gt;
    timeout check           10s&lt;br /&gt;
    maxconn                 3000&lt;br /&gt;
&lt;br /&gt;
frontend https-in&lt;br /&gt;
    bind *:443 ssl crt /home/sdnog/lab/cert.pem&lt;br /&gt;
    mode http&lt;br /&gt;
    acl host_lab_sdnog hdr(host) -i www.lab.sdnog.sd&lt;br /&gt;
    use_backend www_back if host_lab_sdnog&lt;br /&gt;
    default_backend www_back&lt;br /&gt;
&lt;br /&gt;
frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
backend www_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server nginx_server web01.lab.sdnog.sd:80 check cookie web01&lt;br /&gt;
    server apache_server web02.lab.sdnog.sd:80 check cookie web02&lt;br /&gt;
&lt;br /&gt;
frontend database_frontend&lt;br /&gt;
    bind *:3306&lt;br /&gt;
    mode tcp&lt;br /&gt;
    default_backend database_backend&lt;br /&gt;
&lt;br /&gt;
backend database_backend&lt;br /&gt;
    mode tcp&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    server db01 web01.lab.sdnog.sd:3306 check&lt;br /&gt;
    server db02 web02.lab.sdnog.sd:3306 check&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind 0.0.0.0:8080&lt;br /&gt;
    bind :::8080&lt;br /&gt;
    mode http&lt;br /&gt;
    stats uri /stats&lt;br /&gt;
    stats realm HAProxy\ Statistics&lt;br /&gt;
    stats auth admin:StrongPassword&lt;br /&gt;
    stats admin if TRUE&lt;br /&gt;
    timeout client 5000&lt;br /&gt;
    timeout connect 4000&lt;br /&gt;
    timeout server 30000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 6: SSL Certificate for HAProxy ==&lt;br /&gt;
Generate or copy your SSL certificate and key as `/home/sdnog/lab/cert.pem` (or another path if you adjust your config).&lt;br /&gt;
&lt;br /&gt;
== Step 7: Restart and Enable HAProxy ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart haproxy&lt;br /&gt;
sudo systemctl enable haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 8: Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Web Load Balancing ===&lt;br /&gt;
Test the round-robin backend selection:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -I https://www.lab.sdnog.sd | grep SERVERID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see alternating results like:&lt;br /&gt;
  set-cookie: SERVERID=web01; path=/&lt;br /&gt;
  set-cookie: SERVERID=web02; path=/&lt;br /&gt;
&lt;br /&gt;
See for example output.&lt;br /&gt;
&lt;br /&gt;
[[File:Web servrs test.png|thumb|center|Web test ]]&lt;br /&gt;
&lt;br /&gt;
=== Database Load Balancing ===&lt;br /&gt;
Test DB backend switching:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql -u sdnoguser -p -h db.lab.sdnog.sd -e &amp;quot;show variables like 'hostname';&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see the hostname alternating between `db01.lab.sdnog.sd` and `db02.lab.sdnog.sd` &lt;br /&gt;
&lt;br /&gt;
[[File:DB loadbalancer test.png|thumb|center|Layer 4 loadbalancing ]]&lt;br /&gt;
&lt;br /&gt;
=== HAProxy Stats Page ===&lt;br /&gt;
Browse to: http://lb.lab.sdnog.sd:8080/stats  &lt;br /&gt;
 for an example:&lt;br /&gt;
&lt;br /&gt;
[[File:Stats page.png|thumb|center]]&lt;br /&gt;
&lt;br /&gt;
== HAProxy Log ==&lt;br /&gt;
&lt;br /&gt;
=== How to Enable HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
To enable and view HAProxy logs, follow these steps:&lt;br /&gt;
&lt;br /&gt;
# Edit your HAProxy configuration file (usually &amp;lt;code&amp;gt;/etc/haproxy/haproxy.cfg&amp;lt;/code&amp;gt;) and add the following in the &amp;lt;code&amp;gt;global&amp;lt;/code&amp;gt; and/or &amp;lt;code&amp;gt;defaults&amp;lt;/code&amp;gt; sections:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log 127.0.0.1 local0&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    log     global&lt;br /&gt;
    option  httplog&lt;br /&gt;
    option  dontlognull&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;log 127.0.0.1 local0&amp;lt;/code&amp;gt;: Sends logs to the local syslog server.&lt;br /&gt;
* &amp;lt;code&amp;gt;option httplog&amp;lt;/code&amp;gt;: Enables detailed HTTP log format.&lt;br /&gt;
* &amp;lt;code&amp;gt;option dontlognull&amp;lt;/code&amp;gt;: Avoids logging empty connections.&lt;br /&gt;
&lt;br /&gt;
# Configure your syslog service (such as &amp;lt;code&amp;gt;rsyslog&amp;lt;/code&amp;gt;) to receive HAProxy logs:&lt;br /&gt;
* Add the following to &amp;lt;code&amp;gt;/etc/rsyslog.conf&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/rsyslog.d/haproxy.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ModLoad imudp&lt;br /&gt;
$UDPServerRun 514&lt;br /&gt;
&lt;br /&gt;
local0.*    /var/log/haproxy.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Restart your syslog service:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart rsyslog&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Restart HAProxy:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Check your HAProxy log output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo tail -f /var/log/haproxy.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Example Log Line ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
2025-07-18T15:51:04+00:00 localhost haproxy[8400]: 102.117.90.22:57291 [18/Jul/2025:15:51:04.732] https-in~ www_back/nginx_server 0/0/1/1/2 200 210 - - --NI 1/1/0/0/0 0/0 &amp;quot;HEAD https://www.lab.sdnog.sd/ HTTP/2.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Explanation of Fields ===&lt;br /&gt;
&lt;br /&gt;
; '''Timestamp and Host'''&lt;br /&gt;
: &amp;lt;code&amp;gt;2025-07-18T15:51:04+00:00&amp;lt;/code&amp;gt; — Date and time (ISO 8601 format)&lt;br /&gt;
: &amp;lt;code&amp;gt;localhost&amp;lt;/code&amp;gt; — Hostname where HAProxy is running&lt;br /&gt;
: &amp;lt;code&amp;gt;haproxy[8400]&amp;lt;/code&amp;gt; — Process name and PID&lt;br /&gt;
&lt;br /&gt;
; '''Client Info'''&lt;br /&gt;
: &amp;lt;code&amp;gt;102.117.90.22:57291&amp;lt;/code&amp;gt; — Source IP address and port of the client&lt;br /&gt;
&lt;br /&gt;
; '''Accept Date'''&lt;br /&gt;
: &amp;lt;code&amp;gt;[18/Jul/2025:15:51:04.732]&amp;lt;/code&amp;gt; — When HAProxy accepted the connection/request&lt;br /&gt;
&lt;br /&gt;
; '''Frontend, Backend, Server'''&lt;br /&gt;
: &amp;lt;code&amp;gt;https-in~&amp;lt;/code&amp;gt; — HAProxy frontend handling the request&lt;br /&gt;
: &amp;lt;code&amp;gt;www_back/nginx_server&amp;lt;/code&amp;gt; — Backend and backend server that handled the request&lt;br /&gt;
&lt;br /&gt;
; '''Timers (ms)'''&lt;br /&gt;
: &amp;lt;code&amp;gt;0/0/1/1/2&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''Tq''': Time spent waiting in queue&lt;br /&gt;
* '''Tw''': Time waiting for connection to backend server&lt;br /&gt;
* '''Tc''': Time to establish connection to backend&lt;br /&gt;
* '''Tr''': Time to get the full HTTP request from the client&lt;br /&gt;
* '''Tt''': Total time from accept to response&lt;br /&gt;
&lt;br /&gt;
; '''HTTP Status and Bytes'''&lt;br /&gt;
: &amp;lt;code&amp;gt;200&amp;lt;/code&amp;gt; — HTTP status code returned to the client (OK)&lt;br /&gt;
: &amp;lt;code&amp;gt;210&amp;lt;/code&amp;gt; — Number of bytes sent to the client (response size)&lt;br /&gt;
&lt;br /&gt;
; '''Captured Request/Response Cookies'''&lt;br /&gt;
: &amp;lt;code&amp;gt;- -&amp;lt;/code&amp;gt; — (Dashes mean &amp;quot;not captured&amp;quot; or &amp;quot;not set&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
; '''Termination State'''&lt;br /&gt;
: &amp;lt;code&amp;gt;--NI&amp;lt;/code&amp;gt; — How/why the session ended (see [https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#8.2.4 HAProxy documentation] for codes)&lt;br /&gt;
&lt;br /&gt;
; '''Connections (ActConn/FeConn/BeConn/SrvConn/Retry)'''&lt;br /&gt;
: &amp;lt;code&amp;gt;1/1/0/0/0&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''ActConn''': Active connections on the frontend&lt;br /&gt;
* '''FeConn''': Connections on the frontend&lt;br /&gt;
* '''BeConn''': On the backend&lt;br /&gt;
* '''SrvConn''': On the server&lt;br /&gt;
* '''Retry''': Retries&lt;br /&gt;
&lt;br /&gt;
; '''Queues (SrvQueue/BackendQueue)'''&lt;br /&gt;
: &amp;lt;code&amp;gt;0/0&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''SrvQueue''': Number of queued requests on the server&lt;br /&gt;
* '''BackendQueue''': Number of queued requests on the backend&lt;br /&gt;
&lt;br /&gt;
; '''Request Line'''&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;quot;HEAD https://www.lab.sdnog.sd/ HTTP/2.0&amp;quot;&amp;lt;/code&amp;gt; — The HTTP method, URL, and protocol&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Explanation  ==&lt;br /&gt;
&lt;br /&gt;
* Each line is a single request processed by HAProxy.&lt;br /&gt;
* The log shows: when it happened, who connected, what request they made, what server handled it, how long each step took, and what the result was.&lt;br /&gt;
* If you see different backends/servers (like &amp;lt;code&amp;gt;nginx_server&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;apache_server&amp;lt;/code&amp;gt;), it means HAProxy is load balancing between them.&lt;br /&gt;
* '''Status codes''' like &amp;lt;code&amp;gt;200&amp;lt;/code&amp;gt; mean “OK”. If you see &amp;lt;code&amp;gt;500&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;404&amp;lt;/code&amp;gt;, etc., that means there was an error.&lt;br /&gt;
* '''Timings''' help you diagnose where delays are happening (queue, connection, etc.).&lt;br /&gt;
* '''Termination state''' (&amp;lt;code&amp;gt;--NI&amp;lt;/code&amp;gt;) can show if the connection ended normally or with errors/timeouts.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Quick Reference Table ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field                  !! Example Value                   !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| Timestamp              || 2025-07-18T15:51:04+00:00       || When the event happened&lt;br /&gt;
|-&lt;br /&gt;
| Client IP:Port         || 102.117.90.22:57291             || Who made the request&lt;br /&gt;
|-&lt;br /&gt;
| Accept Date            || [18/Jul/2025:15:51:04.732]      || When HAProxy accepted the request&lt;br /&gt;
|-&lt;br /&gt;
| Frontend~              || https-in~                       || Which frontend handled it&lt;br /&gt;
|-&lt;br /&gt;
| Backend/Server         || www_back/nginx_server           || Backend/server chosen&lt;br /&gt;
|-&lt;br /&gt;
| Timers                 || 0/0/1/1/2                       || Time in each HAProxy phase&lt;br /&gt;
|-&lt;br /&gt;
| Status                 || 200                             || HTTP status code&lt;br /&gt;
|-&lt;br /&gt;
| Bytes                  || 210                             || Bytes sent to client&lt;br /&gt;
|-&lt;br /&gt;
| Term. State            || --NI                            || How session ended&lt;br /&gt;
|-&lt;br /&gt;
| Connections            || 1/1/0/0/0                       || Conn. counts (frontend, backend, etc.)&lt;br /&gt;
|-&lt;br /&gt;
| Queues                 || 0/0                             || Queued requests&lt;br /&gt;
|-&lt;br /&gt;
| Request                || &amp;quot;HEAD ... HTTP/2.0&amp;quot;             || HTTP Method, URL, Protocol&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' For more details, see the [https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#8.2.4 HAProxy log format documentation].&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not already in use.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Make sure Apache/Nginx/MySQL are running on their respective servers.&lt;br /&gt;
#* Check firewall rules (UFW, iptables, or cloud security groups) to allow traffic between HAProxy and backend nodes.&lt;br /&gt;
#* Confirm the correct backend IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the certificate and private key path in your HAProxy config.&lt;br /&gt;
#* Ensure your `.pem` file has correct permissions and the combined format (cert + key).&lt;br /&gt;
&lt;br /&gt;
# '''ACLs/routing not working as expected:'''&lt;br /&gt;
#* Verify that your local `/etc/hosts` or DNS is configured for the lab domains.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect HTTP headers if needed.&lt;br /&gt;
&lt;br /&gt;
# '''Stats page not accessible:'''&lt;br /&gt;
#* Confirm the `listen stats` block in your config.&lt;br /&gt;
#* Make sure port 8080 is open on the HAProxy machine and not blocked by a firewall.&lt;br /&gt;
&lt;br /&gt;
# '''MySQL authentication errors:'''&lt;br /&gt;
#* Ensure user/password is the same on all DB nodes.&lt;br /&gt;
#* Make sure MySQL is listening on 0.0.0.0 or the correct interface.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` and `defaults` sections based on your hardware.&lt;br /&gt;
# '''Enable kernel TCP keepalive:'''&lt;br /&gt;
#* Add `option tcpka` in the `defaults` section if needed.&lt;br /&gt;
# '''Enable HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bind *:443 ssl crt /home/sdnog/lab/cert.pem alpn h2,http/1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider using Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
=== Optimal Configuration Options for Web-Based Frontends  ===&lt;br /&gt;
It's crucial to customize the following according to your application's specific requirements.&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    &lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
   &lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    &lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    &lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    &lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    &lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Appendix: Useful Commands ==&lt;br /&gt;
&lt;br /&gt;
* Check HAProxy config: &amp;lt;pre&amp;gt;haproxy -c -f /etc/haproxy/haproxy.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart HAProxy: &amp;lt;pre&amp;gt;sudo systemctl restart haproxy&amp;lt;/pre&amp;gt;&lt;br /&gt;
* View HAProxy logs: &amp;lt;pre&amp;gt;sudo tail -f /var/log/haproxy.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test backend health: &amp;lt;pre&amp;gt;curl http://web01.lab.sdnog.sd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
* '''Author''': [[User:Manhal.Mohamed|Manhal Mohamed]] , SdNOG Team&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
''This guide is based on practical deployment, tested with Ubuntu 22.04+. For additional features and advanced security, consult the [https://www.haproxy.org/ HAProxy documentation].''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2344</id>
		<title>HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition)</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2344"/>
		<updated>2025-07-18T15:59:28Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition) =&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This guide documents the setup of HAProxy on Ubuntu servers for load balancing web (HTTP/HTTPS) and MySQL database traffic, using the `sdnog.sd` lab domain. The environment includes multiple backend nodes and complete instructions for configuration, testing, and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3+ Ubuntu servers/VMs: 1 for HAProxy (load balancer), at least 2 for web/database backends.&lt;br /&gt;
* Domain names:&lt;br /&gt;
  * `lb.lab.sdnog.sd` (HAProxy/load balancer)&lt;br /&gt;
  * `www.lab.sdnog.sd`, `db.lab.sdnog.sd`, `lb.lab.sdnog.sd` (all pointing to the HAProxy IP)&lt;br /&gt;
  * Backends: `web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`&lt;br /&gt;
* Sudo/root access on all nodes.&lt;br /&gt;
* Ability to update `/etc/hosts` or your DNS zone for lab domains.&lt;br /&gt;
&lt;br /&gt;
== Local Hosts or DNS Configuration ==&lt;br /&gt;
Set the following entries on your local hosts file or DNS server, pointing to your HAProxy IP (`X.X.X.X`):&lt;br /&gt;
&lt;br /&gt;
  X.X.X.X lb.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X www.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X db.lab.sdnog.sd&lt;br /&gt;
&lt;br /&gt;
Backends (`web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`) should resolve to their actual server IPs.&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install HAProxy on Ubuntu ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update&lt;br /&gt;
sudo apt install haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install Web Servers on Backends ==&lt;br /&gt;
On `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`, install Nginx on one and Apache on another:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Nginx (on web01)&lt;br /&gt;
sudo apt install nginx&lt;br /&gt;
echo &amp;quot;This is web01.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&lt;br /&gt;
# Apache (on web02)&lt;br /&gt;
sudo apt install apache2&lt;br /&gt;
echo &amp;quot;This is web02.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install MySQL on Backends ==&lt;br /&gt;
On both `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install mysql-server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 4: Configure MySQL User for HAProxy ==&lt;br /&gt;
On both DB nodes (MySQL prompt):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE USER 'sdnoguser'@'%' IDENTIFIED BY 'StrongPassword';&lt;br /&gt;
GRANT ALL PRIVILEGES ON *.* TO 'sdnoguser'@'%' WITH GRANT OPTION;&lt;br /&gt;
FLUSH PRIVILEGES;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 5: HAProxy Configuration for Web &amp;amp; Database Load Balancing ==&lt;br /&gt;
Edit `/etc/haproxy/haproxy.cfg` on the HAProxy server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log         127.0.0.1:514 local1 info&lt;br /&gt;
    maxconn     4000&lt;br /&gt;
    user        haproxy&lt;br /&gt;
    group       haproxy&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    mode                    http&lt;br /&gt;
    log                     global&lt;br /&gt;
    option                  httplog&lt;br /&gt;
    option                  dontlognull&lt;br /&gt;
    option                  forwardfor except 127.0.0.0/8&lt;br /&gt;
    option                  http-server-close&lt;br /&gt;
    retries                 3&lt;br /&gt;
    timeout http-request    10s&lt;br /&gt;
    timeout queue           1m&lt;br /&gt;
    timeout connect         10s&lt;br /&gt;
    timeout client          1m&lt;br /&gt;
    timeout server          1m&lt;br /&gt;
    timeout http-keep-alive 10s&lt;br /&gt;
    timeout check           10s&lt;br /&gt;
    maxconn                 3000&lt;br /&gt;
&lt;br /&gt;
frontend https-in&lt;br /&gt;
    bind *:443 ssl crt /home/sdnog/lab/cert.pem&lt;br /&gt;
    mode http&lt;br /&gt;
    acl host_lab_sdnog hdr(host) -i www.lab.sdnog.sd&lt;br /&gt;
    use_backend www_back if host_lab_sdnog&lt;br /&gt;
    default_backend www_back&lt;br /&gt;
&lt;br /&gt;
frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
backend www_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server nginx_server web01.lab.sdnog.sd:80 check cookie web01&lt;br /&gt;
    server apache_server web02.lab.sdnog.sd:80 check cookie web02&lt;br /&gt;
&lt;br /&gt;
frontend database_frontend&lt;br /&gt;
    bind *:3306&lt;br /&gt;
    mode tcp&lt;br /&gt;
    default_backend database_backend&lt;br /&gt;
&lt;br /&gt;
backend database_backend&lt;br /&gt;
    mode tcp&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    server db01 web01.lab.sdnog.sd:3306 check&lt;br /&gt;
    server db02 web02.lab.sdnog.sd:3306 check&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind 0.0.0.0:8080&lt;br /&gt;
    bind :::8080&lt;br /&gt;
    mode http&lt;br /&gt;
    stats uri /stats&lt;br /&gt;
    stats realm HAProxy\ Statistics&lt;br /&gt;
    stats auth admin:StrongPassword&lt;br /&gt;
    stats admin if TRUE&lt;br /&gt;
    timeout client 5000&lt;br /&gt;
    timeout connect 4000&lt;br /&gt;
    timeout server 30000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 6: SSL Certificate for HAProxy ==&lt;br /&gt;
Generate or copy your SSL certificate and key as `/home/sdnog/lab/cert.pem` (or another path if you adjust your config).&lt;br /&gt;
&lt;br /&gt;
== Step 7: Restart and Enable HAProxy ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart haproxy&lt;br /&gt;
sudo systemctl enable haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 8: Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Web Load Balancing ===&lt;br /&gt;
Test the round-robin backend selection:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -I https://www.lab.sdnog.sd | grep SERVERID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see alternating results like:&lt;br /&gt;
  set-cookie: SERVERID=web01; path=/&lt;br /&gt;
  set-cookie: SERVERID=web02; path=/&lt;br /&gt;
&lt;br /&gt;
See for example output.&lt;br /&gt;
&lt;br /&gt;
[[File:Web servrs test.png|thumb|center|Web test ]]&lt;br /&gt;
&lt;br /&gt;
=== Database Load Balancing ===&lt;br /&gt;
Test DB backend switching:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql -u sdnoguser -p -h db.lab.sdnog.sd -e &amp;quot;show variables like 'hostname';&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see the hostname alternating between `db01.lab.sdnog.sd` and `db02.lab.sdnog.sd` &lt;br /&gt;
&lt;br /&gt;
[[File:DB loadbalancer test.png|thumb|center|Layer 4 loadbalancing ]]&lt;br /&gt;
&lt;br /&gt;
=== HAProxy Stats Page ===&lt;br /&gt;
Browse to: http://lb.lab.sdnog.sd:8080/stats  &lt;br /&gt;
 for an example:&lt;br /&gt;
&lt;br /&gt;
[[File:Stats page.png|thumb|center]]&lt;br /&gt;
&lt;br /&gt;
== HAProxy Log Explanation ==&lt;br /&gt;
&lt;br /&gt;
=== Example Log Line ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
2025-07-18T15:51:04+00:00 localhost haproxy[8400]: 102.117.90.22:57291 [18/Jul/2025:15:51:04.732] https-in~ www_back/nginx_server 0/0/1/1/2 200 210 - - --NI 1/1/0/0/0 0/0 &amp;quot;HEAD https://www.lab.sdnog.sd/ HTTP/2.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Explanation of Fields ===&lt;br /&gt;
&lt;br /&gt;
; '''Timestamp and Host'''&lt;br /&gt;
: &amp;lt;code&amp;gt;2025-07-18T15:51:04+00:00&amp;lt;/code&amp;gt; — Date and time (ISO 8601 format)&lt;br /&gt;
: &amp;lt;code&amp;gt;localhost&amp;lt;/code&amp;gt; — Hostname where HAProxy is running&lt;br /&gt;
: &amp;lt;code&amp;gt;haproxy[8400]&amp;lt;/code&amp;gt; — Process name and PID&lt;br /&gt;
&lt;br /&gt;
; '''Client Info'''&lt;br /&gt;
: &amp;lt;code&amp;gt;102.117.90.22:57291&amp;lt;/code&amp;gt; — Source IP address and port of the client&lt;br /&gt;
&lt;br /&gt;
; '''Accept Date'''&lt;br /&gt;
: &amp;lt;code&amp;gt;[18/Jul/2025:15:51:04.732]&amp;lt;/code&amp;gt; — When HAProxy accepted the connection/request&lt;br /&gt;
&lt;br /&gt;
; '''Frontend, Backend, Server'''&lt;br /&gt;
: &amp;lt;code&amp;gt;https-in~&amp;lt;/code&amp;gt; — HAProxy frontend handling the request&lt;br /&gt;
: &amp;lt;code&amp;gt;www_back/nginx_server&amp;lt;/code&amp;gt; — Backend and backend server that handled the request&lt;br /&gt;
&lt;br /&gt;
; '''Timers (ms)'''&lt;br /&gt;
: &amp;lt;code&amp;gt;0/0/1/1/2&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''Tq''': Time spent waiting in queue&lt;br /&gt;
* '''Tw''': Time waiting for connection to backend server&lt;br /&gt;
* '''Tc''': Time to establish connection to backend&lt;br /&gt;
* '''Tr''': Time to get the full HTTP request from the client&lt;br /&gt;
* '''Tt''': Total time from accept to response&lt;br /&gt;
&lt;br /&gt;
; '''HTTP Status and Bytes'''&lt;br /&gt;
: &amp;lt;code&amp;gt;200&amp;lt;/code&amp;gt; — HTTP status code returned to the client (OK)&lt;br /&gt;
: &amp;lt;code&amp;gt;210&amp;lt;/code&amp;gt; — Number of bytes sent to the client (response size)&lt;br /&gt;
&lt;br /&gt;
; '''Captured Request/Response Cookies'''&lt;br /&gt;
: &amp;lt;code&amp;gt;- -&amp;lt;/code&amp;gt; — (Dashes mean &amp;quot;not captured&amp;quot; or &amp;quot;not set&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
; '''Termination State'''&lt;br /&gt;
: &amp;lt;code&amp;gt;--NI&amp;lt;/code&amp;gt; — How/why the session ended (see [https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#8.2.4 HAProxy documentation] for codes)&lt;br /&gt;
&lt;br /&gt;
; '''Connections (ActConn/FeConn/BeConn/SrvConn/Retry)'''&lt;br /&gt;
: &amp;lt;code&amp;gt;1/1/0/0/0&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''ActConn''': Active connections on the frontend&lt;br /&gt;
* '''FeConn''': Connections on the frontend&lt;br /&gt;
* '''BeConn''': On the backend&lt;br /&gt;
* '''SrvConn''': On the server&lt;br /&gt;
* '''Retry''': Retries&lt;br /&gt;
&lt;br /&gt;
; '''Queues (SrvQueue/BackendQueue)'''&lt;br /&gt;
: &amp;lt;code&amp;gt;0/0&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''SrvQueue''': Number of queued requests on the server&lt;br /&gt;
* '''BackendQueue''': Number of queued requests on the backend&lt;br /&gt;
&lt;br /&gt;
; '''Request Line'''&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;quot;HEAD https://www.lab.sdnog.sd/ HTTP/2.0&amp;quot;&amp;lt;/code&amp;gt; — The HTTP method, URL, and protocol&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Explanation  ==&lt;br /&gt;
&lt;br /&gt;
* Each line is a single request processed by HAProxy.&lt;br /&gt;
* The log shows: when it happened, who connected, what request they made, what server handled it, how long each step took, and what the result was.&lt;br /&gt;
* If you see different backends/servers (like &amp;lt;code&amp;gt;nginx_server&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;apache_server&amp;lt;/code&amp;gt;), it means HAProxy is load balancing between them.&lt;br /&gt;
* '''Status codes''' like &amp;lt;code&amp;gt;200&amp;lt;/code&amp;gt; mean “OK”. If you see &amp;lt;code&amp;gt;500&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;404&amp;lt;/code&amp;gt;, etc., that means there was an error.&lt;br /&gt;
* '''Timings''' help you diagnose where delays are happening (queue, connection, etc.).&lt;br /&gt;
* '''Termination state''' (&amp;lt;code&amp;gt;--NI&amp;lt;/code&amp;gt;) can show if the connection ended normally or with errors/timeouts.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Quick Reference Table ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Field                  !! Example Value                   !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| Timestamp              || 2025-07-18T15:51:04+00:00       || When the event happened&lt;br /&gt;
|-&lt;br /&gt;
| Client IP:Port         || 102.117.90.22:57291             || Who made the request&lt;br /&gt;
|-&lt;br /&gt;
| Accept Date            || [18/Jul/2025:15:51:04.732]      || When HAProxy accepted the request&lt;br /&gt;
|-&lt;br /&gt;
| Frontend~              || https-in~                       || Which frontend handled it&lt;br /&gt;
|-&lt;br /&gt;
| Backend/Server         || www_back/nginx_server           || Backend/server chosen&lt;br /&gt;
|-&lt;br /&gt;
| Timers                 || 0/0/1/1/2                       || Time in each HAProxy phase&lt;br /&gt;
|-&lt;br /&gt;
| Status                 || 200                             || HTTP status code&lt;br /&gt;
|-&lt;br /&gt;
| Bytes                  || 210                             || Bytes sent to client&lt;br /&gt;
|-&lt;br /&gt;
| Term. State            || --NI                            || How session ended&lt;br /&gt;
|-&lt;br /&gt;
| Connections            || 1/1/0/0/0                       || Conn. counts (frontend, backend, etc.)&lt;br /&gt;
|-&lt;br /&gt;
| Queues                 || 0/0                             || Queued requests&lt;br /&gt;
|-&lt;br /&gt;
| Request                || &amp;quot;HEAD ... HTTP/2.0&amp;quot;             || HTTP Method, URL, Protocol&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' For more details, see the [https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#8.2.4 HAProxy log format documentation].&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not already in use.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Make sure Apache/Nginx/MySQL are running on their respective servers.&lt;br /&gt;
#* Check firewall rules (UFW, iptables, or cloud security groups) to allow traffic between HAProxy and backend nodes.&lt;br /&gt;
#* Confirm the correct backend IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the certificate and private key path in your HAProxy config.&lt;br /&gt;
#* Ensure your `.pem` file has correct permissions and the combined format (cert + key).&lt;br /&gt;
&lt;br /&gt;
# '''ACLs/routing not working as expected:'''&lt;br /&gt;
#* Verify that your local `/etc/hosts` or DNS is configured for the lab domains.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect HTTP headers if needed.&lt;br /&gt;
&lt;br /&gt;
# '''Stats page not accessible:'''&lt;br /&gt;
#* Confirm the `listen stats` block in your config.&lt;br /&gt;
#* Make sure port 8080 is open on the HAProxy machine and not blocked by a firewall.&lt;br /&gt;
&lt;br /&gt;
# '''MySQL authentication errors:'''&lt;br /&gt;
#* Ensure user/password is the same on all DB nodes.&lt;br /&gt;
#* Make sure MySQL is listening on 0.0.0.0 or the correct interface.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` and `defaults` sections based on your hardware.&lt;br /&gt;
# '''Enable kernel TCP keepalive:'''&lt;br /&gt;
#* Add `option tcpka` in the `defaults` section if needed.&lt;br /&gt;
# '''Enable HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bind *:443 ssl crt /home/sdnog/lab/cert.pem alpn h2,http/1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider using Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
=== Optimal Configuration Options for Web-Based Frontends  ===&lt;br /&gt;
It's crucial to customize the following according to your application's specific requirements.&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    &lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
   &lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    &lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    &lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    &lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    &lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Appendix: Useful Commands ==&lt;br /&gt;
&lt;br /&gt;
* Check HAProxy config: &amp;lt;pre&amp;gt;haproxy -c -f /etc/haproxy/haproxy.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart HAProxy: &amp;lt;pre&amp;gt;sudo systemctl restart haproxy&amp;lt;/pre&amp;gt;&lt;br /&gt;
* View HAProxy logs: &amp;lt;pre&amp;gt;sudo tail -f /var/log/haproxy.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test backend health: &amp;lt;pre&amp;gt;curl http://web01.lab.sdnog.sd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
* '''Author''': [[User:Manhal.Mohamed|Manhal Mohamed]] , SdNOG Team&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
''This guide is based on practical deployment, tested with Ubuntu 22.04+. For additional features and advanced security, consult the [https://www.haproxy.org/ HAProxy documentation].''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2343</id>
		<title>HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition)</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2343"/>
		<updated>2025-07-18T15:28:32Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition) =&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This guide documents the setup of HAProxy on Ubuntu servers for load balancing web (HTTP/HTTPS) and MySQL database traffic, using the `sdnog.sd` lab domain. The environment includes multiple backend nodes and complete instructions for configuration, testing, and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3+ Ubuntu servers/VMs: 1 for HAProxy (load balancer), at least 2 for web/database backends.&lt;br /&gt;
* Domain names:&lt;br /&gt;
  * `lb.lab.sdnog.sd` (HAProxy/load balancer)&lt;br /&gt;
  * `www.lab.sdnog.sd`, `db.lab.sdnog.sd`, `lb.lab.sdnog.sd` (all pointing to the HAProxy IP)&lt;br /&gt;
  * Backends: `web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`&lt;br /&gt;
* Sudo/root access on all nodes.&lt;br /&gt;
* Ability to update `/etc/hosts` or your DNS zone for lab domains.&lt;br /&gt;
&lt;br /&gt;
== Local Hosts or DNS Configuration ==&lt;br /&gt;
Set the following entries on your local hosts file or DNS server, pointing to your HAProxy IP (`X.X.X.X`):&lt;br /&gt;
&lt;br /&gt;
  X.X.X.X lb.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X www.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X db.lab.sdnog.sd&lt;br /&gt;
&lt;br /&gt;
Backends (`web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`) should resolve to their actual server IPs.&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install HAProxy on Ubuntu ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update&lt;br /&gt;
sudo apt install haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install Web Servers on Backends ==&lt;br /&gt;
On `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`, install Nginx on one and Apache on another:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Nginx (on web01)&lt;br /&gt;
sudo apt install nginx&lt;br /&gt;
echo &amp;quot;This is web01.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&lt;br /&gt;
# Apache (on web02)&lt;br /&gt;
sudo apt install apache2&lt;br /&gt;
echo &amp;quot;This is web02.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install MySQL on Backends ==&lt;br /&gt;
On both `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install mysql-server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 4: Configure MySQL User for HAProxy ==&lt;br /&gt;
On both DB nodes (MySQL prompt):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE USER 'sdnoguser'@'%' IDENTIFIED BY 'StrongPassword';&lt;br /&gt;
GRANT ALL PRIVILEGES ON *.* TO 'sdnoguser'@'%' WITH GRANT OPTION;&lt;br /&gt;
FLUSH PRIVILEGES;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 5: HAProxy Configuration for Web &amp;amp; Database Load Balancing ==&lt;br /&gt;
Edit `/etc/haproxy/haproxy.cfg` on the HAProxy server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log         127.0.0.1:514 local1 info&lt;br /&gt;
    maxconn     4000&lt;br /&gt;
    user        haproxy&lt;br /&gt;
    group       haproxy&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    mode                    http&lt;br /&gt;
    log                     global&lt;br /&gt;
    option                  httplog&lt;br /&gt;
    option                  dontlognull&lt;br /&gt;
    option                  forwardfor except 127.0.0.0/8&lt;br /&gt;
    option                  http-server-close&lt;br /&gt;
    retries                 3&lt;br /&gt;
    timeout http-request    10s&lt;br /&gt;
    timeout queue           1m&lt;br /&gt;
    timeout connect         10s&lt;br /&gt;
    timeout client          1m&lt;br /&gt;
    timeout server          1m&lt;br /&gt;
    timeout http-keep-alive 10s&lt;br /&gt;
    timeout check           10s&lt;br /&gt;
    maxconn                 3000&lt;br /&gt;
&lt;br /&gt;
frontend https-in&lt;br /&gt;
    bind *:443 ssl crt /home/sdnog/lab/cert.pem&lt;br /&gt;
    mode http&lt;br /&gt;
    acl host_lab_sdnog hdr(host) -i www.lab.sdnog.sd&lt;br /&gt;
    use_backend www_back if host_lab_sdnog&lt;br /&gt;
    default_backend www_back&lt;br /&gt;
&lt;br /&gt;
frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
backend www_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server nginx_server web01.lab.sdnog.sd:80 check cookie web01&lt;br /&gt;
    server apache_server web02.lab.sdnog.sd:80 check cookie web02&lt;br /&gt;
&lt;br /&gt;
frontend database_frontend&lt;br /&gt;
    bind *:3306&lt;br /&gt;
    mode tcp&lt;br /&gt;
    default_backend database_backend&lt;br /&gt;
&lt;br /&gt;
backend database_backend&lt;br /&gt;
    mode tcp&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    server db01 web01.lab.sdnog.sd:3306 check&lt;br /&gt;
    server db02 web02.lab.sdnog.sd:3306 check&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind 0.0.0.0:8080&lt;br /&gt;
    bind :::8080&lt;br /&gt;
    mode http&lt;br /&gt;
    stats uri /stats&lt;br /&gt;
    stats realm HAProxy\ Statistics&lt;br /&gt;
    stats auth admin:StrongPassword&lt;br /&gt;
    stats admin if TRUE&lt;br /&gt;
    timeout client 5000&lt;br /&gt;
    timeout connect 4000&lt;br /&gt;
    timeout server 30000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 6: SSL Certificate for HAProxy ==&lt;br /&gt;
Generate or copy your SSL certificate and key as `/home/sdnog/lab/cert.pem` (or another path if you adjust your config).&lt;br /&gt;
&lt;br /&gt;
== Step 7: Restart and Enable HAProxy ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart haproxy&lt;br /&gt;
sudo systemctl enable haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 8: Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Web Load Balancing ===&lt;br /&gt;
Test the round-robin backend selection:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -I https://www.lab.sdnog.sd | grep SERVERID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see alternating results like:&lt;br /&gt;
  set-cookie: SERVERID=web01; path=/&lt;br /&gt;
  set-cookie: SERVERID=web02; path=/&lt;br /&gt;
&lt;br /&gt;
See for example output.&lt;br /&gt;
&lt;br /&gt;
[[File:Web servrs test.png|thumb|center|Web test ]]&lt;br /&gt;
&lt;br /&gt;
=== Database Load Balancing ===&lt;br /&gt;
Test DB backend switching:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql -u sdnoguser -p -h db.lab.sdnog.sd -e &amp;quot;show variables like 'hostname';&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see the hostname alternating between `db01.lab.sdnog.sd` and `db02.lab.sdnog.sd` &lt;br /&gt;
&lt;br /&gt;
[[File:DB loadbalancer test.png|thumb|center|Layer 4 loadbalancing ]]&lt;br /&gt;
&lt;br /&gt;
=== HAProxy Stats Page ===&lt;br /&gt;
Browse to: http://lb.lab.sdnog.sd:8080/stats  &lt;br /&gt;
 for an example:&lt;br /&gt;
&lt;br /&gt;
[[File:Stats page.png|thumb|center]]&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not already in use.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Make sure Apache/Nginx/MySQL are running on their respective servers.&lt;br /&gt;
#* Check firewall rules (UFW, iptables, or cloud security groups) to allow traffic between HAProxy and backend nodes.&lt;br /&gt;
#* Confirm the correct backend IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the certificate and private key path in your HAProxy config.&lt;br /&gt;
#* Ensure your `.pem` file has correct permissions and the combined format (cert + key).&lt;br /&gt;
&lt;br /&gt;
# '''ACLs/routing not working as expected:'''&lt;br /&gt;
#* Verify that your local `/etc/hosts` or DNS is configured for the lab domains.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect HTTP headers if needed.&lt;br /&gt;
&lt;br /&gt;
# '''Stats page not accessible:'''&lt;br /&gt;
#* Confirm the `listen stats` block in your config.&lt;br /&gt;
#* Make sure port 8080 is open on the HAProxy machine and not blocked by a firewall.&lt;br /&gt;
&lt;br /&gt;
# '''MySQL authentication errors:'''&lt;br /&gt;
#* Ensure user/password is the same on all DB nodes.&lt;br /&gt;
#* Make sure MySQL is listening on 0.0.0.0 or the correct interface.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` and `defaults` sections based on your hardware.&lt;br /&gt;
# '''Enable kernel TCP keepalive:'''&lt;br /&gt;
#* Add `option tcpka` in the `defaults` section if needed.&lt;br /&gt;
# '''Enable HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bind *:443 ssl crt /home/sdnog/lab/cert.pem alpn h2,http/1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider using Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
=== Optimal Configuration Options for Web-Based Frontends  ===&lt;br /&gt;
It's crucial to customize the following according to your application's specific requirements.&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    &lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
   &lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    &lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    &lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    &lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    &lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Appendix: Useful Commands ==&lt;br /&gt;
&lt;br /&gt;
* Check HAProxy config: &amp;lt;pre&amp;gt;haproxy -c -f /etc/haproxy/haproxy.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart HAProxy: &amp;lt;pre&amp;gt;sudo systemctl restart haproxy&amp;lt;/pre&amp;gt;&lt;br /&gt;
* View HAProxy logs: &amp;lt;pre&amp;gt;sudo tail -f /var/log/haproxy.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test backend health: &amp;lt;pre&amp;gt;curl http://web01.lab.sdnog.sd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
* '''Author''': [[User:Manhal.Mohamed|Manhal Mohamed]] , SdNOG Team&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
''This guide is based on practical deployment, tested with Ubuntu 22.04+. For additional features and advanced security, consult the [https://www.haproxy.org/ HAProxy documentation].''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2342</id>
		<title>HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition)</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2342"/>
		<updated>2025-07-18T15:27:19Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Security Considerations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition) =&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This guide documents the setup of HAProxy on Ubuntu servers for load balancing web (HTTP/HTTPS) and MySQL database traffic, using the `sdnog.sd` lab domain. The environment includes multiple backend nodes and complete instructions for configuration, testing, and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3+ Ubuntu servers/VMs: 1 for HAProxy (load balancer), at least 2 for web/database backends.&lt;br /&gt;
* Domain names:&lt;br /&gt;
  * `lb.lab.sdnog.sd` (HAProxy/load balancer)&lt;br /&gt;
  * `www.lab.sdnog.sd`, `db.lab.sdnog.sd`, `lb.lab.sdnog.sd` (all pointing to the HAProxy IP)&lt;br /&gt;
  * Backends: `web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`&lt;br /&gt;
* Sudo/root access on all nodes.&lt;br /&gt;
* Ability to update `/etc/hosts` or your DNS zone for lab domains.&lt;br /&gt;
&lt;br /&gt;
== Local Hosts or DNS Configuration ==&lt;br /&gt;
Set the following entries on your local hosts file or DNS server, pointing to your HAProxy IP (`X.X.X.X`):&lt;br /&gt;
&lt;br /&gt;
  X.X.X.X lb.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X www.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X db.lab.sdnog.sd&lt;br /&gt;
&lt;br /&gt;
Backends (`web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`) should resolve to their actual server IPs.&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install HAProxy on Ubuntu ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update&lt;br /&gt;
sudo apt install haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install Web Servers on Backends ==&lt;br /&gt;
On `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`, install Nginx on one and Apache on another:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Nginx (on web01)&lt;br /&gt;
sudo apt install nginx&lt;br /&gt;
echo &amp;quot;This is web01.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&lt;br /&gt;
# Apache (on web02)&lt;br /&gt;
sudo apt install apache2&lt;br /&gt;
echo &amp;quot;This is web02.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install MySQL on Backends ==&lt;br /&gt;
On both `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install mysql-server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 4: Configure MySQL User for HAProxy ==&lt;br /&gt;
On both DB nodes (MySQL prompt):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE USER 'sdnoguser'@'%' IDENTIFIED BY 'sdnog@sd';&lt;br /&gt;
GRANT ALL PRIVILEGES ON *.* TO 'sdnoguser'@'%' WITH GRANT OPTION;&lt;br /&gt;
FLUSH PRIVILEGES;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 5: HAProxy Configuration for Web &amp;amp; Database Load Balancing ==&lt;br /&gt;
Edit `/etc/haproxy/haproxy.cfg` on the HAProxy server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log         127.0.0.1:514 local1 info&lt;br /&gt;
    maxconn     4000&lt;br /&gt;
    user        haproxy&lt;br /&gt;
    group       haproxy&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    mode                    http&lt;br /&gt;
    log                     global&lt;br /&gt;
    option                  httplog&lt;br /&gt;
    option                  dontlognull&lt;br /&gt;
    option                  forwardfor except 127.0.0.0/8&lt;br /&gt;
    option                  http-server-close&lt;br /&gt;
    retries                 3&lt;br /&gt;
    timeout http-request    10s&lt;br /&gt;
    timeout queue           1m&lt;br /&gt;
    timeout connect         10s&lt;br /&gt;
    timeout client          1m&lt;br /&gt;
    timeout server          1m&lt;br /&gt;
    timeout http-keep-alive 10s&lt;br /&gt;
    timeout check           10s&lt;br /&gt;
    maxconn                 3000&lt;br /&gt;
&lt;br /&gt;
frontend https-in&lt;br /&gt;
    bind *:443 ssl crt /home/sdnog/lab/cert.pem&lt;br /&gt;
    mode http&lt;br /&gt;
    acl host_lab_sdnog hdr(host) -i www.lab.sdnog.sd&lt;br /&gt;
    use_backend www_back if host_lab_sdnog&lt;br /&gt;
    default_backend www_back&lt;br /&gt;
&lt;br /&gt;
frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
backend www_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server nginx_server web01.lab.sdnog.sd:80 check cookie web01&lt;br /&gt;
    server apache_server web02.lab.sdnog.sd:80 check cookie web02&lt;br /&gt;
&lt;br /&gt;
frontend database_frontend&lt;br /&gt;
    bind *:3306&lt;br /&gt;
    mode tcp&lt;br /&gt;
    default_backend database_backend&lt;br /&gt;
&lt;br /&gt;
backend database_backend&lt;br /&gt;
    mode tcp&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    server db01 web01.lab.sdnog.sd:3306 check&lt;br /&gt;
    server db02 web02.lab.sdnog.sd:3306 check&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind 0.0.0.0:8080&lt;br /&gt;
    bind :::8080&lt;br /&gt;
    mode http&lt;br /&gt;
    stats uri /stats&lt;br /&gt;
    stats realm HAProxy\ Statistics&lt;br /&gt;
    stats auth admin:Sdnog@123&lt;br /&gt;
    stats admin if TRUE&lt;br /&gt;
    timeout client 5000&lt;br /&gt;
    timeout connect 4000&lt;br /&gt;
    timeout server 30000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 6: SSL Certificate for HAProxy ==&lt;br /&gt;
Generate or copy your SSL certificate and key as `/home/sdnog/lab/cert.pem` (or another path if you adjust your config).&lt;br /&gt;
&lt;br /&gt;
== Step 7: Restart and Enable HAProxy ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart haproxy&lt;br /&gt;
sudo systemctl enable haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 8: Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Web Load Balancing ===&lt;br /&gt;
Test the round-robin backend selection:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -I https://www.lab.sdnog.sd | grep SERVERID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see alternating results like:&lt;br /&gt;
  set-cookie: SERVERID=web01; path=/&lt;br /&gt;
  set-cookie: SERVERID=web02; path=/&lt;br /&gt;
&lt;br /&gt;
See for example output.&lt;br /&gt;
&lt;br /&gt;
[[File:Web servrs test.png|thumb|center|Web test ]]&lt;br /&gt;
&lt;br /&gt;
=== Database Load Balancing ===&lt;br /&gt;
Test DB backend switching:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql -u sdnoguser -p -h db.lab.sdnog.sd -e &amp;quot;show variables like 'hostname';&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see the hostname alternating between `db01.lab.sdnog.sd` and `db02.lab.sdnog.sd` &lt;br /&gt;
&lt;br /&gt;
[[File:DB loadbalancer test.png|thumb|center|Layer 4 loadbalancing ]]&lt;br /&gt;
&lt;br /&gt;
=== HAProxy Stats Page ===&lt;br /&gt;
Browse to: http://lb.lab.sdnog.sd:8080/stats  &lt;br /&gt;
 for an example:&lt;br /&gt;
&lt;br /&gt;
[[File:Stats page.png|thumb|center]]&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not already in use.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Make sure Apache/Nginx/MySQL are running on their respective servers.&lt;br /&gt;
#* Check firewall rules (UFW, iptables, or cloud security groups) to allow traffic between HAProxy and backend nodes.&lt;br /&gt;
#* Confirm the correct backend IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the certificate and private key path in your HAProxy config.&lt;br /&gt;
#* Ensure your `.pem` file has correct permissions and the combined format (cert + key).&lt;br /&gt;
&lt;br /&gt;
# '''ACLs/routing not working as expected:'''&lt;br /&gt;
#* Verify that your local `/etc/hosts` or DNS is configured for the lab domains.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect HTTP headers if needed.&lt;br /&gt;
&lt;br /&gt;
# '''Stats page not accessible:'''&lt;br /&gt;
#* Confirm the `listen stats` block in your config.&lt;br /&gt;
#* Make sure port 8080 is open on the HAProxy machine and not blocked by a firewall.&lt;br /&gt;
&lt;br /&gt;
# '''MySQL authentication errors:'''&lt;br /&gt;
#* Ensure user/password is the same on all DB nodes.&lt;br /&gt;
#* Make sure MySQL is listening on 0.0.0.0 or the correct interface.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` and `defaults` sections based on your hardware.&lt;br /&gt;
# '''Enable kernel TCP keepalive:'''&lt;br /&gt;
#* Add `option tcpka` in the `defaults` section if needed.&lt;br /&gt;
# '''Enable HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bind *:443 ssl crt /home/sdnog/lab/cert.pem alpn h2,http/1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider using Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
=== Optimal Configuration Options for Web-Based Frontends  ===&lt;br /&gt;
It's crucial to customize the following according to your application's specific requirements.&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    &lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
   &lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    &lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    &lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    &lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    &lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Appendix: Useful Commands ==&lt;br /&gt;
&lt;br /&gt;
* Check HAProxy config: &amp;lt;pre&amp;gt;haproxy -c -f /etc/haproxy/haproxy.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart HAProxy: &amp;lt;pre&amp;gt;sudo systemctl restart haproxy&amp;lt;/pre&amp;gt;&lt;br /&gt;
* View HAProxy logs: &amp;lt;pre&amp;gt;sudo tail -f /var/log/haproxy.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test backend health: &amp;lt;pre&amp;gt;curl http://web01.lab.sdnog.sd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
* '''Author''': [[User:Manhal.Mohamed|Manhal Mohamed]] , SdNOG Team&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
''This guide is based on practical deployment, tested with Ubuntu 22.04+. For additional features and advanced security, consult the [https://www.haproxy.org/ HAProxy documentation].''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2341</id>
		<title>HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition)</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2341"/>
		<updated>2025-07-18T15:25:01Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Database Load Balancing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition) =&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This guide documents the setup of HAProxy on Ubuntu servers for load balancing web (HTTP/HTTPS) and MySQL database traffic, using the `sdnog.sd` lab domain. The environment includes multiple backend nodes and complete instructions for configuration, testing, and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3+ Ubuntu servers/VMs: 1 for HAProxy (load balancer), at least 2 for web/database backends.&lt;br /&gt;
* Domain names:&lt;br /&gt;
  * `lb.lab.sdnog.sd` (HAProxy/load balancer)&lt;br /&gt;
  * `www.lab.sdnog.sd`, `db.lab.sdnog.sd`, `lb.lab.sdnog.sd` (all pointing to the HAProxy IP)&lt;br /&gt;
  * Backends: `web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`&lt;br /&gt;
* Sudo/root access on all nodes.&lt;br /&gt;
* Ability to update `/etc/hosts` or your DNS zone for lab domains.&lt;br /&gt;
&lt;br /&gt;
== Local Hosts or DNS Configuration ==&lt;br /&gt;
Set the following entries on your local hosts file or DNS server, pointing to your HAProxy IP (`X.X.X.X`):&lt;br /&gt;
&lt;br /&gt;
  X.X.X.X lb.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X www.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X db.lab.sdnog.sd&lt;br /&gt;
&lt;br /&gt;
Backends (`web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`) should resolve to their actual server IPs.&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install HAProxy on Ubuntu ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update&lt;br /&gt;
sudo apt install haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install Web Servers on Backends ==&lt;br /&gt;
On `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`, install Nginx on one and Apache on another:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Nginx (on web01)&lt;br /&gt;
sudo apt install nginx&lt;br /&gt;
echo &amp;quot;This is web01.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&lt;br /&gt;
# Apache (on web02)&lt;br /&gt;
sudo apt install apache2&lt;br /&gt;
echo &amp;quot;This is web02.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install MySQL on Backends ==&lt;br /&gt;
On both `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install mysql-server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 4: Configure MySQL User for HAProxy ==&lt;br /&gt;
On both DB nodes (MySQL prompt):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE USER 'sdnoguser'@'%' IDENTIFIED BY 'sdnog@sd';&lt;br /&gt;
GRANT ALL PRIVILEGES ON *.* TO 'sdnoguser'@'%' WITH GRANT OPTION;&lt;br /&gt;
FLUSH PRIVILEGES;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 5: HAProxy Configuration for Web &amp;amp; Database Load Balancing ==&lt;br /&gt;
Edit `/etc/haproxy/haproxy.cfg` on the HAProxy server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log         127.0.0.1:514 local1 info&lt;br /&gt;
    maxconn     4000&lt;br /&gt;
    user        haproxy&lt;br /&gt;
    group       haproxy&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    mode                    http&lt;br /&gt;
    log                     global&lt;br /&gt;
    option                  httplog&lt;br /&gt;
    option                  dontlognull&lt;br /&gt;
    option                  forwardfor except 127.0.0.0/8&lt;br /&gt;
    option                  http-server-close&lt;br /&gt;
    retries                 3&lt;br /&gt;
    timeout http-request    10s&lt;br /&gt;
    timeout queue           1m&lt;br /&gt;
    timeout connect         10s&lt;br /&gt;
    timeout client          1m&lt;br /&gt;
    timeout server          1m&lt;br /&gt;
    timeout http-keep-alive 10s&lt;br /&gt;
    timeout check           10s&lt;br /&gt;
    maxconn                 3000&lt;br /&gt;
&lt;br /&gt;
frontend https-in&lt;br /&gt;
    bind *:443 ssl crt /home/sdnog/lab/cert.pem&lt;br /&gt;
    mode http&lt;br /&gt;
    acl host_lab_sdnog hdr(host) -i www.lab.sdnog.sd&lt;br /&gt;
    use_backend www_back if host_lab_sdnog&lt;br /&gt;
    default_backend www_back&lt;br /&gt;
&lt;br /&gt;
frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
backend www_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server nginx_server web01.lab.sdnog.sd:80 check cookie web01&lt;br /&gt;
    server apache_server web02.lab.sdnog.sd:80 check cookie web02&lt;br /&gt;
&lt;br /&gt;
frontend database_frontend&lt;br /&gt;
    bind *:3306&lt;br /&gt;
    mode tcp&lt;br /&gt;
    default_backend database_backend&lt;br /&gt;
&lt;br /&gt;
backend database_backend&lt;br /&gt;
    mode tcp&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    server db01 web01.lab.sdnog.sd:3306 check&lt;br /&gt;
    server db02 web02.lab.sdnog.sd:3306 check&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind 0.0.0.0:8080&lt;br /&gt;
    bind :::8080&lt;br /&gt;
    mode http&lt;br /&gt;
    stats uri /stats&lt;br /&gt;
    stats realm HAProxy\ Statistics&lt;br /&gt;
    stats auth admin:Sdnog@123&lt;br /&gt;
    stats admin if TRUE&lt;br /&gt;
    timeout client 5000&lt;br /&gt;
    timeout connect 4000&lt;br /&gt;
    timeout server 30000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 6: SSL Certificate for HAProxy ==&lt;br /&gt;
Generate or copy your SSL certificate and key as `/home/sdnog/lab/cert.pem` (or another path if you adjust your config).&lt;br /&gt;
&lt;br /&gt;
== Step 7: Restart and Enable HAProxy ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart haproxy&lt;br /&gt;
sudo systemctl enable haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 8: Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Web Load Balancing ===&lt;br /&gt;
Test the round-robin backend selection:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -I https://www.lab.sdnog.sd | grep SERVERID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see alternating results like:&lt;br /&gt;
  set-cookie: SERVERID=web01; path=/&lt;br /&gt;
  set-cookie: SERVERID=web02; path=/&lt;br /&gt;
&lt;br /&gt;
See for example output.&lt;br /&gt;
&lt;br /&gt;
[[File:Web servrs test.png|thumb|center|Web test ]]&lt;br /&gt;
&lt;br /&gt;
=== Database Load Balancing ===&lt;br /&gt;
Test DB backend switching:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql -u sdnoguser -p -h db.lab.sdnog.sd -e &amp;quot;show variables like 'hostname';&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see the hostname alternating between `db01.lab.sdnog.sd` and `db02.lab.sdnog.sd` &lt;br /&gt;
&lt;br /&gt;
[[File:DB loadbalancer test.png|thumb|center|Layer 4 loadbalancing ]]&lt;br /&gt;
&lt;br /&gt;
=== HAProxy Stats Page ===&lt;br /&gt;
Browse to: http://lb.lab.sdnog.sd:8080/stats  &lt;br /&gt;
 for an example:&lt;br /&gt;
&lt;br /&gt;
[[File:Stats page.png|thumb|center]]&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not already in use.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Make sure Apache/Nginx/MySQL are running on their respective servers.&lt;br /&gt;
#* Check firewall rules (UFW, iptables, or cloud security groups) to allow traffic between HAProxy and backend nodes.&lt;br /&gt;
#* Confirm the correct backend IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the certificate and private key path in your HAProxy config.&lt;br /&gt;
#* Ensure your `.pem` file has correct permissions and the combined format (cert + key).&lt;br /&gt;
&lt;br /&gt;
# '''ACLs/routing not working as expected:'''&lt;br /&gt;
#* Verify that your local `/etc/hosts` or DNS is configured for the lab domains.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect HTTP headers if needed.&lt;br /&gt;
&lt;br /&gt;
# '''Stats page not accessible:'''&lt;br /&gt;
#* Confirm the `listen stats` block in your config.&lt;br /&gt;
#* Make sure port 8080 is open on the HAProxy machine and not blocked by a firewall.&lt;br /&gt;
&lt;br /&gt;
# '''MySQL authentication errors:'''&lt;br /&gt;
#* Ensure user/password is the same on all DB nodes.&lt;br /&gt;
#* Make sure MySQL is listening on 0.0.0.0 or the correct interface.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` and `defaults` sections based on your hardware.&lt;br /&gt;
# '''Enable kernel TCP keepalive:'''&lt;br /&gt;
#* Add `option tcpka` in the `defaults` section if needed.&lt;br /&gt;
# '''Enable HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bind *:443 ssl crt /home/sdnog/lab/cert.pem alpn h2,http/1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider using Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Use strong, unique passwords everywhere'''&lt;br /&gt;
# '''Restrict access to MySQL ports via firewall'''&lt;br /&gt;
# '''Change the HAProxy stats password from the default'''&lt;br /&gt;
# '''Limit access to stats page by IP if possible'''&lt;br /&gt;
# '''Implement strong SSL/TLS settings, disable weak protocols'''&lt;br /&gt;
# '''Consider a Web Application Firewall (WAF) for production'''&lt;br /&gt;
# '''Audit configuration and access logs regularly'''&lt;br /&gt;
&lt;br /&gt;
== Appendix: Useful Commands ==&lt;br /&gt;
&lt;br /&gt;
* Check HAProxy config: &amp;lt;pre&amp;gt;haproxy -c -f /etc/haproxy/haproxy.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart HAProxy: &amp;lt;pre&amp;gt;sudo systemctl restart haproxy&amp;lt;/pre&amp;gt;&lt;br /&gt;
* View HAProxy logs: &amp;lt;pre&amp;gt;sudo tail -f /var/log/haproxy.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test backend health: &amp;lt;pre&amp;gt;curl http://web01.lab.sdnog.sd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
* '''Author''': [[User:Manhal.Mohamed|Manhal Mohamed]] , SdNOG Team&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
''This guide is based on practical deployment, tested with Ubuntu 22.04+. For additional features and advanced security, consult the [https://www.haproxy.org/ HAProxy documentation].''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2340</id>
		<title>HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition)</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2340"/>
		<updated>2025-07-18T15:24:01Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Database Load Balancing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition) =&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This guide documents the setup of HAProxy on Ubuntu servers for load balancing web (HTTP/HTTPS) and MySQL database traffic, using the `sdnog.sd` lab domain. The environment includes multiple backend nodes and complete instructions for configuration, testing, and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3+ Ubuntu servers/VMs: 1 for HAProxy (load balancer), at least 2 for web/database backends.&lt;br /&gt;
* Domain names:&lt;br /&gt;
  * `lb.lab.sdnog.sd` (HAProxy/load balancer)&lt;br /&gt;
  * `www.lab.sdnog.sd`, `db.lab.sdnog.sd`, `lb.lab.sdnog.sd` (all pointing to the HAProxy IP)&lt;br /&gt;
  * Backends: `web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`&lt;br /&gt;
* Sudo/root access on all nodes.&lt;br /&gt;
* Ability to update `/etc/hosts` or your DNS zone for lab domains.&lt;br /&gt;
&lt;br /&gt;
== Local Hosts or DNS Configuration ==&lt;br /&gt;
Set the following entries on your local hosts file or DNS server, pointing to your HAProxy IP (`X.X.X.X`):&lt;br /&gt;
&lt;br /&gt;
  X.X.X.X lb.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X www.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X db.lab.sdnog.sd&lt;br /&gt;
&lt;br /&gt;
Backends (`web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`) should resolve to their actual server IPs.&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install HAProxy on Ubuntu ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update&lt;br /&gt;
sudo apt install haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install Web Servers on Backends ==&lt;br /&gt;
On `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`, install Nginx on one and Apache on another:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Nginx (on web01)&lt;br /&gt;
sudo apt install nginx&lt;br /&gt;
echo &amp;quot;This is web01.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&lt;br /&gt;
# Apache (on web02)&lt;br /&gt;
sudo apt install apache2&lt;br /&gt;
echo &amp;quot;This is web02.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install MySQL on Backends ==&lt;br /&gt;
On both `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install mysql-server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 4: Configure MySQL User for HAProxy ==&lt;br /&gt;
On both DB nodes (MySQL prompt):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE USER 'sdnoguser'@'%' IDENTIFIED BY 'sdnog@sd';&lt;br /&gt;
GRANT ALL PRIVILEGES ON *.* TO 'sdnoguser'@'%' WITH GRANT OPTION;&lt;br /&gt;
FLUSH PRIVILEGES;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 5: HAProxy Configuration for Web &amp;amp; Database Load Balancing ==&lt;br /&gt;
Edit `/etc/haproxy/haproxy.cfg` on the HAProxy server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log         127.0.0.1:514 local1 info&lt;br /&gt;
    maxconn     4000&lt;br /&gt;
    user        haproxy&lt;br /&gt;
    group       haproxy&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    mode                    http&lt;br /&gt;
    log                     global&lt;br /&gt;
    option                  httplog&lt;br /&gt;
    option                  dontlognull&lt;br /&gt;
    option                  forwardfor except 127.0.0.0/8&lt;br /&gt;
    option                  http-server-close&lt;br /&gt;
    retries                 3&lt;br /&gt;
    timeout http-request    10s&lt;br /&gt;
    timeout queue           1m&lt;br /&gt;
    timeout connect         10s&lt;br /&gt;
    timeout client          1m&lt;br /&gt;
    timeout server          1m&lt;br /&gt;
    timeout http-keep-alive 10s&lt;br /&gt;
    timeout check           10s&lt;br /&gt;
    maxconn                 3000&lt;br /&gt;
&lt;br /&gt;
frontend https-in&lt;br /&gt;
    bind *:443 ssl crt /home/sdnog/lab/cert.pem&lt;br /&gt;
    mode http&lt;br /&gt;
    acl host_lab_sdnog hdr(host) -i www.lab.sdnog.sd&lt;br /&gt;
    use_backend www_back if host_lab_sdnog&lt;br /&gt;
    default_backend www_back&lt;br /&gt;
&lt;br /&gt;
frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
backend www_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server nginx_server web01.lab.sdnog.sd:80 check cookie web01&lt;br /&gt;
    server apache_server web02.lab.sdnog.sd:80 check cookie web02&lt;br /&gt;
&lt;br /&gt;
frontend database_frontend&lt;br /&gt;
    bind *:3306&lt;br /&gt;
    mode tcp&lt;br /&gt;
    default_backend database_backend&lt;br /&gt;
&lt;br /&gt;
backend database_backend&lt;br /&gt;
    mode tcp&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    server db01 web01.lab.sdnog.sd:3306 check&lt;br /&gt;
    server db02 web02.lab.sdnog.sd:3306 check&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind 0.0.0.0:8080&lt;br /&gt;
    bind :::8080&lt;br /&gt;
    mode http&lt;br /&gt;
    stats uri /stats&lt;br /&gt;
    stats realm HAProxy\ Statistics&lt;br /&gt;
    stats auth admin:Sdnog@123&lt;br /&gt;
    stats admin if TRUE&lt;br /&gt;
    timeout client 5000&lt;br /&gt;
    timeout connect 4000&lt;br /&gt;
    timeout server 30000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 6: SSL Certificate for HAProxy ==&lt;br /&gt;
Generate or copy your SSL certificate and key as `/home/sdnog/lab/cert.pem` (or another path if you adjust your config).&lt;br /&gt;
&lt;br /&gt;
== Step 7: Restart and Enable HAProxy ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart haproxy&lt;br /&gt;
sudo systemctl enable haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 8: Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Web Load Balancing ===&lt;br /&gt;
Test the round-robin backend selection:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -I https://www.lab.sdnog.sd | grep SERVERID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see alternating results like:&lt;br /&gt;
  set-cookie: SERVERID=web01; path=/&lt;br /&gt;
  set-cookie: SERVERID=web02; path=/&lt;br /&gt;
&lt;br /&gt;
See for example output.&lt;br /&gt;
&lt;br /&gt;
[[File:Web servrs test.png|thumb|center|Web test ]]&lt;br /&gt;
&lt;br /&gt;
=== Database Load Balancing ===&lt;br /&gt;
Test DB backend switching:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql -u sdnoguser -p -h db.lab.sdnog.sd -e &amp;quot;show variables like 'hostname';&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see the hostname alternating between `db01.lab.sdnog.sd` and `db02.lab.sdnog.sd` (see [[File:image1]]).&lt;br /&gt;
&lt;br /&gt;
[[File:DB loadbalancer test.png|thumb|Layer 4 loadbalancing ]]&lt;br /&gt;
&lt;br /&gt;
=== HAProxy Stats Page ===&lt;br /&gt;
Browse to: http://lb.lab.sdnog.sd:8080/stats  &lt;br /&gt;
 for an example:&lt;br /&gt;
&lt;br /&gt;
[[File:Stats page.png|thumb|center]]&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not already in use.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Make sure Apache/Nginx/MySQL are running on their respective servers.&lt;br /&gt;
#* Check firewall rules (UFW, iptables, or cloud security groups) to allow traffic between HAProxy and backend nodes.&lt;br /&gt;
#* Confirm the correct backend IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the certificate and private key path in your HAProxy config.&lt;br /&gt;
#* Ensure your `.pem` file has correct permissions and the combined format (cert + key).&lt;br /&gt;
&lt;br /&gt;
# '''ACLs/routing not working as expected:'''&lt;br /&gt;
#* Verify that your local `/etc/hosts` or DNS is configured for the lab domains.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect HTTP headers if needed.&lt;br /&gt;
&lt;br /&gt;
# '''Stats page not accessible:'''&lt;br /&gt;
#* Confirm the `listen stats` block in your config.&lt;br /&gt;
#* Make sure port 8080 is open on the HAProxy machine and not blocked by a firewall.&lt;br /&gt;
&lt;br /&gt;
# '''MySQL authentication errors:'''&lt;br /&gt;
#* Ensure user/password is the same on all DB nodes.&lt;br /&gt;
#* Make sure MySQL is listening on 0.0.0.0 or the correct interface.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` and `defaults` sections based on your hardware.&lt;br /&gt;
# '''Enable kernel TCP keepalive:'''&lt;br /&gt;
#* Add `option tcpka` in the `defaults` section if needed.&lt;br /&gt;
# '''Enable HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bind *:443 ssl crt /home/sdnog/lab/cert.pem alpn h2,http/1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider using Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Use strong, unique passwords everywhere'''&lt;br /&gt;
# '''Restrict access to MySQL ports via firewall'''&lt;br /&gt;
# '''Change the HAProxy stats password from the default'''&lt;br /&gt;
# '''Limit access to stats page by IP if possible'''&lt;br /&gt;
# '''Implement strong SSL/TLS settings, disable weak protocols'''&lt;br /&gt;
# '''Consider a Web Application Firewall (WAF) for production'''&lt;br /&gt;
# '''Audit configuration and access logs regularly'''&lt;br /&gt;
&lt;br /&gt;
== Appendix: Useful Commands ==&lt;br /&gt;
&lt;br /&gt;
* Check HAProxy config: &amp;lt;pre&amp;gt;haproxy -c -f /etc/haproxy/haproxy.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart HAProxy: &amp;lt;pre&amp;gt;sudo systemctl restart haproxy&amp;lt;/pre&amp;gt;&lt;br /&gt;
* View HAProxy logs: &amp;lt;pre&amp;gt;sudo tail -f /var/log/haproxy.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test backend health: &amp;lt;pre&amp;gt;curl http://web01.lab.sdnog.sd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
* '''Author''': [[User:Manhal.Mohamed|Manhal Mohamed]] , SdNOG Team&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
''This guide is based on practical deployment, tested with Ubuntu 22.04+. For additional features and advanced security, consult the [https://www.haproxy.org/ HAProxy documentation].''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2339</id>
		<title>HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition)</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2339"/>
		<updated>2025-07-18T15:21:12Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Web Load Balancing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition) =&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This guide documents the setup of HAProxy on Ubuntu servers for load balancing web (HTTP/HTTPS) and MySQL database traffic, using the `sdnog.sd` lab domain. The environment includes multiple backend nodes and complete instructions for configuration, testing, and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3+ Ubuntu servers/VMs: 1 for HAProxy (load balancer), at least 2 for web/database backends.&lt;br /&gt;
* Domain names:&lt;br /&gt;
  * `lb.lab.sdnog.sd` (HAProxy/load balancer)&lt;br /&gt;
  * `www.lab.sdnog.sd`, `db.lab.sdnog.sd`, `lb.lab.sdnog.sd` (all pointing to the HAProxy IP)&lt;br /&gt;
  * Backends: `web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`&lt;br /&gt;
* Sudo/root access on all nodes.&lt;br /&gt;
* Ability to update `/etc/hosts` or your DNS zone for lab domains.&lt;br /&gt;
&lt;br /&gt;
== Local Hosts or DNS Configuration ==&lt;br /&gt;
Set the following entries on your local hosts file or DNS server, pointing to your HAProxy IP (`X.X.X.X`):&lt;br /&gt;
&lt;br /&gt;
  X.X.X.X lb.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X www.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X db.lab.sdnog.sd&lt;br /&gt;
&lt;br /&gt;
Backends (`web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`) should resolve to their actual server IPs.&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install HAProxy on Ubuntu ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update&lt;br /&gt;
sudo apt install haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install Web Servers on Backends ==&lt;br /&gt;
On `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`, install Nginx on one and Apache on another:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Nginx (on web01)&lt;br /&gt;
sudo apt install nginx&lt;br /&gt;
echo &amp;quot;This is web01.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&lt;br /&gt;
# Apache (on web02)&lt;br /&gt;
sudo apt install apache2&lt;br /&gt;
echo &amp;quot;This is web02.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install MySQL on Backends ==&lt;br /&gt;
On both `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install mysql-server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 4: Configure MySQL User for HAProxy ==&lt;br /&gt;
On both DB nodes (MySQL prompt):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE USER 'sdnoguser'@'%' IDENTIFIED BY 'sdnog@sd';&lt;br /&gt;
GRANT ALL PRIVILEGES ON *.* TO 'sdnoguser'@'%' WITH GRANT OPTION;&lt;br /&gt;
FLUSH PRIVILEGES;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 5: HAProxy Configuration for Web &amp;amp; Database Load Balancing ==&lt;br /&gt;
Edit `/etc/haproxy/haproxy.cfg` on the HAProxy server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log         127.0.0.1:514 local1 info&lt;br /&gt;
    maxconn     4000&lt;br /&gt;
    user        haproxy&lt;br /&gt;
    group       haproxy&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    mode                    http&lt;br /&gt;
    log                     global&lt;br /&gt;
    option                  httplog&lt;br /&gt;
    option                  dontlognull&lt;br /&gt;
    option                  forwardfor except 127.0.0.0/8&lt;br /&gt;
    option                  http-server-close&lt;br /&gt;
    retries                 3&lt;br /&gt;
    timeout http-request    10s&lt;br /&gt;
    timeout queue           1m&lt;br /&gt;
    timeout connect         10s&lt;br /&gt;
    timeout client          1m&lt;br /&gt;
    timeout server          1m&lt;br /&gt;
    timeout http-keep-alive 10s&lt;br /&gt;
    timeout check           10s&lt;br /&gt;
    maxconn                 3000&lt;br /&gt;
&lt;br /&gt;
frontend https-in&lt;br /&gt;
    bind *:443 ssl crt /home/sdnog/lab/cert.pem&lt;br /&gt;
    mode http&lt;br /&gt;
    acl host_lab_sdnog hdr(host) -i www.lab.sdnog.sd&lt;br /&gt;
    use_backend www_back if host_lab_sdnog&lt;br /&gt;
    default_backend www_back&lt;br /&gt;
&lt;br /&gt;
frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
backend www_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server nginx_server web01.lab.sdnog.sd:80 check cookie web01&lt;br /&gt;
    server apache_server web02.lab.sdnog.sd:80 check cookie web02&lt;br /&gt;
&lt;br /&gt;
frontend database_frontend&lt;br /&gt;
    bind *:3306&lt;br /&gt;
    mode tcp&lt;br /&gt;
    default_backend database_backend&lt;br /&gt;
&lt;br /&gt;
backend database_backend&lt;br /&gt;
    mode tcp&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    server db01 web01.lab.sdnog.sd:3306 check&lt;br /&gt;
    server db02 web02.lab.sdnog.sd:3306 check&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind 0.0.0.0:8080&lt;br /&gt;
    bind :::8080&lt;br /&gt;
    mode http&lt;br /&gt;
    stats uri /stats&lt;br /&gt;
    stats realm HAProxy\ Statistics&lt;br /&gt;
    stats auth admin:Sdnog@123&lt;br /&gt;
    stats admin if TRUE&lt;br /&gt;
    timeout client 5000&lt;br /&gt;
    timeout connect 4000&lt;br /&gt;
    timeout server 30000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 6: SSL Certificate for HAProxy ==&lt;br /&gt;
Generate or copy your SSL certificate and key as `/home/sdnog/lab/cert.pem` (or another path if you adjust your config).&lt;br /&gt;
&lt;br /&gt;
== Step 7: Restart and Enable HAProxy ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart haproxy&lt;br /&gt;
sudo systemctl enable haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 8: Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Web Load Balancing ===&lt;br /&gt;
Test the round-robin backend selection:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -I https://www.lab.sdnog.sd | grep SERVERID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see alternating results like:&lt;br /&gt;
  set-cookie: SERVERID=web01; path=/&lt;br /&gt;
  set-cookie: SERVERID=web02; path=/&lt;br /&gt;
&lt;br /&gt;
See for example output.&lt;br /&gt;
&lt;br /&gt;
[[File:Web servrs test.png|thumb|center|Web test ]]&lt;br /&gt;
&lt;br /&gt;
=== Database Load Balancing ===&lt;br /&gt;
Test DB backend switching:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql -u sdnoguser -p -h db.lab.sdnog.sd -e &amp;quot;show variables like 'hostname';&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see the hostname alternating between `db01.lab.sdnog.sd` and `db02.lab.sdnog.sd` (see [[File:image1]]).&lt;br /&gt;
&lt;br /&gt;
=== HAProxy Stats Page ===&lt;br /&gt;
Browse to: http://lb.lab.sdnog.sd:8080/stats  &lt;br /&gt;
 for an example:&lt;br /&gt;
&lt;br /&gt;
[[File:Stats page.png|thumb|center]]&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not already in use.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Make sure Apache/Nginx/MySQL are running on their respective servers.&lt;br /&gt;
#* Check firewall rules (UFW, iptables, or cloud security groups) to allow traffic between HAProxy and backend nodes.&lt;br /&gt;
#* Confirm the correct backend IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the certificate and private key path in your HAProxy config.&lt;br /&gt;
#* Ensure your `.pem` file has correct permissions and the combined format (cert + key).&lt;br /&gt;
&lt;br /&gt;
# '''ACLs/routing not working as expected:'''&lt;br /&gt;
#* Verify that your local `/etc/hosts` or DNS is configured for the lab domains.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect HTTP headers if needed.&lt;br /&gt;
&lt;br /&gt;
# '''Stats page not accessible:'''&lt;br /&gt;
#* Confirm the `listen stats` block in your config.&lt;br /&gt;
#* Make sure port 8080 is open on the HAProxy machine and not blocked by a firewall.&lt;br /&gt;
&lt;br /&gt;
# '''MySQL authentication errors:'''&lt;br /&gt;
#* Ensure user/password is the same on all DB nodes.&lt;br /&gt;
#* Make sure MySQL is listening on 0.0.0.0 or the correct interface.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` and `defaults` sections based on your hardware.&lt;br /&gt;
# '''Enable kernel TCP keepalive:'''&lt;br /&gt;
#* Add `option tcpka` in the `defaults` section if needed.&lt;br /&gt;
# '''Enable HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bind *:443 ssl crt /home/sdnog/lab/cert.pem alpn h2,http/1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider using Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Use strong, unique passwords everywhere'''&lt;br /&gt;
# '''Restrict access to MySQL ports via firewall'''&lt;br /&gt;
# '''Change the HAProxy stats password from the default'''&lt;br /&gt;
# '''Limit access to stats page by IP if possible'''&lt;br /&gt;
# '''Implement strong SSL/TLS settings, disable weak protocols'''&lt;br /&gt;
# '''Consider a Web Application Firewall (WAF) for production'''&lt;br /&gt;
# '''Audit configuration and access logs regularly'''&lt;br /&gt;
&lt;br /&gt;
== Appendix: Useful Commands ==&lt;br /&gt;
&lt;br /&gt;
* Check HAProxy config: &amp;lt;pre&amp;gt;haproxy -c -f /etc/haproxy/haproxy.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart HAProxy: &amp;lt;pre&amp;gt;sudo systemctl restart haproxy&amp;lt;/pre&amp;gt;&lt;br /&gt;
* View HAProxy logs: &amp;lt;pre&amp;gt;sudo tail -f /var/log/haproxy.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test backend health: &amp;lt;pre&amp;gt;curl http://web01.lab.sdnog.sd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
* '''Author''': [[User:Manhal.Mohamed|Manhal Mohamed]] , SdNOG Team&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
''This guide is based on practical deployment, tested with Ubuntu 22.04+. For additional features and advanced security, consult the [https://www.haproxy.org/ HAProxy documentation].''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=File:Web_servrs_test.png&amp;diff=2338</id>
		<title>File:Web servrs test.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=File:Web_servrs_test.png&amp;diff=2338"/>
		<updated>2025-07-18T15:21:00Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Web servers test&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2337</id>
		<title>HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition)</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2337"/>
		<updated>2025-07-18T15:19:11Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition) =&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This guide documents the setup of HAProxy on Ubuntu servers for load balancing web (HTTP/HTTPS) and MySQL database traffic, using the `sdnog.sd` lab domain. The environment includes multiple backend nodes and complete instructions for configuration, testing, and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3+ Ubuntu servers/VMs: 1 for HAProxy (load balancer), at least 2 for web/database backends.&lt;br /&gt;
* Domain names:&lt;br /&gt;
  * `lb.lab.sdnog.sd` (HAProxy/load balancer)&lt;br /&gt;
  * `www.lab.sdnog.sd`, `db.lab.sdnog.sd`, `lb.lab.sdnog.sd` (all pointing to the HAProxy IP)&lt;br /&gt;
  * Backends: `web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`&lt;br /&gt;
* Sudo/root access on all nodes.&lt;br /&gt;
* Ability to update `/etc/hosts` or your DNS zone for lab domains.&lt;br /&gt;
&lt;br /&gt;
== Local Hosts or DNS Configuration ==&lt;br /&gt;
Set the following entries on your local hosts file or DNS server, pointing to your HAProxy IP (`X.X.X.X`):&lt;br /&gt;
&lt;br /&gt;
  X.X.X.X lb.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X www.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X db.lab.sdnog.sd&lt;br /&gt;
&lt;br /&gt;
Backends (`web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`) should resolve to their actual server IPs.&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install HAProxy on Ubuntu ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update&lt;br /&gt;
sudo apt install haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install Web Servers on Backends ==&lt;br /&gt;
On `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`, install Nginx on one and Apache on another:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Nginx (on web01)&lt;br /&gt;
sudo apt install nginx&lt;br /&gt;
echo &amp;quot;This is web01.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&lt;br /&gt;
# Apache (on web02)&lt;br /&gt;
sudo apt install apache2&lt;br /&gt;
echo &amp;quot;This is web02.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install MySQL on Backends ==&lt;br /&gt;
On both `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install mysql-server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 4: Configure MySQL User for HAProxy ==&lt;br /&gt;
On both DB nodes (MySQL prompt):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE USER 'sdnoguser'@'%' IDENTIFIED BY 'sdnog@sd';&lt;br /&gt;
GRANT ALL PRIVILEGES ON *.* TO 'sdnoguser'@'%' WITH GRANT OPTION;&lt;br /&gt;
FLUSH PRIVILEGES;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 5: HAProxy Configuration for Web &amp;amp; Database Load Balancing ==&lt;br /&gt;
Edit `/etc/haproxy/haproxy.cfg` on the HAProxy server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log         127.0.0.1:514 local1 info&lt;br /&gt;
    maxconn     4000&lt;br /&gt;
    user        haproxy&lt;br /&gt;
    group       haproxy&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    mode                    http&lt;br /&gt;
    log                     global&lt;br /&gt;
    option                  httplog&lt;br /&gt;
    option                  dontlognull&lt;br /&gt;
    option                  forwardfor except 127.0.0.0/8&lt;br /&gt;
    option                  http-server-close&lt;br /&gt;
    retries                 3&lt;br /&gt;
    timeout http-request    10s&lt;br /&gt;
    timeout queue           1m&lt;br /&gt;
    timeout connect         10s&lt;br /&gt;
    timeout client          1m&lt;br /&gt;
    timeout server          1m&lt;br /&gt;
    timeout http-keep-alive 10s&lt;br /&gt;
    timeout check           10s&lt;br /&gt;
    maxconn                 3000&lt;br /&gt;
&lt;br /&gt;
frontend https-in&lt;br /&gt;
    bind *:443 ssl crt /home/sdnog/lab/cert.pem&lt;br /&gt;
    mode http&lt;br /&gt;
    acl host_lab_sdnog hdr(host) -i www.lab.sdnog.sd&lt;br /&gt;
    use_backend www_back if host_lab_sdnog&lt;br /&gt;
    default_backend www_back&lt;br /&gt;
&lt;br /&gt;
frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
backend www_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server nginx_server web01.lab.sdnog.sd:80 check cookie web01&lt;br /&gt;
    server apache_server web02.lab.sdnog.sd:80 check cookie web02&lt;br /&gt;
&lt;br /&gt;
frontend database_frontend&lt;br /&gt;
    bind *:3306&lt;br /&gt;
    mode tcp&lt;br /&gt;
    default_backend database_backend&lt;br /&gt;
&lt;br /&gt;
backend database_backend&lt;br /&gt;
    mode tcp&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    server db01 web01.lab.sdnog.sd:3306 check&lt;br /&gt;
    server db02 web02.lab.sdnog.sd:3306 check&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind 0.0.0.0:8080&lt;br /&gt;
    bind :::8080&lt;br /&gt;
    mode http&lt;br /&gt;
    stats uri /stats&lt;br /&gt;
    stats realm HAProxy\ Statistics&lt;br /&gt;
    stats auth admin:Sdnog@123&lt;br /&gt;
    stats admin if TRUE&lt;br /&gt;
    timeout client 5000&lt;br /&gt;
    timeout connect 4000&lt;br /&gt;
    timeout server 30000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 6: SSL Certificate for HAProxy ==&lt;br /&gt;
Generate or copy your SSL certificate and key as `/home/sdnog/lab/cert.pem` (or another path if you adjust your config).&lt;br /&gt;
&lt;br /&gt;
== Step 7: Restart and Enable HAProxy ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart haproxy&lt;br /&gt;
sudo systemctl enable haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 8: Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Web Load Balancing ===&lt;br /&gt;
Test the round-robin backend selection:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -I https://www.lab.sdnog.sd | grep SERVERID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see alternating results like:&lt;br /&gt;
  set-cookie: SERVERID=web01; path=/&lt;br /&gt;
  set-cookie: SERVERID=web02; path=/&lt;br /&gt;
&lt;br /&gt;
See [[File:image3]] for example output.&lt;br /&gt;
&lt;br /&gt;
=== Database Load Balancing ===&lt;br /&gt;
Test DB backend switching:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql -u sdnoguser -p -h db.lab.sdnog.sd -e &amp;quot;show variables like 'hostname';&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see the hostname alternating between `db01.lab.sdnog.sd` and `db02.lab.sdnog.sd` (see [[File:image1]]).&lt;br /&gt;
&lt;br /&gt;
=== HAProxy Stats Page ===&lt;br /&gt;
Browse to: http://lb.lab.sdnog.sd:8080/stats  &lt;br /&gt;
 for an example:&lt;br /&gt;
&lt;br /&gt;
[[File:Stats page.png|thumb|center]]&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not already in use.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Make sure Apache/Nginx/MySQL are running on their respective servers.&lt;br /&gt;
#* Check firewall rules (UFW, iptables, or cloud security groups) to allow traffic between HAProxy and backend nodes.&lt;br /&gt;
#* Confirm the correct backend IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the certificate and private key path in your HAProxy config.&lt;br /&gt;
#* Ensure your `.pem` file has correct permissions and the combined format (cert + key).&lt;br /&gt;
&lt;br /&gt;
# '''ACLs/routing not working as expected:'''&lt;br /&gt;
#* Verify that your local `/etc/hosts` or DNS is configured for the lab domains.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect HTTP headers if needed.&lt;br /&gt;
&lt;br /&gt;
# '''Stats page not accessible:'''&lt;br /&gt;
#* Confirm the `listen stats` block in your config.&lt;br /&gt;
#* Make sure port 8080 is open on the HAProxy machine and not blocked by a firewall.&lt;br /&gt;
&lt;br /&gt;
# '''MySQL authentication errors:'''&lt;br /&gt;
#* Ensure user/password is the same on all DB nodes.&lt;br /&gt;
#* Make sure MySQL is listening on 0.0.0.0 or the correct interface.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` and `defaults` sections based on your hardware.&lt;br /&gt;
# '''Enable kernel TCP keepalive:'''&lt;br /&gt;
#* Add `option tcpka` in the `defaults` section if needed.&lt;br /&gt;
# '''Enable HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bind *:443 ssl crt /home/sdnog/lab/cert.pem alpn h2,http/1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider using Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Use strong, unique passwords everywhere'''&lt;br /&gt;
# '''Restrict access to MySQL ports via firewall'''&lt;br /&gt;
# '''Change the HAProxy stats password from the default'''&lt;br /&gt;
# '''Limit access to stats page by IP if possible'''&lt;br /&gt;
# '''Implement strong SSL/TLS settings, disable weak protocols'''&lt;br /&gt;
# '''Consider a Web Application Firewall (WAF) for production'''&lt;br /&gt;
# '''Audit configuration and access logs regularly'''&lt;br /&gt;
&lt;br /&gt;
== Appendix: Useful Commands ==&lt;br /&gt;
&lt;br /&gt;
* Check HAProxy config: &amp;lt;pre&amp;gt;haproxy -c -f /etc/haproxy/haproxy.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart HAProxy: &amp;lt;pre&amp;gt;sudo systemctl restart haproxy&amp;lt;/pre&amp;gt;&lt;br /&gt;
* View HAProxy logs: &amp;lt;pre&amp;gt;sudo tail -f /var/log/haproxy.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test backend health: &amp;lt;pre&amp;gt;curl http://web01.lab.sdnog.sd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
* '''Author''': [[User:Manhal.Mohamed|Manhal Mohamed]] , SdNOG Team&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
''This guide is based on practical deployment, tested with Ubuntu 22.04+. For additional features and advanced security, consult the [https://www.haproxy.org/ HAProxy documentation].''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=File:Stats_page.png&amp;diff=2336</id>
		<title>File:Stats page.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=File:Stats_page.png&amp;diff=2336"/>
		<updated>2025-07-18T15:18:56Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;stats page&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=File:DB_loadbalancer_test.png&amp;diff=2335</id>
		<title>File:DB loadbalancer test.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=File:DB_loadbalancer_test.png&amp;diff=2335"/>
		<updated>2025-07-18T15:17:08Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;DB test&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2334</id>
		<title>HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition)</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_%E2%80%93_Ubuntu-Based_Multi-Node_Setup_(sdnog_Edition)&amp;diff=2334"/>
		<updated>2025-07-18T15:16:12Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: Created page with &amp;quot;= HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition) =  == Overview == This guide documents the setup of HAProxy on Ubuntu servers for load balancing we...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition) =&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
This guide documents the setup of HAProxy on Ubuntu servers for load balancing web (HTTP/HTTPS) and MySQL database traffic, using the `sdnog.sd` lab domain. The environment includes multiple backend nodes and complete instructions for configuration, testing, and troubleshooting.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3+ Ubuntu servers/VMs: 1 for HAProxy (load balancer), at least 2 for web/database backends.&lt;br /&gt;
* Domain names:&lt;br /&gt;
  * `lb.lab.sdnog.sd` (HAProxy/load balancer)&lt;br /&gt;
  * `www.lab.sdnog.sd`, `db.lab.sdnog.sd`, `lb.lab.sdnog.sd` (all pointing to the HAProxy IP)&lt;br /&gt;
  * Backends: `web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`&lt;br /&gt;
* Sudo/root access on all nodes.&lt;br /&gt;
* Ability to update `/etc/hosts` or your DNS zone for lab domains.&lt;br /&gt;
* Reference Images:&lt;br /&gt;
  * [[File:image1|Database Test Output]]&lt;br /&gt;
  * [[File:image2|HAProxy Stats Page]]&lt;br /&gt;
  * [[File:image3|Web Backend Cookie Test]]&lt;br /&gt;
&lt;br /&gt;
== Local Hosts or DNS Configuration ==&lt;br /&gt;
Set the following entries on your local hosts file or DNS server, pointing to your HAProxy IP (`X.X.X.X`):&lt;br /&gt;
&lt;br /&gt;
  X.X.X.X lb.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X www.lab.sdnog.sd&lt;br /&gt;
  X.X.X.X db.lab.sdnog.sd&lt;br /&gt;
&lt;br /&gt;
Backends (`web01.lab.sdnog.sd`, `web02.lab.sdnog.sd`) should resolve to their actual server IPs.&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install HAProxy on Ubuntu ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update&lt;br /&gt;
sudo apt install haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install Web Servers on Backends ==&lt;br /&gt;
On `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`, install Nginx on one and Apache on another:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Nginx (on web01)&lt;br /&gt;
sudo apt install nginx&lt;br /&gt;
echo &amp;quot;This is web01.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&lt;br /&gt;
# Apache (on web02)&lt;br /&gt;
sudo apt install apache2&lt;br /&gt;
echo &amp;quot;This is web02.lab.sdnog.sd&amp;quot; | sudo tee /var/www/html/index.html&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install MySQL on Backends ==&lt;br /&gt;
On both `web01.lab.sdnog.sd` and `web02.lab.sdnog.sd`:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt install mysql-server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 4: Configure MySQL User for HAProxy ==&lt;br /&gt;
On both DB nodes (MySQL prompt):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE USER 'sdnoguser'@'%' IDENTIFIED BY 'sdnog@sd';&lt;br /&gt;
GRANT ALL PRIVILEGES ON *.* TO 'sdnoguser'@'%' WITH GRANT OPTION;&lt;br /&gt;
FLUSH PRIVILEGES;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 5: HAProxy Configuration for Web &amp;amp; Database Load Balancing ==&lt;br /&gt;
Edit `/etc/haproxy/haproxy.cfg` on the HAProxy server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
global&lt;br /&gt;
    log         127.0.0.1:514 local1 info&lt;br /&gt;
    maxconn     4000&lt;br /&gt;
    user        haproxy&lt;br /&gt;
    group       haproxy&lt;br /&gt;
&lt;br /&gt;
defaults&lt;br /&gt;
    mode                    http&lt;br /&gt;
    log                     global&lt;br /&gt;
    option                  httplog&lt;br /&gt;
    option                  dontlognull&lt;br /&gt;
    option                  forwardfor except 127.0.0.0/8&lt;br /&gt;
    option                  http-server-close&lt;br /&gt;
    retries                 3&lt;br /&gt;
    timeout http-request    10s&lt;br /&gt;
    timeout queue           1m&lt;br /&gt;
    timeout connect         10s&lt;br /&gt;
    timeout client          1m&lt;br /&gt;
    timeout server          1m&lt;br /&gt;
    timeout http-keep-alive 10s&lt;br /&gt;
    timeout check           10s&lt;br /&gt;
    maxconn                 3000&lt;br /&gt;
&lt;br /&gt;
frontend https-in&lt;br /&gt;
    bind *:443 ssl crt /home/sdnog/lab/cert.pem&lt;br /&gt;
    mode http&lt;br /&gt;
    acl host_lab_sdnog hdr(host) -i www.lab.sdnog.sd&lt;br /&gt;
    use_backend www_back if host_lab_sdnog&lt;br /&gt;
    default_backend www_back&lt;br /&gt;
&lt;br /&gt;
frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
backend www_back&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    cookie SERVERID insert indirect nocache&lt;br /&gt;
    server nginx_server web01.lab.sdnog.sd:80 check cookie web01&lt;br /&gt;
    server apache_server web02.lab.sdnog.sd:80 check cookie web02&lt;br /&gt;
&lt;br /&gt;
frontend database_frontend&lt;br /&gt;
    bind *:3306&lt;br /&gt;
    mode tcp&lt;br /&gt;
    default_backend database_backend&lt;br /&gt;
&lt;br /&gt;
backend database_backend&lt;br /&gt;
    mode tcp&lt;br /&gt;
    balance roundrobin&lt;br /&gt;
    server db01 web01.lab.sdnog.sd:3306 check&lt;br /&gt;
    server db02 web02.lab.sdnog.sd:3306 check&lt;br /&gt;
&lt;br /&gt;
listen stats&lt;br /&gt;
    bind 0.0.0.0:8080&lt;br /&gt;
    bind :::8080&lt;br /&gt;
    mode http&lt;br /&gt;
    stats uri /stats&lt;br /&gt;
    stats realm HAProxy\ Statistics&lt;br /&gt;
    stats auth admin:Sdnog@123&lt;br /&gt;
    stats admin if TRUE&lt;br /&gt;
    timeout client 5000&lt;br /&gt;
    timeout connect 4000&lt;br /&gt;
    timeout server 30000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 6: SSL Certificate for HAProxy ==&lt;br /&gt;
Generate or copy your SSL certificate and key as `/home/sdnog/lab/cert.pem` (or another path if you adjust your config).&lt;br /&gt;
&lt;br /&gt;
== Step 7: Restart and Enable HAProxy ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo systemctl restart haproxy&lt;br /&gt;
sudo systemctl enable haproxy&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 8: Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Web Load Balancing ===&lt;br /&gt;
Test the round-robin backend selection:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
curl -I https://www.lab.sdnog.sd | grep SERVERID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see alternating results like:&lt;br /&gt;
  set-cookie: SERVERID=web01; path=/&lt;br /&gt;
  set-cookie: SERVERID=web02; path=/&lt;br /&gt;
&lt;br /&gt;
See [[File:image3]] for example output.&lt;br /&gt;
&lt;br /&gt;
=== Database Load Balancing ===&lt;br /&gt;
Test DB backend switching:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql -u sdnoguser -p -h db.lab.sdnog.sd -e &amp;quot;show variables like 'hostname';&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see the hostname alternating between `db01.lab.sdnog.sd` and `db02.lab.sdnog.sd` (see [[File:image1]]).&lt;br /&gt;
&lt;br /&gt;
=== HAProxy Stats Page ===&lt;br /&gt;
Browse to: http://lb.lab.sdnog.sd:8080/stats  &lt;br /&gt;
See [[File:image2]] for an example.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not already in use.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Make sure Apache/Nginx/MySQL are running on their respective servers.&lt;br /&gt;
#* Check firewall rules (UFW, iptables, or cloud security groups) to allow traffic between HAProxy and backend nodes.&lt;br /&gt;
#* Confirm the correct backend IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the certificate and private key path in your HAProxy config.&lt;br /&gt;
#* Ensure your `.pem` file has correct permissions and the combined format (cert + key).&lt;br /&gt;
&lt;br /&gt;
# '''ACLs/routing not working as expected:'''&lt;br /&gt;
#* Verify that your local `/etc/hosts` or DNS is configured for the lab domains.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect HTTP headers if needed.&lt;br /&gt;
&lt;br /&gt;
# '''Stats page not accessible:'''&lt;br /&gt;
#* Confirm the `listen stats` block in your config.&lt;br /&gt;
#* Make sure port 8080 is open on the HAProxy machine and not blocked by a firewall.&lt;br /&gt;
&lt;br /&gt;
# '''MySQL authentication errors:'''&lt;br /&gt;
#* Ensure user/password is the same on all DB nodes.&lt;br /&gt;
#* Make sure MySQL is listening on 0.0.0.0 or the correct interface.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` and `defaults` sections based on your hardware.&lt;br /&gt;
# '''Enable kernel TCP keepalive:'''&lt;br /&gt;
#* Add `option tcpka` in the `defaults` section if needed.&lt;br /&gt;
# '''Enable HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bind *:443 ssl crt /home/sdnog/lab/cert.pem alpn h2,http/1.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider using Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Use strong, unique passwords everywhere'''&lt;br /&gt;
# '''Restrict access to MySQL ports via firewall'''&lt;br /&gt;
# '''Change the HAProxy stats password from the default'''&lt;br /&gt;
# '''Limit access to stats page by IP if possible'''&lt;br /&gt;
# '''Implement strong SSL/TLS settings, disable weak protocols'''&lt;br /&gt;
# '''Consider a Web Application Firewall (WAF) for production'''&lt;br /&gt;
# '''Audit configuration and access logs regularly'''&lt;br /&gt;
&lt;br /&gt;
== Appendix: Useful Commands ==&lt;br /&gt;
&lt;br /&gt;
* Check HAProxy config: &amp;lt;pre&amp;gt;haproxy -c -f /etc/haproxy/haproxy.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Restart HAProxy: &amp;lt;pre&amp;gt;sudo systemctl restart haproxy&amp;lt;/pre&amp;gt;&lt;br /&gt;
* View HAProxy logs: &amp;lt;pre&amp;gt;sudo tail -f /var/log/haproxy.log&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Test backend health: &amp;lt;pre&amp;gt;curl http://web01.lab.sdnog.sd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
* '''Author''': [[User:Manhal.Mohamed|Manhal Mohamed]] , SdNOG Team&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
''This guide is based on practical deployment, tested with Ubuntu 22.04+. For additional features and advanced security, consult the [https://www.haproxy.org/ HAProxy documentation].''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=Workshops_schedule&amp;diff=2333</id>
		<title>Workshops schedule</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=Workshops_schedule&amp;diff=2333"/>
		<updated>2025-07-18T15:15:12Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: SdNOG]]&lt;br /&gt;
[[Category: Events]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
Here is a list of completed [[SdNOG Workshops]] per year:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align: center;&amp;quot; | '''2015'''&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Management and Monitoring Workshop|Network Management and Monitoring]]&lt;br /&gt;
| 22-24 Dec. 2015&lt;br /&gt;
| -&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align: center;&amp;quot; | '''2016'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| Network Security Workshop&lt;br /&gt;
| 04-05 June 2016&lt;br /&gt;
| -&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align: center;&amp;quot; | '''2017'''&lt;br /&gt;
|-&lt;br /&gt;
| Virtualization Technology&lt;br /&gt;
| 11 Feb. 2017&lt;br /&gt;
| [https://drive.google.com/file/d/0BwP3tk9ZXn81bVZiWUhuYUZfX3M/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX Boot Camp|Unix Boot Camp]] Group1&lt;br /&gt;
| 25 Feb. 2017&lt;br /&gt;
| [https://drive.google.com/file/d/0BwP3tk9ZXn81MTlOOHpPbGNuOHc/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX Boot Camp|Unix Boot Camp]] Group2&lt;br /&gt;
| 04 March 2017&lt;br /&gt;
| [https://drive.google.com/file/d/0BwP3tk9ZXn81bDhsZHJBdnUyZ0k/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX Boot Camp|Unix Boot Camp]] Group3&lt;br /&gt;
| 11 March 2017&lt;br /&gt;
| [https://drive.google.com/file/d/0BwP3tk9ZXn81QUdaTjhGTktMWDA/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX Boot Camp|Unix Boot Camp]] Group4&lt;br /&gt;
| 18 March 2017&lt;br /&gt;
| [https://drive.google.com/file/d/0BwP3tk9ZXn81NXhUS01zSHdzZjA/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Networks Fundamental Workshop|Network Fundamental]] Group1&lt;br /&gt;
| 25 March 2017&lt;br /&gt;
| [https://drive.google.com/file/d/0BwP3tk9ZXn81dFhhZUF4bk9KdFU/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Networks Fundamental Workshop|Network Fundamental]] Group2&lt;br /&gt;
| 01 April 2017&lt;br /&gt;
| [https://drive.google.com/file/d/0BwP3tk9ZXn81cGVwTXVBQ04ybDA/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Networks Fundamental Workshop|Network Fundamental]] Group3&lt;br /&gt;
| 08 April 2017&lt;br /&gt;
| [https://drive.google.com/file/d/0BwP3tk9ZXn81M1lmRC1CN1lSX1k/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Networks Fundamental Workshop|Network Fundamental]] Group4&lt;br /&gt;
| 15 April 2017&lt;br /&gt;
| [https://drive.google.com/file/d/0BwP3tk9ZXn81QlVtX3FHcTlfZGc/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Networks Fundamental Workshop|Network Fundamental]] Group5&lt;br /&gt;
| 22 April 2017&lt;br /&gt;
| [https://drive.google.com/file/d/0BwP3tk9ZXn81Ni00T05odXdEcms/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Ethical Hacking Workshop|Ethical Hacking]] Group1&lt;br /&gt;
| 06 May 2017&lt;br /&gt;
| [https://drive.google.com/open?id=0BwP3tk9ZXn81Mm9scFJSOXNrQnc Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Ethical Hacking Workshop|Ethical Hacking]] Group2&lt;br /&gt;
| 13 May 2017&lt;br /&gt;
| [https://drive.google.com/open?id=0BwP3tk9ZXn81Mm9scFJSOXNrQnc Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[DNS Workshop|DNS workshop]] Group1&lt;br /&gt;
| 09 December 2017&lt;br /&gt;
| [https://drive.google.com/open?id=19uO-jfSmf0alVjF2z1jpsFvSSRk8uHGz Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[DNS Workshop|DNS workshop]] Group2&lt;br /&gt;
| 16 December 2017&lt;br /&gt;
| [https://drive.google.com/open?id=1U-XsMVY4ZaKYWXGlQLcKqS_ZjBOmJsHN Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[High Availability in LAMP Stack workshop|High Availability in LAMP Stack]]&lt;br /&gt;
| 23 December 2017&lt;br /&gt;
| [https://drive.google.com/open?id=1eWoUOrKOFPQfwWILhivbGOBWst2r15Nu Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align: center;&amp;quot; | '''2018'''&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| [[Internet Governance Forum]]&lt;br /&gt;
| 03 March 2018&lt;br /&gt;
| [https://drive.google.com/file/d/1WXnEuS3MCgHAKtTXkSyk7aZWkYU9Hqx5/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[IPv6 Fundamentals Workshop]]&lt;br /&gt;
| 17 March 2018&lt;br /&gt;
| [https://drive.google.com/open?id=1bK3CixvWexA1GA9cMN1XUAXH1v7GY_7O Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[DNS Workshop]]&lt;br /&gt;
| 31 March 2018&lt;br /&gt;
| [https://drive.google.com/open?id=1hcod4W6EinTuTRVzknQI69MNohLwI_tw Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX Boot Camp]]&lt;br /&gt;
| 07 April 2018&lt;br /&gt;
| [https://drive.google.com/open?id=1ySRjiyAOdPPzgo4qGrZZnKhGsDSfZPKe Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX Boot Camp]]&lt;br /&gt;
| 21 April 2018&lt;br /&gt;
| [https://drive.google.com/open?id=1-4mmxe8dymJ2OSGR_KYqDPXZBx0Bjk8W Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Internet Ecosystem]] - International Girls in ICT Day&lt;br /&gt;
| 22 April 2018&lt;br /&gt;
| -&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] Group01&lt;br /&gt;
| 27 May to 17 June 2018&lt;br /&gt;
| [https://drive.google.com/open?id=1VWQ9UOIPvlpQmxmfVoRxABW6Xl2bZUkj Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] Group02&lt;br /&gt;
| 24 June to 17 July 2018&lt;br /&gt;
| [https://drive.google.com/open?id=16ihUwNp69e7CfzWKvwjEt57wmICUmERx Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] Group03&lt;br /&gt;
| 28 August to 17 September 2018&lt;br /&gt;
| [https://drive.google.com/file/d/1giQZH_QzL_K0NVE-v0NvTVnObpzXAHf9/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] Group04&lt;br /&gt;
| 14 October to 4 November 2018&lt;br /&gt;
| [https://drive.google.com/file/d/11NBFeg3jVNecIOn9F7ZhNwmeOrx5IuD-/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] Group05&lt;br /&gt;
| 21 October to 11 November 2018&lt;br /&gt;
| [https://drive.google.com/open?id=1dFrj9fThHgwPpYqEFEHDFR6aMIPeuRJN Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] Group06&lt;br /&gt;
| 16 December 2018 to 6 January 2019&lt;br /&gt;
| [https://drive.google.com/open?id=1N8fsSLGmVlwbDZPLM6pYu-mf5FvTRp5H Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] Group07&lt;br /&gt;
| 16 December 2018 to 6 January 2019&lt;br /&gt;
| [https://drive.google.com/open?id=1HzeZ7WqGRoMwKW6o__LI7W1ZxeDD6Le8 Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align: center;&amp;quot; | '''2019'''&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Services and Monitoring Online Course]] Group01&lt;br /&gt;
| 22 February to 16 March 2019&lt;br /&gt;
| [https://drive.google.com/file/d/1ovI7W4vjSTVQ_mTL5vAcEt52HaQkBNYQ/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] SudREN Group&lt;br /&gt;
| 11 March 2019 to 18 March 2019&lt;br /&gt;
| [https://drive.google.com/open?id=1hF7RSDhiSUsoJR8LagBjGPM2f2p9V9R_ Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[OpenStack Workshop]] &lt;br /&gt;
| 23 March 2019&lt;br /&gt;
| [https://drive.google.com/open?id=14WyxWDMmt7VsTcS_5u8alew5ioF83Yzk Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Services and Monitoring Online Course]] SudREN Group&lt;br /&gt;
| 25 March 2019 to 4 April 2019&lt;br /&gt;
| [https://drive.google.com/open?id=10UEjGLTAszkPY3_3p9lugXZwLvFJPPDs Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Services and Monitoring Online Course]] Group02&lt;br /&gt;
| 30 March 2019 to 20 April 2019&lt;br /&gt;
| [https://drive.google.com/open?id=1o1vfN_zPHM157ydhChPE2NJHQOWJc_rc Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] Group08&lt;br /&gt;
| 30 March 2019 to 20 April 2019&lt;br /&gt;
| [https://drive.google.com/open?id=1dbICp6mm8yX1OrCtLNJDo48A6WwoFWZy Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Services and Monitoring Online Course]] Group03&lt;br /&gt;
| 26 July 2019 to 16 August 2019&lt;br /&gt;
| [https://drive.google.com/open?id=17tBEPgmiBhByTxHKcAD5gIQ3usQwQ9sC Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Services and Monitoring Online Course]] Group04&lt;br /&gt;
| 26 July 2019 to 16 August 2019&lt;br /&gt;
| [https://drive.google.com/open?id=1im37vEXm25x8Jmcq-MiPO7veyHXBc0XM Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] Group09&lt;br /&gt;
| 8 to 29 October 2019 &lt;br /&gt;
| [https://drive.google.com/open?id=1xjQWQTX7xzWb5GgVVHf70ungw9w9Nfyq Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] Group10&lt;br /&gt;
| 8 to 29 October 2019 &lt;br /&gt;
| [https://drive.google.com/open?id=1n-lhZcAQhTc775We67kLUXbZJIY2dU19 Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Layer 2 Security Workshop]]&lt;br /&gt;
| 28 December 2019&lt;br /&gt;
| [https://drive.google.com/open?id=1halDJoBT-dXcTF-HPuWg-tKebA2-bUor Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align: center;&amp;quot; | '''2020'''&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] Group11&lt;br /&gt;
| 12 January to 2 February 2020&lt;br /&gt;
| [https://drive.google.com/file/d/1IIvUopcgZsRnVipFZfC87ocVkxddQmoQ/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Build your own e-mail Server]] Workshop&lt;br /&gt;
| 15 February 2020&lt;br /&gt;
| [https://drive.google.com/file/d/1r9LJIPQMooGMYFKhJEQYurVass4UG6jp/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Introduction to Git Workshop]]&lt;br /&gt;
| 22 February 2020&lt;br /&gt;
| [https://drive.google.com/open?id=165cH70zkDTiEfZX3Iq87sIW1ZT45Bc5v Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[DNS Workshop|DNS workshop]]&lt;br /&gt;
| 29 February 2020&lt;br /&gt;
| [https://drive.google.com/open?id=1Q5aV0vDauByNxl5BE8pJ9nv5HBlk6Z0N Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Automation with Ansible]] Workshop&lt;br /&gt;
| 14 March 2020&lt;br /&gt;
| [https://drive.google.com/file/d/10FaXKUeUMXJbn_XlB18BtilhewwhBGpe/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Services and Monitoring Online Course]] Group05&lt;br /&gt;
| 23 March  to 16 April 2020 &lt;br /&gt;
| [https://drive.google.com/file/d/1jlOF5M0H7RkY3wxNvF0neyCIYyFiiTCH/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[Automation with Ansible - Online]] Workshop&lt;br /&gt;
| 11 - 21  April 2020&lt;br /&gt;
| [https://drive.google.com/file/d/1CAx8Gaiar1nV3hUECsORWOYkgkPYxXYG/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] Group12&lt;br /&gt;
| 12 - 30 September 2020&lt;br /&gt;
| Workshop Report&lt;br /&gt;
|-&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align: center;&amp;quot; | '''2021'''&lt;br /&gt;
|-&lt;br /&gt;
| [[ICANN DNS Workshop]]&lt;br /&gt;
| 16 to 18 February 2021&lt;br /&gt;
| Workshop Report&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] Group13&lt;br /&gt;
| 15 to 30 May 2021&lt;br /&gt;
| Workshop Report&lt;br /&gt;
|-&lt;br /&gt;
| [[Automation with Ansible - Online]] Workshop&lt;br /&gt;
| 20 to 30 May 2021&lt;br /&gt;
| [https://drive.google.com/file/d/1m4v8GThZ3JYzFDaYy6Wl443TUTbLceN3/view?usp=sharing Workshop Report]&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] Group14&lt;br /&gt;
| 27  May to 10 June 2021&lt;br /&gt;
| Workshop Report&lt;br /&gt;
|-&lt;br /&gt;
| [[HAProxy Lab Setup Guide – Ubuntu-Based Multi-Node Setup (sdnog Edition)]] &lt;br /&gt;
| 19 July May 2025&lt;br /&gt;
| Workshop Report&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=Using_Algo_VPN_to_Access_SDNOG_Infrastructure&amp;diff=2329</id>
		<title>Using Algo VPN to Access SDNOG Infrastructure</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=Using_Algo_VPN_to_Access_SDNOG_Infrastructure&amp;diff=2329"/>
		<updated>2025-04-23T05:57:06Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* 8. Access SDNOG Infrastructure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:sdnog]]&lt;br /&gt;
[[Category:SdNOG_KnowBase]]&lt;br /&gt;
&lt;br /&gt;
== Setup and Using Algo VPN to Access SDNOG Infrastructure ==&lt;br /&gt;
=== Introduction ===&lt;br /&gt;
Algo VPN is a tool that simplifies the process of setting up a secure VPN server on various platforms. This guide will walk you through the steps to install and configure Algo VPN on a local Ubuntu server to access SDNOG infrastructure.&lt;br /&gt;
&lt;br /&gt;
=== Prerequisites ===&lt;br /&gt;
&lt;br /&gt;
* An Ubuntu server (18.04 or later)&lt;br /&gt;
* Sudo privileges on the server&lt;br /&gt;
* Basic knowledge of command-line operations&lt;br /&gt;
=== Step-by-Step Guide ===&lt;br /&gt;
&lt;br /&gt;
==== 1. Update Your System ====&lt;br /&gt;
Before installing Algo VPN, ensure that your system is up-to-date. Open a terminal and run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt update&lt;br /&gt;
sudo apt upgrade -y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== 2. Install Dependencies ====&lt;br /&gt;
Algo VPN requires certain dependencies to be installed. Use the following commands to install them:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt-get install git apparmor build-essential python3-dev python3-pip python3-setuptools python3-virtualenv libffi-dev libssl-dev -y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== 3. Clone the Algo VPN Repository ====&lt;br /&gt;
Clone the Algo VPN repository from GitHub to your local server:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
git clone https://github.com/trailofbits/algo.git&lt;br /&gt;
cd algo&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== 4. Create and Activate a Python Virtual Environment ====&lt;br /&gt;
Create a Python virtual environment and activate it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd algo&lt;br /&gt;
python3 -m virtualenv --python=/usr/bin/python3 .env&lt;br /&gt;
source .env/bin/activate&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 5. Install Algo VPN ====&lt;br /&gt;
Install Algo VPN and its dependencies using pip:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
python3 -m pip install -U pip virtualenv&lt;br /&gt;
python3 -m pip install -r requirements.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 6. Configure Algo VPN ====&lt;br /&gt;
Run the Algo VPN setup script to create a configuration file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./algo&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Follow the prompts to configure your VPN. You will need to provide details such as:&lt;br /&gt;
&lt;br /&gt;
The VPN server's public IP address or domain name&lt;br /&gt;
Your preferred VPN protocol (e.g., WireGuard or IPsec)&lt;br /&gt;
User accounts for VPN access&lt;br /&gt;
&lt;br /&gt;
==== 7. Deploy Algo VPN ====&lt;br /&gt;
&lt;br /&gt;
Once the configuration is complete, deploy Algo VPN with the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./algo&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The deployment process will set up the VPN server according to the configuration you provided.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TASK [Set required ansible version as a fact] *************************************************************************************************&lt;br /&gt;
ok: [localhost] =&amp;gt; (item=ansible==2.9.7)&lt;br /&gt;
&lt;br /&gt;
TASK [Verify Python meets Algo VPN requirements] **********************************************************************************************&lt;br /&gt;
ok: [localhost] =&amp;gt; {&lt;br /&gt;
    &amp;quot;changed&amp;quot;: false,&lt;br /&gt;
    &amp;quot;msg&amp;quot;: &amp;quot;All assertions passed&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
TASK [Verify Ansible meets Algo VPN requirements] *********************************************************************************************&lt;br /&gt;
ok: [localhost] =&amp;gt; {&lt;br /&gt;
    &amp;quot;changed&amp;quot;: false,&lt;br /&gt;
    &amp;quot;msg&amp;quot;: &amp;quot;All assertions passed&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
[WARNING]: Found variable using reserved name: no_log&lt;br /&gt;
&lt;br /&gt;
PLAY [Ask user for the input] *****************************************************************************************************************&lt;br /&gt;
&lt;br /&gt;
TASK [Gathering Facts] ************************************************************************************************************************&lt;br /&gt;
ok: [localhost]&lt;br /&gt;
[Cloud prompt]&lt;br /&gt;
What provider would you like to use?&lt;br /&gt;
    1. DigitalOcean&lt;br /&gt;
    2. Amazon Lightsail&lt;br /&gt;
    3. Amazon EC2&lt;br /&gt;
    4. Microsoft Azure&lt;br /&gt;
    5. Google Compute Engine&lt;br /&gt;
    6. Hetzner Cloud&lt;br /&gt;
    7. Vultr&lt;br /&gt;
    8. Scaleway&lt;br /&gt;
    9. OpenStack (DreamCompute optimised)&lt;br /&gt;
    10. CloudStack (Exoscale optimised)&lt;br /&gt;
    11. Linode&lt;br /&gt;
    12. Install to existing Ubuntu 18.04 or 20.04 server (for more advanced users)&lt;br /&gt;
  &lt;br /&gt;
Enter the number of your desired provider&lt;br /&gt;
:&lt;br /&gt;
12&lt;br /&gt;
&lt;br /&gt;
Type 12 and hit Enter to setup Algo VPN on Ubuntu 20.04 server. You will be asked for several questions as shown below:&lt;br /&gt;
&lt;br /&gt;
TASK [Set facts based on the input] ***************************************************************************************************************************************************************************************&lt;br /&gt;
ok: [localhost]&lt;br /&gt;
[Cellular On Demand prompt]&lt;br /&gt;
Do you want macOS/iOS IPsec clients to enable &amp;quot;Connect On Demand&amp;quot; when connected to cellular networks?&lt;br /&gt;
[y/N]&lt;br /&gt;
:y&lt;br /&gt;
&lt;br /&gt;
TASK [Cellular On Demand prompt] ******************************************************************************************************************************************************************************************&lt;br /&gt;
ok: [localhost]&lt;br /&gt;
[Wi-Fi On Demand prompt]&lt;br /&gt;
Do you want macOS/iOS IPsec clients to enable &amp;quot;Connect On Demand&amp;quot; when connected to Wi-Fi?&lt;br /&gt;
[y/N]&lt;br /&gt;
:y&lt;br /&gt;
&lt;br /&gt;
TASK [Wi-Fi On Demand prompt] *********************************************************************************************************************************************************************************************&lt;br /&gt;
ok: [localhost]&lt;br /&gt;
[Trusted Wi-Fi networks prompt]&lt;br /&gt;
List the names of any trusted Wi-Fi networks where macOS/iOS IPsec clients should not use &amp;quot;Connect On Demand&amp;quot;&lt;br /&gt;
(e.g., your home network. Comma-separated value, e.g., HomeNet,OfficeWifi,AlgoWiFi)&lt;br /&gt;
:HomeNet&lt;br /&gt;
&lt;br /&gt;
TASK [Trusted Wi-Fi networks prompt] **************************************************************************************************************************************************************************************&lt;br /&gt;
ok: [localhost]&lt;br /&gt;
[Compatible ciphers prompt]&lt;br /&gt;
Do you want the VPN to support Windows 10 or Linux Desktop clients? (enables compatible ciphers and key exchange, less secure)&lt;br /&gt;
[y/N]&lt;br /&gt;
:y&lt;br /&gt;
&lt;br /&gt;
TASK [Compatible ciphers prompt] ******************************************************************************************************************************************************************************************&lt;br /&gt;
ok: [localhost]&lt;br /&gt;
[Retain the CA key prompt]&lt;br /&gt;
Do you want to retain the CA key? (required to add users in the future, but less secure)&lt;br /&gt;
[y/N]&lt;br /&gt;
:y&lt;br /&gt;
&lt;br /&gt;
TASK [Retain the CA key prompt] *******************************************************************************************************************************************************************************************&lt;br /&gt;
ok: [localhost]&lt;br /&gt;
[DNS adblocking prompt]&lt;br /&gt;
Do you want to install an ad blocking DNS resolver on this VPN server?&lt;br /&gt;
[y/N]&lt;br /&gt;
:y&lt;br /&gt;
&lt;br /&gt;
TASK [DNS adblocking prompt] **********************************************************************************************************************************************************************************************&lt;br /&gt;
ok: [localhost]&lt;br /&gt;
[SSH tunneling prompt]&lt;br /&gt;
Do you want each user to have their own account for SSH tunneling?&lt;br /&gt;
[y/N]&lt;br /&gt;
:N&lt;br /&gt;
Enter the IP address of your server: (or use localhost for local installation):&lt;br /&gt;
[localhost]&lt;br /&gt;
:&lt;br /&gt;
localhost&lt;br /&gt;
TASK [local : pause] **************************************************************************************************************************&lt;br /&gt;
ok: [localhost]&lt;br /&gt;
&lt;br /&gt;
TASK [local : Set the facts] ******************************************************************************************************************&lt;br /&gt;
ok: [localhost]&lt;br /&gt;
[local : pause]&lt;br /&gt;
What user should we use to login on the server? (note: passwordless login required, or ignore if you're deploying to localhost)&lt;br /&gt;
[root]&lt;br /&gt;
:&lt;br /&gt;
root&lt;br /&gt;
&lt;br /&gt;
Enter the public IP address or domain name of your server: (IMPORTANT! This is used to verify the certificate)&lt;br /&gt;
vpn.jnb.sdnog.sd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== 8. Access SDNOG Infrastructure ====&lt;br /&gt;
Once the installation has been completed successfully, you should get the following output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TASK [debug] **********************************************************************************************************************************&lt;br /&gt;
ok: [localhost] =&amp;gt; {&lt;br /&gt;
    &amp;quot;msg&amp;quot;: [&lt;br /&gt;
        [&lt;br /&gt;
            &amp;quot;\&amp;quot;#                          Congratulations!                            #\&amp;quot;&amp;quot;,&lt;br /&gt;
            &amp;quot;\&amp;quot;#                     Your Algo server is running.                     #\&amp;quot;&amp;quot;,&lt;br /&gt;
            &amp;quot;\&amp;quot;#    Config files and certificates are in the ./configs/ directory.    #\&amp;quot;&amp;quot;,&lt;br /&gt;
            &amp;quot;\&amp;quot;#              Go to https://whoer.net/ after connecting               #\&amp;quot;&amp;quot;,&lt;br /&gt;
            &amp;quot;\&amp;quot;#        and ensure that all your traffic passes through the VPN.      #\&amp;quot;&amp;quot;,&lt;br /&gt;
            &amp;quot;\&amp;quot;#                     Local DNS resolver 172.18.7.104                   #\&amp;quot;&amp;quot;,&lt;br /&gt;
            &amp;quot;&amp;quot;&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;    \&amp;quot;#        The p12 and SSH keys password for new users is SomePassword       #\&amp;quot;\n&amp;quot;,&lt;br /&gt;
        &amp;quot;    \&amp;quot;#        The CA key password is SomePassword@4AN       #\&amp;quot;\n&amp;quot;,&lt;br /&gt;
        &amp;quot;    &amp;quot;&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
PLAY RECAP ************************************************************************************************************************************&lt;br /&gt;
localhost                  : ok=125  changed=39   unreachable=0    failed=0    skipped=53   rescued=0    ignored=0   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the installation, you should see the configuration file for each VPN profile using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls configs/your-server-ip/wireguard/&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should see all the profile in the following output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apple  desktop.conf  desktop.png  laptop.conf  laptop.png  phone.conf  phone.png  user1.conf  user1.png&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can use any of the above files on your client device to connect to the Algo VPN server.&lt;br /&gt;
&lt;br /&gt;
To access SDNOG infrastructure via the VPN, you need to configure your local machine to connect to the VPN server. Download the VPN client configuration files from the Algo VPN setup and import them into your VPN client.&lt;br /&gt;
&lt;br /&gt;
For WireGuard, you can use the wg-quick tool to connect:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo wg-quick up /path/to/your/configuration.conf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For IPsec, follow the instructions specific to your operating system to import the configuration and connect.&lt;br /&gt;
&lt;br /&gt;
==== 9. Adding new VPN users  ====&lt;br /&gt;
* Update the users list in your config.cfg.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vim config.cfg &lt;br /&gt;
users:&lt;br /&gt;
  - laptop&lt;br /&gt;
  - desktop&lt;br /&gt;
  - sdnog&lt;br /&gt;
  - Sara&lt;br /&gt;
  - Nishal&lt;br /&gt;
  - Manhal&lt;br /&gt;
  - Hafiz&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Open a terminal, cd to the algo directory, and activate the virtual environment with : &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
source .env/bin/activate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run the command and it will require password , us the output password from step 8  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./algo update-user&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After this process completes, the Algo VPN server will contain only the users listed in the config.cfg file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
* If you encounter issues during installation or configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd algo/&lt;br /&gt;
sudo rm -rf /etc/wireguard/*&lt;br /&gt;
rm -rf configs/* &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then immediately re-run ./algo.&lt;br /&gt;
&lt;br /&gt;
* Check the Algo VPN documentation for troubleshooting tips.&lt;br /&gt;
* Ensure that your firewall rules allow VPN traffic.&lt;br /&gt;
* Verify that your VPN client is correctly configured.&lt;br /&gt;
&lt;br /&gt;
=== Conclusion ===&lt;br /&gt;
By following these steps, you should have a functioning Algo VPN setup on your local Ubuntu server, providing secure access to the SDNOG infrastructure. For more advanced configurations and additional features, refer to the Algo VPN GitHub repository.&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
* '''Author''': [[User:Manhal.Mohamed|Manhal Mohamed]]'' , SdNOG Team&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2323</id>
		<title>HAProxy Lab Setup Guide - Multi-OS Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2323"/>
		<updated>2024-10-16T04:18:27Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide - Multi-OS Installation =&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3 VMs (or use VirtualBox/VMware Workstation to create them)&lt;br /&gt;
* Web browser access (for those using AFNOG infrastructure)&lt;br /&gt;
&lt;br /&gt;
== VM Setup ==&lt;br /&gt;
# '''VM1:''' HAProxy       &lt;br /&gt;
#* IP: 192.168.1.X&lt;br /&gt;
# '''VM2:''' Apache Server  &lt;br /&gt;
#* IP: 192.168.1.Y&lt;br /&gt;
# '''VM3:''' Nginx Server   &lt;br /&gt;
#* IP: 192.168.1.Z&lt;br /&gt;
&lt;br /&gt;
== Local Hosts File Configuration ==&lt;br /&gt;
Add the following entries to your local hosts file, pointing them all to the HAProxy IP (192.168.1.X):&lt;br /&gt;
&lt;br /&gt;
 192.168.1.X lb.lab.afnog.org &lt;br /&gt;
 192.168.1.X www.lab.afnog.org      &lt;br /&gt;
 192.168.1.X nginx.lab.afnog.org&lt;br /&gt;
 192.168.1.X apache.lab.afnog.org&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install and Configure HAProxy (VM1) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems (CentOS, Fedora) ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install haproxy&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems (Ubuntu, Debian) ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install haproxy&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install haproxy&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install and Configure Apache (VM2) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install httpd&lt;br /&gt;
 sudo systemctl start httpd&lt;br /&gt;
 sudo systemctl enable httpd&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install apache2&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install apache24&lt;br /&gt;
 sudo sysrc apache24_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service apache24 start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /var/www/html/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 On FreeBSD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /usr/local/www/apache24/data/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install and Configure Nginx (VM3) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install nginx&lt;br /&gt;
 sudo systemctl start nginx&lt;br /&gt;
 sudo systemctl enable nginx&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install nginx&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install nginx&lt;br /&gt;
 sudo sysrc nginx_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service nginx start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
''' &lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; |  tee /var/www/html/index.html &amp;lt;/code&amp;gt; &lt;br /&gt;
  # For FreeBSD:&lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; | tee /usr/local/www/nginx/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== HAProxy Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Basic Frontend and Backend Setup (Round-Robin) ===&lt;br /&gt;
&lt;br /&gt;
==== HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
==== Edit the HAProxy configuration file: ====&lt;br /&gt;
* '''Red Hat and Debian:''' /etc/haproxy/haproxy.cfg&lt;br /&gt;
* '''FreeBSD:''' /usr/local/etc/haproxy.conf&lt;br /&gt;
&lt;br /&gt;
==== Add the following configuration: ====&lt;br /&gt;
'''&lt;br /&gt;
 global&lt;br /&gt;
     log         127.0.0.1:514 local1 info&lt;br /&gt;
     chroot      /var/empty&lt;br /&gt;
     pidfile     /var/run/haproxy.pid&lt;br /&gt;
     maxconn     4000&lt;br /&gt;
     user        haproxy&lt;br /&gt;
     group       haproxy&lt;br /&gt;
     daemon&lt;br /&gt;
 &lt;br /&gt;
 defaults&lt;br /&gt;
     mode                    http&lt;br /&gt;
     log                     global&lt;br /&gt;
     option                  httplog&lt;br /&gt;
     option                  dontlognull&lt;br /&gt;
     option http-server-close&lt;br /&gt;
     option forwardfor       except 127.0.0.0/8&lt;br /&gt;
     retries                 3&lt;br /&gt;
     timeout http-request    10s&lt;br /&gt;
     timeout queue           1m&lt;br /&gt;
     timeout connect         10s&lt;br /&gt;
     timeout client          1m&lt;br /&gt;
     timeout server          1m&lt;br /&gt;
     timeout http-keep-alive 10s&lt;br /&gt;
     timeout check           10s&lt;br /&gt;
     maxconn                 3000&lt;br /&gt;
 &lt;br /&gt;
 frontend http-in&lt;br /&gt;
     bind *:80&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server vm1.log.afnog.org:80 check&lt;br /&gt;
     server apache_server vm2.lab.afnog.org:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Advanced Configuration with ACLs (Access Control Lists) ===&lt;br /&gt;
&lt;br /&gt;
==== Updated HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Modify the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 frontend http_front&lt;br /&gt;
     bind *:80&lt;br /&gt;
     acl url_nginx hdr(host) -i nginx.lab.afnog.org&lt;br /&gt;
     acl url_apache hdr(host) -i apache.lab.afnog.org&lt;br /&gt;
     use_backend nginx_back if url_nginx&lt;br /&gt;
     use_backend apache_back if url_apache&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend nginx_back&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend apache_back&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
To set up an active-passive configuration for your backend node, adjust the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check backup &lt;br /&gt;
 '''&lt;br /&gt;
&lt;br /&gt;
this setup will make node apache_server as a passive node and will not recive traffic unless node nginx_server is down&lt;br /&gt;
&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Adding a Status Page ===&lt;br /&gt;
&lt;br /&gt;
==== Final HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Add the following configuration for the status page:&lt;br /&gt;
'''&lt;br /&gt;
 listen stats&lt;br /&gt;
     bind *:8404&lt;br /&gt;
     stats enable&lt;br /&gt;
     stats uri /&lt;br /&gt;
     stats refresh 5s&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
==== Testing the Status Page: ====&lt;br /&gt;
&lt;br /&gt;
You can access the status page by navigating to http://192.168.1.X:8404/ in your web browser.&lt;br /&gt;
&lt;br /&gt;
== SSL Termination on HAProxy ==&lt;br /&gt;
&lt;br /&gt;
=== Generate a Self-Signed Certificate: ===&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/haproxy.key -out /etc/ssl/certs/haproxy.crt&lt;br /&gt;
&lt;br /&gt;
=== Combine the Certificate and Key: ===&lt;br /&gt;
 cat /etc/ssl/certs/haproxy.crt /etc/ssl/private/haproxy.key |  tee /etc/ssl/certs/haproxy.pem&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For development SSL certificates, you can use the repository at https://github.com/BenMorel/dev-certificates&lt;br /&gt;
&lt;br /&gt;
=== Update HAProxy Configuration to Use SSL: ===&lt;br /&gt;
&lt;br /&gt;
Add the following to the `frontend http_front` section:&lt;br /&gt;
&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem&lt;br /&gt;
 redirect scheme https if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
=== Restart HAProxy: ===&lt;br /&gt;
 sudo systemctl restart haproxy&lt;br /&gt;
=== Example for Layer 4 Load balancing , DB port : ===&lt;br /&gt;
'''&lt;br /&gt;
 frontend mysql&lt;br /&gt;
  mode tcp&lt;br /&gt;
  bind :3306&lt;br /&gt;
  default_backend mysql_servers&lt;br /&gt;
&lt;br /&gt;
 backend mysql_servers&lt;br /&gt;
  mode tcp&lt;br /&gt;
  balance leastconn&lt;br /&gt;
  server s1 192.168.0.10:3306 check&lt;br /&gt;
  server s2 192.168.0.11:3306 check&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Configure Syslog for HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
# Open the syslog configuration file for editing:&lt;br /&gt;
 vi /etc/syslog.conf&lt;br /&gt;
&lt;br /&gt;
# Add the following lines to configure logging:&lt;br /&gt;
 *.err;kern.warning;auth.notice;mail.crit                /dev/console&lt;br /&gt;
 local1.*                                                /var/log/haproxy.log&lt;br /&gt;
 *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Create the HAProxy log file:&lt;br /&gt;
 touch /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Set the appropriate ownership for the log file:&lt;br /&gt;
 chown haproxy:haproxy /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Update the syslogd flags to bind to localhost and run in compatibility mode:&lt;br /&gt;
 sysrc syslogd_flags=&amp;quot;-b localhost -C&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Restart the syslog service to apply changes:&lt;br /&gt;
 service syslogd restart&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Using `web browser`: ===&lt;br /&gt;
&lt;br /&gt;
# Test round-robin for `www.lab.afnog.org`:&lt;br /&gt;
# Repeat the command several times to see alternating responses from Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
  nginx.lab.afnog.org&lt;br /&gt;
 # This should consistently return the Nginx server response.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
  apache.lab.afnog.org&lt;br /&gt;
 # This should consistently return the Apache server response.&lt;br /&gt;
&lt;br /&gt;
# Test SSL termination:&lt;br /&gt;
  https://www.lab.afnog.org&lt;br /&gt;
 # This should return responses over HTTPS, with round-robin load balancing between Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
=== Optimal Configuration Options for Web-Based Frontends  ===&lt;br /&gt;
It's crucial to customize the following according to your application's specific requirements.&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    &lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
   &lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    &lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    &lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    &lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    &lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Implement strong SSL/TLS configurations'''&lt;br /&gt;
# '''Use IP whitelisting for the HAProxy stats page'''&lt;br /&gt;
# '''Consider implementing Web Application Firewall (WAF) rules in HAProxy'''&lt;br /&gt;
# '''Regularly audit your HAProxy configurations and access logs'''&lt;br /&gt;
&lt;br /&gt;
This guide provides a comprehensive setup process for HAProxy, starting from a basic configuration and progressing to more advanced setups with ACLs, SSL termination, and performance optimization. Always ensure to test thoroughly in a staging environment before applying changes to production systems.&lt;br /&gt;
&lt;br /&gt;
== Author ==&lt;br /&gt;
* '''Author''': [[User:Manhal.Mohamed|Manhal Mohamed]]'' , SdNOG Team&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=SdNOG_Workshops&amp;diff=2322</id>
		<title>SdNOG Workshops</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=SdNOG_Workshops&amp;diff=2322"/>
		<updated>2024-10-15T20:04:01Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:SdNOG]]&lt;br /&gt;
[[Category:Events]]&lt;br /&gt;
[[Category:Workshops]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;background-color: #F8F9FA; border: 1px solid #A2A9B1; padding: 15px; margin-bottom: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
SdNOG Workshops on Network Technology aim to offer advanced training to people who are in the process of developing and enhancing an Internet-connected network in Sudan. The target audience includes senior and mid-level technical staff in IT field, Internet service providers (ISPs), academic networks, government networks, or NGO networks.&lt;br /&gt;
&lt;br /&gt;
SdNOG has scheduled many workshops before. To know more, '''check our [[Workshops schedule]] page.'''🗓&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Workshops List ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;width: 100%; border-collapse: collapse;&amp;quot;&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Workshop Name&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Note&lt;br /&gt;
|-&lt;br /&gt;
| [[IPv6 Fundamentals Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[DNS Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[DNSSEC Workshop]] || [[SdNOG-2]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Ethical Hacking Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Hardening a web-server for the modern internet]] || [[SdNOG-4]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[High Availability in LAMP Stack workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[How to Secure your Network Workshop]] || [[SdNOG-3]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Internet Governance Forum]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[IPv6 Workshop]] || [[SdNOG-4]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[IXP Best Practices]] || [[SdNOG-2]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Networks Fundamental Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Management and Monitoring Workshop]] || [[SdNOG-3]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Networking Best Practices Workshop]] || [[SdNOG-2]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX Boot Camp]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] || [https://www.internetsociety.org/ ISOC] Online Course&lt;br /&gt;
|-&lt;br /&gt;
| [[Automation Tool: Ansible]] || [[SdNOG-5]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[IPv6 for Services]] || [[SdNOG-5]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Services and Monitoring Online Course]] || [https://www.internetsociety.org/ ISOC] Online Course&lt;br /&gt;
|-&lt;br /&gt;
| [[OpenStack Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Ansible for DevOps Workshop]] || [[SdNOG-6]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Monitoring Workshop]] || [[SdNOG-6]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Security Workshop - Ethical Hacking]] || [[SdNOG-6]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Layer 2 Security Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Build your own e-mail Server]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Introduction to Git Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Automation with Ansible]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Automation with Ansible - Online]] || Online workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[ICANN DNS Workshop]] || Online workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[BGP Resource Management Workshop]] || Online workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Load Balancing Strategies: From Theory to Practice with HAProxy]] || [https://internetsummit.africa/ Africa Internet Summit - AIS 2024]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;background-color: #F8F9FA; border: 1px solid #A2A9B1; padding: 15px; margin-top: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
'''Note:''' This list is regularly updated. Please check back for new workshops or visit our [[Workshops schedule]] page for the most current information.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=SdNOG_Workshops&amp;diff=2321</id>
		<title>SdNOG Workshops</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=SdNOG_Workshops&amp;diff=2321"/>
		<updated>2024-10-15T20:03:41Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* SdNOG Workshops */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:SdNOG]]&lt;br /&gt;
[[Category:Events]]&lt;br /&gt;
[[Category:Workshops]]&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;div style=&amp;quot;background-color: #F8F9FA; border: 1px solid #A2A9B1; padding: 15px; margin-bottom: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
SdNOG Workshops on Network Technology aim to offer advanced training to people who are in the process of developing and enhancing an Internet-connected network in Sudan. The target audience includes senior and mid-level technical staff in IT field, Internet service providers (ISPs), academic networks, government networks, or NGO networks.&lt;br /&gt;
&lt;br /&gt;
SdNOG has scheduled many workshops before. To know more, '''check our [[Workshops schedule]] page.'''🗓&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Workshops List ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;width: 100%; border-collapse: collapse;&amp;quot;&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Workshop Name&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Note&lt;br /&gt;
|-&lt;br /&gt;
| [[IPv6 Fundamentals Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[DNS Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[DNSSEC Workshop]] || [[SdNOG-2]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Ethical Hacking Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Hardening a web-server for the modern internet]] || [[SdNOG-4]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[High Availability in LAMP Stack workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[How to Secure your Network Workshop]] || [[SdNOG-3]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Internet Governance Forum]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[IPv6 Workshop]] || [[SdNOG-4]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[IXP Best Practices]] || [[SdNOG-2]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Networks Fundamental Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Management and Monitoring Workshop]] || [[SdNOG-3]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Networking Best Practices Workshop]] || [[SdNOG-2]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX Boot Camp]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] || [https://www.internetsociety.org/ ISOC] Online Course&lt;br /&gt;
|-&lt;br /&gt;
| [[Automation Tool: Ansible]] || [[SdNOG-5]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[IPv6 for Services]] || [[SdNOG-5]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Services and Monitoring Online Course]] || [https://www.internetsociety.org/ ISOC] Online Course&lt;br /&gt;
|-&lt;br /&gt;
| [[OpenStack Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Ansible for DevOps Workshop]] || [[SdNOG-6]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Monitoring Workshop]] || [[SdNOG-6]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Security Workshop - Ethical Hacking]] || [[SdNOG-6]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Layer 2 Security Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Build your own e-mail Server]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Introduction to Git Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Automation with Ansible]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Automation with Ansible - Online]] || Online workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[ICANN DNS Workshop]] || Online workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[BGP Resource Management Workshop]] || Online workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Load Balancing Strategies: From Theory to Practice with HAProxy]] || [https://internetsummit.africa/ Africa Internet Summit - AIS 2024]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;background-color: #F8F9FA; border: 1px solid #A2A9B1; padding: 15px; margin-top: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
'''Note:''' This list is regularly updated. Please check back for new workshops or visit our [[Workshops schedule]] page for the most current information.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=SdNOG_Workshops&amp;diff=2320</id>
		<title>SdNOG Workshops</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=SdNOG_Workshops&amp;diff=2320"/>
		<updated>2024-10-15T20:03:14Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:SdNOG]]&lt;br /&gt;
[[Category:Events]]&lt;br /&gt;
[[Category:Workshops]]&lt;br /&gt;
&lt;br /&gt;
= SdNOG Workshops  =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;background-color: #F8F9FA; border: 1px solid #A2A9B1; padding: 15px; margin-bottom: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
SdNOG Workshops on Network Technology aim to offer advanced training to people who are in the process of developing and enhancing an Internet-connected network in Sudan. The target audience includes senior and mid-level technical staff in IT field, Internet service providers (ISPs), academic networks, government networks, or NGO networks.&lt;br /&gt;
&lt;br /&gt;
SdNOG has scheduled many workshops before. To know more, '''check our [[Workshops schedule]] page.'''🗓&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Workshops List ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot; style=&amp;quot;width: 100%; border-collapse: collapse;&amp;quot;&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Workshop Name&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Note&lt;br /&gt;
|-&lt;br /&gt;
| [[IPv6 Fundamentals Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[DNS Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[DNSSEC Workshop]] || [[SdNOG-2]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Ethical Hacking Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Hardening a web-server for the modern internet]] || [[SdNOG-4]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[High Availability in LAMP Stack workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[How to Secure your Network Workshop]] || [[SdNOG-3]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Internet Governance Forum]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[IPv6 Workshop]] || [[SdNOG-4]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[IXP Best Practices]] || [[SdNOG-2]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Networks Fundamental Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Management and Monitoring Workshop]] || [[SdNOG-3]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Networking Best Practices Workshop]] || [[SdNOG-2]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX Boot Camp]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] || [https://www.internetsociety.org/ ISOC] Online Course&lt;br /&gt;
|-&lt;br /&gt;
| [[Automation Tool: Ansible]] || [[SdNOG-5]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[IPv6 for Services]] || [[SdNOG-5]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Services and Monitoring Online Course]] || [https://www.internetsociety.org/ ISOC] Online Course&lt;br /&gt;
|-&lt;br /&gt;
| [[OpenStack Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Ansible for DevOps Workshop]] || [[SdNOG-6]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Monitoring Workshop]] || [[SdNOG-6]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Security Workshop - Ethical Hacking]] || [[SdNOG-6]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Layer 2 Security Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Build your own e-mail Server]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Introduction to Git Workshop]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Automation with Ansible]] || Weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Automation with Ansible - Online]] || Online workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[ICANN DNS Workshop]] || Online workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[BGP Resource Management Workshop]] || Online workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Load Balancing Strategies: From Theory to Practice with HAProxy]] || [https://internetsummit.africa/ Africa Internet Summit - AIS 2024]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;background-color: #F8F9FA; border: 1px solid #A2A9B1; padding: 15px; margin-top: 20px;&amp;quot;&amp;gt;&lt;br /&gt;
'''Note:''' This list is regularly updated. Please check back for new workshops or visit our [[Workshops schedule]] page for the most current information.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=Business_Model_Canvas_for_SDNOG&amp;diff=2319</id>
		<title>Business Model Canvas for SDNOG</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=Business_Model_Canvas_for_SDNOG&amp;diff=2319"/>
		<updated>2024-10-15T19:44:26Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* SDNOG Business Model Canvas */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%; border-collapse: collapse;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #C41617; color: white; padding: 10px;&amp;quot; | Key Partners&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #C41617; color: white; padding: 10px;&amp;quot; | Key Activities&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #C41617; color: white; padding: 10px;&amp;quot; | Key Resources&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Internet Service Providers in Sudan&lt;br /&gt;
* Technology companies&lt;br /&gt;
* Educational institutions&lt;br /&gt;
* Government agencies related to telecommunications&lt;br /&gt;
* International network operator groups&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Organizing forums and events for knowledge exchange&lt;br /&gt;
* Providing network education and training&lt;br /&gt;
* Facilitating technical collaboration&lt;br /&gt;
* Promoting open-source technologies&lt;br /&gt;
* Conducting research on network technologies&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Volunteer network engineers and experts&lt;br /&gt;
* Technical knowledge and expertise&lt;br /&gt;
* Community of network professionals&lt;br /&gt;
* Online platforms for communication and collaboration&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Value Propositions&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Customer Relationships&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Channels&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Open platform for knowledge exchange in networking&lt;br /&gt;
* Capacity building in network engineering&lt;br /&gt;
* Enhancing the quality of Internet services in Sudan&lt;br /&gt;
* Promoting collaboration among network professionals&lt;br /&gt;
* Access to cutting-edge network technologies and practices&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Community-based interactions&lt;br /&gt;
* Peer-to-peer learning and support&lt;br /&gt;
* Long-term engagement through regular events and forums&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Online forums and discussion boards&lt;br /&gt;
* Physical events and meetups&lt;br /&gt;
* Workshops and training sessions&lt;br /&gt;
* Social media platforms&lt;br /&gt;
* Website and email newsletters&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Customer Segments&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Cost Structure&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Revenue Streams&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Network engineers in Sudan&lt;br /&gt;
* Internet Service Providers&lt;br /&gt;
* Technology companies&lt;br /&gt;
* Students and researchers in networking fields&lt;br /&gt;
* Government agencies involved in telecommunications&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Event organization expenses&lt;br /&gt;
* Online platform maintenance&lt;br /&gt;
* Educational materials development&lt;br /&gt;
* Volunteer coordination costs&lt;br /&gt;
* Marketing and outreach expenses&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Membership fees (if applicable)&lt;br /&gt;
* Sponsorships from technology companies&lt;br /&gt;
* Grants from educational or research institutions&lt;br /&gt;
* Donations from community members&lt;br /&gt;
* Fees for specialized workshops or training sessions&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=Business_Model_Canvas_for_SDNOG&amp;diff=2318</id>
		<title>Business Model Canvas for SDNOG</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=Business_Model_Canvas_for_SDNOG&amp;diff=2318"/>
		<updated>2024-10-15T19:44:13Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= SDNOG Business Model Canvas =&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%; border-collapse: collapse;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #C41617; color: white; padding: 10px;&amp;quot; | Key Partners&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #C41617; color: white; padding: 10px;&amp;quot; | Key Activities&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #C41617; color: white; padding: 10px;&amp;quot; | Key Resources&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Internet Service Providers in Sudan&lt;br /&gt;
* Technology companies&lt;br /&gt;
* Educational institutions&lt;br /&gt;
* Government agencies related to telecommunications&lt;br /&gt;
* International network operator groups&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Organizing forums and events for knowledge exchange&lt;br /&gt;
* Providing network education and training&lt;br /&gt;
* Facilitating technical collaboration&lt;br /&gt;
* Promoting open-source technologies&lt;br /&gt;
* Conducting research on network technologies&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Volunteer network engineers and experts&lt;br /&gt;
* Technical knowledge and expertise&lt;br /&gt;
* Community of network professionals&lt;br /&gt;
* Online platforms for communication and collaboration&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Value Propositions&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Customer Relationships&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Channels&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Open platform for knowledge exchange in networking&lt;br /&gt;
* Capacity building in network engineering&lt;br /&gt;
* Enhancing the quality of Internet services in Sudan&lt;br /&gt;
* Promoting collaboration among network professionals&lt;br /&gt;
* Access to cutting-edge network technologies and practices&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Community-based interactions&lt;br /&gt;
* Peer-to-peer learning and support&lt;br /&gt;
* Long-term engagement through regular events and forums&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Online forums and discussion boards&lt;br /&gt;
* Physical events and meetups&lt;br /&gt;
* Workshops and training sessions&lt;br /&gt;
* Social media platforms&lt;br /&gt;
* Website and email newsletters&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Customer Segments&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Cost Structure&lt;br /&gt;
! style=&amp;quot;background-color: #C41617; color: white; padding: 10px;&amp;quot; | Revenue Streams&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Network engineers in Sudan&lt;br /&gt;
* Internet Service Providers&lt;br /&gt;
* Technology companies&lt;br /&gt;
* Students and researchers in networking fields&lt;br /&gt;
* Government agencies involved in telecommunications&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Event organization expenses&lt;br /&gt;
* Online platform maintenance&lt;br /&gt;
* Educational materials development&lt;br /&gt;
* Volunteer coordination costs&lt;br /&gt;
* Marketing and outreach expenses&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Membership fees (if applicable)&lt;br /&gt;
* Sponsorships from technology companies&lt;br /&gt;
* Grants from educational or research institutions&lt;br /&gt;
* Donations from community members&lt;br /&gt;
* Fees for specialized workshops or training sessions&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=Business_Model_Canvas_for_SDNOG&amp;diff=2317</id>
		<title>Business Model Canvas for SDNOG</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=Business_Model_Canvas_for_SDNOG&amp;diff=2317"/>
		<updated>2024-10-15T19:42:14Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%; border-collapse: collapse;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #C41617; padding: 10px;&amp;quot; | Key Partners&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #C41617; padding: 10px;&amp;quot; | Key Activities&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #C41617; padding: 10px;&amp;quot; | Key Resources&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Internet Service Providers in Sudan&lt;br /&gt;
* Technology companies&lt;br /&gt;
* Educational institutions&lt;br /&gt;
* Government agencies related to telecommunications&lt;br /&gt;
* International network operator groups&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Organizing forums and events for knowledge exchange&lt;br /&gt;
* Providing network education and training&lt;br /&gt;
* Facilitating technical collaboration&lt;br /&gt;
* Promoting open-source technologies&lt;br /&gt;
* Conducting research on network technologies&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Volunteer network engineers and experts&lt;br /&gt;
* Technical knowledge and expertise&lt;br /&gt;
* Community of network professionals&lt;br /&gt;
* Online platforms for communication and collaboration&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Value Propositions&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Customer Relationships&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Channels&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Open platform for knowledge exchange in networking&lt;br /&gt;
* Capacity building in network engineering&lt;br /&gt;
* Enhancing the quality of Internet services in Sudan&lt;br /&gt;
* Promoting collaboration among network professionals&lt;br /&gt;
* Access to cutting-edge network technologies and practices&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Community-based interactions&lt;br /&gt;
* Peer-to-peer learning and support&lt;br /&gt;
* Long-term engagement through regular events and forums&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Online forums and discussion boards&lt;br /&gt;
* Physical events and meetups&lt;br /&gt;
* Workshops and training sessions&lt;br /&gt;
* Social media platforms&lt;br /&gt;
* Website and email newsletters&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Customer Segments&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Cost Structure&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Revenue Streams&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Network engineers in Sudan&lt;br /&gt;
* Internet Service Providers&lt;br /&gt;
* Technology companies&lt;br /&gt;
* Students and researchers in networking fields&lt;br /&gt;
* Government agencies involved in telecommunications&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Event organization expenses&lt;br /&gt;
* Online platform maintenance&lt;br /&gt;
* Educational materials development&lt;br /&gt;
* Volunteer coordination costs&lt;br /&gt;
* Marketing and outreach expenses&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Membership fees (if applicable)&lt;br /&gt;
* Sponsorships from technology companies&lt;br /&gt;
* Grants from educational or research institutions&lt;br /&gt;
* Donations from community members&lt;br /&gt;
* Fees for specialized workshops or training sessions&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=Business_Model_Canvas_for_SDNOG&amp;diff=2316</id>
		<title>Business Model Canvas for SDNOG</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=Business_Model_Canvas_for_SDNOG&amp;diff=2316"/>
		<updated>2024-10-15T19:40:22Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* SDNOG Business Model Canvas */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%; border-collapse: collapse;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #e6f2ff; padding: 10px;&amp;quot; | Key Partners&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #e6f2ff; padding: 10px;&amp;quot; | Key Activities&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #e6f2ff; padding: 10px;&amp;quot; | Key Resources&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Internet Service Providers in Sudan&lt;br /&gt;
* Technology companies&lt;br /&gt;
* Educational institutions&lt;br /&gt;
* Government agencies related to telecommunications&lt;br /&gt;
* International network operator groups&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Organizing forums and events for knowledge exchange&lt;br /&gt;
* Providing network education and training&lt;br /&gt;
* Facilitating technical collaboration&lt;br /&gt;
* Promoting open-source technologies&lt;br /&gt;
* Conducting research on network technologies&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Volunteer network engineers and experts&lt;br /&gt;
* Technical knowledge and expertise&lt;br /&gt;
* Community of network professionals&lt;br /&gt;
* Online platforms for communication and collaboration&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Value Propositions&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Customer Relationships&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Channels&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Open platform for knowledge exchange in networking&lt;br /&gt;
* Capacity building in network engineering&lt;br /&gt;
* Enhancing the quality of Internet services in Sudan&lt;br /&gt;
* Promoting collaboration among network professionals&lt;br /&gt;
* Access to cutting-edge network technologies and practices&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Community-based interactions&lt;br /&gt;
* Peer-to-peer learning and support&lt;br /&gt;
* Long-term engagement through regular events and forums&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Online forums and discussion boards&lt;br /&gt;
* Physical events and meetups&lt;br /&gt;
* Workshops and training sessions&lt;br /&gt;
* Social media platforms&lt;br /&gt;
* Website and email newsletters&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Customer Segments&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Cost Structure&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Revenue Streams&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Network engineers in Sudan&lt;br /&gt;
* Internet Service Providers&lt;br /&gt;
* Technology companies&lt;br /&gt;
* Students and researchers in networking fields&lt;br /&gt;
* Government agencies involved in telecommunications&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Event organization expenses&lt;br /&gt;
* Online platform maintenance&lt;br /&gt;
* Educational materials development&lt;br /&gt;
* Volunteer coordination costs&lt;br /&gt;
* Marketing and outreach expenses&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Membership fees (if applicable)&lt;br /&gt;
* Sponsorships from technology companies&lt;br /&gt;
* Grants from educational or research institutions&lt;br /&gt;
* Donations from community members&lt;br /&gt;
* Fees for specialized workshops or training sessions&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=Business_Model_Canvas_for_SDNOG&amp;diff=2315</id>
		<title>Business Model Canvas for SDNOG</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=Business_Model_Canvas_for_SDNOG&amp;diff=2315"/>
		<updated>2024-10-15T19:39:59Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: Created page with &amp;quot;= SDNOG Business Model Canvas =  {| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%; border-collapse: collapse;&amp;quot; |- ! style=&amp;quot;width: 33%; background-color: #e6f2ff; padding: 10px;&amp;quot; | Key...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= SDNOG Business Model Canvas =&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width: 100%; border-collapse: collapse;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #e6f2ff; padding: 10px;&amp;quot; | Key Partners&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #e6f2ff; padding: 10px;&amp;quot; | Key Activities&lt;br /&gt;
! style=&amp;quot;width: 33%; background-color: #e6f2ff; padding: 10px;&amp;quot; | Key Resources&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Internet Service Providers in Sudan&lt;br /&gt;
* Technology companies&lt;br /&gt;
* Educational institutions&lt;br /&gt;
* Government agencies related to telecommunications&lt;br /&gt;
* International network operator groups&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Organizing forums and events for knowledge exchange&lt;br /&gt;
* Providing network education and training&lt;br /&gt;
* Facilitating technical collaboration&lt;br /&gt;
* Promoting open-source technologies&lt;br /&gt;
* Conducting research on network technologies&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Volunteer network engineers and experts&lt;br /&gt;
* Technical knowledge and expertise&lt;br /&gt;
* Community of network professionals&lt;br /&gt;
* Online platforms for communication and collaboration&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Value Propositions&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Customer Relationships&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Channels&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Open platform for knowledge exchange in networking&lt;br /&gt;
* Capacity building in network engineering&lt;br /&gt;
* Enhancing the quality of Internet services in Sudan&lt;br /&gt;
* Promoting collaboration among network professionals&lt;br /&gt;
* Access to cutting-edge network technologies and practices&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Community-based interactions&lt;br /&gt;
* Peer-to-peer learning and support&lt;br /&gt;
* Long-term engagement through regular events and forums&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Online forums and discussion boards&lt;br /&gt;
* Physical events and meetups&lt;br /&gt;
* Workshops and training sessions&lt;br /&gt;
* Social media platforms&lt;br /&gt;
* Website and email newsletters&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Customer Segments&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Cost Structure&lt;br /&gt;
! style=&amp;quot;background-color: #e6f2ff; padding: 10px;&amp;quot; | Revenue Streams&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Network engineers in Sudan&lt;br /&gt;
* Internet Service Providers&lt;br /&gt;
* Technology companies&lt;br /&gt;
* Students and researchers in networking fields&lt;br /&gt;
* Government agencies involved in telecommunications&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Event organization expenses&lt;br /&gt;
* Online platform maintenance&lt;br /&gt;
* Educational materials development&lt;br /&gt;
* Volunteer coordination costs&lt;br /&gt;
* Marketing and outreach expenses&lt;br /&gt;
| style=&amp;quot;vertical-align: top; padding: 10px;&amp;quot; |&lt;br /&gt;
* Membership fees (if applicable)&lt;br /&gt;
* Sponsorships from technology companies&lt;br /&gt;
* Grants from educational or research institutions&lt;br /&gt;
* Donations from community members&lt;br /&gt;
* Fees for specialized workshops or training sessions&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=Documentations&amp;diff=2314</id>
		<title>Documentations</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=Documentations&amp;diff=2314"/>
		<updated>2024-10-15T19:33:43Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Pages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:SdNOG]]&lt;br /&gt;
[[Category:SdNOG_KnowBase]]&lt;br /&gt;
Welcome to the SDNOG documentation page. This resource provides comprehensive details about our infrastructure and services. Here, you'll find information on how SDNOG's systems are designed, built, and maintained, including various how-to articles and technical documentation. Our goal is to offer clear and detailed insights into the operations and management of SDNOG services.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pages ==&lt;br /&gt;
* [[sdnog Infrasturcture]]&lt;br /&gt;
* [[sdnog Services]]&lt;br /&gt;
* [[Business Model Canvas for SDNOG]]&lt;br /&gt;
* DMARC and DKIM records for mail.sdnog.sd &lt;br /&gt;
* [[Verify sdnog.sd domain with google Postmaster Tools]]&lt;br /&gt;
* [[SdNOG DNS infrastructure]]&lt;br /&gt;
* [[SdNOG Users creation Ansible code ]]&lt;br /&gt;
* [[Using Algo VPN to Access SDNOG Infrastructure ]]&lt;br /&gt;
* [[Install and Configure NetBox IPAM on Ubuntu ]]&lt;br /&gt;
* [[ IPv6 subnetting for sdnog]]&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=Load_Balancing_Strategies:_From_Theory_to_Practice_with_HAProxy&amp;diff=2313</id>
		<title>Load Balancing Strategies: From Theory to Practice with HAProxy</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=Load_Balancing_Strategies:_From_Theory_to_Practice_with_HAProxy&amp;diff=2313"/>
		<updated>2024-09-05T13:06:48Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Lead Instructor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Workshop: Load Balancing and Advanced Configuration =&lt;br /&gt;
&lt;br /&gt;
== Date &amp;amp; Time ==&lt;br /&gt;
* **Event**: [https://internetsummit.africa/ Africa Internet Summit - AIS 2024]&lt;br /&gt;
* **Date**: September 5, 2024&lt;br /&gt;
* **Time**: 13:00 - 15:30&lt;br /&gt;
&lt;br /&gt;
== Intended Audience ==&lt;br /&gt;
This workshop is specifically designed for **Senior Systems Engineers** who are looking to deepen their understanding of load balancing and HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
This workshop is a comprehensive 2-hour session that includes both theoretical concepts and practical hands-on labs, with a short break. The session covers the following topics:&lt;br /&gt;
&lt;br /&gt;
=== Introduction (5 minutes) ===&lt;br /&gt;
* Brief overview of load balancing concepts&lt;br /&gt;
* Importance of load balancing in modern infrastructure&lt;br /&gt;
&lt;br /&gt;
=== Load Balancing Fundamentals (15 minutes) ===&lt;br /&gt;
* Types of load balancers:&lt;br /&gt;
  * Layer 4 (L4) vs. Layer 7 (L7)&lt;br /&gt;
* Common load balancing algorithms:&lt;br /&gt;
  * Round Robin&lt;br /&gt;
  * Least Connections&lt;br /&gt;
  * IP Hash&lt;br /&gt;
* Health checks and failure handling&lt;br /&gt;
&lt;br /&gt;
=== Introduction to HAProxy (10 minutes) ===&lt;br /&gt;
* Overview of HAProxy and its key features&lt;br /&gt;
* Architecture and components of HAProxy&lt;br /&gt;
&lt;br /&gt;
=== HAProxy Configuration Basics (20 minutes) ===&lt;br /&gt;
* Structure of the HAProxy configuration file&lt;br /&gt;
* Key sections: &lt;br /&gt;
  * Frontend&lt;br /&gt;
  * Backend&lt;br /&gt;
* Access Control Lists (ACLs) and `use_backend` rules&lt;br /&gt;
&lt;br /&gt;
=== Advanced HAProxy Features (20 minutes) ===&lt;br /&gt;
* SSL termination&lt;br /&gt;
* Sticky sessions&lt;br /&gt;
* HTTP rewriting and redirection&lt;br /&gt;
* Logging and monitoring&lt;br /&gt;
&lt;br /&gt;
=== Live Demo: Setting up HAProxy (30 minutes) ===&lt;br /&gt;
* Installing HAProxy&lt;br /&gt;
* Configuring a basic load balancer&lt;br /&gt;
* Testing and verifying the setup&lt;br /&gt;
* Demonstration of advanced features&lt;br /&gt;
=== Best Practices and Performance Tuning (10 minutes) ===&lt;br /&gt;
* Optimization of HAProxy configuration&lt;br /&gt;
* Security considerations&lt;br /&gt;
* Scaling HAProxy&lt;br /&gt;
&lt;br /&gt;
== Session Hands-On ==&lt;br /&gt;
* Slides [https://drive.google.com/file/d/1FkagbjrE2u-B5TVzihiZ7idzuJ78iMP-/view?usp=sharing &amp;quot;click here&amp;quot;] &lt;br /&gt;
* [[HAProxy Lab Setup Guide - Multi-OS Installation ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Lead Instructor ==&lt;br /&gt;
* '''[https://www.linkedin.com/in/manhalmohammed/ Manhal M. Mokhtar]'''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=Load_Balancing_Strategies:_From_Theory_to_Practice_with_HAProxy&amp;diff=2312</id>
		<title>Load Balancing Strategies: From Theory to Practice with HAProxy</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=Load_Balancing_Strategies:_From_Theory_to_Practice_with_HAProxy&amp;diff=2312"/>
		<updated>2024-09-05T13:06:01Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Lead Instructor */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Workshop: Load Balancing and Advanced Configuration =&lt;br /&gt;
&lt;br /&gt;
== Date &amp;amp; Time ==&lt;br /&gt;
* **Event**: [https://internetsummit.africa/ Africa Internet Summit - AIS 2024]&lt;br /&gt;
* **Date**: September 5, 2024&lt;br /&gt;
* **Time**: 13:00 - 15:30&lt;br /&gt;
&lt;br /&gt;
== Intended Audience ==&lt;br /&gt;
This workshop is specifically designed for **Senior Systems Engineers** who are looking to deepen their understanding of load balancing and HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
This workshop is a comprehensive 2-hour session that includes both theoretical concepts and practical hands-on labs, with a short break. The session covers the following topics:&lt;br /&gt;
&lt;br /&gt;
=== Introduction (5 minutes) ===&lt;br /&gt;
* Brief overview of load balancing concepts&lt;br /&gt;
* Importance of load balancing in modern infrastructure&lt;br /&gt;
&lt;br /&gt;
=== Load Balancing Fundamentals (15 minutes) ===&lt;br /&gt;
* Types of load balancers:&lt;br /&gt;
  * Layer 4 (L4) vs. Layer 7 (L7)&lt;br /&gt;
* Common load balancing algorithms:&lt;br /&gt;
  * Round Robin&lt;br /&gt;
  * Least Connections&lt;br /&gt;
  * IP Hash&lt;br /&gt;
* Health checks and failure handling&lt;br /&gt;
&lt;br /&gt;
=== Introduction to HAProxy (10 minutes) ===&lt;br /&gt;
* Overview of HAProxy and its key features&lt;br /&gt;
* Architecture and components of HAProxy&lt;br /&gt;
&lt;br /&gt;
=== HAProxy Configuration Basics (20 minutes) ===&lt;br /&gt;
* Structure of the HAProxy configuration file&lt;br /&gt;
* Key sections: &lt;br /&gt;
  * Frontend&lt;br /&gt;
  * Backend&lt;br /&gt;
* Access Control Lists (ACLs) and `use_backend` rules&lt;br /&gt;
&lt;br /&gt;
=== Advanced HAProxy Features (20 minutes) ===&lt;br /&gt;
* SSL termination&lt;br /&gt;
* Sticky sessions&lt;br /&gt;
* HTTP rewriting and redirection&lt;br /&gt;
* Logging and monitoring&lt;br /&gt;
&lt;br /&gt;
=== Live Demo: Setting up HAProxy (30 minutes) ===&lt;br /&gt;
* Installing HAProxy&lt;br /&gt;
* Configuring a basic load balancer&lt;br /&gt;
* Testing and verifying the setup&lt;br /&gt;
* Demonstration of advanced features&lt;br /&gt;
=== Best Practices and Performance Tuning (10 minutes) ===&lt;br /&gt;
* Optimization of HAProxy configuration&lt;br /&gt;
* Security considerations&lt;br /&gt;
* Scaling HAProxy&lt;br /&gt;
&lt;br /&gt;
== Session Hands-On ==&lt;br /&gt;
* Slides [https://drive.google.com/file/d/1FkagbjrE2u-B5TVzihiZ7idzuJ78iMP-/view?usp=sharing &amp;quot;click here&amp;quot;] &lt;br /&gt;
* [[HAProxy Lab Setup Guide - Multi-OS Installation ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Lead Instructor ==&lt;br /&gt;
* '''Manhal M. Mokhtar'''&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=SdNOG_Workshops&amp;diff=2311</id>
		<title>SdNOG Workshops</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=SdNOG_Workshops&amp;diff=2311"/>
		<updated>2024-09-05T13:04:17Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: SdNOG]]&lt;br /&gt;
[[Category: Events]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
&lt;br /&gt;
sdnog Workshops on Network Technology aim to offer advanced training to people who are in the process of developing and enhancing an Internet-connected network in Sudan, The target audience includes senior and mid-level technical staff in IT field, Internet service providers (ISPs), academic networks, government networks, or NGO networks.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SdNOG has scheduled many workshops before, to know more '''check our [[Workshops schedule]] page.'''🗓&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Workshop name !! Note&lt;br /&gt;
|-&lt;br /&gt;
| [[IPv6 Fundamentals Workshop]] || weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[DNS Workshop]] || weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[DNSSEC Workshop]] || [[SdNOG-2]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Ethical Hacking Workshop]] || weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Hardening a web-server for the modern internet]] || [[SdNOG-4]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[High Availability in LAMP Stack workshop]] || weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[How to Secure your Network Workshop]] || [[SdNOG-3]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Internet Governance Forum]]|| weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[IPv6 Workshop]] || [[SdNOG-4]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[IXP Best Practices]] || [[SdNOG-2]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Networks Fundamental Workshop ]]|| weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Management and Monitoring Workshop]]|| [[SdNOG-3]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Networking Best Practices Workshop]] || [[SdNOG-2]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX Boot Camp]]|| weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[UNIX/Linux, Networking and DNS Online Course]] || [https://www.internetsociety.org/ ISOC] Online Course&lt;br /&gt;
|-&lt;br /&gt;
|[[Automation Tool: Ansible]] || [[SdNOG-5]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
|[[IPv6 for Services]]||[[SdNOG-5]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Services and Monitoring Online Course]] || [https://www.internetsociety.org/ ISOC] Online Course&lt;br /&gt;
|-&lt;br /&gt;
| [[OpenStack Workshop]]|| weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Ansible for DevOPs Workshop]] || [[SdNOG-6]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Network Monitoring Workshop]] || [[SdNOG-6]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Security Workshop - Ethical Hacking]] || [[SdNOG-6]] Meeting&lt;br /&gt;
|-&lt;br /&gt;
| [[Layer 2 Security Workshop]]|| weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Build your own e-mail Server]] || weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Introduction to Git Workshop]] || weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Automation with Ansible]] || weekly workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Automation with Ansible - Online ]] || Online workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[ICANN DNS Workshop]] - Online || Online workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[BGP Resource Management Workshop]] - Online || Online workshop&lt;br /&gt;
|-&lt;br /&gt;
| [[Load Balancing Strategies: From Theory to Practice with HAProxy]] - Online || [https://internetsummit.africa/ Africa Internet Summit - AIS 2024]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2310</id>
		<title>HAProxy Lab Setup Guide - Multi-OS Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2310"/>
		<updated>2024-09-05T13:01:32Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Optimal Configuration Options for Web-Based Frontends */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide - Multi-OS Installation =&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3 VMs (or use VirtualBox/VMware Workstation to create them)&lt;br /&gt;
* Web browser access (for those using AFNOG infrastructure)&lt;br /&gt;
&lt;br /&gt;
== VM Setup ==&lt;br /&gt;
# '''VM1:''' HAProxy       &lt;br /&gt;
#* IP: 192.168.1.X&lt;br /&gt;
# '''VM2:''' Apache Server  &lt;br /&gt;
#* IP: 192.168.1.Y&lt;br /&gt;
# '''VM3:''' Nginx Server   &lt;br /&gt;
#* IP: 192.168.1.Z&lt;br /&gt;
&lt;br /&gt;
== Local Hosts File Configuration ==&lt;br /&gt;
Add the following entries to your local hosts file, pointing them all to the HAProxy IP (192.168.1.X):&lt;br /&gt;
&lt;br /&gt;
 192.168.1.X lb.lab.afnog.org &lt;br /&gt;
 192.168.1.X www.lab.afnog.org      &lt;br /&gt;
 192.168.1.X nginx.lab.afnog.org&lt;br /&gt;
 192.168.1.X apache.lab.afnog.org&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install and Configure HAProxy (VM1) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems (CentOS, Fedora) ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install haproxy&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems (Ubuntu, Debian) ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install haproxy&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install haproxy&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install and Configure Apache (VM2) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install httpd&lt;br /&gt;
 sudo systemctl start httpd&lt;br /&gt;
 sudo systemctl enable httpd&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install apache2&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install apache24&lt;br /&gt;
 sudo sysrc apache24_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service apache24 start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /var/www/html/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 On FreeBSD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /usr/local/www/apache24/data/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install and Configure Nginx (VM3) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install nginx&lt;br /&gt;
 sudo systemctl start nginx&lt;br /&gt;
 sudo systemctl enable nginx&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install nginx&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install nginx&lt;br /&gt;
 sudo sysrc nginx_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service nginx start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
''' &lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; |  tee /var/www/html/index.html &amp;lt;/code&amp;gt; &lt;br /&gt;
  # For FreeBSD:&lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; | tee /usr/local/www/nginx/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== HAProxy Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Basic Frontend and Backend Setup (Round-Robin) ===&lt;br /&gt;
&lt;br /&gt;
==== HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
==== Edit the HAProxy configuration file: ====&lt;br /&gt;
* '''Red Hat and Debian:''' /etc/haproxy/haproxy.cfg&lt;br /&gt;
* '''FreeBSD:''' /usr/local/etc/haproxy.conf&lt;br /&gt;
&lt;br /&gt;
==== Add the following configuration: ====&lt;br /&gt;
'''&lt;br /&gt;
 global&lt;br /&gt;
     log         127.0.0.1:514 local1 info&lt;br /&gt;
     chroot      /var/empty&lt;br /&gt;
     pidfile     /var/run/haproxy.pid&lt;br /&gt;
     maxconn     4000&lt;br /&gt;
     user        haproxy&lt;br /&gt;
     group       haproxy&lt;br /&gt;
     daemon&lt;br /&gt;
 &lt;br /&gt;
 defaults&lt;br /&gt;
     mode                    http&lt;br /&gt;
     log                     global&lt;br /&gt;
     option                  httplog&lt;br /&gt;
     option                  dontlognull&lt;br /&gt;
     option http-server-close&lt;br /&gt;
     option forwardfor       except 127.0.0.0/8&lt;br /&gt;
     retries                 3&lt;br /&gt;
     timeout http-request    10s&lt;br /&gt;
     timeout queue           1m&lt;br /&gt;
     timeout connect         10s&lt;br /&gt;
     timeout client          1m&lt;br /&gt;
     timeout server          1m&lt;br /&gt;
     timeout http-keep-alive 10s&lt;br /&gt;
     timeout check           10s&lt;br /&gt;
     maxconn                 3000&lt;br /&gt;
 &lt;br /&gt;
 frontend http-in&lt;br /&gt;
     bind *:80&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server vm1.log.afnog.org:80 check&lt;br /&gt;
     server apache_server vm2.lab.afnog.org:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Advanced Configuration with ACLs (Access Control Lists) ===&lt;br /&gt;
&lt;br /&gt;
==== Updated HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Modify the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 frontend http_front&lt;br /&gt;
     bind *:80&lt;br /&gt;
     acl url_nginx hdr(host) -i nginx.lab.afnog.org&lt;br /&gt;
     acl url_apache hdr(host) -i apache.lab.afnog.org&lt;br /&gt;
     use_backend nginx_back if url_nginx&lt;br /&gt;
     use_backend apache_back if url_apache&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend nginx_back&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend apache_back&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
To set up an active-passive configuration for your backend node, adjust the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check backup &lt;br /&gt;
 '''&lt;br /&gt;
&lt;br /&gt;
this setup will make node apache_server as a passive node and will not recive traffic unless node nginx_server is down&lt;br /&gt;
&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Adding a Status Page ===&lt;br /&gt;
&lt;br /&gt;
==== Final HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Add the following configuration for the status page:&lt;br /&gt;
'''&lt;br /&gt;
 listen stats&lt;br /&gt;
     bind *:8404&lt;br /&gt;
     stats enable&lt;br /&gt;
     stats uri /&lt;br /&gt;
     stats refresh 5s&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
==== Testing the Status Page: ====&lt;br /&gt;
&lt;br /&gt;
You can access the status page by navigating to http://192.168.1.X:8404/ in your web browser.&lt;br /&gt;
&lt;br /&gt;
== SSL Termination on HAProxy ==&lt;br /&gt;
&lt;br /&gt;
=== Generate a Self-Signed Certificate: ===&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/haproxy.key -out /etc/ssl/certs/haproxy.crt&lt;br /&gt;
&lt;br /&gt;
=== Combine the Certificate and Key: ===&lt;br /&gt;
 cat /etc/ssl/certs/haproxy.crt /etc/ssl/private/haproxy.key |  tee /etc/ssl/certs/haproxy.pem&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For development SSL certificates, you can use the repository at https://github.com/BenMorel/dev-certificates&lt;br /&gt;
&lt;br /&gt;
=== Update HAProxy Configuration to Use SSL: ===&lt;br /&gt;
&lt;br /&gt;
Add the following to the `frontend http_front` section:&lt;br /&gt;
&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem&lt;br /&gt;
 redirect scheme https if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
=== Restart HAProxy: ===&lt;br /&gt;
 sudo systemctl restart haproxy&lt;br /&gt;
=== Example for Layer 4 Load balancing , DB port : ===&lt;br /&gt;
'''&lt;br /&gt;
 frontend mysql&lt;br /&gt;
  mode tcp&lt;br /&gt;
  bind :3306&lt;br /&gt;
  default_backend mysql_servers&lt;br /&gt;
&lt;br /&gt;
 backend mysql_servers&lt;br /&gt;
  mode tcp&lt;br /&gt;
  balance leastconn&lt;br /&gt;
  server s1 192.168.0.10:3306 check&lt;br /&gt;
  server s2 192.168.0.11:3306 check&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Configure Syslog for HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
# Open the syslog configuration file for editing:&lt;br /&gt;
 vi /etc/syslog.conf&lt;br /&gt;
&lt;br /&gt;
# Add the following lines to configure logging:&lt;br /&gt;
 *.err;kern.warning;auth.notice;mail.crit                /dev/console&lt;br /&gt;
 local1.*                                                /var/log/haproxy.log&lt;br /&gt;
 *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Create the HAProxy log file:&lt;br /&gt;
 touch /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Set the appropriate ownership for the log file:&lt;br /&gt;
 chown haproxy:haproxy /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Update the syslogd flags to bind to localhost and run in compatibility mode:&lt;br /&gt;
 sysrc syslogd_flags=&amp;quot;-b localhost -C&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Restart the syslog service to apply changes:&lt;br /&gt;
 service syslogd restart&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Using `web browser`: ===&lt;br /&gt;
&lt;br /&gt;
# Test round-robin for `www.lab.afnog.org`:&lt;br /&gt;
# Repeat the command several times to see alternating responses from Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
  nginx.lab.afnog.org&lt;br /&gt;
 # This should consistently return the Nginx server response.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
  apache.lab.afnog.org&lt;br /&gt;
 # This should consistently return the Apache server response.&lt;br /&gt;
&lt;br /&gt;
# Test SSL termination:&lt;br /&gt;
  https://www.lab.afnog.org&lt;br /&gt;
 # This should return responses over HTTPS, with round-robin load balancing between Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
=== Optimal Configuration Options for Web-Based Frontends  ===&lt;br /&gt;
It's crucial to customize the following according to your application's specific requirements.&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    &lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
   &lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    &lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    &lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    &lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    &lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Implement strong SSL/TLS configurations'''&lt;br /&gt;
# '''Use IP whitelisting for the HAProxy stats page'''&lt;br /&gt;
# '''Consider implementing Web Application Firewall (WAF) rules in HAProxy'''&lt;br /&gt;
# '''Regularly audit your HAProxy configurations and access logs'''&lt;br /&gt;
&lt;br /&gt;
This guide provides a comprehensive setup process for HAProxy, starting from a basic configuration and progressing to more advanced setups with ACLs, SSL termination, and performance optimization. Always ensure to test thoroughly in a staging environment before applying changes to production systems.&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2309</id>
		<title>HAProxy Lab Setup Guide - Multi-OS Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2309"/>
		<updated>2024-09-05T12:55:52Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Updated HAProxy Configuration: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide - Multi-OS Installation =&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3 VMs (or use VirtualBox/VMware Workstation to create them)&lt;br /&gt;
* Web browser access (for those using AFNOG infrastructure)&lt;br /&gt;
&lt;br /&gt;
== VM Setup ==&lt;br /&gt;
# '''VM1:''' HAProxy       &lt;br /&gt;
#* IP: 192.168.1.X&lt;br /&gt;
# '''VM2:''' Apache Server  &lt;br /&gt;
#* IP: 192.168.1.Y&lt;br /&gt;
# '''VM3:''' Nginx Server   &lt;br /&gt;
#* IP: 192.168.1.Z&lt;br /&gt;
&lt;br /&gt;
== Local Hosts File Configuration ==&lt;br /&gt;
Add the following entries to your local hosts file, pointing them all to the HAProxy IP (192.168.1.X):&lt;br /&gt;
&lt;br /&gt;
 192.168.1.X lb.lab.afnog.org &lt;br /&gt;
 192.168.1.X www.lab.afnog.org      &lt;br /&gt;
 192.168.1.X nginx.lab.afnog.org&lt;br /&gt;
 192.168.1.X apache.lab.afnog.org&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install and Configure HAProxy (VM1) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems (CentOS, Fedora) ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install haproxy&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems (Ubuntu, Debian) ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install haproxy&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install haproxy&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install and Configure Apache (VM2) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install httpd&lt;br /&gt;
 sudo systemctl start httpd&lt;br /&gt;
 sudo systemctl enable httpd&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install apache2&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install apache24&lt;br /&gt;
 sudo sysrc apache24_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service apache24 start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /var/www/html/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 On FreeBSD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /usr/local/www/apache24/data/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install and Configure Nginx (VM3) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install nginx&lt;br /&gt;
 sudo systemctl start nginx&lt;br /&gt;
 sudo systemctl enable nginx&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install nginx&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install nginx&lt;br /&gt;
 sudo sysrc nginx_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service nginx start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
''' &lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; |  tee /var/www/html/index.html &amp;lt;/code&amp;gt; &lt;br /&gt;
  # For FreeBSD:&lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; | tee /usr/local/www/nginx/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== HAProxy Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Basic Frontend and Backend Setup (Round-Robin) ===&lt;br /&gt;
&lt;br /&gt;
==== HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
==== Edit the HAProxy configuration file: ====&lt;br /&gt;
* '''Red Hat and Debian:''' /etc/haproxy/haproxy.cfg&lt;br /&gt;
* '''FreeBSD:''' /usr/local/etc/haproxy.conf&lt;br /&gt;
&lt;br /&gt;
==== Add the following configuration: ====&lt;br /&gt;
'''&lt;br /&gt;
 global&lt;br /&gt;
     log         127.0.0.1:514 local1 info&lt;br /&gt;
     chroot      /var/empty&lt;br /&gt;
     pidfile     /var/run/haproxy.pid&lt;br /&gt;
     maxconn     4000&lt;br /&gt;
     user        haproxy&lt;br /&gt;
     group       haproxy&lt;br /&gt;
     daemon&lt;br /&gt;
 &lt;br /&gt;
 defaults&lt;br /&gt;
     mode                    http&lt;br /&gt;
     log                     global&lt;br /&gt;
     option                  httplog&lt;br /&gt;
     option                  dontlognull&lt;br /&gt;
     option http-server-close&lt;br /&gt;
     option forwardfor       except 127.0.0.0/8&lt;br /&gt;
     retries                 3&lt;br /&gt;
     timeout http-request    10s&lt;br /&gt;
     timeout queue           1m&lt;br /&gt;
     timeout connect         10s&lt;br /&gt;
     timeout client          1m&lt;br /&gt;
     timeout server          1m&lt;br /&gt;
     timeout http-keep-alive 10s&lt;br /&gt;
     timeout check           10s&lt;br /&gt;
     maxconn                 3000&lt;br /&gt;
 &lt;br /&gt;
 frontend http-in&lt;br /&gt;
     bind *:80&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server vm1.log.afnog.org:80 check&lt;br /&gt;
     server apache_server vm2.lab.afnog.org:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Advanced Configuration with ACLs (Access Control Lists) ===&lt;br /&gt;
&lt;br /&gt;
==== Updated HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Modify the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 frontend http_front&lt;br /&gt;
     bind *:80&lt;br /&gt;
     acl url_nginx hdr(host) -i nginx.lab.afnog.org&lt;br /&gt;
     acl url_apache hdr(host) -i apache.lab.afnog.org&lt;br /&gt;
     use_backend nginx_back if url_nginx&lt;br /&gt;
     use_backend apache_back if url_apache&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend nginx_back&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend apache_back&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
To set up an active-passive configuration for your backend node, adjust the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check backup &lt;br /&gt;
 '''&lt;br /&gt;
&lt;br /&gt;
this setup will make node apache_server as a passive node and will not recive traffic unless node nginx_server is down&lt;br /&gt;
&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Adding a Status Page ===&lt;br /&gt;
&lt;br /&gt;
==== Final HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Add the following configuration for the status page:&lt;br /&gt;
'''&lt;br /&gt;
 listen stats&lt;br /&gt;
     bind *:8404&lt;br /&gt;
     stats enable&lt;br /&gt;
     stats uri /&lt;br /&gt;
     stats refresh 5s&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
==== Testing the Status Page: ====&lt;br /&gt;
&lt;br /&gt;
You can access the status page by navigating to http://192.168.1.X:8404/ in your web browser.&lt;br /&gt;
&lt;br /&gt;
== SSL Termination on HAProxy ==&lt;br /&gt;
&lt;br /&gt;
=== Generate a Self-Signed Certificate: ===&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/haproxy.key -out /etc/ssl/certs/haproxy.crt&lt;br /&gt;
&lt;br /&gt;
=== Combine the Certificate and Key: ===&lt;br /&gt;
 cat /etc/ssl/certs/haproxy.crt /etc/ssl/private/haproxy.key |  tee /etc/ssl/certs/haproxy.pem&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For development SSL certificates, you can use the repository at https://github.com/BenMorel/dev-certificates&lt;br /&gt;
&lt;br /&gt;
=== Update HAProxy Configuration to Use SSL: ===&lt;br /&gt;
&lt;br /&gt;
Add the following to the `frontend http_front` section:&lt;br /&gt;
&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem&lt;br /&gt;
 redirect scheme https if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
=== Restart HAProxy: ===&lt;br /&gt;
 sudo systemctl restart haproxy&lt;br /&gt;
=== Example for Layer 4 Load balancing , DB port : ===&lt;br /&gt;
'''&lt;br /&gt;
 frontend mysql&lt;br /&gt;
  mode tcp&lt;br /&gt;
  bind :3306&lt;br /&gt;
  default_backend mysql_servers&lt;br /&gt;
&lt;br /&gt;
 backend mysql_servers&lt;br /&gt;
  mode tcp&lt;br /&gt;
  balance leastconn&lt;br /&gt;
  server s1 192.168.0.10:3306 check&lt;br /&gt;
  server s2 192.168.0.11:3306 check&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Configure Syslog for HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
# Open the syslog configuration file for editing:&lt;br /&gt;
 vi /etc/syslog.conf&lt;br /&gt;
&lt;br /&gt;
# Add the following lines to configure logging:&lt;br /&gt;
 *.err;kern.warning;auth.notice;mail.crit                /dev/console&lt;br /&gt;
 local1.*                                                /var/log/haproxy.log&lt;br /&gt;
 *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Create the HAProxy log file:&lt;br /&gt;
 touch /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Set the appropriate ownership for the log file:&lt;br /&gt;
 chown haproxy:haproxy /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Update the syslogd flags to bind to localhost and run in compatibility mode:&lt;br /&gt;
 sysrc syslogd_flags=&amp;quot;-b localhost -C&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Restart the syslog service to apply changes:&lt;br /&gt;
 service syslogd restart&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Using `web browser`: ===&lt;br /&gt;
&lt;br /&gt;
# Test round-robin for `www.lab.afnog.org`:&lt;br /&gt;
# Repeat the command several times to see alternating responses from Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
  nginx.lab.afnog.org&lt;br /&gt;
 # This should consistently return the Nginx server response.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
  apache.lab.afnog.org&lt;br /&gt;
 # This should consistently return the Apache server response.&lt;br /&gt;
&lt;br /&gt;
# Test SSL termination:&lt;br /&gt;
  https://www.lab.afnog.org&lt;br /&gt;
 # This should return responses over HTTPS, with round-robin load balancing between Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Optimal Configuration Options for Web-Based Frontends  ==&lt;br /&gt;
It's crucial to customize the following according to your application's specific requirements.&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    &lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
   &lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    &lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    &lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    &lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    &lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Implement strong SSL/TLS configurations'''&lt;br /&gt;
# '''Use IP whitelisting for the HAProxy stats page'''&lt;br /&gt;
# '''Consider implementing Web Application Firewall (WAF) rules in HAProxy'''&lt;br /&gt;
# '''Regularly audit your HAProxy configurations and access logs'''&lt;br /&gt;
&lt;br /&gt;
This guide provides a comprehensive setup process for HAProxy, starting from a basic configuration and progressing to more advanced setups with ACLs, SSL termination, and performance optimization. Always ensure to test thoroughly in a staging environment before applying changes to production systems.&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2308</id>
		<title>HAProxy Lab Setup Guide - Multi-OS Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2308"/>
		<updated>2024-09-05T12:37:29Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Create a custom index.html: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide - Multi-OS Installation =&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3 VMs (or use VirtualBox/VMware Workstation to create them)&lt;br /&gt;
* Web browser access (for those using AFNOG infrastructure)&lt;br /&gt;
&lt;br /&gt;
== VM Setup ==&lt;br /&gt;
# '''VM1:''' HAProxy       &lt;br /&gt;
#* IP: 192.168.1.X&lt;br /&gt;
# '''VM2:''' Apache Server  &lt;br /&gt;
#* IP: 192.168.1.Y&lt;br /&gt;
# '''VM3:''' Nginx Server   &lt;br /&gt;
#* IP: 192.168.1.Z&lt;br /&gt;
&lt;br /&gt;
== Local Hosts File Configuration ==&lt;br /&gt;
Add the following entries to your local hosts file, pointing them all to the HAProxy IP (192.168.1.X):&lt;br /&gt;
&lt;br /&gt;
 192.168.1.X lb.lab.afnog.org &lt;br /&gt;
 192.168.1.X www.lab.afnog.org      &lt;br /&gt;
 192.168.1.X nginx.lab.afnog.org&lt;br /&gt;
 192.168.1.X apache.lab.afnog.org&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install and Configure HAProxy (VM1) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems (CentOS, Fedora) ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install haproxy&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems (Ubuntu, Debian) ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install haproxy&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install haproxy&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install and Configure Apache (VM2) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install httpd&lt;br /&gt;
 sudo systemctl start httpd&lt;br /&gt;
 sudo systemctl enable httpd&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install apache2&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install apache24&lt;br /&gt;
 sudo sysrc apache24_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service apache24 start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /var/www/html/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 On FreeBSD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /usr/local/www/apache24/data/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install and Configure Nginx (VM3) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install nginx&lt;br /&gt;
 sudo systemctl start nginx&lt;br /&gt;
 sudo systemctl enable nginx&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install nginx&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install nginx&lt;br /&gt;
 sudo sysrc nginx_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service nginx start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
''' &lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; |  tee /var/www/html/index.html &amp;lt;/code&amp;gt; &lt;br /&gt;
  # For FreeBSD:&lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; | tee /usr/local/www/nginx/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== HAProxy Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Basic Frontend and Backend Setup (Round-Robin) ===&lt;br /&gt;
&lt;br /&gt;
==== HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
==== Edit the HAProxy configuration file: ====&lt;br /&gt;
* '''Red Hat and Debian:''' /etc/haproxy/haproxy.cfg&lt;br /&gt;
* '''FreeBSD:''' /usr/local/etc/haproxy.conf&lt;br /&gt;
&lt;br /&gt;
==== Add the following configuration: ====&lt;br /&gt;
'''&lt;br /&gt;
 global&lt;br /&gt;
     log         127.0.0.1:514 local1 info&lt;br /&gt;
     chroot      /var/empty&lt;br /&gt;
     pidfile     /var/run/haproxy.pid&lt;br /&gt;
     maxconn     4000&lt;br /&gt;
     user        haproxy&lt;br /&gt;
     group       haproxy&lt;br /&gt;
     daemon&lt;br /&gt;
 &lt;br /&gt;
 defaults&lt;br /&gt;
     mode                    http&lt;br /&gt;
     log                     global&lt;br /&gt;
     option                  httplog&lt;br /&gt;
     option                  dontlognull&lt;br /&gt;
     option http-server-close&lt;br /&gt;
     option forwardfor       except 127.0.0.0/8&lt;br /&gt;
     retries                 3&lt;br /&gt;
     timeout http-request    10s&lt;br /&gt;
     timeout queue           1m&lt;br /&gt;
     timeout connect         10s&lt;br /&gt;
     timeout client          1m&lt;br /&gt;
     timeout server          1m&lt;br /&gt;
     timeout http-keep-alive 10s&lt;br /&gt;
     timeout check           10s&lt;br /&gt;
     maxconn                 3000&lt;br /&gt;
 &lt;br /&gt;
 frontend http-in&lt;br /&gt;
     bind *:80&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server vm1.log.afnog.org:80 check&lt;br /&gt;
     server apache_server vm2.lab.afnog.org:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Advanced Configuration with ACLs (Access Control Lists) ===&lt;br /&gt;
&lt;br /&gt;
==== Updated HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Modify the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 frontend http_front&lt;br /&gt;
     bind *:80&lt;br /&gt;
     acl url_nginx hdr(host) -i nginx.lab.afnog.org&lt;br /&gt;
     acl url_apache hdr(host) -i apache.lab.afnog.org&lt;br /&gt;
     use_backend nginx_back if url_nginx&lt;br /&gt;
     use_backend apache_back if url_apache&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend nginx_back&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend apache_back&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Adding a Status Page ===&lt;br /&gt;
&lt;br /&gt;
==== Final HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Add the following configuration for the status page:&lt;br /&gt;
'''&lt;br /&gt;
 listen stats&lt;br /&gt;
     bind *:8404&lt;br /&gt;
     stats enable&lt;br /&gt;
     stats uri /&lt;br /&gt;
     stats refresh 5s&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
==== Testing the Status Page: ====&lt;br /&gt;
&lt;br /&gt;
You can access the status page by navigating to http://192.168.1.X:8404/ in your web browser.&lt;br /&gt;
&lt;br /&gt;
== SSL Termination on HAProxy ==&lt;br /&gt;
&lt;br /&gt;
=== Generate a Self-Signed Certificate: ===&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/haproxy.key -out /etc/ssl/certs/haproxy.crt&lt;br /&gt;
&lt;br /&gt;
=== Combine the Certificate and Key: ===&lt;br /&gt;
 cat /etc/ssl/certs/haproxy.crt /etc/ssl/private/haproxy.key |  tee /etc/ssl/certs/haproxy.pem&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For development SSL certificates, you can use the repository at https://github.com/BenMorel/dev-certificates&lt;br /&gt;
&lt;br /&gt;
=== Update HAProxy Configuration to Use SSL: ===&lt;br /&gt;
&lt;br /&gt;
Add the following to the `frontend http_front` section:&lt;br /&gt;
&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem&lt;br /&gt;
 redirect scheme https if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
=== Restart HAProxy: ===&lt;br /&gt;
 sudo systemctl restart haproxy&lt;br /&gt;
=== Example for Layer 4 Load balancing , DB port : ===&lt;br /&gt;
'''&lt;br /&gt;
 frontend mysql&lt;br /&gt;
  mode tcp&lt;br /&gt;
  bind :3306&lt;br /&gt;
  default_backend mysql_servers&lt;br /&gt;
&lt;br /&gt;
 backend mysql_servers&lt;br /&gt;
  mode tcp&lt;br /&gt;
  balance leastconn&lt;br /&gt;
  server s1 192.168.0.10:3306 check&lt;br /&gt;
  server s2 192.168.0.11:3306 check&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Configure Syslog for HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
# Open the syslog configuration file for editing:&lt;br /&gt;
 vi /etc/syslog.conf&lt;br /&gt;
&lt;br /&gt;
# Add the following lines to configure logging:&lt;br /&gt;
 *.err;kern.warning;auth.notice;mail.crit                /dev/console&lt;br /&gt;
 local1.*                                                /var/log/haproxy.log&lt;br /&gt;
 *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Create the HAProxy log file:&lt;br /&gt;
 touch /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Set the appropriate ownership for the log file:&lt;br /&gt;
 chown haproxy:haproxy /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Update the syslogd flags to bind to localhost and run in compatibility mode:&lt;br /&gt;
 sysrc syslogd_flags=&amp;quot;-b localhost -C&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Restart the syslog service to apply changes:&lt;br /&gt;
 service syslogd restart&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Using `web browser`: ===&lt;br /&gt;
&lt;br /&gt;
# Test round-robin for `www.lab.afnog.org`:&lt;br /&gt;
# Repeat the command several times to see alternating responses from Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
  nginx.lab.afnog.org&lt;br /&gt;
 # This should consistently return the Nginx server response.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
  apache.lab.afnog.org&lt;br /&gt;
 # This should consistently return the Apache server response.&lt;br /&gt;
&lt;br /&gt;
# Test SSL termination:&lt;br /&gt;
  https://www.lab.afnog.org&lt;br /&gt;
 # This should return responses over HTTPS, with round-robin load balancing between Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Optimal Configuration Options for Web-Based Frontends  ==&lt;br /&gt;
It's crucial to customize the following according to your application's specific requirements.&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    &lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
   &lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    &lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    &lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    &lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    &lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Implement strong SSL/TLS configurations'''&lt;br /&gt;
# '''Use IP whitelisting for the HAProxy stats page'''&lt;br /&gt;
# '''Consider implementing Web Application Firewall (WAF) rules in HAProxy'''&lt;br /&gt;
# '''Regularly audit your HAProxy configurations and access logs'''&lt;br /&gt;
&lt;br /&gt;
This guide provides a comprehensive setup process for HAProxy, starting from a basic configuration and progressing to more advanced setups with ACLs, SSL termination, and performance optimization. Always ensure to test thoroughly in a staging environment before applying changes to production systems.&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2307</id>
		<title>HAProxy Lab Setup Guide - Multi-OS Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2307"/>
		<updated>2024-09-05T12:36:45Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide - Multi-OS Installation =&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3 VMs (or use VirtualBox/VMware Workstation to create them)&lt;br /&gt;
* Web browser access (for those using AFNOG infrastructure)&lt;br /&gt;
&lt;br /&gt;
== VM Setup ==&lt;br /&gt;
# '''VM1:''' HAProxy       &lt;br /&gt;
#* IP: 192.168.1.X&lt;br /&gt;
# '''VM2:''' Apache Server  &lt;br /&gt;
#* IP: 192.168.1.Y&lt;br /&gt;
# '''VM3:''' Nginx Server   &lt;br /&gt;
#* IP: 192.168.1.Z&lt;br /&gt;
&lt;br /&gt;
== Local Hosts File Configuration ==&lt;br /&gt;
Add the following entries to your local hosts file, pointing them all to the HAProxy IP (192.168.1.X):&lt;br /&gt;
&lt;br /&gt;
 192.168.1.X lb.lab.afnog.org &lt;br /&gt;
 192.168.1.X www.lab.afnog.org      &lt;br /&gt;
 192.168.1.X nginx.lab.afnog.org&lt;br /&gt;
 192.168.1.X apache.lab.afnog.org&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install and Configure HAProxy (VM1) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems (CentOS, Fedora) ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install haproxy&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems (Ubuntu, Debian) ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install haproxy&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install haproxy&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install and Configure Apache (VM2) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install httpd&lt;br /&gt;
 sudo systemctl start httpd&lt;br /&gt;
 sudo systemctl enable httpd&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install apache2&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install apache24&lt;br /&gt;
 sudo sysrc apache24_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service apache24 start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /var/www/html/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 On FreeBSD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /usr/local/www/apache24/data/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install and Configure Nginx (VM3) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install nginx&lt;br /&gt;
 sudo systemctl start nginx&lt;br /&gt;
 sudo systemctl enable nginx&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install nginx&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install nginx&lt;br /&gt;
 sudo sysrc nginx_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service nginx start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
 &amp;lt;code&amp;gt; echo &amp;quot;This is the Nginx Server&amp;quot; |  tee /var/www/html/index.html &amp;lt;/code&amp;gt; &lt;br /&gt;
 &amp;lt;code&amp;gt; # For FreeBSD:&lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; | tee /usr/local/www/nginx/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Basic Frontend and Backend Setup (Round-Robin) ===&lt;br /&gt;
&lt;br /&gt;
==== HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
==== Edit the HAProxy configuration file: ====&lt;br /&gt;
* '''Red Hat and Debian:''' /etc/haproxy/haproxy.cfg&lt;br /&gt;
* '''FreeBSD:''' /usr/local/etc/haproxy.conf&lt;br /&gt;
&lt;br /&gt;
==== Add the following configuration: ====&lt;br /&gt;
'''&lt;br /&gt;
 global&lt;br /&gt;
     log         127.0.0.1:514 local1 info&lt;br /&gt;
     chroot      /var/empty&lt;br /&gt;
     pidfile     /var/run/haproxy.pid&lt;br /&gt;
     maxconn     4000&lt;br /&gt;
     user        haproxy&lt;br /&gt;
     group       haproxy&lt;br /&gt;
     daemon&lt;br /&gt;
 &lt;br /&gt;
 defaults&lt;br /&gt;
     mode                    http&lt;br /&gt;
     log                     global&lt;br /&gt;
     option                  httplog&lt;br /&gt;
     option                  dontlognull&lt;br /&gt;
     option http-server-close&lt;br /&gt;
     option forwardfor       except 127.0.0.0/8&lt;br /&gt;
     retries                 3&lt;br /&gt;
     timeout http-request    10s&lt;br /&gt;
     timeout queue           1m&lt;br /&gt;
     timeout connect         10s&lt;br /&gt;
     timeout client          1m&lt;br /&gt;
     timeout server          1m&lt;br /&gt;
     timeout http-keep-alive 10s&lt;br /&gt;
     timeout check           10s&lt;br /&gt;
     maxconn                 3000&lt;br /&gt;
 &lt;br /&gt;
 frontend http-in&lt;br /&gt;
     bind *:80&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server vm1.log.afnog.org:80 check&lt;br /&gt;
     server apache_server vm2.lab.afnog.org:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Advanced Configuration with ACLs (Access Control Lists) ===&lt;br /&gt;
&lt;br /&gt;
==== Updated HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Modify the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 frontend http_front&lt;br /&gt;
     bind *:80&lt;br /&gt;
     acl url_nginx hdr(host) -i nginx.lab.afnog.org&lt;br /&gt;
     acl url_apache hdr(host) -i apache.lab.afnog.org&lt;br /&gt;
     use_backend nginx_back if url_nginx&lt;br /&gt;
     use_backend apache_back if url_apache&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend nginx_back&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend apache_back&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Adding a Status Page ===&lt;br /&gt;
&lt;br /&gt;
==== Final HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Add the following configuration for the status page:&lt;br /&gt;
'''&lt;br /&gt;
 listen stats&lt;br /&gt;
     bind *:8404&lt;br /&gt;
     stats enable&lt;br /&gt;
     stats uri /&lt;br /&gt;
     stats refresh 5s&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
==== Testing the Status Page: ====&lt;br /&gt;
&lt;br /&gt;
You can access the status page by navigating to http://192.168.1.X:8404/ in your web browser.&lt;br /&gt;
&lt;br /&gt;
== SSL Termination on HAProxy ==&lt;br /&gt;
&lt;br /&gt;
=== Generate a Self-Signed Certificate: ===&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/haproxy.key -out /etc/ssl/certs/haproxy.crt&lt;br /&gt;
&lt;br /&gt;
=== Combine the Certificate and Key: ===&lt;br /&gt;
 cat /etc/ssl/certs/haproxy.crt /etc/ssl/private/haproxy.key |  tee /etc/ssl/certs/haproxy.pem&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For development SSL certificates, you can use the repository at https://github.com/BenMorel/dev-certificates&lt;br /&gt;
&lt;br /&gt;
=== Update HAProxy Configuration to Use SSL: ===&lt;br /&gt;
&lt;br /&gt;
Add the following to the `frontend http_front` section:&lt;br /&gt;
&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem&lt;br /&gt;
 redirect scheme https if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
=== Restart HAProxy: ===&lt;br /&gt;
 sudo systemctl restart haproxy&lt;br /&gt;
=== Example for Layer 4 Load balancing , DB port : ===&lt;br /&gt;
'''&lt;br /&gt;
 frontend mysql&lt;br /&gt;
  mode tcp&lt;br /&gt;
  bind :3306&lt;br /&gt;
  default_backend mysql_servers&lt;br /&gt;
&lt;br /&gt;
 backend mysql_servers&lt;br /&gt;
  mode tcp&lt;br /&gt;
  balance leastconn&lt;br /&gt;
  server s1 192.168.0.10:3306 check&lt;br /&gt;
  server s2 192.168.0.11:3306 check&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Configure Syslog for HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
# Open the syslog configuration file for editing:&lt;br /&gt;
 vi /etc/syslog.conf&lt;br /&gt;
&lt;br /&gt;
# Add the following lines to configure logging:&lt;br /&gt;
 *.err;kern.warning;auth.notice;mail.crit                /dev/console&lt;br /&gt;
 local1.*                                                /var/log/haproxy.log&lt;br /&gt;
 *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Create the HAProxy log file:&lt;br /&gt;
 touch /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Set the appropriate ownership for the log file:&lt;br /&gt;
 chown haproxy:haproxy /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Update the syslogd flags to bind to localhost and run in compatibility mode:&lt;br /&gt;
 sysrc syslogd_flags=&amp;quot;-b localhost -C&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Restart the syslog service to apply changes:&lt;br /&gt;
 service syslogd restart&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Using `web browser`: ===&lt;br /&gt;
&lt;br /&gt;
# Test round-robin for `www.lab.afnog.org`:&lt;br /&gt;
# Repeat the command several times to see alternating responses from Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
  nginx.lab.afnog.org&lt;br /&gt;
 # This should consistently return the Nginx server response.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
  apache.lab.afnog.org&lt;br /&gt;
 # This should consistently return the Apache server response.&lt;br /&gt;
&lt;br /&gt;
# Test SSL termination:&lt;br /&gt;
  https://www.lab.afnog.org&lt;br /&gt;
 # This should return responses over HTTPS, with round-robin load balancing between Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Optimal Configuration Options for Web-Based Frontends  ==&lt;br /&gt;
It's crucial to customize the following according to your application's specific requirements.&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    &lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
   &lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    &lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    &lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    &lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    &lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Implement strong SSL/TLS configurations'''&lt;br /&gt;
# '''Use IP whitelisting for the HAProxy stats page'''&lt;br /&gt;
# '''Consider implementing Web Application Firewall (WAF) rules in HAProxy'''&lt;br /&gt;
# '''Regularly audit your HAProxy configurations and access logs'''&lt;br /&gt;
&lt;br /&gt;
This guide provides a comprehensive setup process for HAProxy, starting from a basic configuration and progressing to more advanced setups with ACLs, SSL termination, and performance optimization. Always ensure to test thoroughly in a staging environment before applying changes to production systems.&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2306</id>
		<title>HAProxy Lab Setup Guide - Multi-OS Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2306"/>
		<updated>2024-09-05T12:35:18Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* best practice options for web based frontend */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide - Multi-OS Installation =&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3 VMs (or use VirtualBox/VMware Workstation to create them)&lt;br /&gt;
* Web browser access (for those using AFNOG infrastructure)&lt;br /&gt;
&lt;br /&gt;
== VM Setup ==&lt;br /&gt;
# '''VM1:''' HAProxy       &lt;br /&gt;
#* IP: 192.168.1.X&lt;br /&gt;
# '''VM2:''' Apache Server  &lt;br /&gt;
#* IP: 192.168.1.Y&lt;br /&gt;
# '''VM3:''' Nginx Server   &lt;br /&gt;
#* IP: 192.168.1.Z&lt;br /&gt;
&lt;br /&gt;
== Local Hosts File Configuration ==&lt;br /&gt;
Add the following entries to your local hosts file, pointing them all to the HAProxy IP (192.168.1.X):&lt;br /&gt;
&lt;br /&gt;
 192.168.1.X lb.lab.afnog.org &lt;br /&gt;
 192.168.1.X www.lab.afnog.org      &lt;br /&gt;
 192.168.1.X nginx.lab.afnog.org&lt;br /&gt;
 192.168.1.X apache.lab.afnog.org&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install and Configure HAProxy (VM1) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems (CentOS, Fedora) ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install haproxy&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems (Ubuntu, Debian) ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install haproxy&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install haproxy&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install and Configure Apache (VM2) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install httpd&lt;br /&gt;
 sudo systemctl start httpd&lt;br /&gt;
 sudo systemctl enable httpd&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install apache2&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install apache24&lt;br /&gt;
 sudo sysrc apache24_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service apache24 start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /var/www/html/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 On FreeBSD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /usr/local/www/apache24/data/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install and Configure Nginx (VM3) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install nginx&lt;br /&gt;
 sudo systemctl start nginx&lt;br /&gt;
 sudo systemctl enable nginx&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install nginx&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install nginx&lt;br /&gt;
 sudo sysrc nginx_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service nginx start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
 &amp;lt;code&amp;gt; echo &amp;quot;This is the Nginx Server&amp;quot; |  tee /var/www/html/index.html &amp;lt;/code&amp;gt; &lt;br /&gt;
 &amp;lt;code&amp;gt; # For FreeBSD:&lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; | tee /usr/local/www/nginx/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Basic Frontend and Backend Setup (Round-Robin) ===&lt;br /&gt;
&lt;br /&gt;
==== HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
==== Edit the HAProxy configuration file: ====&lt;br /&gt;
* '''Red Hat and Debian:''' /etc/haproxy/haproxy.cfg&lt;br /&gt;
* '''FreeBSD:''' /usr/local/etc/haproxy.conf&lt;br /&gt;
&lt;br /&gt;
==== Add the following configuration: ====&lt;br /&gt;
'''&lt;br /&gt;
 global&lt;br /&gt;
     log         127.0.0.1:514 local1 info&lt;br /&gt;
     chroot      /var/empty&lt;br /&gt;
     pidfile     /var/run/haproxy.pid&lt;br /&gt;
     maxconn     4000&lt;br /&gt;
     user        haproxy&lt;br /&gt;
     group       haproxy&lt;br /&gt;
     daemon&lt;br /&gt;
 &lt;br /&gt;
 defaults&lt;br /&gt;
     mode                    http&lt;br /&gt;
     log                     global&lt;br /&gt;
     option                  httplog&lt;br /&gt;
     option                  dontlognull&lt;br /&gt;
     option http-server-close&lt;br /&gt;
     option forwardfor       except 127.0.0.0/8&lt;br /&gt;
     retries                 3&lt;br /&gt;
     timeout http-request    10s&lt;br /&gt;
     timeout queue           1m&lt;br /&gt;
     timeout connect         10s&lt;br /&gt;
     timeout client          1m&lt;br /&gt;
     timeout server          1m&lt;br /&gt;
     timeout http-keep-alive 10s&lt;br /&gt;
     timeout check           10s&lt;br /&gt;
     maxconn                 3000&lt;br /&gt;
 &lt;br /&gt;
 frontend http-in&lt;br /&gt;
     bind *:80&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server vm1.log.afnog.org:80 check&lt;br /&gt;
     server apache_server vm2.lab.afnog.org:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Advanced Configuration with ACLs (Access Control Lists) ===&lt;br /&gt;
&lt;br /&gt;
==== Updated HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Modify the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 frontend http_front&lt;br /&gt;
     bind *:80&lt;br /&gt;
     acl url_nginx hdr(host) -i nginx.lab.afnog.org&lt;br /&gt;
     acl url_apache hdr(host) -i apache.lab.afnog.org&lt;br /&gt;
     use_backend nginx_back if url_nginx&lt;br /&gt;
     use_backend apache_back if url_apache&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend nginx_back&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend apache_back&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Adding a Status Page ===&lt;br /&gt;
&lt;br /&gt;
==== Final HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Add the following configuration for the status page:&lt;br /&gt;
'''&lt;br /&gt;
 listen stats&lt;br /&gt;
     bind *:8404&lt;br /&gt;
     stats enable&lt;br /&gt;
     stats uri /&lt;br /&gt;
     stats refresh 5s&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
==== Testing the Status Page: ====&lt;br /&gt;
&lt;br /&gt;
You can access the status page by navigating to http://192.168.1.X:8404/ in your web browser.&lt;br /&gt;
&lt;br /&gt;
== SSL Termination on HAProxy ==&lt;br /&gt;
&lt;br /&gt;
=== Generate a Self-Signed Certificate: ===&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/haproxy.key -out /etc/ssl/certs/haproxy.crt&lt;br /&gt;
&lt;br /&gt;
=== Combine the Certificate and Key: ===&lt;br /&gt;
 cat /etc/ssl/certs/haproxy.crt /etc/ssl/private/haproxy.key |  tee /etc/ssl/certs/haproxy.pem&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For development SSL certificates, you can use the repository at https://github.com/BenMorel/dev-certificates&lt;br /&gt;
&lt;br /&gt;
=== Update HAProxy Configuration to Use SSL: ===&lt;br /&gt;
&lt;br /&gt;
Add the following to the `frontend http_front` section:&lt;br /&gt;
&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem&lt;br /&gt;
 redirect scheme https if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
=== Restart HAProxy: ===&lt;br /&gt;
 sudo systemctl restart haproxy&lt;br /&gt;
=== Example for Layer 4 Load balancing , DB port : ===&lt;br /&gt;
'''&lt;br /&gt;
 frontend mysql&lt;br /&gt;
  mode tcp&lt;br /&gt;
  bind :3306&lt;br /&gt;
  default_backend mysql_servers&lt;br /&gt;
&lt;br /&gt;
 backend mysql_servers&lt;br /&gt;
  mode tcp&lt;br /&gt;
  balance leastconn&lt;br /&gt;
  server s1 192.168.0.10:3306 check&lt;br /&gt;
  server s2 192.168.0.11:3306 check&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Configure Syslog for HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
# Open the syslog configuration file for editing:&lt;br /&gt;
 vi /etc/syslog.conf&lt;br /&gt;
&lt;br /&gt;
# Add the following lines to configure logging:&lt;br /&gt;
 *.err;kern.warning;auth.notice;mail.crit                /dev/console&lt;br /&gt;
 local1.*                                                /var/log/haproxy.log&lt;br /&gt;
 *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Create the HAProxy log file:&lt;br /&gt;
 touch /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Set the appropriate ownership for the log file:&lt;br /&gt;
 chown haproxy:haproxy /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Update the syslogd flags to bind to localhost and run in compatibility mode:&lt;br /&gt;
 sysrc syslogd_flags=&amp;quot;-b localhost -C&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Restart the syslog service to apply changes:&lt;br /&gt;
 service syslogd restart&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Using `curl`: ===&lt;br /&gt;
&lt;br /&gt;
# Test round-robin for `www.lab.afnog.org`:&lt;br /&gt;
 curl -H &amp;quot;Host: www.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # Repeat the command several times to see alternating responses from Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 curl -H &amp;quot;Host: nginx.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Nginx server response.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 curl -H &amp;quot;Host: apache.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Apache server response.&lt;br /&gt;
&lt;br /&gt;
# Test SSL termination:&lt;br /&gt;
 curl -k https://www.lab.afnog.org&lt;br /&gt;
 # This should return responses over HTTPS, with round-robin load balancing between Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
=== Using `w3m`: ===&lt;br /&gt;
&lt;br /&gt;
# Browse to `www.lab.afnog.org` using `w3m`:&lt;br /&gt;
 w3m http://www.lab.afnog.org&lt;br /&gt;
 # Navigate the site to ensure both servers (Nginx and Apache) are being served correctly in round-robin fashion.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 w3m http://nginx.lab.afnog.org&lt;br /&gt;
 # Ensure that the Nginx server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 w3m http://apache.lab.afnog.org&lt;br /&gt;
 # Ensure that the Apache server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test SSL with `w3m`:&lt;br /&gt;
 w3m https://www.lab.afnog.org&lt;br /&gt;
 # Verify that SSL termination works and the content is served over HTTPS.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== Optimal Configuration Options for Web-Based Frontends  ==&lt;br /&gt;
It's crucial to customize the following according to your application's specific requirements.&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    &lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
   &lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    &lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    &lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    &lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    &lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Implement strong SSL/TLS configurations'''&lt;br /&gt;
# '''Use IP whitelisting for the HAProxy stats page'''&lt;br /&gt;
# '''Consider implementing Web Application Firewall (WAF) rules in HAProxy'''&lt;br /&gt;
# '''Regularly audit your HAProxy configurations and access logs'''&lt;br /&gt;
&lt;br /&gt;
This guide provides a comprehensive setup process for HAProxy, starting from a basic configuration and progressing to more advanced setups with ACLs, SSL termination, and performance optimization. Always ensure to test thoroughly in a staging environment before applying changes to production systems.&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2305</id>
		<title>HAProxy Lab Setup Guide - Multi-OS Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2305"/>
		<updated>2024-09-05T12:34:05Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* best practice options for web based frontend */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide - Multi-OS Installation =&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3 VMs (or use VirtualBox/VMware Workstation to create them)&lt;br /&gt;
* Web browser access (for those using AFNOG infrastructure)&lt;br /&gt;
&lt;br /&gt;
== VM Setup ==&lt;br /&gt;
# '''VM1:''' HAProxy       &lt;br /&gt;
#* IP: 192.168.1.X&lt;br /&gt;
# '''VM2:''' Apache Server  &lt;br /&gt;
#* IP: 192.168.1.Y&lt;br /&gt;
# '''VM3:''' Nginx Server   &lt;br /&gt;
#* IP: 192.168.1.Z&lt;br /&gt;
&lt;br /&gt;
== Local Hosts File Configuration ==&lt;br /&gt;
Add the following entries to your local hosts file, pointing them all to the HAProxy IP (192.168.1.X):&lt;br /&gt;
&lt;br /&gt;
 192.168.1.X lb.lab.afnog.org &lt;br /&gt;
 192.168.1.X www.lab.afnog.org      &lt;br /&gt;
 192.168.1.X nginx.lab.afnog.org&lt;br /&gt;
 192.168.1.X apache.lab.afnog.org&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install and Configure HAProxy (VM1) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems (CentOS, Fedora) ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install haproxy&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems (Ubuntu, Debian) ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install haproxy&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install haproxy&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install and Configure Apache (VM2) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install httpd&lt;br /&gt;
 sudo systemctl start httpd&lt;br /&gt;
 sudo systemctl enable httpd&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install apache2&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install apache24&lt;br /&gt;
 sudo sysrc apache24_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service apache24 start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /var/www/html/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 On FreeBSD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /usr/local/www/apache24/data/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install and Configure Nginx (VM3) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install nginx&lt;br /&gt;
 sudo systemctl start nginx&lt;br /&gt;
 sudo systemctl enable nginx&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install nginx&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install nginx&lt;br /&gt;
 sudo sysrc nginx_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service nginx start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
 &amp;lt;code&amp;gt; echo &amp;quot;This is the Nginx Server&amp;quot; |  tee /var/www/html/index.html &amp;lt;/code&amp;gt; &lt;br /&gt;
 &amp;lt;code&amp;gt; # For FreeBSD:&lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; | tee /usr/local/www/nginx/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Basic Frontend and Backend Setup (Round-Robin) ===&lt;br /&gt;
&lt;br /&gt;
==== HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
==== Edit the HAProxy configuration file: ====&lt;br /&gt;
* '''Red Hat and Debian:''' /etc/haproxy/haproxy.cfg&lt;br /&gt;
* '''FreeBSD:''' /usr/local/etc/haproxy.conf&lt;br /&gt;
&lt;br /&gt;
==== Add the following configuration: ====&lt;br /&gt;
'''&lt;br /&gt;
 global&lt;br /&gt;
     log         127.0.0.1:514 local1 info&lt;br /&gt;
     chroot      /var/empty&lt;br /&gt;
     pidfile     /var/run/haproxy.pid&lt;br /&gt;
     maxconn     4000&lt;br /&gt;
     user        haproxy&lt;br /&gt;
     group       haproxy&lt;br /&gt;
     daemon&lt;br /&gt;
 &lt;br /&gt;
 defaults&lt;br /&gt;
     mode                    http&lt;br /&gt;
     log                     global&lt;br /&gt;
     option                  httplog&lt;br /&gt;
     option                  dontlognull&lt;br /&gt;
     option http-server-close&lt;br /&gt;
     option forwardfor       except 127.0.0.0/8&lt;br /&gt;
     retries                 3&lt;br /&gt;
     timeout http-request    10s&lt;br /&gt;
     timeout queue           1m&lt;br /&gt;
     timeout connect         10s&lt;br /&gt;
     timeout client          1m&lt;br /&gt;
     timeout server          1m&lt;br /&gt;
     timeout http-keep-alive 10s&lt;br /&gt;
     timeout check           10s&lt;br /&gt;
     maxconn                 3000&lt;br /&gt;
 &lt;br /&gt;
 frontend http-in&lt;br /&gt;
     bind *:80&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server vm1.log.afnog.org:80 check&lt;br /&gt;
     server apache_server vm2.lab.afnog.org:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Advanced Configuration with ACLs (Access Control Lists) ===&lt;br /&gt;
&lt;br /&gt;
==== Updated HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Modify the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 frontend http_front&lt;br /&gt;
     bind *:80&lt;br /&gt;
     acl url_nginx hdr(host) -i nginx.lab.afnog.org&lt;br /&gt;
     acl url_apache hdr(host) -i apache.lab.afnog.org&lt;br /&gt;
     use_backend nginx_back if url_nginx&lt;br /&gt;
     use_backend apache_back if url_apache&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend nginx_back&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend apache_back&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Adding a Status Page ===&lt;br /&gt;
&lt;br /&gt;
==== Final HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Add the following configuration for the status page:&lt;br /&gt;
'''&lt;br /&gt;
 listen stats&lt;br /&gt;
     bind *:8404&lt;br /&gt;
     stats enable&lt;br /&gt;
     stats uri /&lt;br /&gt;
     stats refresh 5s&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
==== Testing the Status Page: ====&lt;br /&gt;
&lt;br /&gt;
You can access the status page by navigating to http://192.168.1.X:8404/ in your web browser.&lt;br /&gt;
&lt;br /&gt;
== SSL Termination on HAProxy ==&lt;br /&gt;
&lt;br /&gt;
=== Generate a Self-Signed Certificate: ===&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/haproxy.key -out /etc/ssl/certs/haproxy.crt&lt;br /&gt;
&lt;br /&gt;
=== Combine the Certificate and Key: ===&lt;br /&gt;
 cat /etc/ssl/certs/haproxy.crt /etc/ssl/private/haproxy.key |  tee /etc/ssl/certs/haproxy.pem&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For development SSL certificates, you can use the repository at https://github.com/BenMorel/dev-certificates&lt;br /&gt;
&lt;br /&gt;
=== Update HAProxy Configuration to Use SSL: ===&lt;br /&gt;
&lt;br /&gt;
Add the following to the `frontend http_front` section:&lt;br /&gt;
&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem&lt;br /&gt;
 redirect scheme https if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
=== Restart HAProxy: ===&lt;br /&gt;
 sudo systemctl restart haproxy&lt;br /&gt;
=== Example for Layer 4 Load balancing , DB port : ===&lt;br /&gt;
'''&lt;br /&gt;
 frontend mysql&lt;br /&gt;
  mode tcp&lt;br /&gt;
  bind :3306&lt;br /&gt;
  default_backend mysql_servers&lt;br /&gt;
&lt;br /&gt;
 backend mysql_servers&lt;br /&gt;
  mode tcp&lt;br /&gt;
  balance leastconn&lt;br /&gt;
  server s1 192.168.0.10:3306 check&lt;br /&gt;
  server s2 192.168.0.11:3306 check&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Configure Syslog for HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
# Open the syslog configuration file for editing:&lt;br /&gt;
 vi /etc/syslog.conf&lt;br /&gt;
&lt;br /&gt;
# Add the following lines to configure logging:&lt;br /&gt;
 *.err;kern.warning;auth.notice;mail.crit                /dev/console&lt;br /&gt;
 local1.*                                                /var/log/haproxy.log&lt;br /&gt;
 *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Create the HAProxy log file:&lt;br /&gt;
 touch /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Set the appropriate ownership for the log file:&lt;br /&gt;
 chown haproxy:haproxy /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Update the syslogd flags to bind to localhost and run in compatibility mode:&lt;br /&gt;
 sysrc syslogd_flags=&amp;quot;-b localhost -C&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Restart the syslog service to apply changes:&lt;br /&gt;
 service syslogd restart&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Using `curl`: ===&lt;br /&gt;
&lt;br /&gt;
# Test round-robin for `www.lab.afnog.org`:&lt;br /&gt;
 curl -H &amp;quot;Host: www.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # Repeat the command several times to see alternating responses from Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 curl -H &amp;quot;Host: nginx.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Nginx server response.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 curl -H &amp;quot;Host: apache.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Apache server response.&lt;br /&gt;
&lt;br /&gt;
# Test SSL termination:&lt;br /&gt;
 curl -k https://www.lab.afnog.org&lt;br /&gt;
 # This should return responses over HTTPS, with round-robin load balancing between Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
=== Using `w3m`: ===&lt;br /&gt;
&lt;br /&gt;
# Browse to `www.lab.afnog.org` using `w3m`:&lt;br /&gt;
 w3m http://www.lab.afnog.org&lt;br /&gt;
 # Navigate the site to ensure both servers (Nginx and Apache) are being served correctly in round-robin fashion.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 w3m http://nginx.lab.afnog.org&lt;br /&gt;
 # Ensure that the Nginx server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 w3m http://apache.lab.afnog.org&lt;br /&gt;
 # Ensure that the Apache server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test SSL with `w3m`:&lt;br /&gt;
 w3m https://www.lab.afnog.org&lt;br /&gt;
 # Verify that SSL termination works and the content is served over HTTPS.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== best practice options for web based frontend  ==&lt;br /&gt;
it's essential to tailor the following based on the specific needs of your application&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    &lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
   &lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    &lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    &lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    &lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    &lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Implement strong SSL/TLS configurations'''&lt;br /&gt;
# '''Use IP whitelisting for the HAProxy stats page'''&lt;br /&gt;
# '''Consider implementing Web Application Firewall (WAF) rules in HAProxy'''&lt;br /&gt;
# '''Regularly audit your HAProxy configurations and access logs'''&lt;br /&gt;
&lt;br /&gt;
This guide provides a comprehensive setup process for HAProxy, starting from a basic configuration and progressing to more advanced setups with ACLs, SSL termination, and performance optimization. Always ensure to test thoroughly in a staging environment before applying changes to production systems.&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2304</id>
		<title>HAProxy Lab Setup Guide - Multi-OS Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2304"/>
		<updated>2024-09-05T12:33:04Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* best practice options for web based frontend */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide - Multi-OS Installation =&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3 VMs (or use VirtualBox/VMware Workstation to create them)&lt;br /&gt;
* Web browser access (for those using AFNOG infrastructure)&lt;br /&gt;
&lt;br /&gt;
== VM Setup ==&lt;br /&gt;
# '''VM1:''' HAProxy       &lt;br /&gt;
#* IP: 192.168.1.X&lt;br /&gt;
# '''VM2:''' Apache Server  &lt;br /&gt;
#* IP: 192.168.1.Y&lt;br /&gt;
# '''VM3:''' Nginx Server   &lt;br /&gt;
#* IP: 192.168.1.Z&lt;br /&gt;
&lt;br /&gt;
== Local Hosts File Configuration ==&lt;br /&gt;
Add the following entries to your local hosts file, pointing them all to the HAProxy IP (192.168.1.X):&lt;br /&gt;
&lt;br /&gt;
 192.168.1.X lb.lab.afnog.org &lt;br /&gt;
 192.168.1.X www.lab.afnog.org      &lt;br /&gt;
 192.168.1.X nginx.lab.afnog.org&lt;br /&gt;
 192.168.1.X apache.lab.afnog.org&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install and Configure HAProxy (VM1) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems (CentOS, Fedora) ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install haproxy&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems (Ubuntu, Debian) ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install haproxy&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install haproxy&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install and Configure Apache (VM2) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install httpd&lt;br /&gt;
 sudo systemctl start httpd&lt;br /&gt;
 sudo systemctl enable httpd&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install apache2&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install apache24&lt;br /&gt;
 sudo sysrc apache24_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service apache24 start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /var/www/html/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 On FreeBSD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /usr/local/www/apache24/data/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install and Configure Nginx (VM3) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install nginx&lt;br /&gt;
 sudo systemctl start nginx&lt;br /&gt;
 sudo systemctl enable nginx&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install nginx&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install nginx&lt;br /&gt;
 sudo sysrc nginx_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service nginx start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
 &amp;lt;code&amp;gt; echo &amp;quot;This is the Nginx Server&amp;quot; |  tee /var/www/html/index.html &amp;lt;/code&amp;gt; &lt;br /&gt;
 &amp;lt;code&amp;gt; # For FreeBSD:&lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; | tee /usr/local/www/nginx/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Basic Frontend and Backend Setup (Round-Robin) ===&lt;br /&gt;
&lt;br /&gt;
==== HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
==== Edit the HAProxy configuration file: ====&lt;br /&gt;
* '''Red Hat and Debian:''' /etc/haproxy/haproxy.cfg&lt;br /&gt;
* '''FreeBSD:''' /usr/local/etc/haproxy.conf&lt;br /&gt;
&lt;br /&gt;
==== Add the following configuration: ====&lt;br /&gt;
'''&lt;br /&gt;
 global&lt;br /&gt;
     log         127.0.0.1:514 local1 info&lt;br /&gt;
     chroot      /var/empty&lt;br /&gt;
     pidfile     /var/run/haproxy.pid&lt;br /&gt;
     maxconn     4000&lt;br /&gt;
     user        haproxy&lt;br /&gt;
     group       haproxy&lt;br /&gt;
     daemon&lt;br /&gt;
 &lt;br /&gt;
 defaults&lt;br /&gt;
     mode                    http&lt;br /&gt;
     log                     global&lt;br /&gt;
     option                  httplog&lt;br /&gt;
     option                  dontlognull&lt;br /&gt;
     option http-server-close&lt;br /&gt;
     option forwardfor       except 127.0.0.0/8&lt;br /&gt;
     retries                 3&lt;br /&gt;
     timeout http-request    10s&lt;br /&gt;
     timeout queue           1m&lt;br /&gt;
     timeout connect         10s&lt;br /&gt;
     timeout client          1m&lt;br /&gt;
     timeout server          1m&lt;br /&gt;
     timeout http-keep-alive 10s&lt;br /&gt;
     timeout check           10s&lt;br /&gt;
     maxconn                 3000&lt;br /&gt;
 &lt;br /&gt;
 frontend http-in&lt;br /&gt;
     bind *:80&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server vm1.log.afnog.org:80 check&lt;br /&gt;
     server apache_server vm2.lab.afnog.org:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Advanced Configuration with ACLs (Access Control Lists) ===&lt;br /&gt;
&lt;br /&gt;
==== Updated HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Modify the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 frontend http_front&lt;br /&gt;
     bind *:80&lt;br /&gt;
     acl url_nginx hdr(host) -i nginx.lab.afnog.org&lt;br /&gt;
     acl url_apache hdr(host) -i apache.lab.afnog.org&lt;br /&gt;
     use_backend nginx_back if url_nginx&lt;br /&gt;
     use_backend apache_back if url_apache&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend nginx_back&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend apache_back&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Adding a Status Page ===&lt;br /&gt;
&lt;br /&gt;
==== Final HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Add the following configuration for the status page:&lt;br /&gt;
'''&lt;br /&gt;
 listen stats&lt;br /&gt;
     bind *:8404&lt;br /&gt;
     stats enable&lt;br /&gt;
     stats uri /&lt;br /&gt;
     stats refresh 5s&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
==== Testing the Status Page: ====&lt;br /&gt;
&lt;br /&gt;
You can access the status page by navigating to http://192.168.1.X:8404/ in your web browser.&lt;br /&gt;
&lt;br /&gt;
== SSL Termination on HAProxy ==&lt;br /&gt;
&lt;br /&gt;
=== Generate a Self-Signed Certificate: ===&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/haproxy.key -out /etc/ssl/certs/haproxy.crt&lt;br /&gt;
&lt;br /&gt;
=== Combine the Certificate and Key: ===&lt;br /&gt;
 cat /etc/ssl/certs/haproxy.crt /etc/ssl/private/haproxy.key |  tee /etc/ssl/certs/haproxy.pem&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For development SSL certificates, you can use the repository at https://github.com/BenMorel/dev-certificates&lt;br /&gt;
&lt;br /&gt;
=== Update HAProxy Configuration to Use SSL: ===&lt;br /&gt;
&lt;br /&gt;
Add the following to the `frontend http_front` section:&lt;br /&gt;
&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem&lt;br /&gt;
 redirect scheme https if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
=== Restart HAProxy: ===&lt;br /&gt;
 sudo systemctl restart haproxy&lt;br /&gt;
=== Example for Layer 4 Load balancing , DB port : ===&lt;br /&gt;
'''&lt;br /&gt;
 frontend mysql&lt;br /&gt;
  mode tcp&lt;br /&gt;
  bind :3306&lt;br /&gt;
  default_backend mysql_servers&lt;br /&gt;
&lt;br /&gt;
 backend mysql_servers&lt;br /&gt;
  mode tcp&lt;br /&gt;
  balance leastconn&lt;br /&gt;
  server s1 192.168.0.10:3306 check&lt;br /&gt;
  server s2 192.168.0.11:3306 check&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Configure Syslog for HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
# Open the syslog configuration file for editing:&lt;br /&gt;
 vi /etc/syslog.conf&lt;br /&gt;
&lt;br /&gt;
# Add the following lines to configure logging:&lt;br /&gt;
 *.err;kern.warning;auth.notice;mail.crit                /dev/console&lt;br /&gt;
 local1.*                                                /var/log/haproxy.log&lt;br /&gt;
 *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Create the HAProxy log file:&lt;br /&gt;
 touch /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Set the appropriate ownership for the log file:&lt;br /&gt;
 chown haproxy:haproxy /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Update the syslogd flags to bind to localhost and run in compatibility mode:&lt;br /&gt;
 sysrc syslogd_flags=&amp;quot;-b localhost -C&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Restart the syslog service to apply changes:&lt;br /&gt;
 service syslogd restart&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Using `curl`: ===&lt;br /&gt;
&lt;br /&gt;
# Test round-robin for `www.lab.afnog.org`:&lt;br /&gt;
 curl -H &amp;quot;Host: www.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # Repeat the command several times to see alternating responses from Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 curl -H &amp;quot;Host: nginx.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Nginx server response.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 curl -H &amp;quot;Host: apache.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Apache server response.&lt;br /&gt;
&lt;br /&gt;
# Test SSL termination:&lt;br /&gt;
 curl -k https://www.lab.afnog.org&lt;br /&gt;
 # This should return responses over HTTPS, with round-robin load balancing between Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
=== Using `w3m`: ===&lt;br /&gt;
&lt;br /&gt;
# Browse to `www.lab.afnog.org` using `w3m`:&lt;br /&gt;
 w3m http://www.lab.afnog.org&lt;br /&gt;
 # Navigate the site to ensure both servers (Nginx and Apache) are being served correctly in round-robin fashion.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 w3m http://nginx.lab.afnog.org&lt;br /&gt;
 # Ensure that the Nginx server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 w3m http://apache.lab.afnog.org&lt;br /&gt;
 # Ensure that the Apache server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test SSL with `w3m`:&lt;br /&gt;
 w3m https://www.lab.afnog.org&lt;br /&gt;
 # Verify that SSL termination works and the content is served over HTTPS.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== best practice options for web based frontend  ==&lt;br /&gt;
it's essential to tailor the following based on the specific needs of your application&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    &lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Implement strong SSL/TLS configurations'''&lt;br /&gt;
# '''Use IP whitelisting for the HAProxy stats page'''&lt;br /&gt;
# '''Consider implementing Web Application Firewall (WAF) rules in HAProxy'''&lt;br /&gt;
# '''Regularly audit your HAProxy configurations and access logs'''&lt;br /&gt;
&lt;br /&gt;
This guide provides a comprehensive setup process for HAProxy, starting from a basic configuration and progressing to more advanced setups with ACLs, SSL termination, and performance optimization. Always ensure to test thoroughly in a staging environment before applying changes to production systems.&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2303</id>
		<title>HAProxy Lab Setup Guide - Multi-OS Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2303"/>
		<updated>2024-09-05T12:32:19Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* best practice options for web based frontend */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide - Multi-OS Installation =&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3 VMs (or use VirtualBox/VMware Workstation to create them)&lt;br /&gt;
* Web browser access (for those using AFNOG infrastructure)&lt;br /&gt;
&lt;br /&gt;
== VM Setup ==&lt;br /&gt;
# '''VM1:''' HAProxy       &lt;br /&gt;
#* IP: 192.168.1.X&lt;br /&gt;
# '''VM2:''' Apache Server  &lt;br /&gt;
#* IP: 192.168.1.Y&lt;br /&gt;
# '''VM3:''' Nginx Server   &lt;br /&gt;
#* IP: 192.168.1.Z&lt;br /&gt;
&lt;br /&gt;
== Local Hosts File Configuration ==&lt;br /&gt;
Add the following entries to your local hosts file, pointing them all to the HAProxy IP (192.168.1.X):&lt;br /&gt;
&lt;br /&gt;
 192.168.1.X lb.lab.afnog.org &lt;br /&gt;
 192.168.1.X www.lab.afnog.org      &lt;br /&gt;
 192.168.1.X nginx.lab.afnog.org&lt;br /&gt;
 192.168.1.X apache.lab.afnog.org&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install and Configure HAProxy (VM1) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems (CentOS, Fedora) ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install haproxy&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems (Ubuntu, Debian) ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install haproxy&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install haproxy&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install and Configure Apache (VM2) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install httpd&lt;br /&gt;
 sudo systemctl start httpd&lt;br /&gt;
 sudo systemctl enable httpd&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install apache2&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install apache24&lt;br /&gt;
 sudo sysrc apache24_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service apache24 start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /var/www/html/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 On FreeBSD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /usr/local/www/apache24/data/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install and Configure Nginx (VM3) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install nginx&lt;br /&gt;
 sudo systemctl start nginx&lt;br /&gt;
 sudo systemctl enable nginx&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install nginx&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install nginx&lt;br /&gt;
 sudo sysrc nginx_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service nginx start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
 &amp;lt;code&amp;gt; echo &amp;quot;This is the Nginx Server&amp;quot; |  tee /var/www/html/index.html &amp;lt;/code&amp;gt; &lt;br /&gt;
 &amp;lt;code&amp;gt; # For FreeBSD:&lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; | tee /usr/local/www/nginx/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Basic Frontend and Backend Setup (Round-Robin) ===&lt;br /&gt;
&lt;br /&gt;
==== HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
==== Edit the HAProxy configuration file: ====&lt;br /&gt;
* '''Red Hat and Debian:''' /etc/haproxy/haproxy.cfg&lt;br /&gt;
* '''FreeBSD:''' /usr/local/etc/haproxy.conf&lt;br /&gt;
&lt;br /&gt;
==== Add the following configuration: ====&lt;br /&gt;
'''&lt;br /&gt;
 global&lt;br /&gt;
     log         127.0.0.1:514 local1 info&lt;br /&gt;
     chroot      /var/empty&lt;br /&gt;
     pidfile     /var/run/haproxy.pid&lt;br /&gt;
     maxconn     4000&lt;br /&gt;
     user        haproxy&lt;br /&gt;
     group       haproxy&lt;br /&gt;
     daemon&lt;br /&gt;
 &lt;br /&gt;
 defaults&lt;br /&gt;
     mode                    http&lt;br /&gt;
     log                     global&lt;br /&gt;
     option                  httplog&lt;br /&gt;
     option                  dontlognull&lt;br /&gt;
     option http-server-close&lt;br /&gt;
     option forwardfor       except 127.0.0.0/8&lt;br /&gt;
     retries                 3&lt;br /&gt;
     timeout http-request    10s&lt;br /&gt;
     timeout queue           1m&lt;br /&gt;
     timeout connect         10s&lt;br /&gt;
     timeout client          1m&lt;br /&gt;
     timeout server          1m&lt;br /&gt;
     timeout http-keep-alive 10s&lt;br /&gt;
     timeout check           10s&lt;br /&gt;
     maxconn                 3000&lt;br /&gt;
 &lt;br /&gt;
 frontend http-in&lt;br /&gt;
     bind *:80&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server vm1.log.afnog.org:80 check&lt;br /&gt;
     server apache_server vm2.lab.afnog.org:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Advanced Configuration with ACLs (Access Control Lists) ===&lt;br /&gt;
&lt;br /&gt;
==== Updated HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Modify the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 frontend http_front&lt;br /&gt;
     bind *:80&lt;br /&gt;
     acl url_nginx hdr(host) -i nginx.lab.afnog.org&lt;br /&gt;
     acl url_apache hdr(host) -i apache.lab.afnog.org&lt;br /&gt;
     use_backend nginx_back if url_nginx&lt;br /&gt;
     use_backend apache_back if url_apache&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend nginx_back&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend apache_back&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Adding a Status Page ===&lt;br /&gt;
&lt;br /&gt;
==== Final HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Add the following configuration for the status page:&lt;br /&gt;
'''&lt;br /&gt;
 listen stats&lt;br /&gt;
     bind *:8404&lt;br /&gt;
     stats enable&lt;br /&gt;
     stats uri /&lt;br /&gt;
     stats refresh 5s&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
==== Testing the Status Page: ====&lt;br /&gt;
&lt;br /&gt;
You can access the status page by navigating to http://192.168.1.X:8404/ in your web browser.&lt;br /&gt;
&lt;br /&gt;
== SSL Termination on HAProxy ==&lt;br /&gt;
&lt;br /&gt;
=== Generate a Self-Signed Certificate: ===&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/haproxy.key -out /etc/ssl/certs/haproxy.crt&lt;br /&gt;
&lt;br /&gt;
=== Combine the Certificate and Key: ===&lt;br /&gt;
 cat /etc/ssl/certs/haproxy.crt /etc/ssl/private/haproxy.key |  tee /etc/ssl/certs/haproxy.pem&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For development SSL certificates, you can use the repository at https://github.com/BenMorel/dev-certificates&lt;br /&gt;
&lt;br /&gt;
=== Update HAProxy Configuration to Use SSL: ===&lt;br /&gt;
&lt;br /&gt;
Add the following to the `frontend http_front` section:&lt;br /&gt;
&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem&lt;br /&gt;
 redirect scheme https if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
=== Restart HAProxy: ===&lt;br /&gt;
 sudo systemctl restart haproxy&lt;br /&gt;
=== Example for Layer 4 Load balancing , DB port : ===&lt;br /&gt;
'''&lt;br /&gt;
 frontend mysql&lt;br /&gt;
  mode tcp&lt;br /&gt;
  bind :3306&lt;br /&gt;
  default_backend mysql_servers&lt;br /&gt;
&lt;br /&gt;
 backend mysql_servers&lt;br /&gt;
  mode tcp&lt;br /&gt;
  balance leastconn&lt;br /&gt;
  server s1 192.168.0.10:3306 check&lt;br /&gt;
  server s2 192.168.0.11:3306 check&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Configure Syslog for HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
# Open the syslog configuration file for editing:&lt;br /&gt;
 vi /etc/syslog.conf&lt;br /&gt;
&lt;br /&gt;
# Add the following lines to configure logging:&lt;br /&gt;
 *.err;kern.warning;auth.notice;mail.crit                /dev/console&lt;br /&gt;
 local1.*                                                /var/log/haproxy.log&lt;br /&gt;
 *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Create the HAProxy log file:&lt;br /&gt;
 touch /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Set the appropriate ownership for the log file:&lt;br /&gt;
 chown haproxy:haproxy /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Update the syslogd flags to bind to localhost and run in compatibility mode:&lt;br /&gt;
 sysrc syslogd_flags=&amp;quot;-b localhost -C&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Restart the syslog service to apply changes:&lt;br /&gt;
 service syslogd restart&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Using `curl`: ===&lt;br /&gt;
&lt;br /&gt;
# Test round-robin for `www.lab.afnog.org`:&lt;br /&gt;
 curl -H &amp;quot;Host: www.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # Repeat the command several times to see alternating responses from Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 curl -H &amp;quot;Host: nginx.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Nginx server response.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 curl -H &amp;quot;Host: apache.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Apache server response.&lt;br /&gt;
&lt;br /&gt;
# Test SSL termination:&lt;br /&gt;
 curl -k https://www.lab.afnog.org&lt;br /&gt;
 # This should return responses over HTTPS, with round-robin load balancing between Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
=== Using `w3m`: ===&lt;br /&gt;
&lt;br /&gt;
# Browse to `www.lab.afnog.org` using `w3m`:&lt;br /&gt;
 w3m http://www.lab.afnog.org&lt;br /&gt;
 # Navigate the site to ensure both servers (Nginx and Apache) are being served correctly in round-robin fashion.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 w3m http://nginx.lab.afnog.org&lt;br /&gt;
 # Ensure that the Nginx server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 w3m http://apache.lab.afnog.org&lt;br /&gt;
 # Ensure that the Apache server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test SSL with `w3m`:&lt;br /&gt;
 w3m https://www.lab.afnog.org&lt;br /&gt;
 # Verify that SSL termination works and the content is served over HTTPS.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== best practice options for web based frontend  ==&lt;br /&gt;
it's essential to tailor the following based on the specific needs of your application&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
&lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Implement strong SSL/TLS configurations'''&lt;br /&gt;
# '''Use IP whitelisting for the HAProxy stats page'''&lt;br /&gt;
# '''Consider implementing Web Application Firewall (WAF) rules in HAProxy'''&lt;br /&gt;
# '''Regularly audit your HAProxy configurations and access logs'''&lt;br /&gt;
&lt;br /&gt;
This guide provides a comprehensive setup process for HAProxy, starting from a basic configuration and progressing to more advanced setups with ACLs, SSL termination, and performance optimization. Always ensure to test thoroughly in a staging environment before applying changes to production systems.&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2302</id>
		<title>HAProxy Lab Setup Guide - Multi-OS Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2302"/>
		<updated>2024-09-05T12:32:09Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* best practice options for web based frontend */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide - Multi-OS Installation =&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3 VMs (or use VirtualBox/VMware Workstation to create them)&lt;br /&gt;
* Web browser access (for those using AFNOG infrastructure)&lt;br /&gt;
&lt;br /&gt;
== VM Setup ==&lt;br /&gt;
# '''VM1:''' HAProxy       &lt;br /&gt;
#* IP: 192.168.1.X&lt;br /&gt;
# '''VM2:''' Apache Server  &lt;br /&gt;
#* IP: 192.168.1.Y&lt;br /&gt;
# '''VM3:''' Nginx Server   &lt;br /&gt;
#* IP: 192.168.1.Z&lt;br /&gt;
&lt;br /&gt;
== Local Hosts File Configuration ==&lt;br /&gt;
Add the following entries to your local hosts file, pointing them all to the HAProxy IP (192.168.1.X):&lt;br /&gt;
&lt;br /&gt;
 192.168.1.X lb.lab.afnog.org &lt;br /&gt;
 192.168.1.X www.lab.afnog.org      &lt;br /&gt;
 192.168.1.X nginx.lab.afnog.org&lt;br /&gt;
 192.168.1.X apache.lab.afnog.org&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install and Configure HAProxy (VM1) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems (CentOS, Fedora) ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install haproxy&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems (Ubuntu, Debian) ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install haproxy&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install haproxy&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install and Configure Apache (VM2) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install httpd&lt;br /&gt;
 sudo systemctl start httpd&lt;br /&gt;
 sudo systemctl enable httpd&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install apache2&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install apache24&lt;br /&gt;
 sudo sysrc apache24_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service apache24 start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /var/www/html/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 On FreeBSD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /usr/local/www/apache24/data/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install and Configure Nginx (VM3) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install nginx&lt;br /&gt;
 sudo systemctl start nginx&lt;br /&gt;
 sudo systemctl enable nginx&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install nginx&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install nginx&lt;br /&gt;
 sudo sysrc nginx_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service nginx start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
 &amp;lt;code&amp;gt; echo &amp;quot;This is the Nginx Server&amp;quot; |  tee /var/www/html/index.html &amp;lt;/code&amp;gt; &lt;br /&gt;
 &amp;lt;code&amp;gt; # For FreeBSD:&lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; | tee /usr/local/www/nginx/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Basic Frontend and Backend Setup (Round-Robin) ===&lt;br /&gt;
&lt;br /&gt;
==== HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
==== Edit the HAProxy configuration file: ====&lt;br /&gt;
* '''Red Hat and Debian:''' /etc/haproxy/haproxy.cfg&lt;br /&gt;
* '''FreeBSD:''' /usr/local/etc/haproxy.conf&lt;br /&gt;
&lt;br /&gt;
==== Add the following configuration: ====&lt;br /&gt;
'''&lt;br /&gt;
 global&lt;br /&gt;
     log         127.0.0.1:514 local1 info&lt;br /&gt;
     chroot      /var/empty&lt;br /&gt;
     pidfile     /var/run/haproxy.pid&lt;br /&gt;
     maxconn     4000&lt;br /&gt;
     user        haproxy&lt;br /&gt;
     group       haproxy&lt;br /&gt;
     daemon&lt;br /&gt;
 &lt;br /&gt;
 defaults&lt;br /&gt;
     mode                    http&lt;br /&gt;
     log                     global&lt;br /&gt;
     option                  httplog&lt;br /&gt;
     option                  dontlognull&lt;br /&gt;
     option http-server-close&lt;br /&gt;
     option forwardfor       except 127.0.0.0/8&lt;br /&gt;
     retries                 3&lt;br /&gt;
     timeout http-request    10s&lt;br /&gt;
     timeout queue           1m&lt;br /&gt;
     timeout connect         10s&lt;br /&gt;
     timeout client          1m&lt;br /&gt;
     timeout server          1m&lt;br /&gt;
     timeout http-keep-alive 10s&lt;br /&gt;
     timeout check           10s&lt;br /&gt;
     maxconn                 3000&lt;br /&gt;
 &lt;br /&gt;
 frontend http-in&lt;br /&gt;
     bind *:80&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server vm1.log.afnog.org:80 check&lt;br /&gt;
     server apache_server vm2.lab.afnog.org:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Advanced Configuration with ACLs (Access Control Lists) ===&lt;br /&gt;
&lt;br /&gt;
==== Updated HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Modify the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 frontend http_front&lt;br /&gt;
     bind *:80&lt;br /&gt;
     acl url_nginx hdr(host) -i nginx.lab.afnog.org&lt;br /&gt;
     acl url_apache hdr(host) -i apache.lab.afnog.org&lt;br /&gt;
     use_backend nginx_back if url_nginx&lt;br /&gt;
     use_backend apache_back if url_apache&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend nginx_back&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend apache_back&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Adding a Status Page ===&lt;br /&gt;
&lt;br /&gt;
==== Final HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Add the following configuration for the status page:&lt;br /&gt;
'''&lt;br /&gt;
 listen stats&lt;br /&gt;
     bind *:8404&lt;br /&gt;
     stats enable&lt;br /&gt;
     stats uri /&lt;br /&gt;
     stats refresh 5s&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
==== Testing the Status Page: ====&lt;br /&gt;
&lt;br /&gt;
You can access the status page by navigating to http://192.168.1.X:8404/ in your web browser.&lt;br /&gt;
&lt;br /&gt;
== SSL Termination on HAProxy ==&lt;br /&gt;
&lt;br /&gt;
=== Generate a Self-Signed Certificate: ===&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/haproxy.key -out /etc/ssl/certs/haproxy.crt&lt;br /&gt;
&lt;br /&gt;
=== Combine the Certificate and Key: ===&lt;br /&gt;
 cat /etc/ssl/certs/haproxy.crt /etc/ssl/private/haproxy.key |  tee /etc/ssl/certs/haproxy.pem&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For development SSL certificates, you can use the repository at https://github.com/BenMorel/dev-certificates&lt;br /&gt;
&lt;br /&gt;
=== Update HAProxy Configuration to Use SSL: ===&lt;br /&gt;
&lt;br /&gt;
Add the following to the `frontend http_front` section:&lt;br /&gt;
&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem&lt;br /&gt;
 redirect scheme https if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
=== Restart HAProxy: ===&lt;br /&gt;
 sudo systemctl restart haproxy&lt;br /&gt;
=== Example for Layer 4 Load balancing , DB port : ===&lt;br /&gt;
'''&lt;br /&gt;
 frontend mysql&lt;br /&gt;
  mode tcp&lt;br /&gt;
  bind :3306&lt;br /&gt;
  default_backend mysql_servers&lt;br /&gt;
&lt;br /&gt;
 backend mysql_servers&lt;br /&gt;
  mode tcp&lt;br /&gt;
  balance leastconn&lt;br /&gt;
  server s1 192.168.0.10:3306 check&lt;br /&gt;
  server s2 192.168.0.11:3306 check&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Configure Syslog for HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
# Open the syslog configuration file for editing:&lt;br /&gt;
 vi /etc/syslog.conf&lt;br /&gt;
&lt;br /&gt;
# Add the following lines to configure logging:&lt;br /&gt;
 *.err;kern.warning;auth.notice;mail.crit                /dev/console&lt;br /&gt;
 local1.*                                                /var/log/haproxy.log&lt;br /&gt;
 *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Create the HAProxy log file:&lt;br /&gt;
 touch /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Set the appropriate ownership for the log file:&lt;br /&gt;
 chown haproxy:haproxy /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Update the syslogd flags to bind to localhost and run in compatibility mode:&lt;br /&gt;
 sysrc syslogd_flags=&amp;quot;-b localhost -C&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Restart the syslog service to apply changes:&lt;br /&gt;
 service syslogd restart&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Using `curl`: ===&lt;br /&gt;
&lt;br /&gt;
# Test round-robin for `www.lab.afnog.org`:&lt;br /&gt;
 curl -H &amp;quot;Host: www.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # Repeat the command several times to see alternating responses from Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 curl -H &amp;quot;Host: nginx.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Nginx server response.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 curl -H &amp;quot;Host: apache.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Apache server response.&lt;br /&gt;
&lt;br /&gt;
# Test SSL termination:&lt;br /&gt;
 curl -k https://www.lab.afnog.org&lt;br /&gt;
 # This should return responses over HTTPS, with round-robin load balancing between Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
=== Using `w3m`: ===&lt;br /&gt;
&lt;br /&gt;
# Browse to `www.lab.afnog.org` using `w3m`:&lt;br /&gt;
 w3m http://www.lab.afnog.org&lt;br /&gt;
 # Navigate the site to ensure both servers (Nginx and Apache) are being served correctly in round-robin fashion.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 w3m http://nginx.lab.afnog.org&lt;br /&gt;
 # Ensure that the Nginx server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 w3m http://apache.lab.afnog.org&lt;br /&gt;
 # Ensure that the Apache server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test SSL with `w3m`:&lt;br /&gt;
 w3m https://www.lab.afnog.org&lt;br /&gt;
 # Verify that SSL termination works and the content is served over HTTPS.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== best practice options for web based frontend  ==&lt;br /&gt;
it's essential to tailor the following based on the specific needs of your application&lt;br /&gt;
'''&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    default_backend servers&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Implement strong SSL/TLS configurations'''&lt;br /&gt;
# '''Use IP whitelisting for the HAProxy stats page'''&lt;br /&gt;
# '''Consider implementing Web Application Firewall (WAF) rules in HAProxy'''&lt;br /&gt;
# '''Regularly audit your HAProxy configurations and access logs'''&lt;br /&gt;
&lt;br /&gt;
This guide provides a comprehensive setup process for HAProxy, starting from a basic configuration and progressing to more advanced setups with ACLs, SSL termination, and performance optimization. Always ensure to test thoroughly in a staging environment before applying changes to production systems.&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2301</id>
		<title>HAProxy Lab Setup Guide - Multi-OS Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2301"/>
		<updated>2024-09-05T12:31:38Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: /* Example for Layer 4 Load balancing , DB port : */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide - Multi-OS Installation =&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3 VMs (or use VirtualBox/VMware Workstation to create them)&lt;br /&gt;
* Web browser access (for those using AFNOG infrastructure)&lt;br /&gt;
&lt;br /&gt;
== VM Setup ==&lt;br /&gt;
# '''VM1:''' HAProxy       &lt;br /&gt;
#* IP: 192.168.1.X&lt;br /&gt;
# '''VM2:''' Apache Server  &lt;br /&gt;
#* IP: 192.168.1.Y&lt;br /&gt;
# '''VM3:''' Nginx Server   &lt;br /&gt;
#* IP: 192.168.1.Z&lt;br /&gt;
&lt;br /&gt;
== Local Hosts File Configuration ==&lt;br /&gt;
Add the following entries to your local hosts file, pointing them all to the HAProxy IP (192.168.1.X):&lt;br /&gt;
&lt;br /&gt;
 192.168.1.X lb.lab.afnog.org &lt;br /&gt;
 192.168.1.X www.lab.afnog.org      &lt;br /&gt;
 192.168.1.X nginx.lab.afnog.org&lt;br /&gt;
 192.168.1.X apache.lab.afnog.org&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install and Configure HAProxy (VM1) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems (CentOS, Fedora) ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install haproxy&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems (Ubuntu, Debian) ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install haproxy&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install haproxy&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install and Configure Apache (VM2) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install httpd&lt;br /&gt;
 sudo systemctl start httpd&lt;br /&gt;
 sudo systemctl enable httpd&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install apache2&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install apache24&lt;br /&gt;
 sudo sysrc apache24_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service apache24 start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /var/www/html/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 On FreeBSD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /usr/local/www/apache24/data/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install and Configure Nginx (VM3) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install nginx&lt;br /&gt;
 sudo systemctl start nginx&lt;br /&gt;
 sudo systemctl enable nginx&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install nginx&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install nginx&lt;br /&gt;
 sudo sysrc nginx_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service nginx start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
 &amp;lt;code&amp;gt; echo &amp;quot;This is the Nginx Server&amp;quot; |  tee /var/www/html/index.html &amp;lt;/code&amp;gt; &lt;br /&gt;
 &amp;lt;code&amp;gt; # For FreeBSD:&lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; | tee /usr/local/www/nginx/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Basic Frontend and Backend Setup (Round-Robin) ===&lt;br /&gt;
&lt;br /&gt;
==== HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
==== Edit the HAProxy configuration file: ====&lt;br /&gt;
* '''Red Hat and Debian:''' /etc/haproxy/haproxy.cfg&lt;br /&gt;
* '''FreeBSD:''' /usr/local/etc/haproxy.conf&lt;br /&gt;
&lt;br /&gt;
==== Add the following configuration: ====&lt;br /&gt;
'''&lt;br /&gt;
 global&lt;br /&gt;
     log         127.0.0.1:514 local1 info&lt;br /&gt;
     chroot      /var/empty&lt;br /&gt;
     pidfile     /var/run/haproxy.pid&lt;br /&gt;
     maxconn     4000&lt;br /&gt;
     user        haproxy&lt;br /&gt;
     group       haproxy&lt;br /&gt;
     daemon&lt;br /&gt;
 &lt;br /&gt;
 defaults&lt;br /&gt;
     mode                    http&lt;br /&gt;
     log                     global&lt;br /&gt;
     option                  httplog&lt;br /&gt;
     option                  dontlognull&lt;br /&gt;
     option http-server-close&lt;br /&gt;
     option forwardfor       except 127.0.0.0/8&lt;br /&gt;
     retries                 3&lt;br /&gt;
     timeout http-request    10s&lt;br /&gt;
     timeout queue           1m&lt;br /&gt;
     timeout connect         10s&lt;br /&gt;
     timeout client          1m&lt;br /&gt;
     timeout server          1m&lt;br /&gt;
     timeout http-keep-alive 10s&lt;br /&gt;
     timeout check           10s&lt;br /&gt;
     maxconn                 3000&lt;br /&gt;
 &lt;br /&gt;
 frontend http-in&lt;br /&gt;
     bind *:80&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server vm1.log.afnog.org:80 check&lt;br /&gt;
     server apache_server vm2.lab.afnog.org:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Advanced Configuration with ACLs (Access Control Lists) ===&lt;br /&gt;
&lt;br /&gt;
==== Updated HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Modify the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 frontend http_front&lt;br /&gt;
     bind *:80&lt;br /&gt;
     acl url_nginx hdr(host) -i nginx.lab.afnog.org&lt;br /&gt;
     acl url_apache hdr(host) -i apache.lab.afnog.org&lt;br /&gt;
     use_backend nginx_back if url_nginx&lt;br /&gt;
     use_backend apache_back if url_apache&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend nginx_back&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend apache_back&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Adding a Status Page ===&lt;br /&gt;
&lt;br /&gt;
==== Final HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Add the following configuration for the status page:&lt;br /&gt;
'''&lt;br /&gt;
 listen stats&lt;br /&gt;
     bind *:8404&lt;br /&gt;
     stats enable&lt;br /&gt;
     stats uri /&lt;br /&gt;
     stats refresh 5s&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
==== Testing the Status Page: ====&lt;br /&gt;
&lt;br /&gt;
You can access the status page by navigating to http://192.168.1.X:8404/ in your web browser.&lt;br /&gt;
&lt;br /&gt;
== SSL Termination on HAProxy ==&lt;br /&gt;
&lt;br /&gt;
=== Generate a Self-Signed Certificate: ===&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/haproxy.key -out /etc/ssl/certs/haproxy.crt&lt;br /&gt;
&lt;br /&gt;
=== Combine the Certificate and Key: ===&lt;br /&gt;
 cat /etc/ssl/certs/haproxy.crt /etc/ssl/private/haproxy.key |  tee /etc/ssl/certs/haproxy.pem&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For development SSL certificates, you can use the repository at https://github.com/BenMorel/dev-certificates&lt;br /&gt;
&lt;br /&gt;
=== Update HAProxy Configuration to Use SSL: ===&lt;br /&gt;
&lt;br /&gt;
Add the following to the `frontend http_front` section:&lt;br /&gt;
&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem&lt;br /&gt;
 redirect scheme https if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
=== Restart HAProxy: ===&lt;br /&gt;
 sudo systemctl restart haproxy&lt;br /&gt;
=== Example for Layer 4 Load balancing , DB port : ===&lt;br /&gt;
'''&lt;br /&gt;
 frontend mysql&lt;br /&gt;
  mode tcp&lt;br /&gt;
  bind :3306&lt;br /&gt;
  default_backend mysql_servers&lt;br /&gt;
&lt;br /&gt;
 backend mysql_servers&lt;br /&gt;
  mode tcp&lt;br /&gt;
  balance leastconn&lt;br /&gt;
  server s1 192.168.0.10:3306 check&lt;br /&gt;
  server s2 192.168.0.11:3306 check&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Configure Syslog for HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
# Open the syslog configuration file for editing:&lt;br /&gt;
 vi /etc/syslog.conf&lt;br /&gt;
&lt;br /&gt;
# Add the following lines to configure logging:&lt;br /&gt;
 *.err;kern.warning;auth.notice;mail.crit                /dev/console&lt;br /&gt;
 local1.*                                                /var/log/haproxy.log&lt;br /&gt;
 *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Create the HAProxy log file:&lt;br /&gt;
 touch /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Set the appropriate ownership for the log file:&lt;br /&gt;
 chown haproxy:haproxy /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Update the syslogd flags to bind to localhost and run in compatibility mode:&lt;br /&gt;
 sysrc syslogd_flags=&amp;quot;-b localhost -C&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Restart the syslog service to apply changes:&lt;br /&gt;
 service syslogd restart&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Using `curl`: ===&lt;br /&gt;
&lt;br /&gt;
# Test round-robin for `www.lab.afnog.org`:&lt;br /&gt;
 curl -H &amp;quot;Host: www.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # Repeat the command several times to see alternating responses from Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 curl -H &amp;quot;Host: nginx.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Nginx server response.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 curl -H &amp;quot;Host: apache.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Apache server response.&lt;br /&gt;
&lt;br /&gt;
# Test SSL termination:&lt;br /&gt;
 curl -k https://www.lab.afnog.org&lt;br /&gt;
 # This should return responses over HTTPS, with round-robin load balancing between Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
=== Using `w3m`: ===&lt;br /&gt;
&lt;br /&gt;
# Browse to `www.lab.afnog.org` using `w3m`:&lt;br /&gt;
 w3m http://www.lab.afnog.org&lt;br /&gt;
 # Navigate the site to ensure both servers (Nginx and Apache) are being served correctly in round-robin fashion.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 w3m http://nginx.lab.afnog.org&lt;br /&gt;
 # Ensure that the Nginx server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 w3m http://apache.lab.afnog.org&lt;br /&gt;
 # Ensure that the Apache server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test SSL with `w3m`:&lt;br /&gt;
 w3m https://www.lab.afnog.org&lt;br /&gt;
 # Verify that SSL termination works and the content is served over HTTPS.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== best practice options for web based frontend  ==&lt;br /&gt;
it's essential to tailor the following based on the specific needs of your application&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    default_backend servers&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Implement strong SSL/TLS configurations'''&lt;br /&gt;
# '''Use IP whitelisting for the HAProxy stats page'''&lt;br /&gt;
# '''Consider implementing Web Application Firewall (WAF) rules in HAProxy'''&lt;br /&gt;
# '''Regularly audit your HAProxy configurations and access logs'''&lt;br /&gt;
&lt;br /&gt;
This guide provides a comprehensive setup process for HAProxy, starting from a basic configuration and progressing to more advanced setups with ACLs, SSL termination, and performance optimization. Always ensure to test thoroughly in a staging environment before applying changes to production systems.&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2300</id>
		<title>HAProxy Lab Setup Guide - Multi-OS Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2300"/>
		<updated>2024-09-05T12:31:00Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide - Multi-OS Installation =&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3 VMs (or use VirtualBox/VMware Workstation to create them)&lt;br /&gt;
* Web browser access (for those using AFNOG infrastructure)&lt;br /&gt;
&lt;br /&gt;
== VM Setup ==&lt;br /&gt;
# '''VM1:''' HAProxy       &lt;br /&gt;
#* IP: 192.168.1.X&lt;br /&gt;
# '''VM2:''' Apache Server  &lt;br /&gt;
#* IP: 192.168.1.Y&lt;br /&gt;
# '''VM3:''' Nginx Server   &lt;br /&gt;
#* IP: 192.168.1.Z&lt;br /&gt;
&lt;br /&gt;
== Local Hosts File Configuration ==&lt;br /&gt;
Add the following entries to your local hosts file, pointing them all to the HAProxy IP (192.168.1.X):&lt;br /&gt;
&lt;br /&gt;
 192.168.1.X lb.lab.afnog.org &lt;br /&gt;
 192.168.1.X www.lab.afnog.org      &lt;br /&gt;
 192.168.1.X nginx.lab.afnog.org&lt;br /&gt;
 192.168.1.X apache.lab.afnog.org&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install and Configure HAProxy (VM1) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems (CentOS, Fedora) ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install haproxy&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems (Ubuntu, Debian) ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install haproxy&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install haproxy&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install and Configure Apache (VM2) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install httpd&lt;br /&gt;
 sudo systemctl start httpd&lt;br /&gt;
 sudo systemctl enable httpd&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install apache2&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install apache24&lt;br /&gt;
 sudo sysrc apache24_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service apache24 start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /var/www/html/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 On FreeBSD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /usr/local/www/apache24/data/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install and Configure Nginx (VM3) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install nginx&lt;br /&gt;
 sudo systemctl start nginx&lt;br /&gt;
 sudo systemctl enable nginx&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install nginx&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install nginx&lt;br /&gt;
 sudo sysrc nginx_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service nginx start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
 &amp;lt;code&amp;gt; echo &amp;quot;This is the Nginx Server&amp;quot; |  tee /var/www/html/index.html &amp;lt;/code&amp;gt; &lt;br /&gt;
 &amp;lt;code&amp;gt; # For FreeBSD:&lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; | tee /usr/local/www/nginx/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Basic Frontend and Backend Setup (Round-Robin) ===&lt;br /&gt;
&lt;br /&gt;
==== HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
==== Edit the HAProxy configuration file: ====&lt;br /&gt;
* '''Red Hat and Debian:''' /etc/haproxy/haproxy.cfg&lt;br /&gt;
* '''FreeBSD:''' /usr/local/etc/haproxy.conf&lt;br /&gt;
&lt;br /&gt;
==== Add the following configuration: ====&lt;br /&gt;
'''&lt;br /&gt;
 global&lt;br /&gt;
     log         127.0.0.1:514 local1 info&lt;br /&gt;
     chroot      /var/empty&lt;br /&gt;
     pidfile     /var/run/haproxy.pid&lt;br /&gt;
     maxconn     4000&lt;br /&gt;
     user        haproxy&lt;br /&gt;
     group       haproxy&lt;br /&gt;
     daemon&lt;br /&gt;
 &lt;br /&gt;
 defaults&lt;br /&gt;
     mode                    http&lt;br /&gt;
     log                     global&lt;br /&gt;
     option                  httplog&lt;br /&gt;
     option                  dontlognull&lt;br /&gt;
     option http-server-close&lt;br /&gt;
     option forwardfor       except 127.0.0.0/8&lt;br /&gt;
     retries                 3&lt;br /&gt;
     timeout http-request    10s&lt;br /&gt;
     timeout queue           1m&lt;br /&gt;
     timeout connect         10s&lt;br /&gt;
     timeout client          1m&lt;br /&gt;
     timeout server          1m&lt;br /&gt;
     timeout http-keep-alive 10s&lt;br /&gt;
     timeout check           10s&lt;br /&gt;
     maxconn                 3000&lt;br /&gt;
 &lt;br /&gt;
 frontend http-in&lt;br /&gt;
     bind *:80&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server vm1.log.afnog.org:80 check&lt;br /&gt;
     server apache_server vm2.lab.afnog.org:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Advanced Configuration with ACLs (Access Control Lists) ===&lt;br /&gt;
&lt;br /&gt;
==== Updated HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Modify the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 frontend http_front&lt;br /&gt;
     bind *:80&lt;br /&gt;
     acl url_nginx hdr(host) -i nginx.lab.afnog.org&lt;br /&gt;
     acl url_apache hdr(host) -i apache.lab.afnog.org&lt;br /&gt;
     use_backend nginx_back if url_nginx&lt;br /&gt;
     use_backend apache_back if url_apache&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend nginx_back&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend apache_back&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Adding a Status Page ===&lt;br /&gt;
&lt;br /&gt;
==== Final HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Add the following configuration for the status page:&lt;br /&gt;
'''&lt;br /&gt;
 listen stats&lt;br /&gt;
     bind *:8404&lt;br /&gt;
     stats enable&lt;br /&gt;
     stats uri /&lt;br /&gt;
     stats refresh 5s&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
==== Testing the Status Page: ====&lt;br /&gt;
&lt;br /&gt;
You can access the status page by navigating to http://192.168.1.X:8404/ in your web browser.&lt;br /&gt;
&lt;br /&gt;
== SSL Termination on HAProxy ==&lt;br /&gt;
&lt;br /&gt;
=== Generate a Self-Signed Certificate: ===&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/haproxy.key -out /etc/ssl/certs/haproxy.crt&lt;br /&gt;
&lt;br /&gt;
=== Combine the Certificate and Key: ===&lt;br /&gt;
 cat /etc/ssl/certs/haproxy.crt /etc/ssl/private/haproxy.key |  tee /etc/ssl/certs/haproxy.pem&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For development SSL certificates, you can use the repository at https://github.com/BenMorel/dev-certificates&lt;br /&gt;
&lt;br /&gt;
=== Update HAProxy Configuration to Use SSL: ===&lt;br /&gt;
&lt;br /&gt;
Add the following to the `frontend http_front` section:&lt;br /&gt;
&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem&lt;br /&gt;
 redirect scheme https if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
=== Restart HAProxy: ===&lt;br /&gt;
 sudo systemctl restart haproxy&lt;br /&gt;
=== Example for Layer 4 Load balancing , DB port : ===&lt;br /&gt;
'''&lt;br /&gt;
 frontend mysql&lt;br /&gt;
  mode tcp&lt;br /&gt;
  bind :3306&lt;br /&gt;
  default_backend mysql_servers&lt;br /&gt;
&lt;br /&gt;
 backend mysql_servers&lt;br /&gt;
  mode tcp&lt;br /&gt;
  balance leastconn&lt;br /&gt;
  server s1 192.168.0.10:3306&lt;br /&gt;
  server s2 192.168.0.11:3306&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
=== Configure Syslog for HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
# Open the syslog configuration file for editing:&lt;br /&gt;
 vi /etc/syslog.conf&lt;br /&gt;
&lt;br /&gt;
# Add the following lines to configure logging:&lt;br /&gt;
 *.err;kern.warning;auth.notice;mail.crit                /dev/console&lt;br /&gt;
 local1.*                                                /var/log/haproxy.log&lt;br /&gt;
 *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Create the HAProxy log file:&lt;br /&gt;
 touch /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Set the appropriate ownership for the log file:&lt;br /&gt;
 chown haproxy:haproxy /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Update the syslogd flags to bind to localhost and run in compatibility mode:&lt;br /&gt;
 sysrc syslogd_flags=&amp;quot;-b localhost -C&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Restart the syslog service to apply changes:&lt;br /&gt;
 service syslogd restart&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Using `curl`: ===&lt;br /&gt;
&lt;br /&gt;
# Test round-robin for `www.lab.afnog.org`:&lt;br /&gt;
 curl -H &amp;quot;Host: www.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # Repeat the command several times to see alternating responses from Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 curl -H &amp;quot;Host: nginx.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Nginx server response.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 curl -H &amp;quot;Host: apache.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Apache server response.&lt;br /&gt;
&lt;br /&gt;
# Test SSL termination:&lt;br /&gt;
 curl -k https://www.lab.afnog.org&lt;br /&gt;
 # This should return responses over HTTPS, with round-robin load balancing between Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
=== Using `w3m`: ===&lt;br /&gt;
&lt;br /&gt;
# Browse to `www.lab.afnog.org` using `w3m`:&lt;br /&gt;
 w3m http://www.lab.afnog.org&lt;br /&gt;
 # Navigate the site to ensure both servers (Nginx and Apache) are being served correctly in round-robin fashion.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 w3m http://nginx.lab.afnog.org&lt;br /&gt;
 # Ensure that the Nginx server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 w3m http://apache.lab.afnog.org&lt;br /&gt;
 # Ensure that the Apache server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test SSL with `w3m`:&lt;br /&gt;
 w3m https://www.lab.afnog.org&lt;br /&gt;
 # Verify that SSL termination works and the content is served over HTTPS.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== best practice options for web based frontend  ==&lt;br /&gt;
it's essential to tailor the following based on the specific needs of your application&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    default_backend servers&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Implement strong SSL/TLS configurations'''&lt;br /&gt;
# '''Use IP whitelisting for the HAProxy stats page'''&lt;br /&gt;
# '''Consider implementing Web Application Firewall (WAF) rules in HAProxy'''&lt;br /&gt;
# '''Regularly audit your HAProxy configurations and access logs'''&lt;br /&gt;
&lt;br /&gt;
This guide provides a comprehensive setup process for HAProxy, starting from a basic configuration and progressing to more advanced setups with ACLs, SSL termination, and performance optimization. Always ensure to test thoroughly in a staging environment before applying changes to production systems.&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2299</id>
		<title>HAProxy Lab Setup Guide - Multi-OS Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.sdnog.sd/index.php?title=HAProxy_Lab_Setup_Guide_-_Multi-OS_Installation&amp;diff=2299"/>
		<updated>2024-09-05T12:29:41Z</updated>

		<summary type="html">&lt;p&gt;Manhal.Mohamed: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= HAProxy Lab Setup Guide - Multi-OS Installation =&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* 3 VMs (or use VirtualBox/VMware Workstation to create them)&lt;br /&gt;
* Web browser access (for those using AFNOG infrastructure)&lt;br /&gt;
&lt;br /&gt;
== VM Setup ==&lt;br /&gt;
# '''VM1:''' HAProxy       &lt;br /&gt;
#* IP: 192.168.1.X&lt;br /&gt;
# '''VM2:''' Apache Server  &lt;br /&gt;
#* IP: 192.168.1.Y&lt;br /&gt;
# '''VM3:''' Nginx Server   &lt;br /&gt;
#* IP: 192.168.1.Z&lt;br /&gt;
&lt;br /&gt;
== Local Hosts File Configuration ==&lt;br /&gt;
Add the following entries to your local hosts file, pointing them all to the HAProxy IP (192.168.1.X):&lt;br /&gt;
&lt;br /&gt;
 192.168.1.X lb.lab.afnog.org &lt;br /&gt;
 192.168.1.X www.lab.afnog.org      &lt;br /&gt;
 192.168.1.X nginx.lab.afnog.org&lt;br /&gt;
 192.168.1.X apache.lab.afnog.org&lt;br /&gt;
&lt;br /&gt;
== Step 1: Install and Configure HAProxy (VM1) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems (CentOS, Fedora) ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install haproxy&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems (Ubuntu, Debian) ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install haproxy&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install haproxy&lt;br /&gt;
&lt;br /&gt;
== Step 2: Install and Configure Apache (VM2) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install httpd&lt;br /&gt;
 sudo systemctl start httpd&lt;br /&gt;
 sudo systemctl enable httpd&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install apache2&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install apache24&lt;br /&gt;
 sudo sysrc apache24_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service apache24 start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /var/www/html/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 On FreeBSD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; echo &amp;quot;This is the Apache Server&amp;quot; | tee /usr/local/www/apache24/data/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Step 3: Install and Configure Nginx (VM3) ==&lt;br /&gt;
&lt;br /&gt;
=== Red Hat-based systems ===&lt;br /&gt;
 sudo yum update&lt;br /&gt;
 sudo yum install nginx&lt;br /&gt;
 sudo systemctl start nginx&lt;br /&gt;
 sudo systemctl enable nginx&lt;br /&gt;
&lt;br /&gt;
=== Debian-based systems ===&lt;br /&gt;
 sudo apt update&lt;br /&gt;
 sudo apt install nginx&lt;br /&gt;
&lt;br /&gt;
=== FreeBSD ===&lt;br /&gt;
 sudo pkg update&lt;br /&gt;
 sudo pkg install nginx&lt;br /&gt;
 sudo sysrc nginx_enable=&amp;quot;YES&amp;quot;&lt;br /&gt;
 sudo service nginx start&lt;br /&gt;
&lt;br /&gt;
==== Create a custom index.html: ====&lt;br /&gt;
 &amp;lt;code&amp;gt; echo &amp;quot;This is the Nginx Server&amp;quot; |  tee /var/www/html/index.html &amp;lt;/code&amp;gt; &lt;br /&gt;
 &amp;lt;code&amp;gt; # For FreeBSD:&lt;br /&gt;
 echo &amp;quot;This is the Nginx Server&amp;quot; | tee /usr/local/www/nginx/index.html &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HAProxy Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Step 1: Basic Frontend and Backend Setup (Round-Robin) ===&lt;br /&gt;
&lt;br /&gt;
==== HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
==== Edit the HAProxy configuration file: ====&lt;br /&gt;
* '''Red Hat and Debian:''' /etc/haproxy/haproxy.cfg&lt;br /&gt;
* '''FreeBSD:''' /usr/local/etc/haproxy.conf&lt;br /&gt;
&lt;br /&gt;
==== Add the following configuration: ====&lt;br /&gt;
'''&lt;br /&gt;
 global&lt;br /&gt;
     log         127.0.0.1:514 local1 info&lt;br /&gt;
     chroot      /var/empty&lt;br /&gt;
     pidfile     /var/run/haproxy.pid&lt;br /&gt;
     maxconn     4000&lt;br /&gt;
     user        haproxy&lt;br /&gt;
     group       haproxy&lt;br /&gt;
     daemon&lt;br /&gt;
 &lt;br /&gt;
 defaults&lt;br /&gt;
     mode                    http&lt;br /&gt;
     log                     global&lt;br /&gt;
     option                  httplog&lt;br /&gt;
     option                  dontlognull&lt;br /&gt;
     option http-server-close&lt;br /&gt;
     option forwardfor       except 127.0.0.0/8&lt;br /&gt;
     retries                 3&lt;br /&gt;
     timeout http-request    10s&lt;br /&gt;
     timeout queue           1m&lt;br /&gt;
     timeout connect         10s&lt;br /&gt;
     timeout client          1m&lt;br /&gt;
     timeout server          1m&lt;br /&gt;
     timeout http-keep-alive 10s&lt;br /&gt;
     timeout check           10s&lt;br /&gt;
     maxconn                 3000&lt;br /&gt;
 &lt;br /&gt;
 frontend http-in&lt;br /&gt;
     bind *:80&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server vm1.log.afnog.org:80 check&lt;br /&gt;
     server apache_server vm2.lab.afnog.org:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 2: Advanced Configuration with ACLs (Access Control Lists) ===&lt;br /&gt;
&lt;br /&gt;
==== Updated HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Modify the existing HAProxy configuration to include the following:&lt;br /&gt;
'''&lt;br /&gt;
 frontend http_front&lt;br /&gt;
     bind *:80&lt;br /&gt;
     acl url_nginx hdr(host) -i nginx.lab.afnog.org&lt;br /&gt;
     acl url_apache hdr(host) -i apache.lab.afnog.org&lt;br /&gt;
     use_backend nginx_back if url_nginx&lt;br /&gt;
     use_backend apache_back if url_apache&lt;br /&gt;
     default_backend www_back&lt;br /&gt;
 &lt;br /&gt;
 backend www_back&lt;br /&gt;
     balance roundrobin&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend nginx_back&lt;br /&gt;
     server nginx_server 192.168.1.Z:80 check&lt;br /&gt;
 &lt;br /&gt;
 backend apache_back&lt;br /&gt;
     server apache_server 192.168.1.Y:80 check&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
 ''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
=== Step 3: Adding a Status Page ===&lt;br /&gt;
&lt;br /&gt;
==== Final HAProxy Configuration: ====&lt;br /&gt;
&lt;br /&gt;
Add the following configuration for the status page:&lt;br /&gt;
'''&lt;br /&gt;
 listen stats&lt;br /&gt;
     bind *:8404&lt;br /&gt;
     stats enable&lt;br /&gt;
     stats uri /&lt;br /&gt;
     stats refresh 5s&lt;br /&gt;
'''&lt;br /&gt;
==== Restart HAProxy: ====&lt;br /&gt;
''' sudo systemctl restart haproxy '''&lt;br /&gt;
&lt;br /&gt;
==== Testing the Status Page: ====&lt;br /&gt;
&lt;br /&gt;
You can access the status page by navigating to http://192.168.1.X:8404/ in your web browser.&lt;br /&gt;
&lt;br /&gt;
== SSL Termination on HAProxy ==&lt;br /&gt;
&lt;br /&gt;
=== Generate a Self-Signed Certificate: ===&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/haproxy.key -out /etc/ssl/certs/haproxy.crt&lt;br /&gt;
&lt;br /&gt;
=== Combine the Certificate and Key: ===&lt;br /&gt;
 cat /etc/ssl/certs/haproxy.crt /etc/ssl/private/haproxy.key |  tee /etc/ssl/certs/haproxy.pem&lt;br /&gt;
&lt;br /&gt;
'''Note:''' For development SSL certificates, you can use the repository at https://github.com/BenMorel/dev-certificates&lt;br /&gt;
&lt;br /&gt;
=== Update HAProxy Configuration to Use SSL: ===&lt;br /&gt;
&lt;br /&gt;
Add the following to the `frontend http_front` section:&lt;br /&gt;
&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem&lt;br /&gt;
 redirect scheme https if !{ ssl_fc }&lt;br /&gt;
&lt;br /&gt;
=== Restart HAProxy: ===&lt;br /&gt;
 sudo systemctl restart haproxy&lt;br /&gt;
=== Example for Layer 4 Load balancing , DB port : ===&lt;br /&gt;
''''&lt;br /&gt;
frontend mysql&lt;br /&gt;
  mode tcp&lt;br /&gt;
  bind :3306&lt;br /&gt;
  default_backend mysql_servers&lt;br /&gt;
&lt;br /&gt;
backend mysql_servers&lt;br /&gt;
  mode tcp&lt;br /&gt;
  balance leastconn&lt;br /&gt;
  server s1 192.168.0.10:3306&lt;br /&gt;
  server s2 192.168.0.11:3306&lt;br /&gt;
''''&lt;br /&gt;
&lt;br /&gt;
=== Configure Syslog for HAProxy Logging ===&lt;br /&gt;
&lt;br /&gt;
# Open the syslog configuration file for editing:&lt;br /&gt;
 vi /etc/syslog.conf&lt;br /&gt;
&lt;br /&gt;
# Add the following lines to configure logging:&lt;br /&gt;
 *.err;kern.warning;auth.notice;mail.crit                /dev/console&lt;br /&gt;
 local1.*                                                /var/log/haproxy.log&lt;br /&gt;
 *.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err   /var/log/messages&lt;br /&gt;
&lt;br /&gt;
# Create the HAProxy log file:&lt;br /&gt;
 touch /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Set the appropriate ownership for the log file:&lt;br /&gt;
 chown haproxy:haproxy /var/log/haproxy.log&lt;br /&gt;
&lt;br /&gt;
# Update the syslogd flags to bind to localhost and run in compatibility mode:&lt;br /&gt;
 sysrc syslogd_flags=&amp;quot;-b localhost -C&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Restart the syslog service to apply changes:&lt;br /&gt;
 service syslogd restart&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
&lt;br /&gt;
=== Using `curl`: ===&lt;br /&gt;
&lt;br /&gt;
# Test round-robin for `www.lab.afnog.org`:&lt;br /&gt;
 curl -H &amp;quot;Host: www.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # Repeat the command several times to see alternating responses from Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 curl -H &amp;quot;Host: nginx.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Nginx server response.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 curl -H &amp;quot;Host: apache.lab.afnog.org&amp;quot; http://192.168.1.X&lt;br /&gt;
 # This should consistently return the Apache server response.&lt;br /&gt;
&lt;br /&gt;
# Test SSL termination:&lt;br /&gt;
 curl -k https://www.lab.afnog.org&lt;br /&gt;
 # This should return responses over HTTPS, with round-robin load balancing between Nginx and Apache.&lt;br /&gt;
&lt;br /&gt;
=== Using `w3m`: ===&lt;br /&gt;
&lt;br /&gt;
# Browse to `www.lab.afnog.org` using `w3m`:&lt;br /&gt;
 w3m http://www.lab.afnog.org&lt;br /&gt;
 # Navigate the site to ensure both servers (Nginx and Apache) are being served correctly in round-robin fashion.&lt;br /&gt;
&lt;br /&gt;
# Test Nginx backend:&lt;br /&gt;
 w3m http://nginx.lab.afnog.org&lt;br /&gt;
 # Ensure that the Nginx server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test Apache backend:&lt;br /&gt;
 w3m http://apache.lab.afnog.org&lt;br /&gt;
 # Ensure that the Apache server's content is being served.&lt;br /&gt;
&lt;br /&gt;
# Test SSL with `w3m`:&lt;br /&gt;
 w3m https://www.lab.afnog.org&lt;br /&gt;
 # Verify that SSL termination works and the content is served over HTTPS.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Common Issues and Solutions ===&lt;br /&gt;
&lt;br /&gt;
# '''HAProxy not starting:'''&lt;br /&gt;
#* Check the configuration file for syntax errors:&lt;br /&gt;
 haproxy -c -f /etc/haproxy/haproxy.cfg&lt;br /&gt;
#* Verify that the ports HAProxy is trying to bind to are not in use by other services.&lt;br /&gt;
&lt;br /&gt;
# '''Backend servers not responding:'''&lt;br /&gt;
#* Ensure that Apache and Nginx are running on their respective VMs.&lt;br /&gt;
#* Check firewall rules to allow traffic between HAProxy and backend servers.&lt;br /&gt;
#* Verify the IP addresses and ports in the HAProxy configuration.&lt;br /&gt;
&lt;br /&gt;
# '''SSL certificate issues:'''&lt;br /&gt;
#* Double-check the path to the SSL certificate and key in the HAProxy configuration.&lt;br /&gt;
#* Ensure the combined PEM file has the correct permissions.&lt;br /&gt;
&lt;br /&gt;
# '''ACLs not working as expected:'''&lt;br /&gt;
#* Verify that your local hosts file is correctly configured.&lt;br /&gt;
#* Use `tcpdump` or `wireshark` to inspect the HTTP headers and ensure the correct `Host` header is being sent.&lt;br /&gt;
&lt;br /&gt;
== Performance Tuning ==&lt;br /&gt;
&lt;br /&gt;
=== Optimizing HAProxy ===&lt;br /&gt;
&lt;br /&gt;
# '''Increase maximum connections:'''&lt;br /&gt;
#* Adjust the `maxconn` parameter in the `global` section based on your server's capacity.&lt;br /&gt;
&lt;br /&gt;
# '''Enable kernel TCP splicing:'''&lt;br /&gt;
#* Add `option tcpka` to the `defaults` section for keep-alive connections.&lt;br /&gt;
&lt;br /&gt;
# '''Use HTTP/2:'''&lt;br /&gt;
#* Update your SSL binding to support HTTP/2:&lt;br /&gt;
 bind *:443 ssl crt /etc/ssl/certs/haproxy.pem alpn h2,http/1.1&lt;br /&gt;
&lt;br /&gt;
# '''Implement caching:'''&lt;br /&gt;
#* Consider adding a caching layer with Varnish in front of HAProxy for static content.&lt;br /&gt;
&lt;br /&gt;
== best practice options for web based frontend  ==&lt;br /&gt;
it's essential to tailor the following based on the specific needs of your application&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
    frontend http-in&lt;br /&gt;
    bind *:80&lt;br /&gt;
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem no-sslv3&lt;br /&gt;
    mode http&lt;br /&gt;
    option httplog&lt;br /&gt;
    log global&lt;br /&gt;
    # Redirect HTTP to HTTPS (enforce HTTPS for all traffic)&lt;br /&gt;
    http-request redirect scheme https code 301 if !{ ssl_fc }&lt;br /&gt;
    # Set default security headers for responses&lt;br /&gt;
    # Enforce HSTS for HTTPS (1 year, include subdomains, preload)&lt;br /&gt;
    http-response set-header Strict-Transport-Security &amp;quot;max-age=31536000; includeSubDomains; preload&amp;quot;&lt;br /&gt;
    # Clickjacking protection, allow only the same origin to embed this site&lt;br /&gt;
    http-response set-header X-Frame-Options &amp;quot;SAMEORIGIN&amp;quot;&lt;br /&gt;
    # XSS filtering enabled in browsers, block if an attack is detected&lt;br /&gt;
    http-response set-header X-XSS-Protection &amp;quot;1; mode=block&amp;quot;&lt;br /&gt;
    # Prevent MIME type sniffing (force browser to honor content type declared by the server)&lt;br /&gt;
    http-response set-header X-Content-Type-Options &amp;quot;nosniff&amp;quot;&lt;br /&gt;
    # Add Content Security Policy to mitigate XSS and data injection attacks&lt;br /&gt;
    http-response set-header Content-Security-Policy &amp;quot;default-src 'self'; script-src 'self'; object-src 'none'&amp;quot;&lt;br /&gt;
    # Disable referrer information leakage when navigating to a different origin&lt;br /&gt;
    http-response set-header Referrer-Policy &amp;quot;no-referrer-when-downgrade&amp;quot;&lt;br /&gt;
    # Prevent browsers and proxies from caching sensitive data&lt;br /&gt;
    http-response set-header Cache-Control &amp;quot;no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0&amp;quot;&lt;br /&gt;
    # Set secure cookies (only for HTTPS, HttpOnly, and prevent cross-site requests)&lt;br /&gt;
    acl secure_cookie hdr_sub(cookie) Secure&lt;br /&gt;
    http-response set-header Set-Cookie %[res.hdr(Set-Cookie)] if secure_cookie&lt;br /&gt;
    http-response set-header Set-Cookie Secure; HttpOnly; SameSite=Strict if secure_cookie&lt;br /&gt;
    # Forward client's original IP in X-Forwarded-For header&lt;br /&gt;
    http-request add-header X-Forwarded-For %[src]&lt;br /&gt;
    # Forward the protocol used by the client (HTTP/HTTPS) in X-Forwarded-Proto header&lt;br /&gt;
    http-request add-header X-Forwarded-Proto https if { ssl_fc }&lt;br /&gt;
    http-request add-header X-Forwarded-Proto http if !{ ssl_fc }&lt;br /&gt;
    # Preserve the original Host header&lt;br /&gt;
    http-request add-header X-Forwarded-Host %[req.hdr(host)]&lt;br /&gt;
    default_backend servers&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Security Considerations ==&lt;br /&gt;
&lt;br /&gt;
# '''Regularly update HAProxy and backend servers'''&lt;br /&gt;
# '''Implement strong SSL/TLS configurations'''&lt;br /&gt;
# '''Use IP whitelisting for the HAProxy stats page'''&lt;br /&gt;
# '''Consider implementing Web Application Firewall (WAF) rules in HAProxy'''&lt;br /&gt;
# '''Regularly audit your HAProxy configurations and access logs'''&lt;br /&gt;
&lt;br /&gt;
This guide provides a comprehensive setup process for HAProxy, starting from a basic configuration and progressing to more advanced setups with ACLs, SSL termination, and performance optimization. Always ensure to test thoroughly in a staging environment before applying changes to production systems.&lt;/div&gt;</summary>
		<author><name>Manhal.Mohamed</name></author>
		
	</entry>
</feed>