
===================================================================
= This file describes how to build, install, and configure Psyche =
===================================================================

These instructions assume you have installed Fedora 10 (with the 'Software 
Development' platform option) on your Psyche system. Psyche will benefit 
greatly from multiple processors, a lot of RAM, and fast disk, especially 
if you plan to run the database, collector and UI on the same machine.

Summary of installation tasks
-----------------------------

  * Update Fedora and install postgres

  * Install psyche python dependencies

  * Build, install and configure psyche

  * Configure Linux

  * Configure PostgreSQL


+------------------------------------+
| Update Fedora and install postgres |
+------------------------------------+

This section describes how to install the requisite version of postgres on your
Fedora 10 platform.  Execute the following commands as root:

#update Fedora packages
yum update

#install PostgreSQL server and development headers/libraries
yum install postgresql-{server,devel}

+------------------------------------+
| Install psyche python dependencies |
+------------------------------------+

Execute the following commands as root to install psyche
python requirements.

#remove packages that require python(abi) = 2.5 and have
#no replacement, yet, in rawhide
rpm -e setroubleshoot{,-{plugins,server}}

#install TurboGears and all its ~200 dependencies (including
#python 2.6) from the rawhide development repository
yum --enablerepo=rawhide install TurboGears

#if the previous update breaks openssl (libssl.so.7 is no longer
#available), execute the following command to resolve the problem.
#Note that the upgraded library to which you must link may be different
#than below -- check your system for the specific library name.
ln -s /lib/libssl.so.0.9.8j /lib/libssl.so.7; ldconfig

 
Install TurboGears and its dependencies

#install easy_install command required to install TGExtJS and
#its dependency, Scriptaculous
yum --enablerepo=rawhide install python-setuptools-devel

#install TGExtJS and Scriptaculous
env PYTHON_EGG_CACHE=. easy_install 'TGExtJs==0.2.3b'

+-------------------------------------+
| Build, install and configure psyche |
+-------------------------------------+

These instructions assume the psyche flow collector, pfcapd, the PostgreSQL
database, and psyche UI all run on the same machine

Ensure nspr-devel is installed
------------------------------

  sudo yum install nspr-devel

Build psyche
------------

Extract the tarball into subdirectory psyche-0.4.

  tar xzf psyche-0.4.tar.gz

Enter the source subdirectory.

  cd psyche-0.4

Review the configure script help output for information about configurable
items.  The defaults should work fine for most environments, but the following
items may be of interest.

  ./configure --help
  ...
  --prefix=PREFIX          install architecture-independent files in PREFIX
                           [/usr/local]
  ...
  --with-dbname=NAME       the default PostgreSQL database name for PSyCHE data
                           (default psyche)
  --with-dbhost=HOST       the default PostgreSQL database host (default null -
                           localhost)
  --with-dbport=HOST       the default PostgreSQL database port (default null -
                           unix socket)
  --with-pgroot=USERNAME   the PostgreSQL superuser name (default postgres)
  --with-dbroot=NAME       the PostgreSQL superuser database (default postgres)
  --with-pfuser=USERNAME   the username as which pfcapd runs (default pfcapd)
  --with-pfuserpw=PASSWORD the password used by pfuser for PSyCHE database
                           connections (default null - unix socket or ident)
  --with-w3user=USERNAME   the username as which web server runs (default
                           psyche)
  --with-w3userpw=PASSWORD the password used by w3user for PSyCHE database
                           connections (default null - ident)

Run the configure script.  For now, the --enable-debug option is recommended,
along with other options to override the above defaults if necessary.

  ./configure --enable-debug ...

Build the executables.

  make

Install psyche.

  sudo make install


ALL COMMANDS BELOW THIS POINT MUST BE RUN AS THE ROOT USER
..........................................................


Configure pfcapd
----------------

Copy the sample script that starts pfcapd into the system 'rc' script
hierarchy, so we can configure it to start automatically at boot.

  cp /usr/local/share/psyche/pfcapd.redhat /etc/init.d/pfcapd

Edit the following items in /etc/init.d/pfcapd, which are documented in the
script's comments.

  * Set the PFUSER variable to match the user name as which pfcapd will
    execute.  This username must have collector (psyche_col) privileges as
    defined in the init_db.sql file.  To use the default, create a user named
    pfcapd by running 'useradd -m pfcapd -s /sbin/nologin' as root. [On Debian
    or Ubuntu, use -s /usr/sbin/nologin]

  * By default, pfcapd logs messages to file pfcapd.log in the PFUSER home
    directory.  If that doesn't suit you, then you can change the PFLOGFILE
    variable to the full path (must begin with '/') of the desired log
    file. You must ensure that PFUSER has write access to this file.

  * By default, pfcapd logs are rotated each time the collector starts.  These
    logs are saved with numeric extensions from .1 up to the value of
    MAXGFLOGS each time pfcapd is started, from newest to oldest log file,
    respectively.  Set MAXGFLOGS=0 to disable log rotation, in which case the
    log file will be overwritten each time pfcapd is started.

  * Uncomment the following line when debug messages are required to diagnose
    a problem.  Debug logging only works when pfcapd is built with the
    --enable-debug configuration option.  See the documentation for the
    debugLoglevel variable in the [Globals] section in pfcapd.conf for
    information about what debug messages are logged.

      #PFLOGMODS=debug

Make /etc/init.d/pfcapd executable.

  chmod +x /etc/init.d/pfcapd

Configure the pfcapd script to automatically run at boot time.

  /sbin/chkconfig --add pfcapd

Edit /usr/local/etc/pfcapd.conf to configure the pfcapd runtime parameters,
which are documented as comments in the file.

  * Set exporters in the [Global] section to the number of exporter sections
    in the file (number of exporters/routers pfcapd will collect flows from).

  * Set threads to the number of threads you want to process flow datagrams,
    where the allowed minimum is the exporters value, but the recommended
    value is 3*exporters.

  * Set listen to the interface address on which pfcapd listens (0.0.0.0 means
    listen on all interfaces).

  * Set the port number on which to listen, to which the exporters send
    their datagrams.

  * Set the dbConnect string to the database name to which the flow records
    are written.

  * Set the debugLoglevel as documented in the VARIABLES and NOTES comments.

  * The default value of 4 for the aggregation rate variables, tcpSessAggHz,
    srcTraffAggHz, and dstTraffAggHz, is good for most systems.

  * If the exporter clocks are not NTP-synchronized, you may want to
    set 'normalizeFlowTimes = yes' to normalize flow timestamps based on the
    pfcapd system clock (assuming the system time itself is NTP-synchronized).

  * Configure [Exporter*] sections, one for each exporter/router.



+-----------------+
| Configure Linux |
+-----------------+

Add user accounts for the collector and web services
----------------------------------------------------

These usernames must match those specified at configure time via the
--with-pfuser and --with-w3user.  The commands below reflect the defaults.

  useradd -c 'Pfcapd User' -s /sbin/nologin pfcapd
  useradd -c 'Psyche User' -s /sbin/nologin psyche


Configure Linux kernel memory options
-------------------------------------

Edit /etc/sysctl.conf to add the following, for which you should have at least
2GB RAM (4GB recommended).

  # maximum shared memory segment size
  kernel.shmmax = 536870912
  # max socket receive buffer size
  net.core.rmem_max = 33554432
  # default socket receive buffer size
  net.core.rmem_default = 16777216

Activate the new /etc/sysctl.conf settings.

  /sbin/sysctl -p


+----------------------+
| Configure PostgreSQL |
+----------------------+

Configure postgresql.conf tuning options
----------------------------------------

If this is the first time PostgreSQL is being run, first execute the 
following commands:
  sudo /sbin/service postgresql initdb
  sudo /sbin/service postgresql start
  
To modify the configuration settings, edit the postgresql.conf file (at
~postgres/data/postgresql.conf) to contain the following values:

  max_fsm_pages = 400000
  default_statistics_target = 100
  shared_buffers = 480MB
  temp_buffers = 512MB
  max_prepared_transactions = 256
  work_mem = 256MB
  maintenance_work_mem = 1024MB
  effective_cache_size = 1024MB

Following these configuration changes, restart the PostgreSQL service:
  sudo /sbin/service postgresql restart


Initialize the psyche database
------------------------------

Execute the psyche database initialization sql as the PostgreSQL super user.

  sudo -u postgres psql
  postgres=# \i /usr/local/share/psyche/init_db.sql
  postgres=# \q

You can delete the database, if necessary, by executing
/usr/local/share/psyche/drop_db.sql.

+----------------------------+
| Configure Psyche Front-End |
+----------------------------+

There are a few steps needed to get the front-end configured prior to use.

NOTE: the following instructions reference your Project Directory, which
is determined at install time. By default, PROJECT_DIR = /usr/local/var/psyche

Set up DB connection information
--------------------------------

DB connection information is set in the PROJECT_DIR/prod.cfg file and 
PROJECT_DIR/psychefe/model.py file. If you changed default installation 
settings, the connect strings in these files must be updated now. The 
following lines are the relevant ones from these two files:

prod.cfg:  psyche.dburi="dbname='psyche' user='psyche' password='' host='localhost'"
model.py:  flow_metadata = MetaData('postgres://psyche:psyche@localhost/psyche')

Identity management is handled in a sqlite db; if you want to specify a
different DBMS for identity management, change the following line within
prod.cfg to an appropriate connection string for your backend (there are 
examples in prod.cfg).

	sqlalchemy.dburi="sqlite:///devdata.sqlite"


Create your project database
----------------------------

NOTE: for the following tg-admin command to succeed, your pg_hba.conf file
may need to be updated to enable the appropriate client authentication. 
PostgreSQL must then be restarted for your changes to take effect.

You have to create the database/schema for managing your project; do this by
changing to the PROJECT_DIR and entering

	tg-admin --config=prod.cfg sql create


Create users and groups
-----------------------

Once the DB is created, execute the following command from within the PROJECT_DIR
to open a Turbogears shell for your project:

	tg-admin --config=prod.cfg shell

For those unfamiliar with Turbogears, this simply drops you into a Python shell
with access to your model (DB backend)

Create a user for the analyst and admin groups. The psyche front-end is currently
designed to only allow users belonging to these groups access to the site. If you want
to add/change a group, you must change the appropriate lines in the controllers.py
file. This requires working knowledge of Turbogears. There are future plans for an
admin only page, but currently users in both the admin & analyst groups have access
to all of the same pages.

Enter the following lines into the python shell; remember to change the username and
password information:

u = User(user_name=u'user-username', email_address=u'youremail@yourdomain', display_name=u'Display Name', password=u'password')
g = Group(group_name=u'analyst', display_name=u'Analysts')
g.users.append(u)
u = User(user_name=u'admin-username', email_address=u'youremail@youradmindomain', display_name=u'Display Name', password=u'password')
g = Group(group_name=u'admin', display_name=u'Administrators')
g.users.append(u)

Disconnect from the python shell (CTRL-D) and choose to commit your changes. By selecting
'yes' to commit your changes, you will be writing your new users/groups to your project
database.

That's it -- at this point, the front-end is set up. You're ready to get started. For
information on starting/stopping the front-end, see the README file in the PROJECT_DIR.
