/data/opengrok-0.11.1       # opengrok 应用程序包
/data/apache-tomcat-7.0.6   # apache-tomecat路径
/data/opengrok_data         # opengrok数据,配置文件,log存放路径
/data/opengrok_projects     # 需要创建索引的项目代码路径


  1. 以opengrok用户身份登录

  2. 安装jdk和Exuberant Ctags

    $ sudo apt-get install sun-java6-jdk ctags

  3. 下载opengrok安装包(opengrok-0.11.1.tar.gz)和tomcat安装包(apachetomcat-7.0.6.tar.gz)解压安装包到/data目录下面

    $ cd /data $ tar -zxvf /path/to/opengrok-0.11.1.tar.gz $ tar -zxvf /path/to/apachetomcat-7.0.6.tar.gz

  4. 启动tomcat,确认tomcat没有问题

    $ /data/apache-tomcat-7.0.6/bin/


  5. 下载需要创建索引的项目

    $ mkdir -p /data/opengrok_projects/project1 $ mkdir -p /data/opengrok_projects/project2 $ cd /data/opengrok_projects/project1 $ # download code of project1 (such as: git clone … or repo init … && repo sync) $ cd /data/opengrok_projects/project2 $ # download code of project2 (such as: git clone … or repo init … && repo sync)





$ OPENGROK_TOMCAT_BASE=/data/apache-tomcat-7.0.6 /data/opengrok-0.11.1/bin/OpenGrok deploy


访问http://, 已经可以看到opengrok页面了,但是没有项目的数据信息.




$ OPENGROK_VERBOSE=true OPENGROK_INSTANCE_BASE=/data/opengrok_data /data/opengrok-0.11.1/bin/OpenGrok index /data/opengrok_projects


如果不想生成脚本的历史记录Cache, 可以修改/data/opengrok-0.11.1/bin/OpenGrok脚本的UpdateGeneratedData 方法,去掉StdInvocation -H-H.

因此在执行创建索引文件之前,建议去掉-H, 不会影响到OpenGrok的正常使用.


最后会在/data/opengrok_data/目录下面生成data,etc,log 三个目录

        ├── data   # 索引数据
        │   ├── historycache
        │   ├── index
        │   ├── spellIndex
        │   ├── timestamp
        │   └── xref
        ├── etc   # 配置文件
        │   └── configuration.xml
        ├── log   # log文件
        │   ├── opengrok0.0.log
        │   ├── opengrok1.0.log
        │   └── opengrok2.0.log


CONFIGURATION /var/opengrok/etc/configuration.xml Full path to the configuration file where OpenGrok can read it’s configuration


修改web.xml文件这步操作只需要在首次搭建opengrok环境的时候修改一次即可, 以后只有在配 置文件/data/opengrok_data/etc/configuration.xml的路径发生改变时,再修改就可以了.

访问http://, Enjoy it!




$ OPENGROK_VERBOSE=true OPENGROK_INSTANCE_BASE=/data/opengrok_data/ /data/opengrok-0.11.1/bin/OpenGrok index /data/opengrok_projects/


可以通过修改/data/apache-tomcat-7.0.6/webapps/source/index_body.html 来定制化你的OpenGrok首页. 如添加公司LOGO或一些有用的帮助信息。



$ OPENGROK_VERBOSE=true OPENGROK_INSTANCE_BASE=/data/opengrok_data /data/opengrok-0.11.1/bin/OpenGrok index /data/opengrok_projects/

其实调用的是opengrok lib目录下的jar包:

java -Xmx2048m -Dorg.opensolaris.opengrok.history.cvs=/usr/bin/cvs
-jar /data/opengrok-0.11.1/bin/../lib/opengrok.jar
-P -S -r on -v -c /usr/bin/ctags-exuberant -a on
-W /data/opengrok_data/etc/configuration.xml
-U localhost:2424 -s /data/opengrok_projects/
-d /data/opengrok_data/data -H..


$ java -jar opengrok.jar

Usage: opengrok.jar [options]

-A ext:analyzer
    Files with the named extension should be analyzed with the specified class

-a on/off
    Allow or disallow leading wildcards in a search

-B url
    Base URL of the user Information provider. Default: ""

    Print per project percentage progress information(I/O extensive, since one read through dir structure is made before indexing, needs -v, otherwise it just goes to the log)

-c /path/to/ctags
    Path to Exuberant Ctags from by default takes the Exuberant Ctags in PATH.

    Store history cache in a database (needs the JDBC driver in the classpath, typically derbyclient.jar or derby.jar)

-d /path/to/data/root
    The directory where OpenGrok stores the generated data

    Economical - consumes less disk space. It does not generate hyper text cross reference files offline, but will do so on demand - which could be sightly slow.

    Generate history cache for all repositories

-h /path/to/repository
    just generate history cache for the specified repos (absolute path from source root)

-I pattern
    Only files matching this pattern will be examined (supports wildcards, example: -I *.java -I *.c)

-i pattern
    Ignore the named files or directories (supports wildcards, example: -i *.so -i *.dll)

-j class
    Name of the JDBC driver class used by the history cache. Can use one of the shorthands "client" (org.apache.derby.jdbc.ClientDriver) or "embedded" (org.apache.derby.jdbc.EmbeddedDriver). Default: "client"

-k /path/to/repository
    Kill the history cache for the given repository and exit. Use '*' to delete the cache for all repositories.

    List all repository pathes and exit.

-L path
    Path to the subdirectory in the web-application containing the requested stylesheet. The following factory-defaults exist: "default", "offwhite" and "polished"

-l on/off
    Turn on/off locking of the Lucene database during index generation

-m number
    The maximum words to index in a file

-N /path/to/symlink
    Allow this symlink to be followed. Option may be repeated.

    Do not generate indexes, but process all other command line options

-O on/off
    Turn on/off the optimization of the index database as part of the indexing step

-P Generate a project for each of the top-level directories in source root 
-p /path/to/default/project
    This is the path to the project that should be selected by default in the web application(when no other project set either in cookie or in parameter). You should strip off the source root.

-Q on/off
    Turn on/off quick context scan. By default only the first 32k of a file is scanned, and a '[..all..]' link is inserted if the file is bigger. Activating this may slow the server down (Note: this is setting only affects the web application)

    Run as quietly as possible

-R /path/to/configuration
    Read configuration from the specified file

-r on/off
    Turn on/off support for remote SCM systems

    Search for "external" source repositories and add them

-s /path/to/source/root
    The root directory of the source tree

-T number
    The number of threads to use for index generation. By default the number of threads will be set to the number of available CPUs

-t number
    Default tabsize to use (number of spaces per tab character)

-U host:port
    Send the current configuration to the specified address (This is most likely the web-app configured with ConfigAddress)

-u url
    URL to the database that contains the history cache. Default: If -j specifies "embedded", "jdbc:derby:$DATA_ROOT/cachedb;create=true"; otherwise, "jdbc:derby://localhost/cachedb;create=true"

    Print version and quit

    Print progress information as we go along

-W /path/to/configuration
    Write the current configuration to the specified file (so that the web application can use the same configuration

-w webapp-context
    Context of webapp. Default is /source. If you specify a different name, make sure to rename source.war to that name.

-X url:suffix
    URL Suffix for the user Information provider. Default: ""

-z number
    depth of scanning for repositories in directory structure relative to source root