=== modified file 'src/docbkx/en/dhis2_implementation_guide_installation.xml' --- src/docbkx/en/dhis2_implementation_guide_installation.xml 2012-02-29 13:06:05 +0000 +++ src/docbkx/en/dhis2_implementation_guide_installation.xml 2012-03-13 10:46:46 +0000 @@ -11,12 +11,11 @@ This section describes how to set up a server instance of DHIS 2 on Ubuntu 10.04 64 bit with PostgreSQL as database system and Tomcat as Servlet container. The term invoke refers to executing a given command in a terminal. You can find the terminal in Applications - Accessories - Terminal. For a national server the recommended configuration is a quad-core 2 Ghz processor or higher and 12 Gb RAM or higher. Note that a 64 bit operating system is required for utilizing more than 4 Gb of RAM, the Ubuntu 10.04 64 bit edition is thus recommended. For this guide we assume that 4 Gb RAM is allocated for PostgreSQL and 7 GB RAM is allocated for Tomcat. If you are running a different configuration please adjust the suggested values accordingly. The steps related to performance tuning are not compulsory and can be done at a later stage. Create new user (optional) - You might want to create a dedicated user for running DHIS - it is not recommended to run as the root user. Create a new user called dhis by invoking useradd -d /home/dhis -m dhis -s /bin/bash Then make the user able to perform operations temporarily as root user by invoking adduser dhis admin Then invoke passwd dhis to set the password for your account.MM + You might want to create a dedicated user for running DHIS - it is not recommended to run as the root user. Create a new user called dhis by invoking useradd -d /home/dhis -m dhis -s /bin/bash Then make the user able to perform operations temporarily as root user by invoking adduser dhis admin Then invoke passwd dhis to set the password for your account. Make sure you set a strong password with at least 15 random characters. Install Java - Enable Partner repositories by opening /etc/apt/sources.listand adding the line deb http://archive.canonical.com/ubuntu maverick partner at the end of the file. Then invoke sudo apt-get -f install to update the package list. - Install Java by invoking sudo apt-get install sun-java6-jdk + Install Java by invoking sudo apt-get install openjdk-7-jdk Install PostgreSQL - Install PostgreSQL by invoking sudo apt-get install postgresql-8.4 + Install PostgreSQL by invoking sudo apt-get install postgresql-9.1 Set the password for the postgres Unix user by invoking sudo passwd postgres and following the instructions. Switch to the postgres user by invoking su postgres and entering the password when prompted. Log into psql by invoking psql Create a user called dhis by invoking create user dhis with password '<dhis>' Replace the password <dhis> with something secure. Create a database by invoking create database dhis2 with owner dhis encoding 'utf' Exit psql by invoking \q Return to your session by invoking exit You now have a PostgreSQL user called dhis and a database called dhis2. Do basic performance tuning by increasing the operating system kernel shared memory by opening file /etc/sysctl.conf and adding the line kernel.shmmax = 1073741824 at the end of it. Make the change take effect by invoking sysctl -p Then open file /etc/postgresql/8.4/main/postgresql.conf and set the following properties: @@ -37,66 +36,106 @@ Restart PostgreSQL by invoking sudo /etc/init.d/postgresql restart Set the database configuration The database connection information is provided to DHIS 2 through a configuration file called hibernate.properties. Create this file and save it in a convenient location. A file corresponding to the above setup has these properties: - hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect hibernate.connection.driver_class = org.postgresql.Driver hibernate.connection.url = jdbc:postgresql:dhis2 hibernate.connection.username = dhis hibernate.connection.password = dhis hibernate.hbm2ddl.auto = update - A common mistake is to have a white-space after the last property value - make sure there is no white-space at the end of the line. + hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect +hibernate.connection.driver_class = org.postgresql.Driver +hibernate.connection.url = jdbc:postgresql:dhis2 +hibernate.connection.username = dhis +hibernate.connection.password = dhis +hibernate.hbm2ddl.auto = update + A common mistake is to have a white-space after the last property value - make sure there is no white-space at the end of any line. Install Tomcat Download the Tomcat binary distribution from http://tomcat.apache.org/download-70.cgi A useful tool for downloading files from the web is wget. Extract to a convenient location. This guide assumes that you have navigated to the root directory of the extracted archive. Clear the pre-installed web applications by invoking rm -rf webapps/* Download the latest DHIS 2 WAR file from http://dhis2.org/download and move it to the webapps directory. Open file bin/setclasspath.sh and add the lines below. The first will set the location of your Java Runtime Environment, the second will dedicate memory to Tomcat and the third will set the location for where DHIS 2 will search for the hibernate.properties configuration file, note that you should adjust this to your environment: - JAVA_HOME='/usr/lib/jvm/java-6-sun' | JAVA_OPTS='-Xmx6000m -XX:MaxPermSize=1000m' | DHIS2_HOME='/home/dhis/config' - To do basic performance tuning you can install the native APR library by invoking sudo apt-get install libtcnative-1 Then open file bin/setclasspath.sh and add this line at the end of the file: LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH + JAVA_HOME='/usr/lib/jvm/java-7-openjdk' +JAVA_OPTS='-Xmx6000m -XX:MaxPermSize=1000m' +DHIS2_HOME='/home/dhis/config' + To do basic performance tuning (optional) you can install the native APR library by invoking sudo apt-get install libtcnative-1 Then open file bin/setclasspath.sh and add this line at the end of the file: LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH If you need to change the port of which Tomcat listens for requests you can open the Tomcat configuration file /conf/server.xml, locate the <Connector> element which is not commented out and change the port attribute value to the desired port number. To monitor the behavior of Tomcat the log is the primary source of information. The log can be easily viewed with the command tail -f logs/catalina.out Run DHIS 2 - Make the startup script executable by invoking chmod 755 bin/* DHIS 2 can now be started by invoking bin/startup.sh The log can be monitored by invoking tail -f logs/catalina.out DHIS 2 can be stopped by invoking bin/shutdown.sh + Make the startup script executable by invoking chmod 755 bin/* DHIS 2 can now be started by invoking bin/startup.sh The log can be monitored by invoking tail -f logs/catalina.out DHIS 2 can be stopped by invoking bin/shutdown.sh Assuming that the WAR file is called dhis.war, you can now access your DHIS instance at http://localhost:8080/dhis
- nginx - - - Reverse Proxy - - - - Encrypted connections with SSL - After tomcat is set up behind the reverse proxy, it is time to configure nginx to use SSL. Using SSL for serving DHIS 2 will provide better security since it encrypts the connection to the server. - To configure nginx to use SSL you will need a proper SSL certificate from an SSL provider. The cost of a certificate varies a lot depending on encryption strength. An affordable certificate from https://www.rapidsslonline.com should serve most purposes. - When you have your certificate files (.pem and .key) you will need to place them in a location which is reachable by nginx. A good location for this can be the same directory as where your nginx.conf file is located. - Below is an nginx server block where the files are named server.pem and server.key and using a reverse proxy from port 443 (HTTPS) passed on to a DHIS 2 instance running on port 8080. - - Please note that this requires that you enter your SSL password every time you start your server. You can have SSL certificates without a password, but this is not recommended. + Reverse proxy (optional) + A reverse proxy is a proxy server that acts on behalf of a server. Using a reverse proxy in combination with a servlet container is optional but has many advantages: + + + Requests can be mapped and passed on to multiple servlet containers - this improves flexibility and makes it easier to run multiple instances of DHIS on the same server. It also makes it possible to change the internal server setup without affecting clients. + + + The DHIS application can be run as a non-root user on a port different than 80 which reduces the consequences of session hijacking. + + + The reverse proxy can act as a single SSL server and be configured to inspect requests for malicious content, log requests and responses and provide non-sensitive error messages which will improve security. + + + nginx + We recommend using nginx (http://wiki.nginx.org) as reverse proxy due to its low memory footprint and ease of use. To get the latest version we recommend installing from source: + sudo apt-get install make gcc libpcre3 libpcre3-dev zlibc zlib1g zlib1g-dev libssl-dev openssl + wget http://nginx.org/download/nginx-1.0.13.tar.gz (check for latest!) + tar xzvf nginx-1.0.13.tar.gz + cd nginx-1.0.13 + ./configure --with-http_ssl_module + make + sudo make install + nginx can now be started and stopped with the following commands: + sudo /usr/local/nginx/sbin/nginx + sudo /usr/local/nginx/sbin/nginx -s stop + Now that we have installed nginx we will now continue to configure regular proxying of requests to our Tomcat instance, which we assume runs at http://localhost:8080/dhis. To configure nginx you can open the configuration file by invoking + sudo nano /usr/local/nginx/conf/nginx.conf + nginx configuration is built around a hierarchy of blocks representing http, server and location, where each block inherit settings from parent blocks. To configure nginx to proxy pass (redirect) requests from port 80 (which is the port nginx will listen on by default) to our Tomcat instance include the following configuration in nginx.conf: + + Now that the reverse proxy is set up we can improve security by making Tomcat only listen for local connections. In /conf/server.xml you can add an address attribute with the value localhost to the Connetor element for HTTP 1.1 like this: + <Connector address="localhost" protocol="HTTP/1.1" ... > + Encrypted connections with SSL + In order to improve security it is recommended to configure the server running DHIS to communicate with clients over an encrypted connection and to identify itself to clients using a trusted certificate. This can be achieved through SSL which is an cryptographic communication protocol running on top of TCP/IP. + To configure nginx to use SSL you will need a proper SSL certificate from an SSL provider. The cost of a certificate varies a lot depending on encryption strength. An affordable certificate from https://www.rapidsslonline.com should serve most purposes. + When you have your certificate files (.pem and .key) you will need to place them in a location which is reachable by nginx. A good location for this can be the same directory as where your nginx.conf file is located. + Below is an nginx server block where the certificate files are named server.pem and server.key. Since SSL connections usually occur on port 443 (HTTPS) we pass requests on that port (443) on to the DHIS instance running on http://localhost:8080/dhis. The first server block will rewrite all requests connecting to port 80 and force the use of HTTPS/SSL. This is also necessary because DHIS is using a lot of redirects internally which must be passed on to use HTTPS. + $request_uri? permanent; +} + +# SSL server block + +server { + listen 443; + server_name localhost; + + ssl on; + ssl_certificate server.pem; + ssl_certificate_key server.key; + + ssl_session_timeout 5m; + + ssl_protocols SSLv2 SSLv3 TLSv1; + ssl_ciphers HIGH:!aNULL:!MD5; + ssl_prefer_server_ciphers on; + + location / { + proxy_pass http://localhost:8080/dhis; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } +}]]>
DHIS 2 Live setup @@ -110,6 +149,6 @@ Backup should be central in a disaster recovery plan. Even though such a plan should cover additional subjects, the database is the key component to consider since this is where all data used in the DHIS 2 application is stored. Most other parts of the IT infrastructure surrounding the application can be restored based on standard components. There are of course many ways to set up backup; however the following describes a setup where the database is copied into a dump file and saved on the file system. This can be considered a full backup. The backup is done with a cron job, which is a time-based scheduler in Unix/Linux operating systems. You can download both files from http://dhis2.com/download/pg_backup.zip - The cron job is set up with two files. The first is a script which performs the actual task of backup up the database. It uses a PostgreSQL program called pg_dump for creating the database copy. The second is a crontab file which runs the backup script every day at 23:00. Note that this script backs up the database file to the local disk. It is strongly recommended to store a copy of the backup at a location outside the server where the application is hosted. This can be achieved with the scp tool. + The cron job is set up with two files. The first is a script which performs the actual task of backup up the database. It uses a PostgreSQL program called pg_dump for creating the database copy. The second is a crontab file which runs the backup script every day at 23:00. Note that this script backs up the database file to the local disk. It is strongly recommended to store a copy of the backup at a location outside the server where the application is hosted. This can be achieved with the scp tool. Make sure that you have set the system date correctly on your server.