2018 Raspberry Pi and HaProxy

2018 Raspberry Pi and HaProxy

I will fetch the latest Haproxy
>wget http://www.haproxy.org/download/1.8/src/haproxy-1.8.4.tar.gz

https://linuxacademy.com/howtoguides/posts/show/topic/13169-installation-of-haproxy
Unzip that file and use make compile to build
>make TARGET=linux2628
>sudo make install

Set up the Mysql(MariaDB)
http://sillycat.iteye.com/blog/2393787

Here is the set up for my current Haproxy Docker Configuration
Makefile
IMAGE=sillycat/public
TAG=raspberrypi-haproxy
NAME=raspberrypi-haproxy

docker-context:

build: docker-context
docker build -t $(IMAGE):$(TAG) .

run:
docker run -d -p 80:80 -p 3306:3306 --name $(NAME) $(IMAGE):$(TAG)

debug:
docker run -ti -p 80:80 -p 3306:3306 --name $(NAME) $(IMAGE):$(TAG) /bin/bash

clean:
docker stop ${NAME}
docker rm ${NAME}

logs:
docker logs ${NAME}

publish:
docker push ${IMAGE}:${TAG}

fetch:
docker pull ${IMAGE}:${TAG}

start.sh to start the Process
#!/bin/sh -ex

#start the haproxy
cd /tool/haproxy-1.8.4
haproxy -f conf/haproxy.conf

Here comes the most important file Dockerfile
#Set up haproxy in Docker

#Prepre the OS
FROM resin/rpi-raspbian:jessie
MAINTAINER Carl Luo <[email protected]>

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -y update
RUN apt-get install -y apt-utils
RUN apt-get -y dist-upgrade
RUN apt-get install -y build-essential gcc make
RUN apt-get install -y libpcre3 libpcre3-dev zlib1g-dev libgcrypt11-dev

#install haproxy
RUN     mkdir -p /tool
RUN     mkdir -p /install
ADDinstall/haproxy-1.8.4.tar.gz /install/
WORKDIR /install/haproxy-1.8.4
RUN     make TARGET=linux2628
RUN     make install

#config haproxy
RUN     mkdir -p /tool/haproxy-1.8.4/conf
ADD     conf/haproxy.conf /tool/haproxy-1.8.4/conf/
RUN     mkdir -p /var/lib/haproxy

#start the application
EXPOSE  80 3306
RUN     mkdir -p /app/
ADD     start.sh /app/
WORKDIR /app/
CMD[ "./start.sh" ]

I plan to support 2 different websites which host static resources, and one proxy to my backend MySQL in conf/haproxy.conf
global
maxconn     400
#daemon

defaults
timeout connect         30000
timeout client          50000
timeout server          50000

stats enable
stats hide-version
stats uri     /stats
stats auth    useradmin:xxxxx

frontend http-in
bind *:80
mode http
acl url_water       path_beg       -i /water
acl url_price       path_beg       -i /price

use_backend web_water          if url_water
default_backend web_price

backend web_water
        mode http
balance roundrobin
server web_water1 192.168.1.108:8081 check

backend web_price
mode http
balance roundrobin
server web_price1 192.168.1.108:8081 check

listen mysql
      bind *:3306      
      mode      tcp     
      balance roundrobin      
      server mysql2  192.168.1.109:3306 check

Then we can visit the proxy status page as follow:
http://192.168.1.108/stats

Static Website 1
http://192.168.1.108/water/

Static Website 2
http://192.168.1.108/price/

References:
http://www.haproxy.org/
http://sillycat.iteye.com/blog/1055846
http://sillycat.iteye.com/blog/2066118
http://sillycat.iteye.com/blog/562645
http://sillycat.iteye.com/blog/1055846
http://sillycat.iteye.com/blog/2066119

http://liaoph.com/haproxy-tutorial/



猜你喜欢

转载自sillycat.iteye.com/blog/2411095