Upload
jay-ren
View
755
Download
0
Embed Size (px)
DESCRIPTION
Fabric - a server management tool from Instagram. It's written in Python
Citation preview
Fabric - a server management tool from Instagram
Jay <[email protected]> 2014.03.28 Shanghai, China
Agenda
What Powers Instagram?
Fabric Introduction
Fabric Demo
Q&A
What Powers Instagram ?
Instagram was acquired by Facebook in April 2012 for approximately US$1 billion in cash and stock.
So, what powers Instagram?
What Powers Instagram ?
OS/Hosting: Ubuntu on Amazon EC2
Load Balance: Amazon’s Elastic Load Balancer
Application Server: Django + Gunicorn
Data Storage: PostgreSQL + Redis + Memcached + Solr
Task Queue & Push Notifications: Gearman + Pyapns
Monitoring: Python-Munin + Pingdom + Sentry
From: http://instagram-engineering.tumblr.com/post/13649370142/what-powers-instagram-hundreds-of-instances-dozens-of
Fabric Introduction (1) - Overview
Fabric is a Python (2.5-2.7) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.
!
from: http://docs.fabfile.org/en/1.8/#about
Fabric Introduction (2) - Features
execute local or remote shell commands
parallel execution
upload/download files
prompt the running user for input
abort execution
Fabric Introduction (3) - Environment
Environment as configuration (fabric.state.env) env.host env.hosts (a list of hosts) env.port env.user env.password env.passwords (a dict of host/password pairs) env.warn_only env.parallel env.roledefs (a dict defining role name to host list mappings)
The settings context manager (temporarily modify env vars so that a given settings change only applies to a block of code)
Fabric Introduction (3) - Execution model
Execution strategy
A list of tasks is created.
For each task, a task-specific host list is generated from various sources.
The task list is walked through in order, and each task is run once per host in its host list.
Tasks with no hosts in their host list are considered local-only, and will always run once and only once.
Fabric Introduction (4) - Defining tasks
New-style (Task based; Exclusive)
The @task decorator
Task subclasses
Classic
Fabric will consider any callable object found in your fabfile, except the following:
Callables whose name starts with an underscore (_).
Callables defined within Fabric itself.
Fabric Introduction (5) - Parallel execution
Serial execution (by default)
Concurrent execution
command-line flag -P or the env variable env.parallel
Bubble size: the pool_size keyword argument to @parallel, or globally via -z.
Fabric Introduction (6) -Context Managers
Context managers for use with the with statement.
fabric.context_managers.cd(), lcd()
hide(), show(), quiet()
settings()
shell_env()
prefix()
path()
warn_only()
Fabric Introduction (7) - Managing output
Standard output levels
status, aborts, warnings, running, stdout, stderr, user
Debug output
debug
Output level aliases
output, everything, commands
Hiding and/or showing output levels
Direct modification of fabric.state.output: fabric.state.output
Context managers: hide()/show()
Command-line arguments: --hide and/or --show arguments
Fabric Introduction (8) - APIs
Core API
Color output functions
Context Managers
Decorators
Documentation helpers
Network
Operations
Tasks
Utils
Contrib API
Console Output Utilities
Django Integration
File and Directory Management
Project Tools
Fabric Demo
Q&A
THE END