Statistics
| Branch: | Tag: | Revision:

root / doc / source / install.rst @ 51ce199a

History | View | Annotate | Download (12 kB)

1
************
2
Installation
3
************
4

    
5
.. toctree::
6
   :maxdepth: 2
7

    
8
Ubuntu 12.04.3 (64) - Django 1.3.x
9
==================================
10

    
11
This guide assumes that installation is carried out in /srv/flowspy directory. If other directory is to be used, please change the corresponding configuration files. It is also assumed that the root user will perform every action.
12

    
13
Required system packages
14
------------------------
15

    
16
Update and install the required packages::
17

    
18
	apt-get update
19
	apt-get upgrade
20
	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
21

    
22
.. note::
23
 Set username and password for mysql if used
24

    
25
.. note::
26
	If you wish to deploy an outgoing mail server, now it is time to do it. Otherwise you could set FoD to send out mails via a third party account
27

    
28
Required application packages
29
-----------------------------
30
Get the required packages and install them
31

    
32
- ncclient: NETCONF python client::
33

    
34
	cd ~
35
	git clone https://github.com/leopoul/ncclient.git
36
	cd ncclient
37
	python setup.py install
38

    
39
- nxpy: Python Objects from/to XML proxy::
40

    
41
	cd ~
42
	git clone https://code.grnet.gr/git/nxpy
43
	cd nxpy
44
	python setup.py install
45

    
46
- flowspy: core application. Installation is done at /srv/flowspy::
47

    
48
	cd /srv
49
	git clone https://code.grnet.gr/git/flowspy
50
	cd flowspy
51

    
52
Application configuration
53
=========================
54

    
55
Copy settings.py.dist to settings.py::
56

    
57
	cp settings.py.dist settings.py
58

    
59
Edit settings.py file and set the following according to your configuration::
60

    
61
	ADMINS: set your admin name and email (assuming that your server can send notifications)
62
	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
63
	SECRET_KEY : Make this unique, and don't share it with anybody
64
	STATIC_URL (static media directory) . If you have followed the above this should be: /srv/flowspy/static
65
	TEMPLATE_DIRS : If you have followed the above this should be: /srv/flowspy/templates
66
	CACHE_BACKEND:  If you have followed the above this should be: memcached://127.0.0.1:11211/?timeout=3600
67
	Alternatively you could go for redis with the corresponding Django client lib.
68
	NETCONF_DEVICE (tested with Juniper EX4200 but any BGP enabled Juniper should work). This is the flowspec capable device
69
	NETCONF_USER (enable ssh and netconf on device)
70
	NETCONF_PASS
71
	If beanstalk is selected the following should be left intact.
72
	BROKER_HOST (beanstalk host)
73
	BROKER_PORT (beanstalk port)
74
	SERVER_EMAIL
75
	EMAIL_SUBJECT_PREFIX
76
	If beanstalk is selected the following should be left intact.
77
	BROKER_URL (beanstalk url)
78
	SHIB_AUTH_ENTITLEMENT (if you go for Shibboleth authentication)
79
	NOTIFY_ADMIN_MAILS (bcc mail addresses)
80
	PROTECTED_SUBNETS (subnets for which source or destination address will prevent rule creation and notify the NOTIFY_ADMIN_MAILS)
81
	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.
82
	PRIMARY_WHOIS
83
	ALTERNATE_WHOIS
84
	If you wish to deploy FoD with Shibboleth change the following attributes according to your setup:
85
	SHIB_AUTH_ENTITLEMENT = 'urn:mace'
86
	SHIB_ADMIN_DOMAIN = 'example.com'
87
	SHIB_LOGOUT_URL = 'https://example.com/Shibboleth.sso/Logout'
88
	SHIB_USERNAME = ['HTTP_EPPN']
89
	SHIB_MAIL = ['mail', 'HTTP_MAIL', 'HTTP_SHIB_INETORGPERSON_MAIL']
90
	SHIB_FIRSTNAME = ['HTTP_SHIB_INETORGPERSON_GIVENNAME']
91
	SHIB_LASTNAME = ['HTTP_SHIB_PERSON_SURNAME']
92
	SHIB_ENTITLEMENT = ['HTTP_SHIB_EP_ENTITLEMENT']
93

    
94
If you have not installed an outgoing mail server you can always use your own account (either corporate or gmail, hotmail ,etc) by adding the following lines in settings.py::
95

    
96
	EMAIL_USE_TLS = True #(or False)
97
	EMAIL_HOST = 'smtp.example.com'
98
	EMAIL_HOST_USER = 'username'
99
	EMAIL_HOST_PASSWORD = 'yourpassword'
100
	EMAIL_PORT = 587 #(outgoing)
101

    
102

    
103
.. note::
104
	Soon we will release a version with django-registration as a means to add users and Shibboleth as an alternative
105

    
106
Let's move on with some copies and dir creations::
107

    
108
	cp urls.py.dist urls.py
109
	mkdir log
110
	chown -R root:www-data log/
111
	chmod -R g+w log
112

    
113
System configuration
114
====================
115
Apache operates as a gunicorn Proxy with WSGI and Shibboleth modules enabled.
116
Depending on the setup the apache configuration may vary::
117

    
118
	a2enmod rewrite
119
	a2enmod proxy
120
	a2enmod ssl
121
	a2enmod proxy_http
122

    
123
If shibboleth is to be used::
124

    
125
	apt-get install libapache2-mod-shib2
126
	a2enmod shib2
127

    
128
Now it is time to configure beanstalk, gunicorn, celery and apache.
129

    
130
beanstalkd
131
----------
132

    
133
Enable beanstalk by editting /etc/default/beanstalkd::
134

    
135
	vim /etc/default/beanstalkd
136

    
137
Uncomment the line **START=yes** to enable beanstalk
138

    
139
Start beanstalkd::
140

    
141
	service beanstalkd start
142

    
143
gunicorn.d
144
----------
145

    
146
create and edit /etc/gunicorn.d/fod::
147

    
148
	vim /etc/gunicorn.d/fod
149

    
150
FoD is served via gunicorn and is then proxied by Apache. If the above directory conventions have been followed so far, then your configuration should be::
151

    
152
	CONFIG = {
153
	    'mode': 'django',
154
	    'working_dir': '/srv/flowspy',
155
	    'args': (
156
	        '--bind=127.0.0.1:8081',
157
	        '--workers=1',
158
	        '--timeout=360',
159
	        '--worker-class=egg:gunicorn#gevent',
160
	        '--log-level=debug',
161
	        'settings.py',
162
	    ),
163
	}
164

    
165
celery.d
166
--------
167

    
168
Celery is used over beanstalkd to apply firewall rules in a serial manner so that locks are avoided on the flowspec capable device. In our setup celery runs via django. That is why the python-django-celery package was installed.
169

    
170
.. note::
171
	Make sure that /etc/init.d/celeryd exists.
172

    
173
celeryd requires a /etc/default/celeryd file to be in place.
174
Thus we are going to create this file (/etc/default/celeryd)::
175

    
176
	vim /etc/default/celeryd
177

    
178
Again if the directory conventions have been followed the file should be::
179

    
180
	# Name of nodes to start, here we have a single node
181
	CELERYD_NODES="w1"
182
	# or we could have three nodes:
183
	#CELERYD_NODES="w1 w2 w3"
184

    
185
	# Where to chdir at start.
186
	CELERYD_CHDIR="/srv/flowspy/"
187
	# How to call "manage.py celeryd_multi"
188
	CELERYD_MULTI="$CELERYD_CHDIR/manage.py celeryd_multi"
189

    
190
	# How to call "manage.py celeryctl"
191
	CELERYCTL="$CELERYD_CHDIR/manage.py celeryctl"
192

    
193
	# Extra arguments to celeryd
194
	#CELERYD_OPTS="--time-limit=300 --concurrency=8"
195
	CELERYD_OPTS="-E -B"
196
	# Name of the celery config module.
197
	CELERY_CONFIG_MODULE="celeryconfig"
198

    
199
	# %n will be replaced with the nodename.
200
	CELERYD_LOG_FILE="$CELERYD_CHDIR/celery_var/log/celery/%n.log"
201
	CELERYD_PID_FILE="$CELERYD_CHDIR/celery_var/run/celery/%n.pid"
202

    
203
	# Workers should run as an unprivileged user.
204
	CELERYD_USER="root"
205
	CELERYD_GROUP="root"
206

    
207
	# Name of the projects settings module.
208
	export DJANGO_SETTINGS_MODULE="settings"
209

    
210
Apache
211
------
212
Apache proxies gunicorn. Things are more flexible here as you may follow your own configuration and conventions. Create and edit /etc/apache2/sites-available/fod. You should set <server_name> and <admin_mail> along with your certificates. If under testing environment, you can use the provided snakeoil certs. If you do not intent to use Shibboleth delete or comment the corresponding configuration parts inside **Shibboleth configuration** ::
213

    
214
	vim /etc/apache2/sites-available/fod
215

    
216
Again if the directory conventions have been followed the file should be::
217

    
218
	<VirtualHost *:80>
219
		ServerAdmin webmaster@localhost
220
		ServerName	<server_name>
221
		DocumentRoot /var/www
222
		<Directory />
223
			Options FollowSymLinks
224
			AllowOverride None
225
		</Directory>
226
		<Directory /var/www/>
227
			Options Indexes FollowSymLinks MultiViews
228
			AllowOverride None
229
			Order allow,deny
230
			allow from all
231
		</Directory>
232

    
233
		ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
234
		<Directory "/usr/lib/cgi-bin">
235
			AllowOverride None
236
			Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
237
			Order allow,deny
238
			Allow from all
239
		</Directory>
240

    
241
		ErrorLog ${APACHE_LOG_DIR}/error.log
242

    
243
		# Possible values include: debug, info, notice, warn, error, crit,
244
		# alert, emerg.
245
		LogLevel warn
246

    
247
		CustomLog ${APACHE_LOG_DIR}/access.log combined
248

    
249
	    Alias /doc/ "/usr/share/doc/"
250
	    <Directory "/usr/share/doc/">
251
	        Options Indexes MultiViews FollowSymLinks
252
	        AllowOverride None
253
	        Order deny,allow
254
	        Deny from all
255
	        Allow from 127.0.0.0/255.0.0.0 ::1/128
256
	    </Directory>
257

    
258
		RewriteEngine On
259
		RewriteCond %{HTTPS} off
260
		RewriteRule ^/(.*) https://<server_name>/$1 [L,R]
261

    
262
	</VirtualHost>
263
	<VirtualHost *:443>
264
		ServerName	 <server_name>
265
		ServerAdmin		<admin_mail>
266
		ServerSignature		On
267

    
268
		SSLEngine on
269
		SSLCertificateFile	/etc/ssl/certs/example.com.crt
270
		SSLCertificateChainFile	/etc/ssl/certs/example.com.crt
271
		SSLCertificateKeyFile	/etc/ssl/private/example.com.key
272

    
273
		AddDefaultCharset	UTF-8
274
		IndexOptions		+Charset=UTF-8
275

    
276
		# Shibboleth configuration
277
		ShibConfig		/etc/shibboleth/shibboleth2.xml
278
		Alias			/shibboleth-sp	/usr/share/shibboleth
279

    
280
		<Location /fod/login>
281
	        AuthType shibboleth
282
	        ShibRequireSession On
283
	        ShibUseHeaders On
284
	        require valid-user
285
	    </Location>
286

    
287
		# Shibboleth debugging CGI script
288
		ScriptAlias /shibboleth/test /usr/lib/cgi-bin/shibtest.cgi
289
		<Location /shibboleth/test>
290
			AuthType shibboleth
291
			ShibRequireSession On
292
			ShibUseHeaders On
293
			require valid-user
294
		</Location>
295

    
296
		<Location /Shibboleth.sso>
297
			SetHandler shib
298
		</Location>
299

    
300
		# End of Shibboleth configuration
301

    
302
		<Location /admin/media/>
303
			SetHandler      None
304
		</Location>
305

    
306
		Alias /admin/media	/usr/share/pyshared/django/contrib/admin/media
307
		Alias /media  /usr/share/pyshared/django/contrib/admin/media
308
			DocumentRoot /var/www
309
	        <Directory /var/www/>
310
	                Options Indexes FollowSymLinks MultiViews
311
	                AllowOverride None
312
	                Order allow,deny
313
	                allow from all
314
	        </Directory>
315

    
316

    
317

    
318
		<Proxy *>
319
	  	Order allow,deny
320
		Allow from all
321
		</Proxy>
322

    
323
		SSLProxyEngine        off
324
		ProxyErrorOverride    off
325
	    ProxyTimeout    28800
326
		ProxyPass        /fod http://localhost:8081/fod retry=0
327
		ProxyPassReverse /fod http://localhost:8081/fod
328

    
329
		LogLevel warn
330
		ErrorLog /var/log/apache2/ssl-error.log
331
		CustomLog /var/log/apache2/ssl-access.log combined
332

    
333

    
334

    
335

    
336
		Alias /fodstatic	/srv/flowspy/static
337

    
338
	</VirtualHost>
339

    
340
You are not far away from deploying FoD. When asked for a super user, create one::
341

    
342
	cd /srv/flowspy
343
	python manage.py syncdb
344
	python manage.py migrate
345

    
346
Restart, gunicorn and apache::
347

    
348
	service gunicorn restart && service apache2 restart
349

    
350
Testing the platform
351
====================
352
Log in to the admin interface via https://<your ip>/fod/admin. Go to Peer ranges and add a new range (part of/or a complete subnet), eg. 83.212.0.0/19
353
Go to Peers and add a new peer, eg. id: 1, name: Test, AS: 16503, tag: TEST and move the network you have crteated from Avalable to Chosen. From the admin front, go to User, and edit your user. From the bottom of the page, select the TEST peer and save.
354
Last but not least, modify as required the existing (example.com) Site instance. You are done. As you are logged-n via the admin, there is no need for Shibboleth. Go to https://<your ip>/fod/ and create a new rule. Your rule should be applied on the flowspec capable device after aprox. 10 seconds.
355

    
356
Branding
357
========
358
Via the admin interface you can modify flatpages to suit your needs
359

    
360
Logos
361
-----
362
Inside the static folder you will find two empty png files: fod_logo.xcf (Gimp file) and shib_login.dist.png. Edit those two with your favourite image processing software and save them as fod_logo.png (under static/img/) and shib_login.png (under static/). Image sizes are optimized to operate without any other code changes. In case you want to incorporate images of different sizes you have to fine tune css and/or html as well.
363

    
364
Footer
365
------
366
Under the templates folder (templates), you can alter the footer.html file to include your own footer messages, badges, etc.
367

    
368
Welcome Page
369
------------
370
Under the templates folder (templates), you can alter the welcome page - welcome.html with your own images, carousel, videos, etc.