Slide 1

Slide 1 text

httpd.conf programming OSDC.tw 2013

Slide 2

Slide 2 text

@jeffhung • www.jeffhung.net/blog • Trend Micro Developer • Hadoop, Big Data • and.. PaaS

Slide 3

Slide 3 text

PaaS?

Slide 4

Slide 4 text

Platform as a Service

Slide 5

Slide 5 text

Google AppEngine

Slide 6

Slide 6 text

TCloud, 2010

Slide 7

Slide 7 text

The Path to Pass into PasS Talk @ OSDC.tw 2011

Slide 8

Slide 8 text

Dispatcher MySQL& Database& MySQL& Database& MySQL& Database& MySQL& Database& Java&Web& Container& Java&Web& Container& Java&Web& Container& Java&Web& Container& Hadoop& HBase& Hadoop& HBase& Hadoop& HBase& Hadoop& HBase& Lucene& Indexer& Lucene& Indexer& Lucene& Indexer& Search& Engine& Elaster&CAP&Service& (API&Server)& Elaster&CAP&Service& (API&Server)& Elaster&CAP&Service& (API&Server)& Elaster&CAP&Service& (API&Server)& api.elasterlabs.com.tw *.app.elasterlabs.com.tw Internet& Balancer Manage&

Slide 9

Slide 9 text

nginx

Slide 10

Slide 10 text

ZooKeeper

Slide 11

Slide 11 text

Lots of Java codes to implement the agents to control nginx according to routing rules subscribed from ZK

Slide 12

Slide 12 text

Jserv: 㑌೥౎ཁሜҰ౟ ࡞ۀܥ౷

Slide 13

Slide 13 text

lunastorm: 㑌೥౎ཁሜ Ұ౟ message system

Slide 14

Slide 14 text

jeffhung: 㑌೥౎ཁሜҰ ౟ PaaS

Slide 15

Slide 15 text

20 RD + 6 months to built Elaster CAP

Slide 16

Slide 16 text

5 RD + 6 weeks to bootstrap a private PaaS for our own

Slide 17

Slide 17 text

How?

Slide 18

Slide 18 text

We have a strong OPS team

Slide 19

Slide 19 text

do more with less don’t code anything

Slide 20

Slide 20 text

Apache HTTPd ++

Slide 21

Slide 21 text

Dispatcher done in httpd.conf

Slide 22

Slide 22 text

If it works, it works.

Slide 23

Slide 23 text

Bug? It’s apache’s fault

Slide 24

Slide 24 text

Redis replaces ZK

Slide 25

Slide 25 text

Apache replaces nginx

Slide 26

Slide 26 text

Glue together with httpd.conf

Slide 27

Slide 27 text

httpd.conf programming

Slide 28

Slide 28 text

function REDIS (cmd) { ... } # Call REDIS()?

Slide 29

Slide 29 text

# function REDIS (cmd) { ... } RewriteMap REDIS "prg:redis-cli --raw" # Call REDIS()? ${REDIS:cmd}

Slide 30

Slide 30 text

if url == "/index.html" redirect "/404.html" else if proxy "/app/...", "http://app/REDIS(app)"

Slide 31

Slide 31 text

# function REDIS (cmd) { ... } RewriteMap REDIS "prg:redis-cli --raw" # if url == "/index.html" # redirect "/404.html" RewriteRule ^/index.html /404.html [L,P] # else if # proxy "/app/...", "http://app/REDIS(app)" RewriteRule ^([^\/]*)/(.*) ${REDIS:GET\ $1}/$2 [L,P]

Slide 32

Slide 32 text

Live Demo simplified https://github.com/jeffhung/osdc-2013-lightning

Slide 33

Slide 33 text

The Actual httpd.conf • Authentication & Authorization • Customer Header Injection • Dispatching & Load Balancing

Slide 34

Slide 34 text

~200 lines of httpd.conf And several filter scripts

Slide 35

Slide 35 text

~200 lines of httpd.conf And several filter scripts dash2under.pl: #!/usr/bin/perl $| = 1; # Turn off I/O buffering while () { s/-/_/g; # Replace dashes with underscores print $_; }

Slide 36

Slide 36 text

If it works, it works.