OpenGrok是一个毫秒级代码搜索的工具, 它最大的优点就是搜索速度贼快
1.安装jdk
sudo apt install openjdk-8-jdk
2.安装编译ctags
sudo apt install exuberant-ctags
git clone https://github.com/universal-ctags/ctags.git
cd ctags
./autogen.sh
./configure
make
sudo make install
3.下载并解压Tomcat
# http://tomcat.apache.org/
tar -xvf apache-tomcat-9.0.37.tar.gz
4.启动Tomcat(关闭Tomcat脚本是shutdonw.sh)
sh apache-tomcat-9.0.37/bin/startup.sh
(关闭Tomcat脚本是shutdonw.sh)
使用浏览器打开http://本地服务器ip:8080
5.下载解压OpenGrok# https://oracle.github.io/opengrok/
tar -xvf opengrok-1.3.16.tar.gz
6.复制source.war到Tomcat
# 可以重命名source,并且链接也会改成对应的名称
cp opengrok-1.3.16/lib/source.war apache-tomcat-9.0.37/webapps/
7.配置环境变量
sudo vi ~/.bashrc
# opengrok
export JAVA_HOME=/usr
export OPENGROK_TOMCAT_BASE=/home/xxx/opengrok/apache-tomcat-9.0.37
export CATALINA_HOME=/home/xxx/opengrok/apache-tomcat-9.0.37
export OPENGROK_APP_SERVER=Tomcat
export OPENGROK_INSTANCE_BASE=/home/xxx/opengrok/opengrok-1.3.16
export LANG=zh_CN.gb2312
source ~/.bashrc 使环境变量生效
8.创建对应目录
mkdir opengrok-1.3.16/etc opengrok-1.3.16/src opengrok-1.3.16/data
9.cp 或者软连接 我们的代码
cp -r xxx opengrok-1.3.16/src/test # or ln -s dirpath dir_name
10.生成索引(之后每次在src目录下有更新需要重新索引)
java -jar opengrok-1.3.16/lib/opengrok.jar -P -S -v -s opengrok-1.3.16/src -d opengrok-1.3.16/data -W opengrok-1.3.16/etc/configuration.xml
找不到ctags 时 可以which ctags 或者在下载目录find ,命令加上 -c /xxx/ctags
11.修改实际configuration路径,将CONFIGURATION的value改成configuration.xml实际路径。(生成索引后会产生此文件)
# sudo vi apache-tomcat-9.0.37/webapps/source/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>/home/xxx/opengrok/opengrok-1.3.16/etc/configuration.xml</param-value></context-param>
如果有端口冲突可以手动修改端口:
- 将server端口由6005改完8006
- 将HTTP端口由8080改为8081
- 将AJP端口由8009改为8010
# sudo cat conf/server.xml
<Server port="8006" shutdown="SHUTDOWN"><Connector port="8081" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" /><Connector protocol="AJP/1.3"address="::1"port="8010"redirectPort="8443" />
重启
sh apache-tomcat-9.0.37/bin/shutdown.sh && sh apache-tomcat-9.0.37/bin/startup.sh