搭建代码搜索神器 OpenGrok

一、安装jdk

1
2
3
4
5
6
7
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
sudo update-java-alternatives -s java-8-oracle
java -version
javac -version

二、安装tomcat

2.1 下载

官网http://tomcat.apache.org/
下载tomcat并解压至/opt/apache-tomcat

2.2 环境变量配置

1
2
3
4
5
export CLASSPATH=$CLASSPATH:%JAVA_HOME/lib/tools.jar
export TOMCAT_HOME=/opt/apache-tomcat
export CATALINA_HOME=$TOMCAT_HOME
export PATH=$PATH:$TOMCAT_HOME/bin
打开apache-tomcat/bin/catalina.sh文件,在cygwin=false之后添加JAVA_HOME=/usr/lib/jvm/java-8-oracle.

2.3 启动/关闭Tomcat

1
2
3
4
sudo ./startup.sh #启动Tomcat
sudo ./shutdown.sh #关闭Tomcat
ps -ef|grep tomcat #检测Tomcat是否运行
sudo apt-get install exuberant-ctags

在浏览器中输入http://localhost:8080, 若能显示tomcat页面则表示tomcat已经安装且启动成功。

三、安装OpenGrok

下载地址:http://opengrok.github.io/OpenGrok/

解压后将source/source.war文件拷贝到tomcat/webapps/opengrok.war

配置tomcat、index路径
vim opengrok/bin/OpenGrok
OPENGROK_INSTANCE_BASE=”${OPENGROK_INSTANCE_BASE:-/mnt/data/code/opengrok}”(index存储路径)
在Usage()上面一行添加:
export OPENGROK_TOMCAT_BASE=”/opt/apache-tomcat/“ #tomcat7安装路径
JAVA_HOME=”/usr/lib/jvm/java-8-oracle/“

建立索引
export OPENGROK_INSTANCE_BASE=”/mnt/data/code/opengrok/test001/“
export OPENGROK_WEBAPP_CONTEXT=”/test001/“
./OpenGrok index /mnt/data/code/opengrok/test001

安装opengrok
cp opengrok/lib/source.war /opt/apache-tomcat/webapps/test001.war
cd /opt/apache-tomcat/bin
./startup.sh
在/opt/apache-tomcat/webapps/下生成test001目录

修改配置文件参数
cd /opt/apache-tomcat/webapps/test001
vim WEB-INF/web.xml
将CONFIGURATION的param-value修改为/mnt/data/code/test001/etc/configuration.xml

访问网址即可搜索
http://localhost:8080/test001
(局域网访问只需将localhost变更为本机IP即可)

netstat -ap | grep 2424
lsof -i:2424

四、多项目配置opengrok

1
2
3
4
5
6
7
8
9
10
11
12
13
14
export OPENGROK_INSTANCE_BASE="/mnt/data/code/opengrok/msm8917_n"
#export OPENGROK_WEBAPP_NAME="/msm8917_n"
export OPENGROK_WEBAPP_CONTEXT="/MSM8917_N"
export OPENGROK_TOMCAT_BASE="/home/xiezeyang/software/apache-tomcat/"
/home/xiezeyang/software/opengrok/bin/OpenGrok index /mnt/data/code/MSM8917_N

export OPENGROK_INSTANCE_BASE="/mnt/data/code/opengrok/mt6735_m"
#export OPENGROK_WEBAPP_NAME="mt6735_m"
export OPENGROK_WEBAPP_CONTEXT="/MT6735_M"
/home/xiezeyang/software/opengrok/bin/OpenGrok deploy
/home/xiezeyang/software/opengrok/bin/OpenGrok index /mnt/data/code/MT6735_M

cp /home/xiezeyang/software/opengrok/lib/source.war /home/xiezeyang/software/apache-tomcat/msm8917_n.war
cp /home/xiezeyang/software/opengrok/lib/source.war /home/xiezeyang/software/apache-tomcat/mt6735_m.war

五、开机自启动

1
2
3
4
5
6
7
8
9
cp /usr/local/tomcat/bin/catalina.sh /etc/init.d/
mv /etc/init.d/catalina.sh tomcat

vim tomcat
CATALINA_HOME=/usr/local/tomcat
JAVA_HOME=/usr/lib/java/jdk1.7.0_79

update-rc.d –f tomcat defaults
sysv-rc-conf --list tomcat