Project

General

Profile

ClientPgGraph2Install » History » Version 8

Aurynn Shaw, 05/15/2008 07:44 AM

1 1 Aurynn Shaw
README -- Mar 13, 2008 -- Aurynn Shaw -- ashaw@commandprompt.com
2
3
4 8 Aurynn Shaw
h2. Python Dependencies
5
6
7 1 Aurynn Shaw
Make sure before you begin that you've got the following Python packages installed via apt-get:
8 5 John Worsley
9 8 Aurynn Shaw
* python-imaging
10
* python-paramiko
11
* python-psycopg
12
* python-psycopg2
13
* python-libreport
14 1 Aurynn Shaw
15
Report Lab note: you will need to compile the rl_addon renderPM lib from source (the installed python class is a stub). It is available via SVN at svn co http://www.reportlab.co.uk/svn/public/reportlab/trunk
16
17
18 8 Aurynn Shaw
h2. Pre-Installation Setup & Notes
19 1 Aurynn Shaw
20 8 Aurynn Shaw
* Create "pggraph_clients"  database, with "clients" table, for the installer script to INSERT to.
21
* Create "pggraph" database, install SQL average functions from .sql file in install path.
22
* The Python Path will need to be configured to point to the _main installation files (the directory you are installing from) so that fonts and common classes are available.
23
* Do NOT create the desired installation directory before you run the script, it is part of the script's function.
24
25
26
h2. At A Glance Installation
27
28
29
* Use /var/www/pggraph/_main/install.py. Consult this document for specifics.
30
* symlink busy_dml_report.py into your new install dir.
31
* Run the forwarder, /var/www/python/_main/forward.py /path/to/your/new/install
32
* Check if you need to set up a bastion install
33
*** If you do, ssh to the bastion and run
34
***** screen
35
***** inside screen: ssh -L7750:localhost:5432 cmd@the_actual_db_server
36
***** ctrl-a ctrl-d, detach from screen. It keeps on truckin'.
37
* Run python /var/www/pggraph/_main/bridge.py /path/to/your/new/install/config.ini
38
* Wait until it returns. Now run it again.
39
* check http://www.cmdalert.com/pggraph/your_install/
40
* Make sure there's graphs.
41
* Go edit the Apache config, copy and paste the existing format for PG-backed password auth.
42
*** The file is 001-something in /etc/apache2/sites-enabled
43
* Using the existing format, dump and add the database users from the client 
44 1 Aurynn Shaw
   Trac to serve as the auth for pggraph.
45 8 Aurynn Shaw
* Reload apache.
46
* Add the cronjob, based on the other cronjobs for pggraph.
47
* Fini.
48 1 Aurynn Shaw
     
49
50 8 Aurynn Shaw
h2. Introduction
51
52
53 1 Aurynn Shaw
If youre reading this document, congratulations! Youve managed to 
54
successfully install the server software for PGGraph! Youve done an amazing
55
thing, and you ought to be proud of yourself.
56
57
This document will be discussing the next step, setting up client systems for
58
pggraph, the configuration weirdness and gotchas that you need to know.
59
60
The specific sections in this document are as follows:
61
62 8 Aurynn Shaw
* The Installer
63
* Server preparation
64
* Running it the first time
65
* Cronjob
66
* Cursing
67 1 Aurynn Shaw
 
68
69 8 Aurynn Shaw
h2. The Installer
70
71
72 1 Aurynn Shaw
Step one, setting up a client instance.
73
Given PGGraphs curious evolutionary path, the process of installing a client
74
was once much more difficult than it is now, and thus, I created the 
75
Installer.
76 3 Aurynn Shaw
77 1 Aurynn Shaw
The installer is run from the source directory of all PGGGraph scripts - in
78
the case of cmdalert.com, /var/www/pggraph/_main/
79 3 Aurynn Shaw
80
The software is executed thusly:
81 8 Aurynn Shaw
<pre>
82 1 Aurynn Shaw
  $ python ./install.py
83 8 Aurynn Shaw
</pre>
84 1 Aurynn Shaw
It will then ask you a number of questions specifically relating to the 
85
install process.
86
For clarity, the installer is reproduced here to give you a basic walkthrough
87 4 Aurynn Shaw
on what values are expected and a basic concept of how PGGraph works.
88 1 Aurynn Shaw
89
For clarity, the || || characters have been added to delineate between my 
90
comments and what will be shown by the installer.
91
92 8 Aurynn Shaw
<pre>
93 1 Aurynn Shaw
    
94
    Installation directory?  || Requires absolute path: This is the exact path to the install. /var/www/pggraph/some_dir. || 
95
    Relative WWW path?  || Usually pggraph/prefix: pggraph/some_dir. Controls HTML generation. || 
96
    Full text title?  || Usually customer name: Page title, in the databse || 
97
    Now for some database configuration..
98
99
    Local pggraph database name? [pggraph]  || Don't change this, unless you're putting their data in a new DB || 
100
    Table prefix?  || some prefix, like aweber or vltlgx or something. To keep tables from colliding. || 
101 8 Aurynn Shaw
    Local database port? r5432  || It's on 5432. || 
102 1 Aurynn Shaw
    Local pggraph host? usually localhost [localhost]  || It's always localhost. Except when it isn't. || 
103
    
104
    Local username? usually pggraph [pggraph]  || It's pggraph. || 
105
    Password? Can be blank [8sm4LA2]  || It's this password. || 
106
107
    Remote DB username?  || Username we connect to the remote DB with. cmd, postgres, or other. || 
108
    Remote DB password?  || As described || 
109
    Remote DB host? [localhost]  || Almost always localhost. || 
110 8 Aurynn Shaw
    Local port to bind to remote PG port? r7555  || Always a non-5432 local port. Be sure this is numeric and not "None" as it may default if this is the first run. || 
111 5 John Worsley
112 1 Aurynn Shaw
    Some pggraph settings..
113
114 8 Aurynn Shaw
    Shortest display interval, in minutes? r10  || How frequently we're updating the database. || 
115
    Maximum number of images per page? r10  || Suffers from an off-by-one error, so enter 1 more than you want to display. || 
116
    Delay before continuing PGGraph startup r7  || Number of seconds after initializing a new tunnel via forward, that the script waits before attempting to connect. || 
117 1 Aurynn Shaw
118
    So far, so good. Now for the SSH configuration for the PG tunnel.
119
120
    SSH User?  || SSH user name. almost always cmd || 
121
    SSH Password?  || Deprecated in favour of || 
122
    Authentication keyfile? [/home/pggraph/.ssh/id_dsa]  || the default admin ssh key. Good almost everywhere. || 
123
    Remote server?  || remote server IP || 
124 8 Aurynn Shaw
    Port to SSH to? r22  || Remote port to SSH to || 
125
    Bind to what port? r5432  || Remote port to bind to - not always 5432, in cases of bastions. || 
126 1 Aurynn Shaw
    Bind to which remote address? [localhost]  || Again, not always, in case of bastions. || 
127
    Use a twin tunnel mechanism? Leave blank if you dont know currently buggy:  || Don't use this. It was a prior attempt at making bastions work. || 
128
        Address for 2nd server?  || Only shows up if you select twin tunnel. So don't. :) || 
129
    
130 8 Aurynn Shaw
</pre>
131 1 Aurynn Shaw
132
Any question with a [] following it indicates that pressing enter will give 
133
you the default value.
134
135
Once you've answered all the installer's questions, it will go off and create
136
the appropriate directories, create symlinks for all the necessary scripts and
137
libraries, as well as write out the configuration data.
138
139
At this point, you're about halfway done.
140
141
The first step (as of Mar 17, 2008), is to symlink busy_dml_report.py into the
142
freshly created directory. It's a recent addition and is not yet supported by
143
the installer script.
144
145
146 8 Aurynn Shaw
h2. Server Preparation
147
148
149
150
h3. No Bastion
151
152 1 Aurynn Shaw
The next step is, the remote server information needs to be verified. This is 
153
always going to be in the customers' Trac wiki, and easily found.
154
155
To test the tunneling setup:
156
157 8 Aurynn Shaw
<pre>
158 1 Aurynn Shaw
    
159
   $ python /var/www/pggraph/forward.py /var/www/pggraph/new_server
160
   Initializing tunnel..
161
   $ psql -d template1 -U cmd -h localhost -p <the port you gave it>
162 8 Aurynn Shaw
</pre>
163 1 Aurynn Shaw
164
If you connect, success! You can move on to the next phase in the installation.
165
166
If you don't, you can use the error message you got in helping you track down
167
why. The most common errors I've had are specific to pg_hba settings being
168
incorrect, and the cmd user not existing.
169
170
171
172 8 Aurynn Shaw
h3. Bastions
173
174
175 1 Aurynn Shaw
A fact of life, some of our customers don't trust people on the internet. It's
176
hard to not blame them for that, but it does make our life a lot harder when
177
it comes to running pggraph for them.
178
179
To set up a bastion host for pggraph, you're going to need to do a little bit
180
of trickery.
181
182
The specific process I've followed is:
183 8 Aurynn Shaw
* Set up forward.py as normal on cmdalert.
184
* ssh into the bastion server
185
* Using screen, run
186
<pre>
187 1 Aurynn Shaw
       ssh -L7750:localhost:5432 cmd@the_actual_db_server
188 8 Aurynn Shaw
</pre>
189
* Detach from screen, leaving the ssh tunnel open.
190
* Now that you're back on the bastion server, see if you can telnet to port 
191 1 Aurynn Shaw
   7750. 
192 8 Aurynn Shaw
* If you can, disconnect and attempt to connect via psql from cmdalert.
193
*** Retrace your steps in the event that you can't connect.
194
*** Most error messages are going to be caused by incorrect settings in
195 1 Aurynn Shaw
     pg_hba.conf.
196
     
197
You will need to check on your bastion-side tunnel from time to time, as 
198
they are significantly more fragile than the standard pggraph installation,
199
and require manual intervention to recreate.
200
201
202
203 8 Aurynn Shaw
h2. Running PGGraph
204
205
206 1 Aurynn Shaw
At this point, you're close to finished the PGGraph installation. The next 
207
step is to run the data-collecting script and test for proper graph 
208
generation.
209
210
This is fairly easily done, simply
211 8 Aurynn Shaw
<pre>
212 1 Aurynn Shaw
python ../_main/bridge.py ./config.ini
213 8 Aurynn Shaw
</pre>
214 1 Aurynn Shaw
from the newly installed PGGraph client path.
215
216
This will attempt to connect across the tunnel and collect the data that is
217
used to build the graphs.
218
219
At this point, you should open a browser window to the newly created path (as
220
mentioned in the installer), usually http://cmdalert.com/pggraph/your_client/
221
The first graph is a good indicator whether or not data is being correctly
222
collected, and its presence shows that you can move on to the next step.
223
224
If it fails to display, first you should re-run the data collector, and test 
225
the graph again. A lot of the architecture of PGGraph is based around deltas
226
of dataset - (dataset - 1 time unit), so only a single database entry may 
227
cause unintended failure.
228
229
If that fails, verify that your connection chain is intact. Failing that, feel
230
free to email me and ask for help.
231
232
233
234 8 Aurynn Shaw
h2. Cron
235
236
237 1 Aurynn Shaw
In order for PGGraph to continue to collect data about its client systems, the
238
data collector needs to be run on a regular basis. Thus, comes the cronjob.
239
240
Adding the cronjob is simple: as the pggraph user, add a line similar to the 
241
following to your crontab, and you're done.
242
243 8 Aurynn Shaw
<pre>
244 1 Aurynn Shaw
    */10 * * * * /usr/bin/python /var/www/pggraph/_main/bridge.py /var/www/pggraph/your_install_dir/config.ini
245
    or
246
    5,15,25,35,45,55 * * * * /usr/bin/python /var/www/pggraph/_main/bridge.py /var/www/pggraph/your_install_dir/config.ini
247 8 Aurynn Shaw
</pre>
248 1 Aurynn Shaw
249
Write out the crontab, and pggraph is now collecting data on a regular cycle.
250
251
252
253 8 Aurynn Shaw
h2. Apache
254 5 John Worsley
255 8 Aurynn Shaw
256
257
h3. Python
258
259
260 5 John Worsley
Use CGI Python, not mod_python. Example configuration:
261
262 8 Aurynn Shaw
<pre>
263 5 John Worsley
<Directory "/var/www/pggraph/*/">
264
Options +ExecCGI -Indexes -MultiViews +SymLinksIfOwnerMatch
265 8 Aurynn Shaw
[[DirectoryIndex]]
266
[[AddHandler]] cgi-script .py
267 1 Aurynn Shaw
</Directory>
268 8 Aurynn Shaw
</pre>
269 1 Aurynn Shaw
270
271 8 Aurynn Shaw
h3. Access
272
273
274 1 Aurynn Shaw
As pggraph contains a lot of very detailed information on the structure
275
of the clients' database, it's generally a bad idea for anyone who can type in
276 2 Aurynn Shaw
a URL to be able to access it.
277
278
From that, we come to require an authentication system to keep fingers and 
279
eyeballs from where they don't belong.
280
281
As we're using a Pg-backed authentication system in Apache, and as it's 
282
already fully set up, I won't go into any detail regarding installation or
283
configuration issues.
284
285
To set up the directory-specific authentication, you should copy and paste
286
the following configuration and modify it as needed to fit the new PGGraph
287
installation.
288
289
The file that needs to be altered is /etc/apache2/sites-enabled/default-ssl
290
Please back up this file prior to modification.
291
292 8 Aurynn Shaw
<pre>
293 2 Aurynn Shaw
<Location /pggraph/your_install>
294
295 8 Aurynn Shaw
        [[AuthName]] "Pggraph authentication for: Your Installation"
296
        [[AuthType]] Basic
297 2 Aurynn Shaw
        Auth_PG_host localhost
298
        Auth_PG_port 5432
299
        Auth_PG_user pggraph
300
        Auth_PG_pwd 8sm4LA2
301
        Auth_PG_authoritative on
302
        Auth_PG_database pggraph_users
303
        Auth_PG_pwd_table client_users
304
        Auth_PG_hash_type MD5
305
        Auth_PG_uid_field user_name
306
        Auth_PG_pwd_field user_passwd
307
        Auth_PG_log_table client_access_log
308
        Auth_PG_log_uname_field login
309
        Auth_PG_log_date_field date
310
        Auth_PG_log_uri_field   request
311
        Auth_PG_log_addrs_field  ip_address
312 8 Aurynn Shaw
        [[AuthBasicAuthoritative]] Off
313 1 Aurynn Shaw
        Require valid-user
314
</Location>
315 8 Aurynn Shaw
</pre>
316 1 Aurynn Shaw
317
Reload Apache via /etc/init.d/apache2 reload, and your new 
318
pggraph installation is now completed.