Logoj0ke.net Open Build Service > Projects > Apache:Modules > apache2-mod_asn > INSTALL
Sign Up | Log In

File INSTALL of Package apache2-mod_asn

 
1
2
Prerequirements
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
A recent enough version of the Apache HTTP server is required. 2.2.6 or later
6
should be used. In addition, the apr-util library needs to be 1.3.0 or newer.
7
This is because the DBD database pool functionality was developed mainly
8
between 2006 and 2007, and reached production quality at the time.
9
10
11
12
Install the PostgreSQL ip4r datatype
13
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14
15
* install the postgresql-ip4r package
16
  project page: http://ip4r.projects.postgresql.org/
17
  openSUSE/SLE rpm package: 
18
     http://download.opensuse.org/repositories/server:/database:/postgresql/
19
20
21
* install the datatype, done by executing sql statements from the shipped file:
22
    su - postgres
23
    psql -f /usr/share/postgresql-ip4r/ip4r.sql template1
24
25
  ("template1" means that all databases that are created later will have the datatype.
26
  To install it onto an existing database, use your database name instead.)
27
28
  (It is normal to see a a good screenful of out printed out by psql.)
29
30
31
Create the database table
32
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33
34
* it is assumed that a database exist already.
35
36
* execute the sql statements from asn.sql (shipping with mod_asn):
37
    psql -U <dbuser> -f asn.sql <dbname>
38
39
  In this example, a table named pfx2asn would be created in the 
40
  <dbname>. database.
41
42
  (It is normal to see a "NOTICE" printed out by psql.)
43
44
45
46
Load the database with routing data
47
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48
49
* edit asn_import.py for database connection data 
50
  (hostname, username, password, ...)
51
  FIXME: it is ugly to have to edit a script.
52
53
* download the data and import it into the database:
54
55
    ./asn_get_routeviews.py | ./asn_import.py
56
57
* this will take a few minutes. The routing data is 900 MB uncompressed
58
  (beginning of 2009). 
59
60
* the same command can also be used to update the database later, with fresh
61
  routeviews data. Just run it again. It can be done in production while the
62
  database is in active use.
63
64
* you should set up this script to run once per week by cron, so the database
65
  keeps updated regularly.
66
67
68
Build the Apache module
69
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70
71
* compile, install, and enable it:
72
    apxs2 -ci mod_asn.c
73
74
* or install openSUSE/SLE RPM package from here:
75
  http://download.opensuse.org/repositories/Apache:/Modules/ 
76
77
* and enable it
78
    a2enmod asn
79
80
Configure Apache / mod_dbd
81
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82
83
* mod_dbd is the database adapter that provides a connection pool.
84
  Enable it, e.g.
85
    a2enmod asn
86
87
* Put the following configuration into server-wide context.
88
89
  ------------------------------------------------------------------------
90
  # whis configures the connection pool.
91
  # for prefork, this configuration is inactive. prefork simply uses 1
92
  # connection per child.
93
  <IfModule !prefork.c>
94
          DBDMin  0
95
          DBDMax  32
96
          DBDKeep 4
97
          DBDExptime 10
98
  </IfModule>
99
  ------------------------------------------------------------------------
100
101
* configure the database driver.
102
103
  Put this configuration into server-wide OR vhost context. Make the file
104
  chmod 0640, owned root:root because it will contain the database password.
105
106
  ------------------------------------------------------------------------
107
  DBDriver pgsql
108
  # note that the connection string (which is passed straight through to
109
  # PGconnectdb in this case) looks slightly different - pass vs. password
110
  DBDParams "host=localhost user=mb password=12345 dbname=mb_samba connect_timeout=15"
111
  ------------------------------------------------------------------------
112
113
114
Configure mod_asn
115
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116
117
* simply set "ASLookup On" in the directory context where you want it.
118
* the shipped config (mod_asn.conf) shows an example.
119
120
* set "ASSetHeaders Off" if you don't want the data to be added to the HTTP
121
  response headers.
122
123
* you may use the ASLookupQuery directive (server-wide context) to define a
124
  custom SQL query. The compiled in default is:
125
  SELECT pfx, asn FROM pfx2asn WHERE pfx >>= ip4r(%s) ORDER BY ip4r_size(pfx) LIMIT 1
126
127
* the client IP address is the one that the requests originates from. But if
128
  mod_asn is running behind a frontend server, the frontend can pass the IP via
129
  a header and mod_asn can look at the header instead, and you can configure it
130
  to look at that header like this: 
131
    ASIPHeader X-Forwarded-For
132
133
* alternatively, if you want to use mod_rewrite you can also make mod_asn look
134
  at a variable in Apache's subprocess environment:
135
    ASIPEnvvar CLIENT_IP
136
137
* "ASLookupDebug On" can be set to switch on debug logging. It can be set per
138
  directory.
139
140
141
Logging
142
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
143
144
* since the data being looked up is stored in the subprocess environment, it is
145
  trivial to log it, by adding the following placeholder to the LogFormat:
146
    ASN:%{ASN}e P:%{PFX}e
147
148
149
That's it!
150
151
Questions, bug reports, patches are welcome at info@mirrorbrain.org.
152