Your SlideShare is downloading. ×
0
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Perlbal Tutorial
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Perlbal Tutorial

6,214

Published on

Published in: Technology, Education
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,214
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
52
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Perlbal Tutorial Takatsugu Shigeta YAPC::Asia Tokyo 2009
  • 2. 重田崇嗣 Takatsugu Shigeta
  • 3. http://profile.typepad.com/comewalk TypePad Profiles
  • 4. Perlbal
  • 5. http://www.danga.com/perlbal/
  • 6. "Perlbal is a Perl-based reverse proxy load balancer and web server." Perlbal From Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/Perlbal
  • 7. "Perlbal is a single-threaded event-based server supporting HTTP load balancing, web serving, and a mix of the two (see below)." Perlbal http://www.danga.com/perlbal/
  • 8. install
  • 9. $ cpan Perlbal
  • 10. WARNING: AIO mode disabled or not available.          Perlbal will run slowly under load if          you're doing any          disk operations. (e.g. web_server mode).          Install IO::AIO for better performance.
  • 11. $ cpan IO::AIO
  • 12. http://code.sixapart.com/trac/perlbal/browser/trunk/META.yml?rev=768 requires:      BSD::Resource:       0      Danga::Socket:       1.44      File::Find:          0      HTTP::Date:          0      HTTP::Response:      0      Sys::Syscall:        0      Test::More:          0      Time::HiRes:         0
  • 13. http://code.sixapart.com/svn/perlbal/ Subversion Repository
  • 14.
    • $ svn co http://code.sixapart.com/svn/perlbal/
    • $ cd trunk
    • $ perl Makefile.PL
    • $ make
    • $ sudo make install
  • 15. start Perlbal
  • 16. # ./perlbal --help Usage: perlbal [OPTS]  --help          This usage info  --version       Print perlbal release version  --config=[file] Specify Perlbal config file           (default: /etc/perlbal/perlbal.conf )  --daemon        Daemonize
  • 17. $ perlbal > --config=/path/to/foo.conf > --daemon
  • 18. $ perlbal > -c /path/to/foo.conf > -d
  • 19. roles
  • 20. reverse_proxy web_server management selector upload_tracker
  • 21. reverse proxy
  • 22.
    • CREATE POOL my_apaches   POOL my_apaches ADD 10.0.0.10:8080   POOL my_apaches ADD 10.0.0.11:8080   POOL my_apaches ADD 10.0.0.12   POOL my_apaches ADD 10.0.0.13:8081 CREATE SERVICE balancer   SET listen          = 0.0.0.0:80   SET role            = reverse_proxy   SET pool            = my_apaches   SET persist_client  = on   SET persist_backend = on   SET verify_backend  = on ENABLE balancer
  • 23.
    • CREATE POOL dynamic   SET nodefile = conf/nodelist.dat CREATE SERVICE balancer2   SET listen          = 0.0.0.0:81   SET role            = reverse_proxy   SET pool            = dynamic   SET persist_client  = on   SET persist_backend = on   SET verify_backend  = on
    • ENABLE balancer2
  • 24.
    • # whitespace and comments allowed 10.1.0.10    # test machine #10.1.0.10:8083    # test machine # can include port numbers, but defaults to 80 if not provided: # 10.1.0.4:80
    • In node file, you should list IP addresses.
    • It's a comment after "#".
  • 25. web server
  • 26.
    • CREATE SERVICE docs   SET listen         = 0.0.0.0:80   SET role           = web_server   SET docroot        = /usr/share/doc/   SET dirindexing    = 1   SET persist_client = on ENABLE docs
  • 27. management
  • 28.
    • CREATE SERVICE mgmt   SET role   = management   SET listen = 127.0.0.1:60000 ENABLE mgmt
  • 29. seealso http://code.sixapart.com/trac/perlbal/browser/trunk/doc /config-guide.txt
  • 30. selector
  • 31.
    • LOAD vhosts
    • CREATE SERVICE foo   SET listen      = 0.0.0.0:8081   SET role        = web_server   SET docroot     = /var/www/html/yapcasia2009/foo.com/   SET dirindexing = 1 ENABLE foo CREATE SERVICE bar   SET listen      = 0.0.0.0:8082   SET role        = web_server   SET docroot     = /var/www/html/yapcasia2009/bar.com/   SET dirindexing = 0 ENABLE bar
  • 32.
    • CREATE SERVICE vdemo   SET listen         = 0.0.0.0:8080   SET role           = selector   SET plugins        = vhosts   SET persist_client = on   VHOST *.foo.com = foo   VHOST *.bar.com = bar
    • #  VHOST * = foo ENABLE vdemo
  • 33. upload_tracker
  • 34. I'm sorry. I have never used it. I omitted upload_tracker. But...
  • 35. http://code.sixapart.com/trac/perlbal/browser/trunk/lib/Perlbal/Service.pm?rev=806#L1431 # create UDP upload tracker listener if ($self->{role} eq "upload_tracker") {     $listener = Perlbal::UploadListener->new($self->{listen}, $self); }
  • 36. parameters
  • 37.
    • CREATE POOL poolname
    •   POOL poolname ADD 0.0.0.0:8080
    • CREATE POOL poolname
    •   SET nodefile = /path/to/file
    •   SET balance_method = random
  • 38.
    • CREATE SERVICE foo
    •   SET role = reverse_proxy
    •   SET listen = 192 .168.0.1:81
    •   SET persist_client = false
    •   SET persist_client_timeout = 30
    •  
    •   SET enable_ssl = false
    •   SET ssl_cert_file = certs/server-cert.pem
    •   SET ssl_key_file  = certs/server-key.pem
    •   SET ssl_cipher_list = ALL:!LOW:!EXP
    •   SET always_trusted = false
    •   SET backend_persist_cache = 2
    •   SET buffer_backend_connect = 100k  
    •   SET buffer_size = 256k
    •   SET buffer_size_reproxy_url = 50k
  • 39.
    •   SET buffer_upload_threshold_rate = 0
    •   SET buffer_upload_threshold_size = 250k
    •   SET buffer_upload_threshold_time = 5
    •   SET buffer_uploads = false
    •   SET buffer_uploads_path = /path/to
    •   SET connect_ahead = 0
    •   SET enable_reproxy = false
    •   SET enable_error_retries = false
    •   SET error_retry_schedule = 0,.25,.50,1,1,1,1,1
    •   SET high_priority_cookie
    •   SET high_priority_cookie_contents
    •   SET max_backend_uses = 0
    •   SET persist_backend = false
  • 40.
    •   SET pool
    •   SET queue_relief_chance = 0
    •   SET queue_relief_size = 0
    •   SET trusted_upstream_proxies = 10.0.0.0/24
    •   SET upload_status_listeners = ""
    •   SET verify_backend = false
    •   SET verify_backend_path = *
    •   SET blind_proxy = 0
    •   SET reproxy_cache_maxsize = 0
    •   SET max_chunked_request_size = 209715200
  • 41.
    • CREATE SERVICE foo
    •   SET role = web_server
    •   SET listen = 192 .168.0.1:81
    •   SET persist_client = false
    •   SET persist_client_timeout = 30
    •  
    •   SET enable_ssl = false
    •   SET ssl_cert_file = certs/server-cert.pem
    •   SET ssl_key_file  = certs/server-key.pem
    •   SET ssl_cipher_list = ALL:!LOW:!EXP
    •   SET dirindexing = false
    •   SET docroot = /path/to
    •   SET index_files = index.html
  • 42.
    •   SET max_put_size = 0
    •   SET min_put_directory = 0
    •   SET client_sndbuf_size = 0
    •   SET always_trusted = false
    •   SET enable_concatenate_get = 0
    •   SET enable_delete = 0
    •   SET enable_put = 0
    •   SET max_chunked_request_size = 209715200
  • 43.
    • CREATE SERVICE foo
    •   SET role = selector
    •   SET listen = 192 .168.0.1:81
    •   SET persist_client = false
    •   SET persist_client_timeout = 30
    •  
    •   SET enable_ssl = false
    •   SET ssl_cert_file = certs/server-cert.pem
    •   SET ssl_key_file  = certs/server-key.pem
    •   SET ssl_cipher_list = ALL:!LOW:!EXP
    •   SET default_service
    •   SET latency = 0
    •   SET always_trusted = false
    •   SET max_chunked_request_size = 209715200
  • 44.
    • CREATE SERVICE mgmt   SET role   = management   SET listen = 127.0.0.1:60000
    •  
    •   SET persist_client = false
    •   SET persist_client_timeout = 30
    •  
    •   SET enable_ssl = false
    •   SET ssl_cert_file = certs/server-cert.pem
    •   SET ssl_key_file  = certs/server-key.pem
    •   SET ssl_cipher_list = ALL:!LOW:!EXP
    •   SET always_trusted = false
    •   SET max_chunked_request_size = 209715200
  • 45. architecture
  • 46. Perlbal Classes
    • Perlbal Perlbal::AIO Perlbal::BackendHTTP Perlbal::Cache Perlbal::ChunkedUploadState Perlbal::ClientHTTP Perlbal::ClientHTTPBase Perlbal::ClientManage Perlbal::ClientProxy Perlbal::CommandContext
    • Perlbal::HTTPHeaders Perlbal::ManageCommand Perlbal::Pool Perlbal::ReproxyManager Perlbal::Service Perlbal::Socket Perlbal::SocketSSL Perlbal::TCPListener Perlbal::Test Perlbal::Test::WebClient Perlbal::Test::WebServer Perlbal::UploadListener Perlbal::Util
  • 47. class diagram
  • 48. Created by GraphViz
  • 49. how to work
  • 50.
    • call ENABLE servicename, start to listen on Perlbal::TCPListener
    •                {{ INTERNET }}                       |                       v   [Service]<===>[TCPListener]               ___/    |    __              v        v        v   [ClientManage]  [ClientHTTP] [ClientProxy]                                      ^                                      |                                      v                                [BackendHTTP]
    http://code.sixapart.com/trac/perlbal/browser/trunk/doc/hacking/classes.txt
  • 51. plugins
  • 52. Perlbal::Plugin
    • AccessControl AtomInject AtomStream AutoRemoveLeadingDir Cgilike Cgilike::Request EchoService EchoService::Client
    • Highpri Include LazyCDN
    • MaxContentLength NotModified Palimg Queues Redirect Stats Stats::Storage Vhosts Vpaths
    http://code.sixapart.com/trac/perlbal/browser/trunk/lib/Perlbal/Plugin
  • 53. hooks
  • 54. seealso http://code.sixapart.com/trac/perlbal/browser/trunk/doc/hacking/hooks.txt
  • 55. writing plugins
  • 56.
    • package Perlbal::Plugin ::MyPlugin;
    • use strict;
    • use warnings;
    • # when &quot;LOAD&quot; directive loads us up
    • sub load {
    •      return 1;
    • }
    • # unload our global commands, clear our service object
    • sub unload {
    •      return 1;
    • }
    • # called when we're being added to a service
    • sub register {
    •      return 1;
    • }
    • # called when we're no longer active on a service
    • sub unregister {
    •      return 1;
    • }
    • 1;
    • __END__
  • 57.
    • LOAD MyPlugin
    • LOAD OtherPlugin
    • CREATE SERVICE hogehoge
    •     plugins = OtherPlugin, MyPlugin
    • ENABLE hogehoge
  • 58.
    • $ telnet localhost 60000
    • plugins
    • hogehoge OtherPlugin MyPlugin
  • 59. This slide introduced Perlbal to you. If you are interested in Perlbal, please try again later!
  • 60. BTW, JFYI ,  
  • 61. AnyEvent  
  • 62. Danga::Socket::AnyEvent
    • From: Martin Atkins
    • Date: Mon, 17 Aug 2009 16:26:09 -0700
    • Subject: AnyEvent implementation of Danga::Socket
    •  
    • &quot;This allows Perlbal to, in theory, run in any event loop supported by AnyEvent, and more interestingly allows Perlbal plugins to make use of AnyEvent protocol implementations.&quot;
    •  
    • http://groups.google.com/group/perlbal/browse_thread/thread/3a275de028d1a04b
  • 63. Try Danga::Socket::AnyEvent, if you are interested in AnyEvent! http://search.cpan.org/dist/Danga-Socket-AnyEvent/
  • 64. Resources
    • Perlbal
    • http://www.danga.com/perlbal/
    •  
    • Six Apart Code
    • http://code.sixapart.com/svn/perlbal/
    •  
    • Google Code
    • http://code.google.com/p/perlbal/
    •  
    • Google Groups
    • http://groups.google.com/group/perlbal
  • 65.
    • Thank you!

×