Example application demonstrating load balancing a meteor app using HAProxy
- Install HAProxy
# on OSX with homebrew
brew install haproxy
- Download this example
git clone https://github.com/alanning/meteor-load-balancing
-
Open 5 terminal windows
-
From
meteor-load-balancing
directory:
# term1
haproxy -f haproxy.cfg
# term2
./run
# term3
./run 2
# term4
./run 3
# term5
./run 4
Open http://localhost:3000/ in some browsers.
- Include health checks as found here
- Use Smart Collections to avoid update delays
- Support auto-scaling, ex: haproxy-autoscale
Pull requests welcome.
- AWS Route53 health checks
- AWS HAProxy Layer via OpsCode
- HAProxy architecture examples
- Load Balancing your Meteor App
- SockJS HAProxy config
HAProxy logs to syslog so that there is no downtime required by utils such as logrotate
. On OSX, syslog is not set up to listen to network log requests so a bit of configuration is needed before you will be able to see HAProxy log messages.
To configure syslog on OSX:
- Backup syslogd start up file
sudo cp /System/Library/LaunchDaemons/com.apple.syslogd.plist /System/Library/LaunchDaemons/com.apple.syslogd.plist.backup
- Convert binary file to xml to be human readable / editable
sudo plutil -convert xml1 /System/Library/LaunchDaemons/com.apple.syslogd.plist
- Edit
/System/Library/LaunchDaemons/com.apple.syslogd.plist
and add the following snippet under the sockets node
<key>NetworkListener</key>
<dict>
<key>SockServiceName</key>
<string>syslog</string>
<key>SockType</key>
<string>dgram</string>
</dict>
Should read like this now
<key>Sockets</key>
<dict>
<key>AppleSystemLogger</key>
<dict>
<key>SockPathMode</key>
<integer>438</integer>
<key>SockPathName</key>
<string>/var/run/asl_input</string>
</dict>
<key>BSDSystemLogger</key>
<dict>
<key>SockPathMode</key>
<integer>438</integer>
<key>SockPathName</key>
<string>/var/run/syslog</string>
<key>SockType</key>
<string>dgram</string>
</dict>
<key>NetworkListener</key>
<dict>
<key>SockServiceName</key>
<string>syslog</string>
<key>SockType</key>
<string>dgram</string>
</dict>
</dict>
-
Save the file
-
Convert back to binary file
sudo plutil -convert binary1 /System/Library/LaunchDaemons/com.apple.syslogd.plist
- Restart syslogd
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.syslogd.plist
sudo launchctl load /System/Library/LaunchDaemons/com.apple.syslogd.plist
- Add the following entry to
/etc/syslog.conf
local2.* /var/log/haproxy.log
- Include logging options in
haproxy.cfg
(already included in example haproxy.cfg)
global log 127.0.0.1 local2 debug defaults mode http option httplog log global
- Restart HAproxy
HAProxy output will now log to /var/log/haproxy.log
An easy way to view log output on OSX is to run Console.app