dummy

1 环境配置

1. 下载Opengrok和Tomcat

建立软链接

2. 配置环境变量


2 工程配置

1. 建工程目录

2. 设置每个项目的配置文件

<br>

<br>

3. 创建每个项目源码目录软链接

# tree avro/src/
avro/src/
`-- avro -> /data/opt/avro/avro-src-1.8.2/

<br>

# tree hadoop/src/
hadoop/src/
|-- hadoop-common-project -> /data/opt/hadoop/hadoop-2.7.3-src/hadoop-common-project
|-- hadoop-hdfs-project -> /data/opt/hadoop/hadoop-2.7.3-src/hadoop-hdfs-project/
`-- hadoop-yarn-project -> /data/opt/hadoop/hadoop-2.7.3-src/hadoop-yarn-project/

<br>

# tree hbase/src/
hbase/src/
`-- hbase -> /data/opt/hbase/hbase-1.2.6-src

3 建立或更新

1. opengrok.sh脚本

将opengrok.sh 加入到PATH环境变量中,或者拷贝到/usr/bin cat /usr/bin/opengrok.sh

#!/bin/bash

opengrok_pro_dir=`pwd`
opengrok_bin_dir=`which OpenGrok`
opengrok_bin_dir=`dirname $opengrok_bin_dir`
opengrok_top_dir=`dirname $opengrok_bin_dir`

echo "Info: opengrok_pro_dir: $opengrok_pro_dir"
echo "Info: opengrok_bin_dir: $opengrok_bin_dir"
echo "Info: opengrok_top_dir: $opengrok_top_dir"

if [[ x$opengrok_bin_dir == x ]]
then
    echo -e "\n Error: Not set path to opengrok/bin!\n"
    exit 1
fi

if [[ x$TOMCAT_HOME == x ]]
then
    echo -e "\n Error: Not set env TOMCAT_HOME!\n"
    exit 1
fi

for pro in ${@}
do
    pro_dir=$opengrok_pro_dir/$pro 
    if [ -d $pro_dir ]
    then
        if [ ! -f $pro_dir/etc/opengrok.conf ]
        then
            echo -e "\n Error: $pro_dir/etc/opengrok.conf file Not found!\n"
            continue
        fi
        $TOMCAT_HOME/bin/shutdown.sh
        sleep 3
        webapp_addr=`cat $pro_dir/etc/opengrok.conf | grep OPENGROK_WEBAPP_CFGADD | cut -d= -f2`
        if [[ x$webapp_addr == x ]]
        then
            webapp_addr=localhost:2424
        fi
        port=`echo $webapp_addr | cut -d\: -f2`
        echo -e "\n####check port($port):\n"
        netstat -anp | grep $port
        rm -rf $pro_dir/log/
        rm -rf $pro_dir/etc/configuration.xml
        if [ ! -d $pro_dir/data ]
        then
            mkdir -p $pro_dir/data 
        fi
        if [ ! -d $pro_dir/log ]
        then
            mkdir -p $pro_dir/log
        fi
        cp $opengrok_top_dir/lib/source.war ${pro_dir}.war
        unzip ${pro_dir}.war WEB-INF/web.xml
        sed -i -e 's:/var/opengrok/etc/configuration.xml:'"$pro_dir/etc/configuration.xml"':g' "WEB-INF/web.xml"    
        sed -i -e 's/localhost:2424/'"$webapp_addr"'/g' "WEB-INF/web.xml"
        zip ${pro_dir}.war -u WEB-INF/web.xml
        rm -rf WEB-INF
        rm -rf $TOMCAT_HOME/${pro_dir}*
        $TOMCAT_HOME/bin/startup.sh
        echo "Info: Wait 5s for tomcat startup"
        sleep 5
        mv ${pro_dir}.war $TOMCAT_HOME/webapps/
        OPENGROK_INSTANCE_BASE=$pro_dir OPENGROK_CONFIGURATION=$pro_dir/etc/opengrok.conf OpenGrok index 
    else
        echo "\n Error: $pro_dir directory Not found!\n"
    fi
done

2. 执行脚本

进入工程总目录 > cd /projects/opengrok

多个 > opengrok.sh avro hadoop hbase

单个 > opengrok.sh avro

3. 编写index.html cat /opt/tomcat/webapps/source/index.html

<html>
    <title>Mermaid Opengrok</title>
    <style> 
        body{
            width: 50%;
            margin:0 auto;
            text-align:center
        }
    </style>

    <body>
        <h1 align="center">Opengrok</h1>
        <h2 align="left">Data Mining</h2>
        <ul>
            <li align="left"><a name="hadoop_link" href="../hadoop">Hadoop </a></li>
            <li align="left"><a name="hbase_link" href="../hbase">Hbase </a></li>
            <li align="left"><a name="avro_link" href="../avro">Avro </a></li>
        </ul>
    </body>
</html>

4. 浏览器访问 > http://localhost:8080/source

Opengrok-首页
Opengrok-首页

Opengrok-Hadoop
Opengrok-Hadoop