Opengrok服务器搭建step by step
以下步骤都是经过自己亲手验证过
1)安装jdk(jdk1.8.0_172),安装tomcat(8.5.31)。此为常规操作,忽略不讲
2) 官网下载 opengrok-1.1-rc27.tar.gz 解压缩到安装目录上(本人惯常的安装目录/usr/local/opengrok)
3)把source.war复制到tomcat的webapps目录中
cp /usr/local/opengrok/lib/source.war /usr/local/tomcat/webapps
mv source.war yourprojectname.war
4)登录tomcat所搭建的web网站的指定目录 http://127.0.0.1/yourprojectname/
这时就会在tomcat的webapps中生成yourprojectname文件夹
暂时忽略掉访问网站的报错,因为我们还没有生成configuration.xml的配置文件。
5)改造一下OpenGrok。vi /usr/local/opengrok/bin/OpenGrok
===============================================================
Line 213,设置opengrok的安装目录,如下
OPENGROK_INSTANCE_BASE="${OPENGROK_INSTANCE_BASE:-/usr/local/opengrok}"
Line 655 ~658,添加tomcat的目录
for prefix in \
${OPENGROK_TOMCAT_BASE} \
/var/lib/tomcat8 \
/usr/local/tomcat
Line 236~240,注释掉else的内容
Line 245~249,注释掉else的内容
# REQUIRED: Source Code/Repository Root
# (your source code or the root of all repositories)
if [ -n "${OPENGROK_SRC_ROOT}" ]; then
SRC_ROOT="${OPENGROK_SRC_ROOT}"
#else
#SRC_ROOT="${OPENGROK_INSTANCE_BASE}/src"
fi
# REQUIRED: OpenGrok Generate Data Root
# (for Lucene index and hypertext cross-references)
# This area is rebuilt by "update" / "updateQuietly"
if [ -n "${OPENGROK_DATA_ROOT}" ]; then
DATA_ROOT="${OPENGROK_DATA_ROOT}"
#else
#DATA_ROOT="${OPENGROK_INSTANCE_BASE}/data"
fi
===============================================================
6)设置环境变量,这里我们用一个脚本来实现。需要注意的是红字部分,如果是多项目的时候,每次生成索引前,都要修改并source这个脚本。
#cat mysetenv.sh #------------------------------------------------------------------------------- # - JAVA_HOME Full Path to Java Installation Root # - JAVA Full Path to java binary (to enable 64bit JDK) # - JAVA_OPTS Java options (e.g. for JVM memory increase #------------------------------------------------------------------------------- export JAVA_HOME=/usr/local/java/jdk1.8.0_172 export JRE_HOME=$JAVA_HOME/jre export JAVA_BIN=$JAVA_HOME/bin export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin #------------------------------------------------------------------------------- # - OPENGROK_DISTRIBUTION_BASE Base Directory of the OpenGrok Distribution # - OPENGROK_INSTANCE_BASE Base Directory of the OpenGrok User Data Area # - EXUBERANT_CTAGS Full Path to Exuberant CTags # - OPENGROK_CTAGS_OPTIONS_FILE Full path to file with extra command line # options for CTags program (for its --options #------------------------------------------------------------------------------- # opengrok home directory export OPENGROK_INSTANCE_BASE=/usr/local/opengrok export SCRIPT_DIRECTORY=$OPENGROK_INSTANCE_BASE/bin export OPENGROK_DISTRIBUTION_BASE=$OPENGROK_INSTANCE_BASE/lib # source code root export SRC_ROOT=$OPENGROK_INSTANCE_BASE/database/src/yourproejctname # generated data root export DATA_ROOT=$OPENGROK_INSTANCE_BASE/database/data/yourprojectname # EXUB_CTAGS=/usr/bin/ctags #------------------------------------------------------------------------------- # - OPENGROK_APP_SERVER Application Server ("Tomcat" or "Glassfish") # - OPENGROK_WAR_TARGET_TOMCAT Tomcat Specific WAR Target Directory # - OPENGROK_WAR_TARGET_GLASSFISH Glassfish Specific WAR Target Directory # - OPENGROK_WAR_TARGET Fallback WAR Target Directory # - OPENGROK_TOMCAT_BASE Base Directory for Tomcat (contains webapps) # - OPENGROK_GLASSFISH_BASE Base Directory for Glassfish # (contains domains) #------------------------------------------------------------------------------- export OPENGROK_APP_SERVER=Tomcat export OPENGROK_TOMCAT_BASE=/usr/local/tomcat export OPENGROK_WAR_TARGET_TOMCAT=$OPENGROK_TOMCAT_BASE/webapps export OPENGROK_WAR_TARGET=$OPENGROK_TOMCAT_BASE/webapps export CATALINA_HOME=$OPENGROK_TOMCAT_BASE
7)将源代码放到指定的目录,即上面脚本中SRC_ROOT的所指定的目录。或者建立一个link
例如:先进入SRC_ROOT的所指定的目录中,然后
ln -s 源码所在目录 yourprojectname
8)生成索引
source mysetenv.sh
./OpenGrok index
9)生成的configuration.xml文件在etc目录下(/usr/local/opengrok/etc)
在此路径下,建一个yourprojectname的文件夹,将xml文件放到此文件夹下,然后修改tomcat里的web.xml文件。
vi /usr/local/tomcat/webapps/yourprojectname/WEB-INF/web.xml
修改如下内容
===============================================
<context-param>
<description>Full path to the configuration file where OpenGrok can read its configuration</description>
<param-name>CONFIGURATION</param-name>
<param-value>/usr/local/opengrok/etc/yourprojectname/configuration.xml</param-value>
</context-param>
===============================================
10)重启tomcat,然后访问 http://127.0.0.1/yourprojectname/
***************************
**** 配置多个项目 ****
***************************
配置多个项目有两种方法:
一种是从step1 开始重新操作一遍,只不过把yourprojectname换为相应project的名字即可。
这种情况下,每一个连接,对应一个项目。例如:
http://127.0.0.1/project1/
http://127.0.0.1/project2/
另一种方法是,在SRC_ROOT目录中添加新的工程代码或者添加新的链接,然后step7做起。
这种情况下,一个链接对应所有的项目。例如
http://127.0.0.1/project/