This architecture is more advanced and provides better scalability for load division and therefore better performance.
Performance is crucial factor for such a service providence and a single Raspberry Pi doesn't have much of it. This architecture (2 loadbalanced Raspberry Pi's) provides 33% performance increase and offers easily to connect more nodes.
HA Proxy provides software based loadbalancing, with numerous configuration options with statistics preview, and yet it can by relatively easy configured.
Connecting individual components:
My architecture consist of three nodes (2xRaspberry Pi and 1xNB). Each node is standardized, so there are only minor configuration differences for each of them (listen socket for nginx).
NOTE: this post does not explain how to setup NFS and enable firewall and access to mysql DB. See owncloud with dedicated php-fpm service post for more details.
Rasppi-p:
All basic services are running on this Raspberry (HA Proxy, nginx, php-fpm, mysql, nfsd).
HA Proxy configuration:
I use version 1.4. Configuration consists of two blocks: nginx and mysql.
/etc/haproxy/haproxy.cfg:
global log 127.0.0.1 local0 log 127.0.0.1 local1 notice #log loghost local0 info maxconn 128 #chroot /usr/share/haproxy uid 99 gid 99 daemon #debug #quiet defaults log global mode tcp option tcplog option dontlognull retries 3 option redispatch maxconn 128 contimeout 5000 clitimeout 50000 srvtimeout 50000 listen nginx-rasppi-p 172.16.0.1:443 option ssl-hello-chk # option httpchk GET /alive HTTP/1.0 mode tcp balance roundrobin server rasppi-p 172.16.0.1:8443 weight 15 check inter 5000 rise 2 fall 3 server rasppi-t 172.16.0.3:8443 weight 10 check inter 5000 rise 2 fall 3 server krisko 172.16.0.2:8443 weight 200 check inter 5000 rise 2 fall 3 listen mysql-rasppi-p 172.16.0.1:3306 mode tcp balance roundrobin server rasppi-p 172.16.0.1:3307 check inter 5000 rise 2 fall 3Notice the different weight value, depending on CPU performance. While primary raspberry (rasppi-p) will process more requests as secondary (rasppi-ta), NB (krisko) will process almost all requests when it is connected.
Secondary raspberry should have less weight as primary, based on performance testing.
To add statistics to HA Proxy, add following section to its configuration:
listen stats 172.16.0.1:1936 mode http stats enable stats hide-version stats realm Haproxy\ Statistics stats uri / stats auth user:secret stats refresh 10sNow you can see statistics on URL 172.16.0.1:1936 (login is user, pw: secret).
Nodes configuration:
All nodes have installed nginx and php-fpm instance. HA Proxy section for nginx is connecting to each node (nginx listener). To successfully complete the configuration you need to enable for each node to be able to connect to HA Proxys' mysql listener (which will redirect traffic to mysqld listener).
Another important configuration part is the NFS. In Archlinux you need to enable and mount via NFS following three directories on each node:
- /mnt/owncloud (this is my owncloud data path)
- /usr/share/webapps/owncloud (owncloud installation path)
- /etc/webapps/owncloud/config (owncloud configuration path)
An advantage of sharing owncloud instance via NFS is that you only need to update/modify one instance and all nodes will be the same (with updated/modified owncloud).
Fantastic sharing I will share these guides to all of my staff thanks.
ReplyDeleteaccess Bee MP3 in UK
Nice tutorial , but how you can implement sticky-session , if you can provide me details, l would be thankful
ReplyDeleteHi, you can find an example on stackoverflow:
ReplyDeletehttps://stackoverflow.com/questions/13495235/haproxy-and-sticky-session
and more information in the haproxy documentation:
https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#4-cookie
Hope this helps :)
Hi great tutorial with detail step. It seem easy to works with HA proxy. currently i am using Microleaves Dedicated Proxies It is working fine for me. I will try this one, if you have more information regarding this please send me complete detail.
ReplyDeleteRegards,
Gloria Walton