blob: 834aa3dc411fcfc3343b2bbec07d26222d336aec [file] [log] [blame]
Shawn O. Pearcebad75612009-05-10 16:15:06 -07001Gerrit2 - Installation Guide
2============================
Shawn O. Pearced2b73db2009-01-09 11:55:47 -08003
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -08004You need a SQL database to house the Gerrit2 metadata. Currently
Shawn O. Pearce86816ee2009-05-13 17:37:20 -07005H2, MySQL and PostgreSQL are the only supported databases.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -08006
7Important Links
8---------------
9
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080010PostgreSQL:
11
12* http://www.postgresql.org/docs/[Documentation]
Shawn O. Pearce86816ee2009-05-13 17:37:20 -070013* link:http://jdbc.postgresql.org/download.html[JDBC Driver]
14
15MySQL:
16
17* http://dev.mysql.com/doc/[Documentation]
18* http://dev.mysql.com/downloads/connector/j/5.0.html[JDBC Driver]
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080019
Shawn O. Pearce933fcd92009-02-06 14:38:11 -080020Optional Libraries:
21
Shawn O. Pearce933fcd92009-02-06 14:38:11 -080022* link:http://sourceforge.net/project/showfiles.php?group_id=25357[c3p0 JDBC Driver]
23* link:http://www.bouncycastle.org/java.html[Bouncy Castle Crypto API]
24* link:http://java.sun.com/products/javamail/downloads/index.html[JavaMail]
25
Shawn O. Pearce0b91a632009-02-06 12:53:59 -080026
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080027Downloading Gerrit
28------------------
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080029
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080030Current and past binary releases of Gerrit can be obtained from
31the downloads page at the project site:
32
33* http://code.google.com/p/gerrit/downloads/list[Gerrit Downloads]
34
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -080035Download any current `*.war` package.
36
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080037
38Building Gerrit From Source
39---------------------------
40
41Alternatively, you can build the application distribution using
42Maven from a source download obtained directly from Git:
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080043
44====
Shawn O. Pearce1d394a52009-02-25 09:05:52 -080045 git clone git://android.git.kernel.org/tools/gerrit.git
46 cd gerrit
Shawn O. Pearce8d2f1842009-05-13 07:59:04 -070047 mvn clean package
Shawn O. Pearce263786e2009-02-02 15:49:26 -080048 cp target/gerrit-*.war ...YOUR.DEST.../gerrit.war
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080049====
50
51The first build may take a while as dependencies are searched
52for and downloaded from Maven distribution repositories.
53
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080054Apache Maven:
55
56* http://maven.apache.org/download.html[Download]
57* http://maven.apache.org/run-maven/index.html[Running Maven]
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080058
Shawn O. Pearceb951af12009-02-06 12:32:18 -080059
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080060Setting up the Database
61-----------------------
62
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080063PostgreSQL
64~~~~~~~~~~
65
66Create a Gerrit specific user as a normal user (no superuser access)
67and assign it an encrypted password:
68
69====
70 createuser -A -D -P -E gerrit2
71====
72
73Create the database to store the Gerrit metadata, and set the user
74you just created as the owner of that database:
75
76====
77 createdb -E UTF-8 -O gerrit2 reviewdb
78====
79
Shawn O. Pearce86816ee2009-05-13 17:37:20 -070080MySQL
81~~~~~
82
83Create a Gerrit specific user within the database and assign it a
84password, create a database, and give the user full rights:
85
86====
87 CREATE USER gerrit2 IDENTIFIED BY PASSWORD 'secret';
88 CREATE DATABASE reviewdb;
89 GRANT ALL ON reviewdb.* TO 'gerrit2'@'localhost';
90====
91
Shawn O. Pearce0b91a632009-02-06 12:53:59 -080092
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080093Initialize the Schema
94---------------------
95
96Create the Gerrit 2 Tables
97~~~~~~~~~~~~~~~~~~~~~~~~~~
98
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -080099Either run CreateSchema from the command line:
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800100
101====
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -0800102 java -jar gerrit.war --cat extra/GerritServer.properties_example >GerritServer.properties
103 edit GerritServer.properties
104
105 java -jar gerrit.war CreateSchema
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800106====
107
108Or, run the application once in a container to force it to initialize
109the database schema before accessing it. (See below for deployment
110setup documentation.) If you use this approach, it is recommended
111that you stop the application before continuing with the setup.
112
113Add Indexes
114~~~~~~~~~~~
115
116A script should be run to create the query indexes, so Gerrit
117can avoid table scans when looking up information. Run the
Shawn O. Pearce86816ee2009-05-13 17:37:20 -0700118index script through your database's query tool.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800119
Shawn O. Pearce86816ee2009-05-13 17:37:20 -0700120PostgreSQL:
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800121
122====
Shawn O. Pearce86816ee2009-05-13 17:37:20 -0700123 java -jar gerrit.war --cat sql/index_postgres.sql | psql reviewdb
124====
125
126MySQL:
127
128====
129 java -jar gerrit.war --cat sql/index_generic.sql | mysql reviewdb
130 java -jar gerrit.war --cat sql/mysql_nextval.sql | mysql reviewdb
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800131====
132
133Configure site_path
134~~~~~~~~~~~~~~~~~~~
135
136This directory holds server-specific configuration files and
137assets used to customize the deployment. Gerrit needs read
138access (but not write access) to the directory. The path
139is stored in `system_config.site_path`, so you will need to
140update the database with this value.
141
142====
143 mkdir /home/gerrit/cfg
144 cd /home/gerrit/cfg
145
Shawn O. Pearce86816ee2009-05-13 17:37:20 -0700146 UPDATE system_config SET site_path='/home/gerrit/cfg'
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800147====
148
Shawn O. Pearceaf12e8e2009-02-06 13:49:43 -0800149SSH Host Keys
150~~~~~~~~~~~~~
151
152If you choose to install the Bouncy Castle Crypto APIs (see below)
153you must create RSA and DSA host keys for the daemon:
154====
155 ssh-keygen -t rsa -P '' -f ssh_host_rsa_key
156 ssh-keygen -t dsa -P '' -f ssh_host_dsa_key
157====
158
159These keys are used as the host keys for the internal SSH daemon
160run by Gerrit. You may wish to backup these key files to ensure
161they can be restored in the event of a disaster.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800162
163The private key files (`ssh_host_rsa_key`, `ssh_host_dsa_key`) should
164be readable *only* by the account that is executing Gerrit2's web
165application container. It is a security risk to make these files
166readable by anyone else.
167
Shawn O. Pearceaf12e8e2009-02-06 13:49:43 -0800168If you don't install Bouncy Castle, Gerrit will automatically
169create a host key and save a copy to `'site_path'/ssh_host_key`
170during first startup. For this to work correctly, Gerrit will
171require write access to the directory.
172
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800173Create Git Repository Base
174~~~~~~~~~~~~~~~~~~~~~~~~~~
175
176This directory holds the Git repositories that Gerrit knows about
177and can service. Gerrit needs write access to this directory and
178any Git repository stored within it.
179
180====
181 mkdir /srv/git
Shawn O. Pearce86816ee2009-05-13 17:37:20 -0700182 UPDATE system_config SET git_base_path='/srv/git'
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800183====
184
185You may wish to consider also exporting this directory over the
186anonymous git:// protocol, as it is more efficient than Gerrit's
187internal ssh daemon. See the `git-daemon` documentation for details
188on how to configure this if anonymous access is desired.
189
190* http://www.kernel.org/pub/software/scm/git/docs/git-daemon.html[man git-daemon]
191
192Futher Configuration
193~~~~~~~~~~~~~~~~~~~~
194
195Gerrit2 supports some site-specific customizations. These are
196optional and are not required to run a server, but may be desired.
197
Shawn O. Pearcef384b442009-01-10 16:20:56 -0800198* link:config-sso.html[Single Sign-On Systems]
Shawn O. Pearce5a14d662009-01-23 16:39:51 -0800199* link:config-replication.html[Git Replication/Mirroring]
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800200* link:config-headerfooter.html[Site Header/Footer]
201* link:config-gitweb.html[Gitweb Integration]
Shawn O. Pearce7b405712009-05-08 18:27:53 -0700202* link:config-gerrit.html[Other System Settings]
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800203
Shawn O. Pearce0b91a632009-02-06 12:53:59 -0800204
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800205Application Deployment
206-----------------------
207
208Jetty
209~~~~~
210
Shawn O. Pearce0004f982009-02-20 18:44:51 -0800211[NOTE]
212The instructions listed here were tested with Jetty 6.1.14 or later.
213These are known to not work on much older versions, such as 6.1.3.
214
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800215These directions will configure Gerrit as the default web
216application, allowing URLs like `http://example.com/4543` to
217jump directly to change 4543.
218
219Download and unzip a release version of Jetty. From here on we
220call the unpacked directory `$JETTY_HOME`.
221
Shawn O. Pearceaf12e8e2009-02-06 13:49:43 -0800222* link:http://dist.codehaus.org/jetty/[Jetty Downloads]
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800223
Shawn O. Pearce933fcd92009-02-06 14:38:11 -0800224Install the required JDBC drivers by copying them into the
225`'$JETTY_HOME'/lib/plus` directory. Drivers can be obtained from
226their source projects:
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -0800227
Shawn O. Pearce933fcd92009-02-06 14:38:11 -0800228* link:http://jdbc.postgresql.org/download.html[PostgreSQL JDBC Driver]
229* link:http://sourceforge.net/project/showfiles.php?group_id=25357[c3p0 JDBC Driver]
230
231Consider installing Bouncy Castle Cypto APIs into the
232`'$JETTY_HOME'/lib/plus` directory. Some of the Bouncy Castle
Shawn O. Pearceaf12e8e2009-02-06 13:49:43 -0800233implementations are faster than then ones that come in the JRE,
Shawn O. Pearce933fcd92009-02-06 14:38:11 -0800234and they may support additional encryption algorithms:
Shawn O. Pearceaf12e8e2009-02-06 13:49:43 -0800235
Shawn O. Pearce933fcd92009-02-06 14:38:11 -0800236* link:http://www.bouncycastle.org/java.html[Bouncy Castle Crypto API]
Shawn O. Pearceaf12e8e2009-02-06 13:49:43 -0800237
Shawn O. Pearcece0cb8b2009-05-08 16:22:59 -0700238Jetty comes with JavaMail, so there is no need to install it.
239
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800240Copy Gerrit into the deployment:
241====
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -0800242 java -jar gerrit.war --cat extra/jetty_gerrit.xml >$JETTY_HOME/contexts/gerrit.xml
243 cp gerrit.war $JETTY_HOME/webapps/gerrit.war
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800244
245 rm -f $JETTY_HOME/context/test.xml
246====
247
Shawn O. Pearcece0cb8b2009-05-08 16:22:59 -0700248Edit `'$JETTY_HOME'/contexts/gerrit.xml` to correctly configure
249the database and outgoing SMTP connections, especially the user
250and password fields.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800251
Shawn O. Pearceab583db2009-03-03 17:28:04 -0800252If OpenID authentication is being used, you may need to increase
Shawn O. Pearcece0cb8b2009-05-08 16:22:59 -0700253the header buffer size parameter, due to very long header lines.
254Add the following to `'$JETTY_HOME'/etc/jetty.xml` under
Shawn O. Pearceab583db2009-03-03 17:28:04 -0800255`org.mortbay.jetty.nio.SelectChannelConnector`:
256
257====
258 <Set name="headerBufferSize">16384</Set>
259====
260
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800261To start automatically when the system boots, consider a start
262script such as the following in `/etc/init.d/gerrit2-jetty`
263
264====
265 #!/bin/sh
266
267 export JETTY_HOST=127.0.0.1
268 export JETTY_PORT=8081
269 export JETTY_USER=gerrit2
270 export JETTY_PID=/var/run/jetty$JETTY_PORT.pid
271 export JETTY_HOME=/home/$JETTY_USER/jetty
272 export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.07/jre
273
274 JAVA_OPTIONS=""
275 JAVA_OPTIONS="$JAVA_OPTIONS -Djetty.host=$JETTY_HOST"
276 export JAVA_OPTIONS
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800277
Shawn O. Pearceb546c9b2009-02-24 13:12:39 -0800278 C="jetty-logging jetty"
279 [ -f "$JETTY_HOME/etc/jetty_sslproxy.xml" ] && C="$C jetty_sslproxy"
280
281 exec $JETTY_HOME/bin/jetty.sh "$@" $C
282====
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800283
284[TIP]
285Under Jetty, restarting the web application (e.g. after modifying
Shawn O. Pearcece0cb8b2009-05-08 16:22:59 -0700286`system_config`) is as simple as touching the context config file:
287`'$JETTY_HOME'/contexts/gerrit.xml`
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800288
Shawn O. Pearceb546c9b2009-02-24 13:12:39 -0800289Port 80
290^^^^^^^
291
292To deploy on port 80, you should configure Jetty to listen on another
293port, such as 127.0.0.1:8081 (like the start script above does)
294and then follow the <<apache2,reverse proxy>> section below.
295
296Port 443 (HTTPS / SSL)
297^^^^^^^^^^^^^^^^^^^^^^
298
299To deploy on port 443 with SSL enabled, unpack the SSL proxy handling
Shawn O. Pearcece0cb8b2009-05-08 16:22:59 -0700300rule into `'$JETTY_HOME'/etc`:
Shawn O. Pearceb546c9b2009-02-24 13:12:39 -0800301====
302 java -jar gerrit.war --cat extra/jetty_sslproxy.xml >$JETTY_HOME/etc/jetty_sslproxy.xml
303====
304
305Create a start script like the one above, configuring Jetty to
306listen on another port, such as 127.0.0.1:8081.
307
308Set `canonical_url` in `system_config` to an `https://` style URL
309for your application, so that non-SSL connections are automatically
310upgraded to SSL by issuing a redirect. Gerrit does not currently
311support a dual http/https usage on the same site as it doesn't
312know when to upgrade a non-secure connection to a secure one if
313data needs to be protected.
314
315Follow the <<apache2,reverse proxy>> section below to setup an
316Apache2 server to handle SSL for Jetty.
317
318
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800319Other Servlet Containers
320~~~~~~~~~~~~~~~~~~~~~~~~
321
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -0800322Deploy the `gerrit-*.war` file to your application server as
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800323`gerrit.war`.
324
325Configure the JNDI DataSource `jdbc/ReviewDb` for the Gerrit web
326application context to point to the database you just created.
327Don't forget to ensure your JNDI configuration can load the
328necessary JDBC drivers.
329
Shawn O. Pearce933fcd92009-02-06 14:38:11 -0800330('Optional') Add Bouncy Castle Crypto API to the web application's
331classpath. Usually its best to load this library from the servlet
332container's extensions directory, but gerrit.war could also be
Shawn O. Pearcece0cb8b2009-05-08 16:22:59 -0700333manually repacked to include it.
Shawn O. Pearce933fcd92009-02-06 14:38:11 -0800334
Shawn O. Pearce92a19d22009-01-13 13:27:59 -0800335('Optional') Configure the JNDI name `mail/Outgoing` for the web
336application context to be a factory for a `javax.mail.Session`,
337with the connection information necessary to send outgoing emails.
338You may need to download and install the Java Mail JARs in your
339container's classpath. If this is not configured, Gerrit will
340function, but will not be able to send email.
341
Shawn O. Pearceb546c9b2009-02-24 13:12:39 -0800342
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800343[[apache2]]
344Apache2 Reverse Proxy
345~~~~~~~~~~~~~~~~~~~~~
346
347Enable the necessary Apache2 modules:
348
349====
350 a2enmod proxy_http
351 a2enmod disk_cache ; # optional, but helps performance
Shawn O. Pearceb546c9b2009-02-24 13:12:39 -0800352
353 a2enmod ssl ; # optional, needed for HTTPS / SSL
354 a2enmod headers ; # optional, needed for HTTPS / SSL
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800355====
356
357then setup a VirtualHost to proxy to Gerrit's servlet container,
358setting the `ProxyPass` line to use the port number you configured
359in your servlet container's configuration:
360
361=======================================
362 <VirtualHost *>
363 ServerName review.example.com
364 #
365 ProxyRequests Off
366 ProxyVia Off
367 ProxyPreserveHost On
368 #
369 <Proxy *>
370 Order deny,allow
371 Allow from all
372 </Proxy>
373 ProxyPass / http://127.0.0.1:8081/
374 #
375 <IfModule mod_disk_cache.c>
376 CacheEnable disk /
377 CacheIgnoreHeaders Set-Cookie
378 </IfModule>
379 </VirtualHost>
380=======================================
381
Shawn O. Pearceb546c9b2009-02-24 13:12:39 -0800382if you are using SSL with a Jetty container:
383
384====
385 <VirtualHost *:443>
386 ServerName review.example.com
387 #
388 SSLEngine on
389 SSLCertificateFile conf/server.crt
390 SSLCertificateKeyFile conf/server.key
391 #
392 ProxyRequests Off
393 ProxyVia Off
394 ProxyPreserveHost On
395 ProxyPass / http://127.0.0.1:8081/
396 RequestHeader set X-Forwarded-Scheme https
397 #
398 <IfModule mod_disk_cache.c>
399 CacheEnable disk /
400 CacheIgnoreHeaders Set-Cookie
401 </IfModule>
402 </VirtualHost>
403====
404
405See the Apache `mod_ssl` documentation for more details on how to
406configure SSL within the server, like controlling how strong of an
407encryption algorithm is required.
408
409For Gerrit, the only difference between plain HTTP and HTTPS is
410adding the "`RequestHeader set X-Forwarded-Scheme https`" line
411within the SSL enabled virtual host.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800412
413
414Administrator Setup
415-------------------
416
417Login to Gerrit through the web interface, so that a user account
418is initialized for you.
419
420Add your newly created account to the "Administrators" group,
421so that you can manage the site through the web interface:
422
423====
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800424 INSERT INTO account_group_members
425 (account_id, group_id)
426 VALUES (
427 (SELECT account_id FROM accounts
428 WHERE preferred_email='you@example.com'),
429 (SELECT admin_group_id FROM system_config)
430 );
431====
432
Shawn O. Pearce9ab69422009-02-06 14:49:44 -0800433You can also get your `account_id` from the web UI, under Settings,
434if you don't want to use a SELECT subquery above, or your email
435address wasn't prefilled automatically.
436
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800437Group memberships are cached, so you need to either restart Gerrit,
438or try flushing the caches over SSH.
439
440Since SSH cache flushing requires being in the "Administrators"
441group you may run into a chicken-and-egg problem, where you cannot
442flush the cache to make yourself an administrator because you are
443not yet an administrator. Therefore, restarting the application
444is the recommended bootstrap technique.
445
446To flush the server's caches over SSH, ensure you have an SSH key
447(you can add one through the web UI under Settings, SSH Keys),
448and then run:
449
450====
451 ssh -p 29418 you@example.com gerrit flush-caches
452====
453
Shawn O. Pearce0b91a632009-02-06 12:53:59 -0800454
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800455Project Setup
456-------------
457
458See link:project-setup.html[Project Setup] for further details on
459how to register a project with Gerrit.