| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 1 | Gerrit2 - Installation |
| 2 | ====================== |
| 3 | |
| Shawn O. Pearce | 31af1ff | 2009-01-26 12:04:41 -0800 | [diff] [blame] | 4 | You need a SQL database to house the Gerrit2 metadata. Currently |
| 5 | PostgreSQL is the only supported database. |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 6 | |
| 7 | Important Links |
| 8 | --------------- |
| 9 | |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 10 | PostgreSQL: |
| 11 | |
| 12 | * http://www.postgresql.org/docs/[Documentation] |
| 13 | |
| Shawn O. Pearce | 0b91a63 | 2009-02-06 12:53:59 -0800 | [diff] [blame^] | 14 | |
| Shawn O. Pearce | 31af1ff | 2009-01-26 12:04:41 -0800 | [diff] [blame] | 15 | Downloading Gerrit |
| 16 | ------------------ |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 17 | |
| Shawn O. Pearce | 31af1ff | 2009-01-26 12:04:41 -0800 | [diff] [blame] | 18 | Current and past binary releases of Gerrit can be obtained from |
| 19 | the downloads page at the project site: |
| 20 | |
| 21 | * http://code.google.com/p/gerrit/downloads/list[Gerrit Downloads] |
| 22 | |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 23 | Download any current `*.war` package. |
| 24 | |
| Shawn O. Pearce | 31af1ff | 2009-01-26 12:04:41 -0800 | [diff] [blame] | 25 | |
| 26 | Building Gerrit From Source |
| 27 | --------------------------- |
| 28 | |
| 29 | Alternatively, you can build the application distribution using |
| 30 | Maven from a source download obtained directly from Git: |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 31 | |
| 32 | ==== |
| Shawn O. Pearce | 31af1ff | 2009-01-26 12:04:41 -0800 | [diff] [blame] | 33 | 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. Pearce | b951af1 | 2009-02-06 12:32:18 -0800 | [diff] [blame] | 38 | (cd sshd && mvn install) |
| Shawn O. Pearce | 31af1ff | 2009-01-26 12:04:41 -0800 | [diff] [blame] | 39 | |
| Shawn O. Pearce | 263786e | 2009-02-02 15:49:26 -0800 | [diff] [blame] | 40 | mvn clean package |
| 41 | cp target/gerrit-*.war ...YOUR.DEST.../gerrit.war |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 42 | ==== |
| 43 | |
| 44 | The first build may take a while as dependencies are searched |
| 45 | for and downloaded from Maven distribution repositories. |
| 46 | |
| Shawn O. Pearce | b951af1 | 2009-02-06 12:32:18 -0800 | [diff] [blame] | 47 | Unfortunately you need to install snapshots of both JGit and |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 48 | SSHD to your local Maven repository (typically under `~/.m2`). |
| 49 | These core dependencies are still under active development and have |
| 50 | not made final releases yet. |
| Shawn O. Pearce | 31af1ff | 2009-01-26 12:04:41 -0800 | [diff] [blame] | 51 | |
| 52 | Apache Maven: |
| 53 | |
| 54 | * http://maven.apache.org/download.html[Download] |
| 55 | * http://maven.apache.org/run-maven/index.html[Running Maven] |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 56 | |
| Shawn O. Pearce | b951af1 | 2009-02-06 12:32:18 -0800 | [diff] [blame] | 57 | Apache SSHD: |
| 58 | |
| 59 | * http://mina.apache.org/sshd/[Apache SSHD] |
| 60 | |
| 61 | |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 62 | Setting up the Database |
| 63 | ----------------------- |
| 64 | |
| 65 | Currently PostgreSQL is the only supported database. H2 may also |
| 66 | work, but hasn't been tested in a while. The primary concern is |
| 67 | having support for the database in the gworm project. |
| 68 | |
| 69 | PostgreSQL |
| 70 | ~~~~~~~~~~ |
| 71 | |
| 72 | Create a Gerrit specific user as a normal user (no superuser access) |
| 73 | and assign it an encrypted password: |
| 74 | |
| 75 | ==== |
| 76 | createuser -A -D -P -E gerrit2 |
| 77 | ==== |
| 78 | |
| 79 | Create the database to store the Gerrit metadata, and set the user |
| 80 | you just created as the owner of that database: |
| 81 | |
| 82 | ==== |
| 83 | createdb -E UTF-8 -O gerrit2 reviewdb |
| 84 | ==== |
| 85 | |
| Shawn O. Pearce | 0b91a63 | 2009-02-06 12:53:59 -0800 | [diff] [blame^] | 86 | |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 87 | Initialize the Schema |
| 88 | --------------------- |
| 89 | |
| 90 | Create the Gerrit 2 Tables |
| 91 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 92 | |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 93 | Either run CreateSchema from the command line: |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 94 | |
| 95 | ==== |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 96 | java -jar gerrit.war --cat extra/GerritServer.properties_example >GerritServer.properties |
| 97 | edit GerritServer.properties |
| 98 | |
| 99 | java -jar gerrit.war CreateSchema |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 100 | ==== |
| 101 | |
| 102 | Or, run the application once in a container to force it to initialize |
| 103 | the database schema before accessing it. (See below for deployment |
| 104 | setup documentation.) If you use this approach, it is recommended |
| 105 | that you stop the application before continuing with the setup. |
| 106 | |
| 107 | Add Indexes |
| 108 | ~~~~~~~~~~~ |
| 109 | |
| 110 | A script should be run to create the query indexes, so Gerrit |
| 111 | can avoid table scans when looking up information. Run the |
| 112 | `sql/query_index.sql` script through your database's query tool. |
| 113 | |
| 114 | e.g. with PostgreSQL: |
| 115 | |
| 116 | ==== |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 117 | java -jar gerrit.war --cat sql/query_index.sql | psql reviewdb |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 118 | ==== |
| 119 | |
| 120 | Configure site_path |
| 121 | ~~~~~~~~~~~~~~~~~~~ |
| 122 | |
| 123 | This directory holds server-specific configuration files and |
| 124 | assets used to customize the deployment. Gerrit needs read |
| 125 | access (but not write access) to the directory. The path |
| 126 | is stored in `system_config.site_path`, so you will need to |
| 127 | update 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 | |
| 139 | The SSH keys generated here are used as the host keys for the |
| 140 | internal SSH daemon run by Gerrit. You may wish to backup these |
| 141 | key files to ensure they can be restored in the event of a disaster. |
| 142 | |
| 143 | The private key files (`ssh_host_rsa_key`, `ssh_host_dsa_key`) should |
| 144 | be readable *only* by the account that is executing Gerrit2's web |
| 145 | application container. It is a security risk to make these files |
| 146 | readable by anyone else. |
| 147 | |
| 148 | Create Git Repository Base |
| 149 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 150 | |
| 151 | This directory holds the Git repositories that Gerrit knows about |
| 152 | and can service. Gerrit needs write access to this directory and |
| 153 | any 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 | |
| 160 | You may wish to consider also exporting this directory over the |
| 161 | anonymous git:// protocol, as it is more efficient than Gerrit's |
| 162 | internal ssh daemon. See the `git-daemon` documentation for details |
| 163 | on 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 | |
| 167 | Futher Configuration |
| 168 | ~~~~~~~~~~~~~~~~~~~~ |
| 169 | |
| 170 | Gerrit2 supports some site-specific customizations. These are |
| 171 | optional and are not required to run a server, but may be desired. |
| 172 | |
| Shawn O. Pearce | f384b44 | 2009-01-10 16:20:56 -0800 | [diff] [blame] | 173 | * link:config-sso.html[Single Sign-On Systems] |
| Shawn O. Pearce | 5a14d66 | 2009-01-23 16:39:51 -0800 | [diff] [blame] | 174 | * link:config-replication.html[Git Replication/Mirroring] |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 175 | * 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. Pearce | 0b91a63 | 2009-02-06 12:53:59 -0800 | [diff] [blame^] | 179 | |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 180 | Application Deployment |
| 181 | ----------------------- |
| 182 | |
| 183 | Jetty |
| 184 | ~~~~~ |
| 185 | |
| 186 | These directions will configure Gerrit as the default web |
| 187 | application, allowing URLs like `http://example.com/4543` to |
| 188 | jump directly to change 4543. |
| 189 | |
| 190 | Download and unzip a release version of Jetty. From here on we |
| 191 | call the unpacked directory `$JETTY_HOME`. |
| 192 | |
| 193 | * http://dist.codehaus.org/jetty/[Jetty Downloads] |
| 194 | |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 195 | Install the JDBC drivers, using either the ones that come embedded |
| 196 | with 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. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 202 | Copy Gerrit into the deployment: |
| 203 | ==== |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 204 | 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. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 206 | |
| 207 | rm -f $JETTY_HOME/context/test.xml |
| 208 | ==== |
| 209 | |
| 210 | Edit `$JETTY_HOME/contexts/gerrit.xml` to correctly configure the |
| Shawn O. Pearce | 92a19d2 | 2009-01-13 13:27:59 -0800 | [diff] [blame] | 211 | database and outgoing SMTP connections, especially the user and |
| 212 | password fields. |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 213 | |
| 214 | To start automatically when the system boots, consider a start |
| 215 | script 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 | |
| 234 | To deploy on port 80, or to use SSL, you should configure Jetty |
| 235 | to listen on another port, such as 127.0.0.1:8081 (like the start |
| 236 | script above does) and then follow the <<apache2,reverse proxy>> |
| 237 | section below. |
| 238 | |
| 239 | [TIP] |
| 240 | Under 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 | |
| 244 | Other Servlet Containers |
| 245 | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| 246 | |
| Shawn O. Pearce | b8527ea | 2009-02-02 15:39:12 -0800 | [diff] [blame] | 247 | Deploy the `gerrit-*.war` file to your application server as |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 248 | `gerrit.war`. |
| 249 | |
| 250 | Configure the JNDI DataSource `jdbc/ReviewDb` for the Gerrit web |
| 251 | application context to point to the database you just created. |
| 252 | Don't forget to ensure your JNDI configuration can load the |
| 253 | necessary JDBC drivers. |
| 254 | |
| Shawn O. Pearce | 92a19d2 | 2009-01-13 13:27:59 -0800 | [diff] [blame] | 255 | ('Optional') Configure the JNDI name `mail/Outgoing` for the web |
| 256 | application context to be a factory for a `javax.mail.Session`, |
| 257 | with the connection information necessary to send outgoing emails. |
| 258 | You may need to download and install the Java Mail JARs in your |
| 259 | container's classpath. If this is not configured, Gerrit will |
| 260 | function, but will not be able to send email. |
| 261 | |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 262 | [[apache2]] |
| 263 | Apache2 Reverse Proxy |
| 264 | ~~~~~~~~~~~~~~~~~~~~~ |
| 265 | |
| 266 | Enable the necessary Apache2 modules: |
| 267 | |
| 268 | ==== |
| 269 | a2enmod proxy_http |
| 270 | a2enmod disk_cache ; # optional, but helps performance |
| 271 | ==== |
| 272 | |
| 273 | then setup a VirtualHost to proxy to Gerrit's servlet container, |
| 274 | setting the `ProxyPass` line to use the port number you configured |
| 275 | in 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 *> |
| 286 | Order deny,allow |
| 287 | Allow from all |
| 288 | </Proxy> |
| 289 | ProxyPass / http://127.0.0.1:8081/ |
| 290 | # |
| 291 | <IfModule mod_disk_cache.c> |
| 292 | CacheEnable disk / |
| 293 | CacheIgnoreHeaders Set-Cookie |
| 294 | </IfModule> |
| 295 | </VirtualHost> |
| 296 | ======================================= |
| 297 | |
| 298 | To enable SSL, see the Apache server documentation. |
| 299 | |
| 300 | |
| 301 | Administrator Setup |
| 302 | ------------------- |
| 303 | |
| 304 | Login to Gerrit through the web interface, so that a user account |
| 305 | is initialized for you. |
| 306 | |
| 307 | Add your newly created account to the "Administrators" group, |
| 308 | so 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 | |
| 321 | Group memberships are cached, so you need to either restart Gerrit, |
| 322 | or try flushing the caches over SSH. |
| 323 | |
| 324 | Since SSH cache flushing requires being in the "Administrators" |
| 325 | group you may run into a chicken-and-egg problem, where you cannot |
| 326 | flush the cache to make yourself an administrator because you are |
| 327 | not yet an administrator. Therefore, restarting the application |
| 328 | is the recommended bootstrap technique. |
| 329 | |
| 330 | To 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), |
| 332 | and then run: |
| 333 | |
| 334 | ==== |
| 335 | ssh -p 29418 you@example.com gerrit flush-caches |
| 336 | ==== |
| 337 | |
| Shawn O. Pearce | 0b91a63 | 2009-02-06 12:53:59 -0800 | [diff] [blame^] | 338 | |
| Shawn O. Pearce | d2b73db | 2009-01-09 11:55:47 -0800 | [diff] [blame] | 339 | Project Setup |
| 340 | ------------- |
| 341 | |
| 342 | See link:project-setup.html[Project Setup] for further details on |
| 343 | how to register a project with Gerrit. |