59edf39e82f25147f9312d1c4fd6a8171198d797
[flowspy] / install.txt
1
2 Installation
3 ************
4
5
6 Ubuntu 12.04.3 (64) - Django 1.3.x
7 ==================================
8
9 This guide assumes that installation is carried out in /srv/flowspy
10 directory. If other directory is to be used, please change the
11 corresponding configuration files. It is also assumed that the root
12 user will perform every action.
13
14
15 Required system packages
16 ------------------------
17
18 Update and install the required packages:
19
20    apt-get update
21    apt-get upgrade
22    apt-get install mysql-server apache2 memcached libapache2-mod-proxy-html gunicorn beanstalkd python-django python-django-extensions python-django-south python-django-tinymce tinymce python-mysqldb python-yaml python-memcache python-django-registration python-ipaddr python-lxml mysql-client git python-django-celery python-paramiko python-gevent vim
23
24 Note: Set username and password for mysql if used
25
26 Note: If you wish to deploy an outgoing mail server, now it is time to do
27   it. Otherwise you could set FoD to send out mails via a third party
28   account
29
30
31 Required application packages
32 -----------------------------
33
34 Get the required packages and install them
35
36 * ncclient: NETCONF python client:
37
38      cd ~
39      git clone https://github.com/leopoul/ncclient.git
40      cd ncclient
41      python setup.py install
42
43 * nxpy: Python Objects from/to XML proxy:
44
45      cd ~
46      git clone https://code.grnet.gr/git/nxpy
47      cd nxpy
48      python setup.py install
49
50 * flowspy: core application. Installation is done at /srv/flowspy:
51
52      cd /srv
53      git clone https://code.grnet.gr/git/flowspy
54      cd flowspy
55
56
57 Application configuration
58 =========================
59
60 Copy settings.py.dist to settings.py:
61
62    cp settings.py.dist settings.py
63
64 Edit settings.py file and set the following according to your
65 configuration:
66
67    ADMINS: set your admin name and email (assuming that your server can send notifications)
68    DATABASES (to point to your local database). You could use views instead of tables for models: peer, peercontacts, peernetworks. For this to work we suggest MySQL with MyISAM db engine
69    SECRET_KEY : Make this unique, and don't share it with anybody
70    STATIC_URL (static media directory) . If you have followed the above this should be: /srv/flowspy/static
71    TEMPLATE_DIRS : If you have followed the above this should be: /srv/flowspy/templates
72    CACHE_BACKEND:  If you have followed the above this should be: memcached://127.0.0.1:11211/?timeout=3600
73    Alternatively you could go for redis with the corresponding Django client lib.
74    NETCONF_DEVICE (tested with Juniper EX4200 but any BGP enabled Juniper should work). This is the flowspec capable device
75    NETCONF_USER (enable ssh and netconf on device)
76    NETCONF_PASS
77    If beanstalk is selected the following should be left intact.
78    BROKER_HOST (beanstalk host)
79    BROKER_PORT (beanstalk port)
80    SERVER_EMAIL
81    EMAIL_SUBJECT_PREFIX
82    If beanstalk is selected the following should be left intact.
83    BROKER_URL (beanstalk url)
84    SHIB_AUTH_ENTITLEMENT (if you go for Shibboleth authentication)
85    NOTIFY_ADMIN_MAILS (bcc mail addresses)
86    PROTECTED_SUBNETS (subnets for which source or destination address will prevent rule creation and notify the NOTIFY_ADMIN_MAILS)
87    The whois client is meant to be used in case you have inserted peers with their ASes in the peers table and wish to get network info for each one in an automated manner.
88    PRIMARY_WHOIS
89    ALTERNATE_WHOIS
90    If you wish to deploy FoD with Shibboleth change the following attributes according to your setup:
91    SHIB_AUTH_ENTITLEMENT = 'urn:mace'
92    SHIB_ADMIN_DOMAIN = 'example.com'
93    SHIB_LOGOUT_URL = 'https://example.com/Shibboleth.sso/Logout'
94    SHIB_USERNAME = ['HTTP_EPPN']
95    SHIB_MAIL = ['mail', 'HTTP_MAIL', 'HTTP_SHIB_INETORGPERSON_MAIL']
96    SHIB_FIRSTNAME = ['HTTP_SHIB_INETORGPERSON_GIVENNAME']
97    SHIB_LASTNAME = ['HTTP_SHIB_PERSON_SURNAME']
98    SHIB_ENTITLEMENT = ['HTTP_SHIB_EP_ENTITLEMENT']
99
100 If you have not installed an outgoing mail server you can always use
101 your own account (either corporate or gmail, hotmail ,etc) by adding
102 the following lines in settings.py:
103
104    EMAIL_USE_TLS = True #(or False)
105    EMAIL_HOST = 'smtp.example.com'
106    EMAIL_HOST_USER = 'username'
107    EMAIL_HOST_PASSWORD = 'yourpassword'
108    EMAIL_PORT = 587 #(outgoing)
109
110 Note: Soon we will release a version with django-registration as a means
111   to add users and Shibboleth as an alternative
112
113 Let's move on with some copies and dir creations:
114
115    cp urls.py.dist urls.py
116    mkdir log
117    chown -R root:www-data log/
118    chmod -R g+w log
119
120
121 System configuration
122 ====================
123
124 Apache operates as a gunicorn Proxy with WSGI and Shibboleth modules
125 enabled. Depending on the setup the apache configuration may vary:
126
127    a2enmod rewrite
128    a2enmod proxy
129    a2enmod ssl
130    a2enmod proxy_http
131
132 If shibboleth is to be used:
133
134    apt-get install libapache2-mod-shib2
135    a2enmod shib2
136
137 Now it is time to configure beanstalk, gunicorn, celery and apache.
138
139
140 beanstalkd
141 ----------
142
143 Enable beanstalk by editting /etc/default/beanstalkd:
144
145    vim /etc/default/beanstalkd
146
147 Uncomment the line **START=yes** to enable beanstalk
148
149 Start beanstalkd:
150
151    service beanstalkd start
152
153
154 gunicorn.d
155 ----------
156
157 create and edit /etc/gunicorn.d/fod:
158
159    vim /etc/gunicorn.d/fod
160
161 FoD is served via gunicorn and is then proxied by Apache. If the above
162 directory conventions have been followed so far, then your
163 configuration should be:
164
165    CONFIG = {
166        'mode': 'django',
167        'working_dir': '/srv/flowspy',
168        'args': (
169            '--bind=127.0.0.1:8081',
170            '--workers=1',
171            '--timeout=360',
172            '--worker-class=egg:gunicorn#gevent',
173            '--log-level=debug',
174            'settings.py',
175        ),
176    }
177
178
179 celery.d
180 --------
181
182 Celery is used over beanstalkd to apply firewall rules in a serial
183 manner so that locks are avoided on the flowspec capable device. In
184 our setup celery runs via django. That is why the python-django-celery
185 package was installed.
186
187 Note: Make sure that /etc/init.d/celeryd exists.
188
189 celeryd requires a /etc/default/celeryd file to be in place. Thus we
190 are going to create this file (/etc/default/celeryd):
191
192    vim /etc/default/celeryd
193
194 Again if the directory conventions have been followed the file should
195 be:
196
197    # Name of nodes to start, here we have a single node
198    CELERYD_NODES="w1"
199    # or we could have three nodes:
200    #CELERYD_NODES="w1 w2 w3"
201
202    # Where to chdir at start.
203    CELERYD_CHDIR="/srv/flowspy/"
204    # How to call "manage.py celeryd_multi"
205    CELERYD_MULTI="$CELERYD_CHDIR/manage.py celeryd_multi"
206
207    # How to call "manage.py celeryctl"
208    CELERYCTL="$CELERYD_CHDIR/manage.py celeryctl"
209
210    # Extra arguments to celeryd
211    #CELERYD_OPTS="--time-limit=300 --concurrency=8"
212    CELERYD_OPTS="-E -B"
213    # Name of the celery config module.
214    CELERY_CONFIG_MODULE="celeryconfig"
215
216    # %n will be replaced with the nodename.
217    CELERYD_LOG_FILE="$CELERYD_CHDIR/celery_var/log/celery/%n.log"
218    CELERYD_PID_FILE="$CELERYD_CHDIR/celery_var/run/celery/%n.pid"
219
220    # Workers should run as an unprivileged user.
221    CELERYD_USER="root"
222    CELERYD_GROUP="root"
223
224    # Name of the projects settings module.
225    export DJANGO_SETTINGS_MODULE="settings"
226
227
228 Apache
229 ------
230
231 Apache proxies gunicorn. Things are more flexible here as you may
232 follow your own configuration and conventions. Create and edit
233 /etc/apache2/sites-available/fod. You should set <server_name> and
234 <admin_mail> along with your certificates. If under testing
235 environment, you can use the provided snakeoil certs. If you do not
236 intent to use Shibboleth delete or comment the corresponding
237 configuration parts inside **Shibboleth configuration**
238
239    vim /etc/apache2/sites-available/fod
240
241 Again if the directory conventions have been followed the file should
242 be:
243
244    <VirtualHost *:80>
245            ServerAdmin webmaster@localhost
246            ServerName      <server_name>
247            DocumentRoot /var/www
248            <Directory />
249                    Options FollowSymLinks
250                    AllowOverride None
251            </Directory>
252            <Directory /var/www/>
253                    Options Indexes FollowSymLinks MultiViews
254                    AllowOverride None
255                    Order allow,deny
256                    allow from all
257            </Directory>
258
259            ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
260            <Directory "/usr/lib/cgi-bin">
261                    AllowOverride None
262                    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
263                    Order allow,deny
264                    Allow from all
265            </Directory>
266
267            ErrorLog ${APACHE_LOG_DIR}/error.log
268
269            # Possible values include: debug, info, notice, warn, error, crit,
270            # alert, emerg.
271            LogLevel warn
272
273            CustomLog ${APACHE_LOG_DIR}/access.log combined
274
275        Alias /doc/ "/usr/share/doc/"
276        <Directory "/usr/share/doc/">
277            Options Indexes MultiViews FollowSymLinks
278            AllowOverride None
279            Order deny,allow
280            Deny from all
281            Allow from 127.0.0.0/255.0.0.0 ::1/128
282        </Directory>
283
284            RewriteEngine On
285            RewriteCond %{HTTPS} off
286            RewriteRule ^/(.*) https://<server_name>/$1 [L,R]
287
288    </VirtualHost>
289    <VirtualHost *:443>
290            ServerName       <server_name>
291            ServerAdmin             <admin_mail>
292            ServerSignature         On
293
294            SSLEngine on
295            SSLCertificateFile      /etc/ssl/certs/example.com.crt
296            SSLCertificateChainFile /etc/ssl/certs/example.com.crt
297            SSLCertificateKeyFile   /etc/ssl/private/example.com.key
298
299            AddDefaultCharset       UTF-8
300            IndexOptions            +Charset=UTF-8
301
302            # Shibboleth configuration
303            ShibConfig              /etc/shibboleth/shibboleth2.xml
304            Alias                   /shibboleth-sp  /usr/share/shibboleth
305
306            <Location /fod/login>
307            AuthType shibboleth
308            ShibRequireSession On
309            ShibUseHeaders On
310            require valid-user
311        </Location>
312
313            # Shibboleth debugging CGI script
314            ScriptAlias /shibboleth/test /usr/lib/cgi-bin/shibtest.cgi
315            <Location /shibboleth/test>
316                    AuthType shibboleth
317                    ShibRequireSession On
318                    ShibUseHeaders On
319                    require valid-user
320            </Location>
321
322            <Location /Shibboleth.sso>
323                    SetHandler shib
324            </Location>
325
326            # End of Shibboleth configuration
327
328            <Location /admin/media/>
329                    SetHandler      None
330            </Location>
331
332            Alias /admin/media      /usr/share/pyshared/django/contrib/admin/media
333            Alias /media  /usr/share/pyshared/django/contrib/admin/media
334                    DocumentRoot /var/www
335            <Directory /var/www/>
336                    Options Indexes FollowSymLinks MultiViews
337                    AllowOverride None
338                    Order allow,deny
339                    allow from all
340            </Directory>
341
342
343
344            <Proxy *>
345            Order allow,deny
346            Allow from all
347            </Proxy>
348
349            SSLProxyEngine        off
350            ProxyErrorOverride    off
351        ProxyTimeout    28800
352            ProxyPass        /fod http://localhost:8081/fod retry=0
353            ProxyPassReverse /fod http://localhost:8081/fod
354
355            LogLevel warn
356            ErrorLog /var/log/apache2/ssl-error.log
357            CustomLog /var/log/apache2/ssl-access.log combined
358
359
360
361
362            Alias /fodstatic        /srv/flowspy/static
363
364    </VirtualHost>
365
366 You are not far away from deploying FoD. When asked for a super user,
367 create one:
368
369    cd /srv/flowspy
370    python manage.py syncdb
371    python manage.py migrate
372
373 Restart, gunicorn and apache:
374
375    service gunicorn restart && service apache2 restart
376
377
378 Testing the platform
379 ====================
380
381 Log in to the admin interface via https://<your ip>/fod/admin. Go to
382 Peer ranges and add a new range (part of/or a complete subnet), eg.
383 83.212.0.0/19 Go to Peers and add a new peer, eg. id: 1, name: Test,
384 AS: 16503, tag: TEST and move the network you have crteated from
385 Avalable to Chosen. From the admin front, go to User, and edit your
386 user. From the bottom of the page, select the TEST peer and save. Last
387 but not least, modify as required the existing (example.com) Site
388 instance. You are done. As you are logged-n via the admin, there is no
389 need for Shibboleth. Go to https://<your ip>/fod/ and create a new
390 rule. Your rule should be applied on the flowspec capable device after
391 aprox. 10 seconds.
392
393
394 Branding
395 ========
396
397 Via the admin interface you can modify flatpages to suit your needs
398
399
400 Logos
401 -----
402
403 Inside the static folder you will find two empty png files:
404 fod_logo.xcf (Gimp file) and shib_login.dist.png. Edit those two with
405 your favourite image processing software and save them as fod_logo.png
406 (under static/img/) and shib_login.png (under static/). Image sizes
407 are optimized to operate without any other code changes. In case you
408 want to incorporate images of different sizes you have to fine tune
409 css and/or html as well.
410
411
412 Footer
413 ------
414
415 Under the templates folder (templates), you can alter the footer.html
416 file to include your own footer messages, badges, etc.
417
418
419 Welcome Page
420 ------------
421
422 Under the templates folder (templates), you can alter the welcome page
423 - welcome.html with your own images, carousel, videos, etc.