blob: 1e9d68c314aea4b121089a9debdbdef6f9b4b1eb [file] [log] [blame]
Shawn O. Pearced2b73db2009-01-09 11:55:47 -08001Gerrit2 - Installation
2======================
3
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -08004You need a SQL database to house the Gerrit2 metadata. Currently
5PostgreSQL is the only supported database.
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]
13
Shawn O. Pearce0b91a632009-02-06 12:53:59 -080014
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080015Downloading Gerrit
16------------------
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080017
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080018Current and past binary releases of Gerrit can be obtained from
19the downloads page at the project site:
20
21* http://code.google.com/p/gerrit/downloads/list[Gerrit Downloads]
22
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -080023Download any current `*.war` package.
24
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080025
26Building Gerrit From Source
27---------------------------
28
29Alternatively, you can build the application distribution using
30Maven from a source download obtained directly from Git:
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080031
32====
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080033 mkdir gerrit2
34 cd gerrit2
35 repo init -u git://android.git.kernel.org/tools/manifest.git
36
37 (cd jgit/jgit-maven/jgit && mvn install)
Shawn O. Pearceb951af12009-02-06 12:32:18 -080038 (cd sshd && mvn install)
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080039
Shawn O. Pearce263786e2009-02-02 15:49:26 -080040 mvn clean package
41 cp target/gerrit-*.war ...YOUR.DEST.../gerrit.war
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080042====
43
44The first build may take a while as dependencies are searched
45for and downloaded from Maven distribution repositories.
46
Shawn O. Pearceb951af12009-02-06 12:32:18 -080047Unfortunately you need to install snapshots of both JGit and
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -080048SSHD to your local Maven repository (typically under `~/.m2`).
49These core dependencies are still under active development and have
50not made final releases yet.
Shawn O. Pearce31af1ff2009-01-26 12:04:41 -080051
52Apache Maven:
53
54* http://maven.apache.org/download.html[Download]
55* http://maven.apache.org/run-maven/index.html[Running Maven]
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080056
Shawn O. Pearceb951af12009-02-06 12:32:18 -080057Apache SSHD:
58
59* http://mina.apache.org/sshd/[Apache SSHD]
60
61
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080062Setting up the Database
63-----------------------
64
65Currently PostgreSQL is the only supported database. H2 may also
66work, but hasn't been tested in a while. The primary concern is
67having support for the database in the gworm project.
68
69PostgreSQL
70~~~~~~~~~~
71
72Create a Gerrit specific user as a normal user (no superuser access)
73and assign it an encrypted password:
74
75====
76 createuser -A -D -P -E gerrit2
77====
78
79Create the database to store the Gerrit metadata, and set the user
80you just created as the owner of that database:
81
82====
83 createdb -E UTF-8 -O gerrit2 reviewdb
84====
85
Shawn O. Pearce0b91a632009-02-06 12:53:59 -080086
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080087Initialize the Schema
88---------------------
89
90Create the Gerrit 2 Tables
91~~~~~~~~~~~~~~~~~~~~~~~~~~
92
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -080093Either run CreateSchema from the command line:
Shawn O. Pearced2b73db2009-01-09 11:55:47 -080094
95====
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -080096 java -jar gerrit.war --cat extra/GerritServer.properties_example >GerritServer.properties
97 edit GerritServer.properties
98
99 java -jar gerrit.war CreateSchema
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800100====
101
102Or, run the application once in a container to force it to initialize
103the database schema before accessing it. (See below for deployment
104setup documentation.) If you use this approach, it is recommended
105that you stop the application before continuing with the setup.
106
107Add Indexes
108~~~~~~~~~~~
109
110A script should be run to create the query indexes, so Gerrit
111can avoid table scans when looking up information. Run the
112`sql/query_index.sql` script through your database's query tool.
113
114e.g. with PostgreSQL:
115
116====
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -0800117 java -jar gerrit.war --cat sql/query_index.sql | psql reviewdb
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800118====
119
120Configure site_path
121~~~~~~~~~~~~~~~~~~~
122
123This directory holds server-specific configuration files and
124assets used to customize the deployment. Gerrit needs read
125access (but not write access) to the directory. The path
126is stored in `system_config.site_path`, so you will need to
127update the database with this value.
128
129====
130 mkdir /home/gerrit/cfg
131 cd /home/gerrit/cfg
132
133 ssh-keygen -t rsa -P '' -f ssh_host_rsa_key
134 ssh-keygen -t dsa -P '' -f ssh_host_dsa_key
135
136 psql -c "UPDATE system_config SET site_path='/home/gerrit/cfg'" reviewdb
137====
138
139The SSH keys generated here are used as the host keys for the
140internal SSH daemon run by Gerrit. You may wish to backup these
141key files to ensure they can be restored in the event of a disaster.
142
143The private key files (`ssh_host_rsa_key`, `ssh_host_dsa_key`) should
144be readable *only* by the account that is executing Gerrit2's web
145application container. It is a security risk to make these files
146readable by anyone else.
147
148Create Git Repository Base
149~~~~~~~~~~~~~~~~~~~~~~~~~~
150
151This directory holds the Git repositories that Gerrit knows about
152and can service. Gerrit needs write access to this directory and
153any Git repository stored within it.
154
155====
156 mkdir /srv/git
157 psql -c "UPDATE system_config SET git_base_path='/srv/git'" reviewdb
158====
159
160You may wish to consider also exporting this directory over the
161anonymous git:// protocol, as it is more efficient than Gerrit's
162internal ssh daemon. See the `git-daemon` documentation for details
163on how to configure this if anonymous access is desired.
164
165* http://www.kernel.org/pub/software/scm/git/docs/git-daemon.html[man git-daemon]
166
167Futher Configuration
168~~~~~~~~~~~~~~~~~~~~
169
170Gerrit2 supports some site-specific customizations. These are
171optional and are not required to run a server, but may be desired.
172
Shawn O. Pearcef384b442009-01-10 16:20:56 -0800173* link:config-sso.html[Single Sign-On Systems]
Shawn O. Pearce5a14d662009-01-23 16:39:51 -0800174* link:config-replication.html[Git Replication/Mirroring]
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800175* link:config-headerfooter.html[Site Header/Footer]
176* link:config-gitweb.html[Gitweb Integration]
177* link:config-gerrit.html[Other system_config Settings]
178
Shawn O. Pearce0b91a632009-02-06 12:53:59 -0800179
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800180Application Deployment
181-----------------------
182
183Jetty
184~~~~~
185
186These directions will configure Gerrit as the default web
187application, allowing URLs like `http://example.com/4543` to
188jump directly to change 4543.
189
190Download and unzip a release version of Jetty. From here on we
191call the unpacked directory `$JETTY_HOME`.
192
193* http://dist.codehaus.org/jetty/[Jetty Downloads]
194
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -0800195Install the JDBC drivers, using either the ones that come embedded
196with Gerrit, or by downloading them yourself from their mirrors:
197====
198 java -jar gerrit.war --cat lib/c3p0-0.9.1.2.jar >$JETTY_HOME/lib/plus/c3p0-0.9.1.2.jar
199 java -jar gerrit.war --cat lib/postgresql-8.3-603.jdbc3.jar >$JETTY_HOME/lib/plus/postgresql-8.3-603.jdbc3.jar
200====
201
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800202Copy Gerrit into the deployment:
203====
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -0800204 java -jar gerrit.war --cat extra/jetty_gerrit.xml >$JETTY_HOME/contexts/gerrit.xml
205 cp gerrit.war $JETTY_HOME/webapps/gerrit.war
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800206
207 rm -f $JETTY_HOME/context/test.xml
208====
209
210Edit `$JETTY_HOME/contexts/gerrit.xml` to correctly configure the
Shawn O. Pearce92a19d22009-01-13 13:27:59 -0800211database and outgoing SMTP connections, especially the user and
212password fields.
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800213
214To start automatically when the system boots, consider a start
215script such as the following in `/etc/init.d/gerrit2-jetty`
216
217====
218 #!/bin/sh
219
220 export JETTY_HOST=127.0.0.1
221 export JETTY_PORT=8081
222 export JETTY_USER=gerrit2
223 export JETTY_PID=/var/run/jetty$JETTY_PORT.pid
224 export JETTY_HOME=/home/$JETTY_USER/jetty
225 export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.07/jre
226
227 JAVA_OPTIONS=""
228 JAVA_OPTIONS="$JAVA_OPTIONS -Djetty.host=$JETTY_HOST"
229 export JAVA_OPTIONS
230
231 exec $JETTY_HOME/bin/jetty.sh "$@"
232====
233
234To deploy on port 80, or to use SSL, you should configure Jetty
235to listen on another port, such as 127.0.0.1:8081 (like the start
236script above does) and then follow the <<apache2,reverse proxy>>
237section below.
238
239[TIP]
240Under Jetty, restarting the web application (e.g. after modifying
241`system_config`) is as simple as touching the config file:
242`$JETTY_HOME/contexts/gerrit.xml`
243
244Other Servlet Containers
245~~~~~~~~~~~~~~~~~~~~~~~~
246
Shawn O. Pearceb8527ea2009-02-02 15:39:12 -0800247Deploy the `gerrit-*.war` file to your application server as
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800248`gerrit.war`.
249
250Configure the JNDI DataSource `jdbc/ReviewDb` for the Gerrit web
251application context to point to the database you just created.
252Don't forget to ensure your JNDI configuration can load the
253necessary JDBC drivers.
254
Shawn O. Pearce92a19d22009-01-13 13:27:59 -0800255('Optional') Configure the JNDI name `mail/Outgoing` for the web
256application context to be a factory for a `javax.mail.Session`,
257with the connection information necessary to send outgoing emails.
258You may need to download and install the Java Mail JARs in your
259container's classpath. If this is not configured, Gerrit will
260function, but will not be able to send email.
261
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800262[[apache2]]
263Apache2 Reverse Proxy
264~~~~~~~~~~~~~~~~~~~~~
265
266Enable the necessary Apache2 modules:
267
268====
269 a2enmod proxy_http
270 a2enmod disk_cache ; # optional, but helps performance
271====
272
273then setup a VirtualHost to proxy to Gerrit's servlet container,
274setting the `ProxyPass` line to use the port number you configured
275in your servlet container's configuration:
276
277=======================================
278<VirtualHost *>
279 ServerName review.example.com
280#
281 ProxyRequests Off
282 ProxyVia Off
283 ProxyPreserveHost On
284#
285 <Proxy *>
286Order deny,allow
287Allow from all
288 </Proxy>
289 ProxyPass / http://127.0.0.1:8081/
290#
291 <IfModule mod_disk_cache.c>
292CacheEnable disk /
293CacheIgnoreHeaders Set-Cookie
294 </IfModule>
295</VirtualHost>
296=======================================
297
298To enable SSL, see the Apache server documentation.
299
300
301Administrator Setup
302-------------------
303
304Login to Gerrit through the web interface, so that a user account
305is initialized for you.
306
307Add your newly created account to the "Administrators" group,
308so that you can manage the site through the web interface:
309
310====
311 psql reviewdb
312 INSERT INTO account_group_members
313 (account_id, group_id)
314 VALUES (
315 (SELECT account_id FROM accounts
316 WHERE preferred_email='you@example.com'),
317 (SELECT admin_group_id FROM system_config)
318 );
319====
320
321Group memberships are cached, so you need to either restart Gerrit,
322or try flushing the caches over SSH.
323
324Since SSH cache flushing requires being in the "Administrators"
325group you may run into a chicken-and-egg problem, where you cannot
326flush the cache to make yourself an administrator because you are
327not yet an administrator. Therefore, restarting the application
328is the recommended bootstrap technique.
329
330To flush the server's caches over SSH, ensure you have an SSH key
331(you can add one through the web UI under Settings, SSH Keys),
332and then run:
333
334====
335 ssh -p 29418 you@example.com gerrit flush-caches
336====
337
Shawn O. Pearce0b91a632009-02-06 12:53:59 -0800338
Shawn O. Pearced2b73db2009-01-09 11:55:47 -0800339Project Setup
340-------------
341
342See link:project-setup.html[Project Setup] for further details on
343how to register a project with Gerrit.