HAProxy-Squid

De Wiki Projeto Root
Ir para navegação Ir para pesquisar

Sobre

Olá! Visitante, reunimos aqui, informações sobre o processo de instalação e configuração do HAProxy para utilização do Squid, ou seja, nós teremos um Proxy (squid) com alta disponibilidade (High Availability) em um cenário onde uma ou mais máquinas servidoras podem falhar e o serviço de proxy se mantem funcionando, com isso seu proxy não irá parar caso venha apresentar paradas de manutenção, queda de link, problemas de rede ou hardware.

Vídeo

Link: https://youtu.be/8xpXvzw-e48


  • Configurar Host
 nano /etc/hosts
 nano /etc/hostname
 nano /etc/network/interfaces
  • Instalar Pacotes
 apk add squid ucarp haproxy
 rc-update add squid
  • Configuração do Squid
 nano /etc/squid/squid.conf
 
 acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
 acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
 acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
 
 cache_mem 16 MB
 cache_swap_low 90
 cache_swap_high 95
 maximum_object_size 4096 KB
 cache_dir ufs /var/cache/squid 1000 16 256
 cache_access_log /var/log/squid/access.log
 
 acl manager proto cache_object
 acl SSL_ports port 443 563
 acl Safe_ports port 80          # http
 acl Safe_ports port 21          # ftp
 acl Safe_ports port 443 563     # https, snews
 acl Safe_ports port 70          # gopher
 acl Safe_ports port 210         # wais
 acl Safe_ports port 1025-65535  # unregistered ports
 acl Safe_ports port 280         # http-mgmt
 acl Safe_ports port 488         # gss-http
 acl Safe_ports port 591         # filemaker
 acl Safe_ports port 777         # multiling http
 acl CONNECT method CONNECT
 
 icp_port 3130
 icp_access allow all
 
 cache_peer IP_Server1 sibling 3128 3130
 cache_peer IP_Server2 sibling 3128 3130
 cache_peer IP_Server3 sibling 3128 3130
 cache_peer IP_Server4 sibling 3128 3130
 
 http_access allow localnet
 http_access deny CONNECT !SSL_ports
 http_access deny all
 
 http_port 3128
 
 forwarded_for off
  • Configurando Ucarp
 ln -s /etc/init.d/ucarp /etc/init.d/ucarp.eth0
 cp /etc/conf.d/ucarp /etc/conf.d/ucarp.eth0
 nano /etc/conf.d/ucarp.eth0
  • Configurar conforme infra:
 UCARP_INTERFACE=eth0
 UCARP_SOURCEADDRESS= IP_REAL
 UCARP_VIRTUALADDRESS= IP_PARA_HA
 UCARP_VIRTUALPREFIX= MASK_SUBREDE
 UCARP_VHID= ID [1-255]
 UCARP_PASSFILE=/etc/ucarp/ucarp.pass # <<< Arquivo de SENHA
  • Criar arquivo de Senha
 nano /etc/ucarp/ucarp.pass 
 
 inserir senha (exemplo)
 teste12345
  • Colocar na inicialização o UCARP
 rc-update add ucarp.eth0
  • Configurando HA Proxy
 nano /etc/haproxy/haproxy.cfg
 global
         log /var/log/ha.log   local1
         log 127.0.0.1   local1 notice
         maxconn 4096
         user haproxy
         group haproxy
         daemon
 
 defaults
   # 30 minutes of waiting for a web request is crazy,
   # but some users do it, and then complain the proxy
   # broke the interwebs.
   timeout client 30m
   timeout server 30m
   # If the server doesnt respond in 4 seconds its dead
   timeout connect 4s
 
 listen HOSTNAME
 bind 0.0.0.0:80
 
   # mode tcp ou http ( tcp [sem verificação de camada 7] http [verifica a camada 7] )
   mode tcp
   balance roundrobin
   
   stats enable
   stats realm Statistics
   stats auth admin:admin
   stats scope .
   stats uri /stats?stats
 
   server cache1 IP_Server1:3128 check
   server cache2 IP_Server2:3128 check
   server cache3 IP_Server3:3128 check
   server cache4 IP_Server4:3128 check
 
  • Colocar na inicialização o HAProxy
 rc-update add haproxy