安装索引源码阅读工具 lxr 安装配置初探

新手发帖,很多方面都是刚入门,有错误的地方请大家见谅,欢迎批评指正

    说明:本文是第一次安装 lxr 的记载文章,适合加深对 lxr 的懂得;如果是想迅速使用 lxr 的话,本文中有些地方对 lxr 的配置不太妥当,建议先浏览本文,然后再以 《LXRUserManual-1.2-en_UK-1.4.pdf》 为主实际

    ==================================

    安装 Apache, MySQL, ctags, mod_perl

    ==================================

$ sudo yum install mysql mysql-server mysql-devel
$ sudo yum install httpd
$ sudo yum install ctags

    官网有一句 "Apache httpd with mod_perl is recommended", 所以最好是当初就将 mod_perl 一同安装,后面可以省去很多费事(费事见下文),由于 Apache 是用 yum 方式安装的,所以 mod_perl 最好也用 yum 安装,否则后面会一堆费事(见下文)

$ sudo yum install mod_perl
$ sudo service mysqld stop
$ sudo service mysqld start
$ mysqladmin -u root password <password>

$ sudo service httpd stop
$ sudo service httpd start

    ============

    安装 glimpse

    ============

$ ./configure
$ make
...
make[1]: Leaving directory `/share/linux-data/Downloads/glimpse-4.18.6/index'
make[1]: Entering directory `/share/linux-data/Downloads/glimpse-4.18.6/dynfilters'
flex -F -8 htuml2txt.lex
make[1]: flex: Command not found
make[1]: *** [lex.yy.c] Error 127
make[1]: Leaving directory `/share/linux-data/Downloads/glimpse-4.18.6/dynfilters'
make: *** [build-sub] Error 2

$ sudo yum install flex
$ make
$ make install

    

    =============
安装 lxr
=============

$ cd /usr/local/share
$ tar -xzvf lxr-1.2.0.tgz
$ mv lxr-1.2.0.tgz lxr
$ cd lxr

    LXR root directory 为 "/usr/local/share/lxr"

    

    ====================

    genxref --checkonly

    ====================

$ ./genxref --checkonly
Can't locate File/MMagic.pm in @INC (@INC contains: lib scripts /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./genxref line 30.
BEGIN failed--compilation aborted at ./genxref line 30.
[hwx@hwx lxr]$ ./genxref --checkonly
Can't locate File/MMagic.pm in @INC (@INC contains: lib scripts /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./genxref line 30.
BEGIN failed--compilation aborted at ./genxref line 30.


$ sudo yum install perl-File-MMagic


$ ./genxref --checkonly
ERROR: could not open configuration file lxr.conf
[  OK  ]     Perl     version ... 5.10.1
Parameter 'ectagsbin' not defined - trying to find ctags
ctags found at /usr/bin/ctags
[  OK  ]     ctags    version ... 5.8
Parameter 'glimpsebin' not defined - trying to find glimpse
glimpse found at /usr/local/bin/glimpse
Checked:    glimpse   version ... 4.18.5
Parameter 'glimpseindex' not defined - trying to find glimpseindex
glimpseindex found at /usr/local/bin/glimpseindex
Checked: glimpseindex version ... 4.18.5
Parameter 'swishbin' not defined - trying to find swish-e
swish-e not found, `command -v swish-e` returned a null string
genxref stopped without indexing by --checkonly option

    

    

    ========================================

    配置 lxr(./scripts/configure-lxr.pl -vv)

    ========================================

$ ./scripts/configure-lxr.pl -vv
*** LXR configurator (version: 1.13) ***


LXR root directory is /usr/local/share/lxr
Configuration will be stored in custom.d/
mkdir custom.d: Permission denied at ./scripts/configure-lxr.pl line 223
[hwx@hwx lxr]$ sudo ./scripts/configure-lxr.pl -vv
[sudo] password for root: 
*** LXR configurator (version: 1.13) ***


LXR root directory is /usr/local/share/lxr
Configuration will be stored in custom.d/
directory custom.d created


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


*** LXR web server configuration ***


LXR can be configured as the default server (the only service in your computer),
a section of this default server or an independent server (with its own
host name).
Refer to the User's Manual for a description of the differences.
Web server type? [1.DEFAULT
/2.section in default
/3.indepedent
/4.section in indepedent
] > 2
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.
The following question asks for a primary URL. Later, you'll have
the opportunity to give aliases to this primary URL.
--- Host name or IP? [//localhost] > 
URL section name for LXR in your server? [/lxr] > 
The built-in method to manage several trees with a single instance of LXR is to include
a designation of the tree in the URL at the end of the section name.
This sequence after host name is called "virtual root".
Supposing one of your trees is to be referred as "my-tree", an URL to list the content
of the default version directory would presently be:
     //localhost/lxr/my-tree/source
with virtual root equal to /lxr/my-tree


Use built-in multiple trees management with tree designation at end of virtual root? [YES/no] > YES


*** 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] > MYSQL
The safest option is to create one database per tree.
You can however create a single database for all your trees with a specific set of
tables for each tree (though this is not recommended).
How do you setup the databases? [PER TREE/global] > global
Name of global database? [lxr] > 
All databases can be accessed with the same username and
can also be described under the same names.
Will you share database characteristics? [YES/no] > YES
--- DB user name? [lxr] > 
--- DB password ? [lxrpw] > 
ERROR: neither glimpse nor swish-e found in $PATH!
Is your source tree stored in a VCS repository? [yes/NO] > NO
Does one of them exist in a non standard directory? [YES/no] > YES
--- Which is it? [GLIMPSE/swish-e] > GLIMPSE
--- Location? (e.g. /usr/share/glimpse-dir/glimpse) > /usr/local/bin/glimpse
--- Location of indexer? (e.g. /usr/share/glimpse-dir/glimpseindex) > /usr/local/bin/glimpseindex
--- Directory for glimpse databases? > /hwx/hwx/glimpse_DB


templates directory templates/ now protected read-only
Is your Apache version 2.4 or higher? [YES/no] > no
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
Mercurial support files written into configuration directory


*** LXR master configuration file setup ***
    Global section part


*** Configuring auxiliary tool paths
*** Configuring host name or IP (as http://...)
*** Host name previously defined as //localhost
--- Alias name ? (hit return to stop) > lxr.hwx.com
--- Alias name ? (hit return to stop) > 
*** 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] > YES
*** 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.
*** The tree needs to be uniquely identified as e.g. /lxr/the_tree
--- Tree designation for URL? (e.g. the_tree) > the_tree
--- Caption in page header? (e.g. Project XYZZY displayed by LXR) > hwx's LXR
Do you want a speed switch button for this tree ? [YES/no] > YES
--- Short title for button? (e.g. XYZZY) > speed-hwx
Do you need a specific encoding for this tree ? [yes/NO] > yes
--- Encoding name? (e.g. iso-8859-1) > UTF-8
*** Describing tree location
How is your tree stored? [FILES/cvs/git/svn/hg/bk] > /hwx/hwx/lxr-tree/linux-2.6.11.1
ERROR: invalid answer, try again ...
How is your tree stored? [FILES/cvs/git/svn/hg/bk] > FILES
*** A source directory contains one sub-directory for every version.
--- Source directory? (e.g. /home/myself/project-tree) > /hwx/hwx/lxr-tree/linux-2.6.11.1
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? (hit return to stop) > 2.6.11.1
--- 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] > YES
*** 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
--- DB table prefix? [lxr_] > 


*** Configure another tree? [YES/no] > no
configuration saved in custom.d/lxr.conf
DB initialisation sript is custom.d/initdb.sh

    ==============================

    配置数据库(./custom.d/initdb.sh)

    ==============================

$ sudo ./custom.d/initdb.sh 
[sudo] password for root: 
*** MySQL - Creating global user lxr
Enter password: 
Enter password: 
*** MySQL - Creating global database lxr
*** MySQL - Configuring tables lxr_ in database lxr

    查看 ./custom.d/initdb.sh 文件内容,再登录到 MySQL 看 lxr 用户、lxr 数据库、表是不是跟 ./custom.d/initdb.sh 文件中的分歧

    拷贝刚刚生成的 lxr 配置文件

$ sudo cp custom.d/lxr.conf .

    

    =========

    每日一道理
记不清有多少个夜晚,在我翻阅纸张的指间滑落;记不清有多少支蜡烛,在我的凝视中化为灰烬。逝者如斯,我时时刻刻会听见自己对生命承诺的余音,感到岁月的流转在渐渐稀释我的年少无知,我愿自己是一只上足了发条的时钟,在昼夜不停的流转中留下自己充实的每一刻。

    生成索引

    =========

$ sudo ./genxref --url=http://localhost/lxr/the_tree --version=2.6.11.1
syntax error at configuration file line 252, next token ???
  (Might be a runaway multi-line LL string starting on line 165)
$ sudo vim ./custom.d/lxr.conf

    发现 line 165:

'caption' => 'hwx's LXR'

    很明显,这里有语法问题,改成 'hwx-LXR'

$ sudo cp custom.d/lxr.conf .
$ sudo ./genxref --url=http://localhost/lxr/the_tree --version=2.6.11.1
[  OK  ]     Perl     version ... 5.10.1
[  OK  ]     ctags    version ... 5.8
Checked:    glimpse   version ... 4.18.5
Checked: glimpseindex version ... 4.18.5
Parameter 'swishbin' not defined - trying to find swish-e
swish-e not found, `command -v swish-e` returned a null string


Processing http://localhost/lxr/the_tree  == Version 2.6.11.1 


This is glimpseindex version 4.18.5, 2006.


permission denied or non-existent: /hwx/hwx/lxr-tree/linux-2.6.11.1/2.6.11.1


Size of files being indexed = 0 B, Total #of files = 0


Index-directory: "/hwx/hwx/glimpse_DB/lxr/the_tree/2.6.11.1"
Glimpse-files created here:
-rw-------. 1 root root      2 May 22 00:32 .glimpse_filenames
-rw-------. 1 root root      0 May 22 00:32 .glimpse_filenames_index
-rw-------. 1 root root      0 May 22 00:32 .glimpse_filetimes
-rw-------. 1 root root     18 May 22 00:32 .glimpse_index
-rw-------. 1 root root    163 May 22 00:32 .glimpse_messages
-rw-------. 1 root root      0 May 22 00:32 .glimpse_partitions
-rw-------. 1 root root    124 May 22 00:32 .glimpse_statistics
-rw-------. 1 root root 262144 May 22 00:32 .glimpse_turbo


*** 2.6.11.1 /
*** 2.6.11.1 /

    发现建立索引很快就完成了,内核这么大的文件,不可能这么快,发现:

permission denied or non-existent: /hwx/hwx/lxr-tree/linux-2.6.11.1/2.6.11.1

Size of files being indexed = 0 B, Total #of files = 0

    所以,索引根本就没有建立

$ sudo vim ./custom.d/lxr.conf

    将

'sourceroot' => '/hwx/hwx/lxr-tree/linux-2.6.11.1'

    改成

'sourceroot' => '/hwx/hwx/lxr-tree/linux'

    然后将 linux-2.6.11.1 的路径由 "/hwx/hwx/lxr-tree/linux-2.6.11.1" 变成 “/hwx/hwx/lxr-tree/linux/2.6.11.1”

    重新运行

$ sudo ./genxref --url=http://localhost/lxr/the_tree --version=2.6.11.1

    开始建立索引

    官方文档又这样一段话:

    As an example, indexing the single 3.1 kernel took 2 hours 39 minutes on a high-end computer (Intel i5 3.3GHz processor and 4GB memory under Fedora 17, MySQL and Glimpse).

    看到彻底无语,等到索引完毕,鸡都叫了,个还睡不睡啊?

    ==========

    配置 Apache

    ==========

    $ cp custom.d/apache-lxrserver.conf /etc/httpd/conf.d

    $ chcon --reference /var/www/cgi-bin -R .

    重启 Apache:

$ sudo service httpd stop
停止 httpd:                                               [确定]
[hwx@hwx lxr]$ sudo service httpd start
正在启动 httpd:Syntax error on line 41 of /etc/httpd/conf.d/apache-lxrserver.conf:
Invalid command 'PerlTaintCheck', perhaps misspelled or defined by a module not included in the server configuration
                                                           [失败]

    探明原因("Apache httpd with mod_perl is recommended"),应该是 mod_perl 的问题

    用 yum 方式胜利安装 mod_perl 之后重启 Apache:

$ sudo service httpd start
正在启动 httpd:[Wed May 22 10:08:24 2013] [warn] module perl_module is already loaded, skipping
httpd: Could not reliably determine the server's fully qualified domain name, using hwx.centos for ServerName
                                                           [确定]

    To enable directory listing by Apache server:

    将 ./.htaccess 中的

Options -Indexes

    改成

Options +Indexes

    ==============

    浏览器拜访 tree

    ==============

http://localhost/lxr/the_tree/source

    ==============

    安装 mod_perl

    ==============

    说明:下面是一系列的蛋疼,用 yum 方式安装 mod_perl 的话,这些“蛋疼”就可以省去了(见前文)

    

$ perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs
Can't locate ExtUtils/Embed.pm in @INC (@INC contains: lib Apache-Test/lib /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at lib/Apache2/Build.pm line 27.
BEGIN failed--compilation aborted at lib/Apache2/Build.pm line 27.
Compilation failed in require at Makefile.PL line 37.
BEGIN failed--compilation aborted at Makefile.PL line 37.
$ sudo yum install perl-devel perl-ExtUtils-Embed
$ perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs
Reading Makefile.PL args from @ARGV
   MP_APXS = /usr/local/apache2/bin/apxs
no conflicting prior mod_perl version found - good.
************* WARNING *************


  Your Perl is configured to link against libgdbm,
  but libgdbm.so was not found.
  You could just symlink it to /usr/lib64/libgdbm.so.2.0.0




************* WARNING *************
[  error] Unable to determine server version, aborting.
[  error] Invalid MP_APXS specified?
$ locate libgdbm.so
/usr/lib64/libgdbm.so.2
/usr/lib64/libgdbm.so.2.0.0

$ cd /usr/lib64/
$ sudo ln -s libgdbm.so.2.0.0 libgdbm.so

    

$ perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs
Reading Makefile.PL args from @ARGV
   MP_APXS = /usr/local/apache2/bin/apxs
no conflicting prior mod_perl version found - good.
[  error] Unable to determine server version, aborting.
[  error] Invalid MP_APXS specified?

    由于我是用 yum 安装的 apache, bin 文件的默许路径是 /usr/sbin, 而 "MP_APXS=/usr/local/apache2/bin/apxs" 说明 bin 文件路径为 "MP_APXS=/usr/local/apache2/bin", 因此改成 "MP_APXS=/usr/sbin/apxs"

$ perl Makefile.PL MP_APXS=/usr/sbin/apxs
Reading Makefile.PL args from @ARGV
   MP_APXS = /usr/sbin/apxs
no conflicting prior mod_perl version found - good.
Configuring Apache/2.2.15 mod_perl/2.0.7 Perl/v5.10.1
Checking if your kit is complete...
Looks good
Checking if your kit is complete...
Looks good
Writing Makefile for Apache2::Reload
Checking if your kit is complete...
Looks good
Writing Makefile for Apache2::SizeLimit
Subroutine MY::postamble redefined at ./Makefile.PL line 149.
Subroutine MY::test redefined at ./Makefile.PL line 168.
Subroutine MY::constants redefined at ./Makefile.PL line 188.
[   info] generating script t/TEST
[   info] generating script ./t/cgi-bin/cookies.pl
[   info] generating script ./t/cgi-bin/next_available_port.pl
Writing Makefile for Apache::Test
Checking for File::Spec...ok
Checking for Cwd...ok
[   info] generating script t/TEST
Checking if your kit is complete...
Looks good
Writing Makefile for ModPerl::Registry
Writing Makefile for APR::Base64
Writing Makefile for APR::Brigade
Writing Makefile for APR::Bucket
Writing Makefile for APR::BucketAlloc
Writing Makefile for APR::BucketType
Writing Makefile for APR::Date
Writing Makefile for APR::Error
Writing Makefile for APR::Finfo
Writing Makefile for APR::IpSubnet
Writing Makefile for APR::OS
Writing Makefile for APR::Pool
Writing Makefile for APR::SockAddr
Writing Makefile for APR::Socket
Writing Makefile for APR::Status
Writing Makefile for APR::String
Writing Makefile for APR::Table
Writing Makefile for APR::URI
Writing Makefile for APR::UUID
Writing Makefile for APR::Util
Writing Makefile for APR
Writing Makefile for Apache2::Access
Writing Makefile for Apache2::CmdParms
Writing Makefile for Apache2::Command
Writing Makefile for Apache2::Connection
Writing Makefile for Apache2::ConnectionUtil
Writing Makefile for Apache2::Directive
Writing Makefile for Apache2::Filter
Writing Makefile for Apache2::FilterRec
Writing Makefile for Apache2::HookRun
Writing Makefile for Apache2::Log
Writing Makefile for Apache2::MPM
Writing Makefile for Apache2::Module
Writing Makefile for Apache2::Process
Writing Makefile for Apache2::RequestIO
Writing Makefile for Apache2::RequestRec
Writing Makefile for Apache2::RequestUtil
Writing Makefile for Apache2::Response
Writing Makefile for Apache2::ServerRec
Writing Makefile for Apache2::ServerUtil
Writing Makefile for Apache2::SubProcess
Writing Makefile for Apache2::SubRequest
Writing Makefile for Apache2::URI
Writing Makefile for Apache2::Util
Writing Makefile for Apache2
Writing Makefile for ModPerl::Global
Writing Makefile for ModPerl::Util
Writing Makefile for ModPerl
Writing Makefile for ModPerl::WrapXS
Writing Makefile for APR
Writing Makefile for APR::Const
Writing Makefile for APR::PerlIO
Writing Makefile for libaprext
Writing Makefile for APR_build
Writing Makefile for Apache2::Const
Writing Makefile for Apache2_build
Writing Makefile for ModPerl::Const
Writing Makefile for ModPerl
Writing Makefile for ModPerl::XS
Writing Makefile for mod_perl2
[warning] mod_perl dso library will be built as mod_perl.so
[warning] You'll need to add the following to httpd.conf:
[warning] 
[warning]   LoadModule perl_module modules/mod_perl.so
[warning] 
[warning] depending on your build, mod_perl might not live in
[warning] the modules/ directory.


[warning] Check the results of
[warning] 
[warning]   $ /usr/sbin/apxs -q LIBEXECDIR
[warning] 
[warning] and adjust the LoadModule directive accordingly.
$ sudo make
...
cp lib/ModPerl/StructureMap.pm blib/lib/ModPerl/StructureMap.pm
cp lib/Apache2/BuildConfig.pm blib/lib/Apache2/BuildConfig.pm
cp lib/Apache2/porting.pm blib/lib/Apache2/porting.pm
make[1]: Entering directory `/share/linux-data/Downloads/mod_perl-2.0.7/Apache-Reload'
cp lib/Apache/Reload.pm ../blib/lib/Apache/Reload.pm
cp lib/Apache2/Reload.pm ../blib/lib/Apache2/Reload.pm
Manifying ../blib/man3/Apache::Reload.3pm
Can't write-open ../blib/man3/Apache::Reload.3pm: Invalid argument at /usr/share/perl5/ExtUtils/Command/MM.pm line 141
make[1]: *** [manifypods] Error 22
make[1]: Leaving directory `/share/linux-data/Downloads/mod_perl-2.0.7/Apache-Reload'
make: *** [subdirs] Error 2

    问题一直解决不了,推测应该是 yum 安装 Apache 的路径跟源码安装 Apache 的方式不同,而源码安装 mod_perl 是服从后者的,因此尝试用 yum 安装 mod_perl(见前文),问题解决,重启 Apache 胜利

    =======

    说明

    =======

    LXR root directory 即 "/usr/local/share/lxr"

    ==============

    References

    ==============

    LXR User's Manual,

     http://iweb.dl.sourceforge.net/project/lxr/doc/LXRUserManual-1.2-en_UK-1.4.pdf

    LXR 1.0+ Installation Instructions,

     http://lxr.sourceforge.net/en/1-0-InstallSteps/1-0-install.shtml

    配置多个项目,

    http://lxr.sourceforge.net/en/advancedconfig.shtml

    

文章结束给大家分享下程序员的一些笑话语录: 雅虎最擅长的不是开通新业务,是关闭旧业务。

posted @ 2013-05-22 19:39  坚固66  阅读(703)  评论(0编辑  收藏  举报