Skip to main content

HAproxy saves the day - overview of our built-in-two-days haproxy L4 load balancing system

This project was something I'd been wanting to do for quite some time, but never had the opportunity.  Well, opportunity kicked the door in, so who would I be to not offer tea & crumpets?

I've not had much exposure to load balancers so far aside from 'hey, they are neat' and understanding the basic concepts behind them.  Never had the chance to set one up from scratch, never done actual configuration, etc.  So why not have my first shot be with a pretty complex environment that had been badly maintained for the last 5 years? (they're dropping the contract at any moment, don't bother fixing it up - really)

We were moving said environment as a cost-savings exercise and had decided to forego load balancers (it was leaving behind some Stingray LBs) as another cost-saving exercise (we priced out Netscaler VMs at ~$2k each, Riverbed started at $5k).  Should be simple enough to just static-NAT straight to the servers and remove any redundancy (it was a dev environment, so should be fine) - right?

Well the day before we had that task to do I had to go and suggest that HAproxy should be something we use for our internal web stuff...and my co-worker got the bright idea to give HAproxy a shot for this environment.  Super!  (it was kinda exciting - and our boss had full confidence in us...so hey, why not)

I made the mistake of getting it running inside of two hours, fully redundant in another hour, and actively passing traffic in another hour.  It was decided!  HAproxy or death!

Then my co-worker made me aware of the minor details I'd overlooked when reviewing the Stingray config.  Persistence is not enough - what kind of persistence?  SSL front-end is not enough - what about back-end SSL? (yes this was a thing)  You get the idea.

Further, the way I'd set it up would work great in a 'normal' 443->80 scenario, but not so great with our multi-scenarios.  So then we got into ACLs, if statements, host header files...he laid out the logic, I modified the config, then we did the troubleshooting together.  It was super complicated, and my copy-pasta typos didn't help. (only 5 or 6 :) )

Our final 'done' config was over 500 lines...with 24 supplementary 'subdomain' files.  And we don't even use L7 load balancing...8 frontends, 24 backends, 6 SSL certs (wildcards).  The old LB uses 30+ public IPs for this environment - we are using 8.

It was a crazy couple of days, but we got it working, and I got a great trial-by-fire intro to the guts of load balancers.  I think the best lesson of this whole affair was to keep a really close track of what you're doing.  It is harder when you don't really grasp inner workings of load balancers, but still really valuable - not only for you, but for the next guy.

For example - my spreadsheet to track this looked like:

  • Public URL
  • Internal URL
  • Frontend Port
  • (Frontend Name)
  • SSL Decryption?
  • Old VIP
  • New VIP
  • Backend Port
  • Backend SSL?
  • SessionPersistence? (and what kind - ip or cookie)
  • Backend servers
  • Old BackendServer IPs
  • New BackendServer IPs
  • haproxyBackendName (We read that you should name these by 'where they are going': e.g. WEB12-https = WEB1 WEB2, https)

Some fun features:

  • Rsyslog output - sends to our ELK stack for easy log reading goodness (among other things)
  • Configuration is in Git (we manually deploy it...for now - don't want to install Git on the haproxy nodes however)
  • Keepalived for high availability - hosting 10 VIPs right now
  • check-mk-agent with haproxy plugin (each node outputs ~70 checks) from: https://github.com/hcooper/check_mk-plugins
  • The haproxy stats page is super-handy - I ended up binding this to a spare VIP so the config remains node-agnostic (not sure if this meets best practices)
  • We are also passing through SFTP (mode tcp, had to modify sshd_config)
And some stuff I still want to do:
  • haproxy - figure out how stuff like draining works
  • Build a proper (internet-safe) maintenance page
  • Packetbeat - not sure how it'll react to living on a load balancer
  • Chef - state/config management of the server
  • Add config pushing to our Thoughtworks Go system...overkill?  Or good practice?  :S
And I really need to read up on how to handle Linux servers with this kinda thing.  Weird, huh?  99% of my reading/research has been 'make Microsoft behave for Continuous Deployment'.  At least the Google fodder ratio is with me this time.

Comments

Popular posts from this blog

DFSR - eventid 4312 - replication just won't work

This warning isn't documented that well on the googles, so here's some google fodder:


You are trying to set up replication for a DFS folder (no existing replication)Source server is 2008R2, 'branch office' server is 2012R2 (I'm moving all our infra to 2012R2)You have no issues getting replication configuredYou see the DFSR folders get created on the other end, but nothing stagesFinally you get EventID 4312:
The DFS Replication service failed to get folder information when walking the file system on a journal wrap or loss recovery due to repeated sharing violations encountered on a folder. The service cannot replicate the folder and files in that folder until the sharing violation is resolved.  Additional Information:  Folder: F:\Users$\user.name\Desktop\Random Folder Name\  Replicated Folder Root: F:\Users$  File ID: {00000000-0000-0000-0000-000000000000}-v0  Replicated Folder Name: Users  Replicated Folder ID: 33F0449D-5E67-4DA1-99AC-681B5BACC7E5  Replication Group…

Fixing duplicate SPNs (service principal name)

This is a pretty handy thing to know:

SPNs are used when a specific service/daemon uses Kerberos to authenticate against AD. They map a specific service, port, and object together with this convention: class/host:port/name

If you use a computer object to auth (such as local service):
MSSQLSVC/tor-sql-01.domain.local:1433

If you use a user object to auth (such as a service account, or admin account):
MSSQLSVC/username:1433

Why do we care about duplicate SPNs? If you have two entries trying to auth using the same Kerberos ticket (I think that's right...), they will conflict, and cause errors and service failures.

To check for duplicate SPNs:
The command "setspn.exe -X

C:\Windows\system32>setspn -X
Processing entry 7
MSSQLSvc/server1.company.local:1433 is registered on these accounts:
CN=SERVER1,OU=servers,OU=resources,DC=company,DC=local
CN=SQL Admin,OU=service accounts,OU=resources,DC=company,DC=local

found 1 groups of duplicate SPNs. (truncated/sanitized)

Note that y…

Logstash to Nagios - alerting based on Windows Event ID

This took way longer than it should have to get going...so here's a config and brain dump...

Why?
You want to have a central place to analyze Windows Event/IIS/local application logs, alert off specific events, alert off specific situations.  You don't have the budget for a boxed solution.  You want pretty graphs.  You don't particularly care about individual server states.  (see rationale below - although you certainly have all the tools here to care, I haven't provided that configuration)

How?
ELK stack, OMD, NXlog agent, and Rsyslog.  The premise here is as follows:

Event generated on server into EventLogNXlog ships to Logstash inputLogstash filter adds fields and tags to specified eventsLogstash output sends to a passive Nagios service via the Nagios NSCA outputThe passive service on Nagios (Check_MK c/o OMD) does its thing w. alerting
OMD
Open Monitoring Distribution, but the real point here is Check_MK (IIRC Icinga uses this...).  It makes Nagios easy to use and main…