Django deployment and rpm+yum

32
Django deployment and RPM+YUM by Walter Liu

Transcript of Django deployment and rpm+yum

Page 1: Django deployment and rpm+yum

Django deployment and RPM+YUMby Walter Liu

Page 2: Django deployment and rpm+yum

Agenda

● Apache, WSGI, Django● Django deployment/security note● Using RPM and YUM

Page 3: Django deployment and rpm+yum

Apache+WSGI+Django

Page 4: Django deployment and rpm+yum

Why use Apache?

runserver is not stable

Page 5: Django deployment and rpm+yum

WSGI

WebServerGatewayInterface

Page 6: Django deployment and rpm+yum

Apache, WSGI, Django

Page 7: Django deployment and rpm+yum

Apache contain multi WSGI

Page 8: Django deployment and rpm+yum

Example WSGI parametersTraceEnable Off

WSGIScriptAlias / /var/www/html/axx_service/wsgi.pyWSGIPythonPath /var/www/html/axx_service/

WSGISocketPrefix /var/run/wsgiWSGIProcessGroup axxaisWSGIDaemonProcess axxais processes=4 threads=16 maximum-requests=4096 display-name=%{GROUP}

# no embedded mode for WSGI. for smaller memory and log message.WSGIRestrictEmbedded on

<Directory "/var/www/html/axx_service/"><Files wsgi.py>Order deny,allowAllow from all</Files></Directory>

Page 9: Django deployment and rpm+yum

Questions?

Page 10: Django deployment and rpm+yum

Django deployment note

Page 11: Django deployment and rpm+yum

● DEBUG = False● TEMPLATE_DEBUG = False● 404 template● 500 template● Host static files● Error alert e-mail (ADMINS, MANAGERS)● Logging settings

Deployment note

Page 12: Django deployment and rpm+yum

Apache+wsgi: Host static filesAlias /robots.txt /usr/local/wsgi/static/robots.txtAlias /favicon.ico /usr/local/wsgi/static/favicon.ico

AliasMatch /([^/]*\.css) /usr/local/wsgi/static/styles/$1

Alias /media/ /usr/local/wsgi/static/media/

<Directory /usr/local/wsgi/static>Order deny,allowAllow from all</Directory>

WSGIScriptAlias / /usr/local/wsgi/scripts/myapp.wsgi

<Directory /usr/local/wsgi/scripts>Order allow,denyAllow from all</Directory>

Page 13: Django deployment and rpm+yum

Django Security note

● SQL Injection protection (ORM)● XSS protection● Csrf protection (middleware)● Clickjacking protection

(middleware, default off)● Possible weak points

○ Weak admin password○ DEBUG = True○ Secret Key

Page 14: Django deployment and rpm+yum

Questions?

Page 15: Django deployment and rpm+yum

Using RPM and YUM

Page 16: Django deployment and rpm+yum

Deployment is ?

● ssh to each host● copy files● remove files● check file integrity● [option] config file upgrade● [option] POST: restart httpd● [option] check service/security status● [option] mock test● .......

Page 17: Django deployment and rpm+yum

Using git?

● No remove files. (may lead to accidents)

● No other script action in update.● Config files?● Version report?

(at least not easy to read.)● Not for OPS● No package dependency● Not scalable for large deployment

Page 18: Django deployment and rpm+yum

Using RPM

● Ensure package version.● Add/remove/update files.● Pre/Post installation scripting.● YUM for remote and repository

Page 19: Django deployment and rpm+yum

How to create RPM

● Prepare *.spec file● Use rpmbuild to build rpm. (refer AIS)

Page 20: Django deployment and rpm+yum

RPM SPEC File

Page 21: Django deployment and rpm+yum
Page 22: Django deployment and rpm+yum
Page 23: Django deployment and rpm+yum

rpmbuild script

Page 24: Django deployment and rpm+yum
Page 25: Django deployment and rpm+yum

YUM server and repo RPM

Now, setup a YUM server + repo RPM, and you may● yum install pitlane● yum install pitlane-worker● yum update pitlane● #rollback versionwith● Auto-dependency

Page 26: Django deployment and rpm+yum

What left?

Page 27: Django deployment and rpm+yum

Concurrent command to hosts

Page 28: Django deployment and rpm+yum

omnitty vs. ssh-keygen

● omnitty● ssh-key and scripting● fabric + ssh-key

Page 29: Django deployment and rpm+yum

Omnitty

Page 30: Django deployment and rpm+yum

sshkey + scripting

Example:pitlane_web.py update-> host_list = ......-> for host in host_list:-> os.system("ssh $s yum update pitlane")

How

● generate ssh public key● copy/cat to target host .ssh/authorized_key

Page 31: Django deployment and rpm+yum

Fabric

Based on sshkeyMade for deployment.

Page 32: Django deployment and rpm+yum

Q&A