LXR on Debian

實作時間:2017年10月20日

VirtualBox5.1(Windows10上安裝虛擬機器)安裝Debian9.2

所安裝軟體版本如下。

Apache 2.4

MariaDB 10.1

Perl 5.24

Flex 2.6

glimpse 4.8

lxr2.2.1

安裝步驟

(1)安裝apache2

#sudo apt-get install apache2

#vi /etc/apache2/site-available/000-default.conf

編輯ServerName

#service apache2 start

#update-rc.d apache2 defaults

(2)安裝mysql

#sudo apt-get install mysql-server

#service mysqld start

#update-rc.d mysql defaults

修改mysql的root密碼,不允許root遠端登入,進行安全性設定

#mysql_secure_installation

(3)安裝所需要的套件

#sudo apt-get install ctags

#sudo apt-get install perl perl-modules //通常安裝系統時會一起已安裝

#sudo apt-get install build-essential //安裝C語言開發環境

#cpan App::cpanminus //需用到C語言開發環境編譯程式

#cpanm File::MMagic

#sudo apt-get install libapache2-mod-perl2

#sudo apt-get install libdbi-perl libdbd-mysql-perl //安裝mysql-server會一起安裝

(4)安裝編譯環境

#sudo apt-get install flex

(5)安裝glimpse

sudo apt-get install glimpse

glimpse與swish-e只要使用其中一個就好。

(6)設定LXR

#cp lxr-2.2.1.tgz /var/www/html

#cd /var/www/html

#tar -zxvf lxr-2.2.1.tgz

#mv lxr-2.2.1 lxr

#./scripts/configure-lxr.pl -vv

root@debian:/var/www/html/lxr# ./scripts/configure-lxr.pl -vv

*** LXR configurator (version: 2.2) ***

LXR root directory is /var/www/html/lxr

Configuration will be stored in custom.d/

directory custom.d created

directory custom.d/db-scripts.d created

Configure for single/multiple trees? [S/m] >

Do you intend to add other trees later? [yes/NO] >

*** LXR web server configuration ***

Many different configurations are possible, they are related to the way

LXR service is accessed, i.e. to the structure of the URL.

Refer to the User's Manual for a description of the variants.

LXR can be located at the server-root (so called dedicated)

or lower in the server hierarchy (shared because there are

usually other pages or sections).

Server type? [dedicated/SHARED] >

The computer hosting the server is described by an URL.

The form is scheme://host_name:port

where:

- scheme is either http or https (http: can be omitted),

- host_name can be given as an IP address such as 123.45.67.89

or a domain name like localhost or lxr.url.example,

- port may be omitted if standard for the scheme.

--- Host name or IP? [//localhost] >

--- Alias name or IP? > //192.168.43.73

--- Alias name or IP? >

URL section name for LXR in your server? [/lxr] >

*** LXR database configuration ***

The choice of the database engine can make a difference in indexing performance,

but resource consumption is also an important factor.

* For a small personal project, try SQLite which do not

need a server and is free from configuration burden.

* For medium to large projects, choice is between MySQL,

PostgreSQL and Oracle.

Oracle is not a free software, its interface has not been

tested for a long time.

* PostgreSQL databases are smaller than MySQL's

and performance is roughly equivalent.

* MySQL is at its best with large-sized projects

(such as kernel cross-referencing) where it is fastest at the cost

of bigger databases.

* Take also in consideration the number of connected users.

Database engine? [MYSQL/oracle/postgres/sqlite] >

--- Directory for glimpse databases? > /var/www/html/glimpse

file .htaccess written into LXR root directory

file apache2-require.pl written into configuration directory

file apache-lxrserver.conf written into configuration directory

file lighttpd-lxrserver.conf written into configuration directory

file nginx-lxrserver.conf written into configuration directory

file thttpd-lxrserver.conf written into configuration directory

Mercurial support files written into configuration directory

*** LXR master configuration file setup ***

Global section part

*** Configuring auxiliary tool paths

*** Host name previously defined as http://localhost

*** Configuring HTML parameters

*** 'Buttons-and-menus' interface is recommended for the kernel

*** to avoid screen cluttering.

--- Use 'buttons-and-menus' instead of 'link' interface? [YES/no] >

*** Configuring file subsection

*** Configuring "common factors"

*** Marking tree section

*** LXR master configuration file setup ***

Tree section part

SQL script for database initialisation

*** Configuring LXR server parameters

*** The virtual root is the fixed URL part after the hostname.

*** You previously defined the virtual root as /lxr

--- Caption in page header? (e.g. Project XYZZY displayed by LXR) > LXR

Do you need a specific encoding for this tree ? [yes/NO] >

*** Describing tree location

How is your tree stored? [FILES/cvs/git/svn/hg/bk] >

*** A source directory contains one sub-directory for every version.

--- Source directory? (e.g. /home/myself/project-tree) > /var/www/html

Name to display for the path root? (e.g. Project or $v for version) [$v] >

*** Enumerating versions

Label for version selection menu? [Version] >

*** Versions can be explicitly enumerated, be read from a file or computed

*** by a function. The latter case is recommended for VCS-stored trees.

Version enumeration method? [LIST/file/function] >

--- Version name? > slxr

--- Version name? (hit return to stop) >

*** By default, first version in list is displayed. You may also indicate

*** a prefered version.

--- Default displayed version is first in 'range'? [YES/no] >

*** Setting directory lists

*** Some directories may contain non-public project data (binaries,

*** compilers caches, SCM control data, ...). They can be hidden from LXR.

--- Directory to ignore, e.g. CVSROOT or CVS? (hit return to stop) >

*** If your source code uses "include" statements (#include, require, ...)

*** LXR needs hints to resolve the destination file.

--- Include directory, e.g. /include? (hit return to stop) >

*** Configuring data storage

--- Database name? > lxr

--- DB user name? [lxr] >

--- DB password? [lxrpw] > 資料庫使用者lxr的密碼

--- DB table prefix? [lxr_] >

configuration saved in custom.d/lxr.conf

DB initialisation script is custom.d/initdb.sh

(7)建立資料庫與資料庫使用者

執行「./custom.d/initdb.sh」建立資料庫與新增資料庫使用者lxr

若無法登入,請重新執行./scripts/configure-lxr.pl -vv,輸入正確mysql的使用者lxr密碼,重新產生initdb.sh再執行./custom.d/initdb.sh

(8)拷貝「lxr.conf」到lxr目錄

cp ./custom.d/lxr.conf /var/www/html/lxr

(9)使用ctags與glimpse產生索引

#./genxref --checkonly

可以忽略swish-e找不到的錯誤

#./genxref --url=http://192.168.43.73/lxr --versions=slxr //建立索引

http://192.168.43.73/lxr為LXR原始碼所在網址,slxr為Version Name,在剛剛設定的/var/www/html (source directory)的資料夾下,將要做交叉參照原始碼放在slxr資料夾下。

在 /var/www/html 下,將要建立索引的程式碼放置於slxr資料夾下,本範例放置LXR的原始碼。

以下為建立索引值螢幕顯示的畫面

root@debian:/var/www/html/lxr# ./genxref --url=http://192.168.43.73/lxr --versions=slxr

Unknown option: versions

[ OK ] Perl version ... 5.24.1

[ OK ] ctags version ... 5.9

Checked: glimpse version ... 4.18.7

Checked: glimpseindex version ... 4.18.7

Parameter 'swishbin' not defined - trying to find swish-e

swish-e not found, `command -v swish-e` returned a null string

Processing http://192.168.43.129/lxr == Version slxr

usage: /usr/bin/glimpseindex [-help] [-a] [-d] [-f] [-i] [-n [X]] [-o] [-r delim] [-s] [-t] [-w X] [-B] [-F] [-H DIR] [-I] [-M X] [-R] [-S X] [-T] [-V] NAMES

List of options (see http://webglimpse.net/ for more details):

-help: outputs this menu

-a: add given files/directories to an existing index

-b: build a (large) byte-level index

-B: use a hash table that is 4 times bigger (256k entries instead of 64K)

-d NAMES: delete (file or directory) NAMES from an existing index

-D NAMES: delete NAMES from the list of files (but not from the index!)

-E: do not run a check on file types

-f: incremental indexing (add all newly modified files)

-F: the list of files to index is obtained from standard input

-h: generates some hash-tables for WebGlimpse

-H DIR: the index is put in directory DIR

-i: make .glimpse_include take precedence over .glimpse_exclude

-I: output the list of files that would be indexed (but don't index)

-M X: use X MBytes of memory for temporary tables

-n [X]: index numbers as well as words; warn (into .glimpse_messages)

if file adds > X% numeric words: default is 50

-o: build a small (rather than tiny) size index (the recommended option!)

-r delim: build an index at the granularity of delimiter `delim'

to do booleans by reading ONLY the index

-R: recompute .glimpse_filenames_index from .glimpse_filenames if it changes

-s: build index to support structured (Harvest SOIF type) queries

-S X: adjust the size of the stop list

-t: sort the indexed files by date and time (most recent first)

-T: build .glimpse_turbo for very fast search with -i -w in glimpse

-U: there is extra information after filenames: works only with -F

-w X: warn (into .glimpse_messages) if a file adds >= X words to the index

-X: extract titles of all documents with .html, .htm, .shtm, .shtml suffix

-z: customizable filtering using .glimpse_filters

*** slxr /custom.d/db-scripts.d/

--- slxr m:lxr:lxr_.sh 1508411917-9182 1 :: 0

*** slxr /custom.d/

--- slxr apache2-require.pl 1508411917-379 2 :: 0

--- slxr hg-lxr-ext.py 1508411917-2349 3 :: 4

--- slxr initdb.sh 1508411917-48 4 :: 0

--- slxr lxr.conf 1508411917-11369 5 :: 0

--- slxr lxr.ctxt 1508411917-557 6 :: 0

*** slxr /lib/LXR/Files/

--- slxr BK.pm 1508411917-8224 7 :: 20

--- slxr CVS.pm 1508411917-23460 8 :: 20

--- slxr GIT.pm 1508411917-10683 9 :: 17

--- slxr Mercurial.pm 1508411917-9698 10 :: 16

--- slxr Plain.pm 1508411917-5149 11 :: 15

--- slxr Subversion.pm 1508411917-9775 12 :: 18

*** slxr /lib/LXR/Index/

--- slxr Mysql.pm 1508411917-9669 13 :: 6

--- slxr Oracle.pm 1508411917-2232 14 :: 3

--- slxr Postgres.pm 1508411917-8852 15 :: 6

--- slxr SQLite.pm 1508411917-5321 16 :: 6

*** slxr /lib/LXR/Lang/

--- slxr C.pm 1508411917-2323 17 :: 2

--- slxr Cobol.pm 1508411917-1471 18 :: 3

--- slxr CSharp.pm 1508411917-2950 19 :: 2

--- slxr generic.conf 1508411917-48989 20 :: 3

--- slxr Generic.pm 1508411917-20381 21 :: 12

--- slxr HTML.pm 1508411917-3298 22 :: 2

--- slxr Java.pm 1508411917-3000 23 :: 2

--- slxr Make.pm 1508411917-2837 24 :: 2

--- slxr Pascal.pm 1508411917-4161 25 :: 3

--- slxr Perl.pm 1508411917-3715 26 :: 2

--- slxr Python.pm 1508411917-3928 27 :: 2

--- slxr Ruby.pm 1508411917-2378 28 :: 2

*** slxr /lib/LXR/

......

......

--- slxr showconfig 1508411917-8115 87 +++ 372/175

--- slxr source 1508411917-22551 88 +++ 1032/501

Summary for http://192.168.43.129/lxr == Version slxr

Purge : 0:00:00

Free-text indexing : 0:00:00

Definitions parsing: 0:00:04

References parsing : 0:00:07

...Total duration..: 0:00:11

(10)設定apache

#cp /custom.d/apache-lxrserver.conf /etc/apache2/site-available/

#a2ensite apache-lxrserver.conf //將apache-lxrserver.conf連結到/etc/apache2/site-enable/,啟用此設定

#service apache2 start

apache-lxrserver.conf如下

#

# LXR Apache server configuration

#

# =================================================

# ------- Port list -------

#

# (only if different from 80, 8080 or 443)

# NOTE: remove duplicate ports since they cause trouble

# and uncomment the remaining ones.

#@here_ports:

# =================================================

#

# ------- LXR host name and aliases ------

#

<VirtualHost *>

DocumentRoot /var/www/html/lxr

ServerName localhost

ServerAlias 192.168.43.73

</VirtualHost>

#@here_hosts:

# =================================================

#

# ------- URL mapping to LXR directory ------

#

Alias /lxr "/var/www/html/lxr"

#@here_alias:

# =================================================

#

# ----------- Perl security checks -----------

#

# If these checks cause trouble (i.e. too many

# error or warning messages in Apache's error log),

# comment out the lines.

<IfDefine MODPERL2>

PerlSwitches -T

</IfDefine>

<IfDefine !MODPERL2>

PerlTaintCheck On

</IfDefine>

# =================================================

#

# ----------- LXR startup configuration -----------

#

# This is valid only for Apache 2.x

# Apache 1.x requires manual modification of Perl library.

# See LXR installation manual

<IfModule mod_version.c>

# Assume Apache 2.x and above since mod_version appeared in 2.0

# This is safer than using <IfVersion> since this tag

# causes an error with 1.x

# However, when this configuration file is parsed,

# mod_perl may not yet be loaded; consequently, the older

# directive is used. Happily, it is still recognised by newer

# versions of mod_perl.

<IfDefine MODPERL2>

# ----------------> absolute path to the LXR root directory

PerlPostConfigRequire /var/www/html/lxr/custom.d/apache2-require.pl

</IfDefine>

<IfDefine !MODPERL2>

# ----------------> absolute path to the LXR root directory

PerlRequire /var/www/html/lxr/custom.d/apache2-require.pl

</IfDefine>

</IfModule>

# =================================================

#

# ----------- LXR directory access -----------

#

# ----------------> absolute path to the LXR root directory

<Directory "/var/www/html/lxr">

Options FollowSymLinks

AllowOverride AuthConfig FileInfo Limit Options

<IfModule mod_version.c>

<IfVersion < 2.4>

Order allow,deny

Allow from all

</IfVersion>

<IfVersion >= 2.4>

Require all granted

</IfVersion>

</IfModule>

<IfModule !mod_version.c>

<IfModule !mod_authz_core.c>

Order allow,deny

Allow from all

</IfModule>

<IfModule mod_authz_core.c>

Require all granted

</IfModule>

</IfModule>

</Directory>

(11)在slxr資料夾下加上LXR的原始碼,使用外部電腦瀏覽http://192.168.43.73/lxr結果如下。

點選單一檔案,如下。