美文网首页程序员
OpenGrok-Git-Python新版本离线安装与简单配置

OpenGrok-Git-Python新版本离线安装与简单配置

作者: Gavinxixi臻 | 来源:发表于2018-11-29 21:32 被阅读1次

    0x00 前言

    网上有很多现成的OpenGrok安装与配置的文章,但大多都比较老旧,截止行文前,我使用的版本是:

    opengrok-1.1-rc75
    tomcat-8.5.35
    git-2.19.2
    Python3.7.1(Optional)

    另外,我的Ubuntu在内网,基本上是处于离线状态,有内网的apt-get仓库可以访问,但是不能使用ppa,可想而知,大部分的软件包都没有最新版本。只能通过源码包编译,如果出现依赖缺失,还得找逐一对应的依赖包,然后可能又会有新的依赖缺失,不胜其烦,我捣鼓了好几天才完全弄好。

    0x01 Tomcat

    首先是最简单的Tomcat,解压就可以

    https://tomcat.apache.org/download-80.cgi

    很可能需要更新java到1.8请到Oracle官网下载源码编译,依赖比较少,过程忽略

    https://www.oracle.com/technetwork/java/javase/downloads/index.html

    安装java1.8的原因还由于Opengrok需要用到java1.8以上的版本,否则部署到Tomcat后会发生各种找不到类的错误,直观体验就是访问网页显示404.

    0x02 OpenGrok

    建议还是先看看官方的指导页

    https://github.com/oracle/opengrok/wiki/How-to-setup-OpenGrok

    Requirements

    You need the following:

    • JDK 1.8 or higher (刚刚已经安装好的java8)
    • OpenGrok '''binaries''' from https://github.com/OpenGrok/OpenGrok/releases (.tar.gz file with binaries, not the source code tarball !)(最新版本的OpenGrok发行版)
    • https://github.com/universal-ctags for analysis (avoid Exuberant ctags, they are not maintained anymore)(需要安装universal-ctags)
    • A servlet container like GlassFish or Tomcat 8.0 or later also running with Java at least 1.8(刚刚安装了的Tomcat)
    • GIT version 2.6 or higher for GIT repositories (see PR #1314 for more info)(后面会介绍,git版本过低会出现xref找不到的错误)

    Ctags

    Ctags也是大名鼎鼎的代码标记工具了,到它的GitHub主页下载最新的源码

    https://github.com/universal-ctags/ctags

    How to build and install

    To build with Autotools, see docs/autotools.rst for more information.
    (To build on GNU/Linux, Autotools is your choice.)

    $ ./autogen.sh # 需要安装autogen工具,apt-get或者自行解决
    $ ./configure --prefix=/where/you/want # 默认 /usr/local
    $ make
    $ make install # 如果需要安装在系统分区,需要管理员权限
    

    Git

    同样先下载源码包 https://github.com/git/git/releases
    阅读 https://github.com/git/git/blob/master/INSTALL 安装说明

    $ make configure ;# as yourself
    $ ./configure --prefix=/usr ;# as yourself
    $ make all doc ;# as yourself
    # make install install-doc install-html;# as root
    

    可能会提示缺失 asciidoc 命令,apt-get或者找对应的deb包安装即可。
    https://launchpad.net/ubuntu/disco/amd64/asciidoc/8.6.10-3

    小技巧:
    apt-get缺失的包可以尝试在 https://launchpad.net/ubuntu

    部署OpenGrok,Index

    按照官方步骤,这时应该安装通过Python3生成OpenGrok tool的命令方便后续的index操作的,但不是必须的,而且我安装Python3的时候也踩到无数个坑,因此建议直接跳到部署。
    https://github.com/oracle/opengrok/wiki/How-to-setup-OpenGrok#step2---deploy-the-web-application

    1. 下载最新的Release包:https://github.com/oracle/opengrok/releases 并解压
    2. 复制source.war到Tomcat的webapp目录
    3. 执行Tomcat/bin/startup.sh
    4. 访问 http://localhost:8080/source

    这时候已经可以看到OpenGrok的界面了,但会提示没有找到configuration.xml文件,接下来就是index工程代码。

    Index

    下面的命令中需要代入你各自安装的目录
    [opengrok_解压目录] 例如:~/opengrok-1.1-rc75
    [SOURCE_ROOT] 需要Index的源码根目录
    [WORK_ROOT] OpenGrok的工作目录,生成配置文件和index数据,用户自由选择,主要要有足够的空间,生成的数据量跟源码相当

    java -Djava.util.logging.config.file=[opengrok_解压目录]/doc/logging.properties \
        -jar [opengrok_解压目录]/lib/opengrok.jar \
        -c /usr/local/bin/ctags \
        --depth 10 \
        -s [SOURCE_ROOT] -d [WORK_ROOT]/data -P -S -G \
        -W [WORK_ROOT]/etc/configuration.xml -U http://localhost:8080/source 2>&1
    

    等待命令执行完(Android工程大约需要20分钟),我们得到[WORK_ROOT]/etc/configuration.xml文件。

    Deploy

    编辑Tomcat/webapp/source/WEB-INF/web.xml文件,修改param-value为刚刚生成的配置文件

    <context-param>
        <description>Full path to the configuration file where OpenGrok can read its configuration</description>
        <param-name>CONFIGURATION</param-name>
        <param-value>[WORK_ROOT]/etc/configuration.xml</param-value>
    </context-param>
    

    正常来说,等待一下,访问 http://localhost:8080/source 就可以看到Index过的代码工程了。
    保险起见,可以先清理一下Tomcat:

    Tomcat/bin/shutdown.sh
    rm -rf Tomcat/work/*
    rm -rf Tomcat/log/*
    Tomcat/bin/startup.sh
    

    0x03 附录 安装Python3.7.1 以及 OpenGrok tool

    前面说过,可以通过Python3生成方便管理OpenGrok的命令,例如:opengrok-index, opengrok-reindex-project
    而安装Python3又是一个大坑,因此单独叙述。

    OpenSSL 1.0.2

    Python3 依赖最低 openssl-1.0.2 版本,需要手动编译安装:

    1. 下载解压源码包:https://github.com/openssl/openssl/releases/tag/OpenSSL_1_0_2q
    2. 阅读说明,得知步骤,下面是建议步骤 https://github.com/openssl/openssl/blob/master/INSTALL
    $ ./config
    $ make
    $ make test
    $ make install # as root
    
    1. 默认安装在/usr/local/ssl,最好备份老版本的openssl,并做软连接和配置动态链接库
    sudo mv /usr/bin/openssl /usr/bin/openssl.o
    sudo mv /usr/include/openssl /usr/include/openssl.o
    sudo ln -s /usr/local/ssl/bin/openssl /usr/bin
    sudo ln -s /usr/local/ssl/include/openssl /usr/include/openssl
    sudo echo "/usr/local/ssl/lib" >> /etc/ld.so.conf.d/openssl.conf
    ldconfig -v
    
    1. 运行openssl version输出1.0.2即成功

    安装 Python3.7.1

    ./configure --with-openssl=/usr/local/ssl
    make
    sudo make install
    

    如果出现某些模块安装失败,则找对应的deb包安装上即可。

    安装 OpenGrok tool

    官方讲得很简单 https://github.com/oracle/opengrok/wiki/How-to-setup-OpenGrok#step1---install-management-tools-optional
    一句python3 -m pip install opengrok-tools.tar.gz就搞定了,那是在有网络的情况下,pip工具会自动下载对应操作系统,对应版本,对应依赖的python模块,在这里就需要离线下载pip模块。

    pip离线下载模块

    网上很多文章对这个也是说的不清楚,其实原理很简单,每个pip模块里面都有一个requires.txt描述它的依赖,可以通过pip download命令将依赖包下载下来,然后放到离线机器上作为依赖的目录安装。假设我们在Window上负责下载离线包(其实会涉及到平台问题,

    Window上

    1. [opengrok_解压目录]/tools/opengrok-tools.tar.gz用解压工具打开,提取opengrok_tools.egg-info/requires.txt文件
    2. 安装Python3,运行
    python -m pip download -r E:\requires.txt -d E:\opengrok_tools_tmp
    
    1. 依赖包就会下载到E:\opengrok_tools_tmp,这时要留意,有些包是针对window使用的,需要到pip的网站上下载,例如:
    PyYAML-3.13-cp37-cp37m-win_amd64.whl
    

    需要到 https://pypi.org/project/pip/ 搜索 PyYAML 下载 https://pypi.org/project/PyYAML/#files

    PyYAML-3.13.tar.gz (270.6 kB)  Copy SHA256 hash SHA256
    
    1. 把 E:\opengrok_tools_tmp 打包 放到Linux上 ~/opengrok_tools_tmp

    Linux上

    1. 运行
    python3 -m pip install --no-index --find-links=~/opengrok_tools_tmp [opengrok_解压目录]/tools/opengrok-tools.tar.gz
    

    正常来说,就成功了,可能还会提示缺少模块,可以继续从Window下载对应的模块,放到Linux的tmp目录,重复第5步,例如,提示缺少pytest-runner:

    python -m pip download -d E:\opengrok_tools_tmp --only-binary=:none: pytest-runner
    

    0x04 结语

    离线配置Linux真的好累。中间还发生过为了安装新版本软件,更新了错的dpkg(用了debian发行版的deb安装到Ubuntu上),导致正常的apt-get命令都出错。最后不得不找回旧版本的deb包,一个个安装回去,引以为戒

    2018/11/22  15:13         9,642,757 apache-tomcat-8.5.35.tar.gz
    2018/11/22  18:46           181,872 ca-certificates_20161130+nmu1+deb9u1_all.deb
    2018/11/22  15:20         2,632,021 ctags-master.zip
    2018/11/22  19:30           159,498 debconf_1.5.61_all.deb
    2018/11/22  20:05         1,595,256 dpkg-dev_1.18.25_all.deb
    2018/11/22  20:08         2,115,334 dpkg_1.18.25_amd64.deb
    2018/11/22  19:34           779,468 libc-bin_2.24-11+deb9u3_amd64.deb
    2018/11/22  19:34           819,858 libc-l10n_2.24-11+deb9u3_all.deb
    2018/11/22  19:32         2,693,080 libc6_2.24-11+deb9u3_amd64.deb
    2018/11/22  20:07         1,287,170 libdpkg-perl_1.18.25_all.deb
    2018/11/22  19:09           161,174 libffi-dev_3.2.1-6_amd64.deb
    2018/11/22  19:09            20,388 libffi6_3.2.1-6_amd64.deb
    2018/11/22  20:11           234,010 liblzma5_5.2.2-1.2+b1_amd64.deb
    2018/11/22  20:13           101,376 libselinux1_2.6-3+b3_amd64.deb
    2018/11/22  19:18         1,574,992 libssl-dev_1.1.0f-3+deb9u2_amd64.deb
    2018/11/22  19:17         1,343,734 libssl1.1_1.1.0f-3+deb9u2_amd64.deb
    2018/11/22  19:34         3,287,368 locales_2.24-11+deb9u3_all.deb
    2018/11/22  15:08        45,676,887 opengrok-1.1-rc75.tar.gz
    2018/11/27  13:10         5,345,604 openssl-1.0.2q.tar.gz
    2018/11/22  19:18           724,790 openssl_1.1.0f-3+deb9u2_amd64.deb
    2018/11/22  19:30         1,344,606 perl-base_5.24.1-3+deb9u4_amd64.deb
    2018/11/22  19:05         1,259,370 pip-18.1.tar.gz
    2018/11/22  15:55        22,802,018 Python-3.7.1.tgz
    2018/11/22  18:46         1,405,972 python-pip-whl_9.0.1-2_all.deb
    2018/11/22  19:02           178,870 python-pip_9.0.1-2_all.deb
    2018/11/22  19:06           297,136 python-setuptools_33.1.1-1_all.deb
    2018/11/22  18:46           142,204 python3-pip_9.0.1-2_all.deb
    2018/11/22  20:09           759,354 tar_1.29b-1.1_amd64.deb
    

    相关文章

      网友评论

        本文标题:OpenGrok-Git-Python新版本离线安装与简单配置

        本文链接:https://www.haomeiwen.com/subject/ggsqcqtx.html