ubuntu18.04上建立opengrok-1.1-rc41
参考链接:https://blog.csdn.net/qq305013720/article/details/82593149 //这个帖子里安装的版本都太老了,opengrok建立更新索引会有各种问题,建议只是参考学习用。
opengrok在github上有安装说明,请看:https://github.com/oracle/opengrok
安装JAVA运行环境
OpenGrok 和Tomcat都依赖于 JAVA , 因此我们首先需要 JDK 来支持其运行,最新的opengrok需要java 11的环境。
jdk官网下载比较麻烦,需要账号,可以在此 https://repo.huaweicloud.com/java/jdk/ 网站下载需要的版本,我选择了jdk-11.0.2
//然后使用dpkg命令安装软件包:
sudo dpkg -i jdk-11.0.2_linux-x64_bin.deb
如果遇到依赖性问题,请运行:
$ sudo apt -f install
$ sudo dpkg -i jdk-11.0.2_linux-x64_bin.deb
Reading database … 105838 files and directories currently installed.)
Preparing to unpack jdk-11.0.2_linux-x64_bin.deb …
Unpacking jdk-11.0.2 (11.0.2-1) over (11.0.2-1) …
Setting up jdk-11.0.2 (11.0.2-1) …
设置环境变量:
sudo vim /etc/profile
加入如下代码:
JAVA_HOME=/usr/lib/jvm/jdk-11.0.2
PATH=$JAVA_HOME/bin:$PATH
然后执行:
source /etc/profile
再执行:
java -version //查看java是否正确安装
安装tomcat
新版本的opengrok要求tomcat版本是10以上,手动通过apache官网下载了apache-tomcat-10.1.9.tar.gz版本并进行了安装,步骤如下
下载完成后执行:
sudo tar -zxvf apache-tomcat-10.1.9.tar.gz -C /usr/
cd /usr/apache-tomcat-10.1.9/
chmod 777 * -R
然后执行如下命令
cd /usr/apache-tomcat-10.1.9/bin
./startup.sh
如果需要停止tomcat则执行
cd /usr/apache-tomcat-10.1.9/bin
./shutdown.sh
然后在浏览器中输入网址 http://localhost:8080/ 如果看到tomcat的欢迎页就说明tomcat服务器启动成功了。
安装OpenGrok
安装好 Tomcat 后, 接下来就是配置 OpenGrok 了.
OpenGrok 下载地址 :
http://opengrok.github.io/OpenGrok
https://github.com/oracle/opengrok/releases
在该网址中可以下载 OpenGrok 的编译文件, 也可以下载源文件. 在此我们直接下载编译文件(对OpenGrok感兴趣的同学可以下载源码查看究竟)
opengrok路径可以自己选,放到哪里都可以/opt下也可以,我放到/media/lishuo/workspace/work/opengrok下了,最后将opengrok-1.12.7重命名为opengrok了,所以我的opengrok实际路径为/media/lishuo/workspace/work/opengrok/opengrok
我下载了opengrok-1.12.7.tar.gz这个版本的压缩包,然后执行如下指令:
cd /media/lishuo/workspace/work
mkdir opengrok
cd /media/lishuo/workspace/work/opengrok
mkdir -p ./opengrok/{src,data,dist,etc,log}
tar -C /media/lishuo/workspace/work/opengrok/opengrok/dist --strip-components=1 -xzf opengrok-1.12.7.tar.gz
cd /media/lishuo/workspace/work/opengrok/opengrok
cp dist/doc/logging.properties etc/
配置OpenGrok
将 /media/lishuo/workspace/work/opengrok/opengrok/lib 目录下的 source.war 包拷贝到apache-tomcat安装路径的/usr/apache-tomcat-10.1.9/webapps/目录下,重新运行tomcat
cp /media/lishuo/workspace/work/opengrok/opengrok/dist/lib/source.war /usr/apache-tomcat-10.1.9/webapps/
cd /usr/apache-tomcat-10.1.9/bin
./shutdown.sh
./startup.sh
查看/usr/apache-tomcat-10.1.9/webapps目录下会多出了source目录,后面会用到,此时通过浏览器访问 http://localhost:8080/source/ 就会出现opengrok的主页就证明OpenGrok运行成功.
接下需要更改 apache-tomcat/webapps/source/WEB-INF 目录下的web.xml配置文件
cd /usr/apache-tomcat-10.1.9/webapps/source/WEB-INF
vim web.xml
配置 configuration.xml 的路径为 /media/lishuo/workspace/work/opengrok/opengrok/etc 配置目录, 这个configuration.xm会在下面的建立源码索引步骤自动生成, 这里预先填上
<context-param>
<description>Full path to the configuration file where OpenGrok can read its configuration</description>
<param-name>CONFIGURATION</param-name>
<param-value>/media/lishuo/workspace/work/opengrok/opengrok/etc/configuration.xml</param-value>
</context-param>
安装 universal-ctags
参考 https://docs.ctags.io/en/latest/autotools.html
$ git clone https://github.com/universal-ctags/ctags.git
$ cd ctags
$ ./autogen.sh
$ ./configure --prefix=/where/you/want # defaults to /usr/local
$ make
$ make install # may require extra privileges depending on where to install
可能运行autogen.sh时会报错,请尝试
$ sudo apt install \
gcc make \
pkg-config autoconf automake \
python3-docutils \
libseccomp-dev \
libjansson-dev \
libyaml-dev \
libxml2-dev
建立源码索引
接着我们将需要索引的源码放在 src 目录下即可, 当然我们其实没必要把源码真的放到这里, 只需要为其创建一个链接即可
ln -s /media/lishuo/workspace/aml982/dev aml982_dev
然后执行如下命令生成索引
java \
-Djava.util.logging.config.file=/media/lishuo/workspace/work/opengrok/opengrok/etc/logging.properties \
-Xmx8g -jar /media/lishuo/workspace/work/opengrok/opengrok/dist/lib/opengrok.jar \
-c /opt/universal-ctags/bin/ctags \
-s /media/lishuo/workspace/work/opengrok/opengrok/src \
-d /media/lishuo/workspace/work/opengrok/opengrok/data -H -P -S -G \
-W /media/lishuo/workspace/work/opengrok/opengrok/etc/configuration.xml \
-U http://localhost:8080/source
最后再去访问 http://localhost:8080/source/ 网址就可以看到代码了