太陽の魔術師

编译安装 BugZilla

  Bugzilla是用于软件缺陷追踪的网络应用程序。

  简单介绍一下我的测试环境:系统为CentOS 5.4 ,使用系统自带的 Apache、MySQL 。整个安装过程使用 root 用户进行操作。

  用yum安装mysql-server、mysql-devel、gd-devel、mod_perl-devel、ImageMagick-devel、ImageMagick-perl 。当然,并非只依赖这几个包,不过安装这几个包就能通过依赖关系把其他相关的包一起安装完。
  yum install mysql-server mysql-devel gd-devel mod_perl-devel ImageMagick-devel ImageMagick-perl

# 解压源代码包:
tar -xvzf bugzilla-3.2.5.tar.gz -C /usr/local/src/
cd /usr/local/src/bugzilla-3.2.5/


# 进行安装检测
./checksetup.pl --check-modules
* This is Bugzilla 3.2.5 on perl 5.8.8
* Running on Linux 2.6.18-164.el5 #1 SMP Thu Sep 3 03:33:56 EDT 2009

Checking perl modules...
Checking for CGI.pm (v3.21) found v3.15
Checking for TimeDate (v2.21) not found
Checking for PathTools (v0.84) ok: found v3.12
Checking for DBI (v1.41) ok: found v1.52
Checking for Template-Toolkit (v2.15) not found
Checking for Email-Send (v2.00) not found
Checking for Email-MIME (v1.861) not found
Checking for Email-MIME-Encodings (v1.313) not found
Checking for Email-MIME-Modifier (v1.442) not found

Checking available perl DBD modules...
Checking for DBD-Pg (v1.45) not found
Checking for DBD-mysql (v4.00) found v3.0007
Checking for DBD-Oracle (v1.19) not found

The following Perl modules are optional:
Checking for GD (v1.20) not found
Checking for Chart (v1.0) not found
Checking for Template-GD (any) not found
Checking for GDTextUtil (any) not found
Checking for GDGraph (any) not found
Checking for XML-Twig (any) not found
Checking for MIME-tools (v5.406) not found
Checking for libwww-perl (any) not found
Checking for PatchReader (v0.9.4) not found
Checking for PerlMagick (any) ok: found v6.2.8
Checking for perl-ldap (any) not found
Checking for Authen-SASL (any) not found
Checking for RadiusPerl (any) not found
Checking for SOAP-Lite (any) not found
Checking for HTML-Parser (v3.40) not found
Checking for HTML-Scrubber (any) not found
Checking for Email-MIME-Attachment-Stripper (any) not found
Checking for Email-Reply (any) not found
Checking for mod_perl (v1.999022) ok: found v2.000004
***********************************************************************
* REQUIRED MODULES *
***********************************************************************
* Bugzilla requires you to install some Perl modules which are either *
* missing from your system, or the version on your system is too old. *
* *
* The latest versions of each module can be installed by running the *
* commands below. *
***********************************************************************
COMMANDS:

/usr/bin/perl install-module.pl CGI
/usr/bin/perl install-module.pl Date::Format
/usr/bin/perl install-module.pl Template
/usr/bin/perl install-module.pl Email::Send
/usr/bin/perl install-module.pl Email::MIME
/usr/bin/perl install-module.pl Email::MIME::Encodings
/usr/bin/perl install-module.pl Email::MIME::Modifier

***********************************************************************
* DATABASE ACCESS *
***********************************************************************
* In order to access your database, Bugzilla requires that the *
* correct "DBD" module be installed for the database that you are *
* running. *
* *
* Pick and run the correct command below for the database that you *
* plan to use with Bugzilla. *
***********************************************************************
COMMANDS:

PostgreSQL: /usr/bin/perl install-module.pl DBD::Pg
Minimum version required: 1.45
MySQL: /usr/bin/perl install-module.pl DBD::mysql
Minimum version required: 4.00
Oracle: /usr/bin/perl install-module.pl DBD::Oracle
Minimum version required: 1.19

**********************************************************************
* OPTIONAL MODULES *
**********************************************************************
* Certain Perl modules are not required by Bugzilla, but by *
* installing the latest version you gain access to additional *
* features. *
* *
* The optional modules you do not have installed are listed below, *
* with the name of the feature they enable. If you want to install *
* one of these modules, just run the appropriate command in the *
* "COMMANDS TO INSTALL" section. *
**********************************************************************

***********************************************************************
* MODULE NAME * ENABLES FEATURE(S) *
***********************************************************************
* GD * Graphical Reports, New Charts, Old Charts *
* Chart * New Charts, Old Charts *
* Template-GD * Graphical Reports *
* GDTextUtil * Graphical Reports *
* GDGraph * Graphical Reports *
* XML-Twig * Move Bugs Between Installations *
* MIME-tools * Move Bugs Between Installations *
* libwww-perl * Automatic Update Notifications *
* PatchReader * Patch Viewer *
* perl-ldap * LDAP Authentication *
* Authen-SASL * SMTP Authentication *
* RadiusPerl * RADIUS Authentication *
* SOAP-Lite * XML-RPC Interface *
* HTML-Parser * More HTML in Product/Group Descriptions *
* HTML-Scrubber * More HTML in Product/Group Descriptions *
* Email-MIME-Attachment-Stripper * Inbound Email *
* Email-Reply * Inbound Email *
***********************************************************************
COMMANDS TO INSTALL:

GD: /usr/bin/perl install-module.pl GD
Chart: /usr/bin/perl install-module.pl Chart::Base
Template-GD: /usr/bin/perl install-module.pl Template::Plugin::GD::Image
GDTextUtil: /usr/bin/perl install-module.pl GD::Text
GDGraph: /usr/bin/perl install-module.pl GD::Graph
XML-Twig: /usr/bin/perl install-module.pl XML::Twig
MIME-tools: /usr/bin/perl install-module.pl MIME::Parser
libwww-perl: /usr/bin/perl install-module.pl LWP::UserAgent
PatchReader: /usr/bin/perl install-module.pl PatchReader
perl-ldap: /usr/bin/perl install-module.pl Net::LDAP
Authen-SASL: /usr/bin/perl install-module.pl Authen::SASL
RadiusPerl: /usr/bin/perl install-module.pl Authen::Radius
SOAP-Lite: /usr/bin/perl install-module.pl SOAP::Lite
HTML-Parser: /usr/bin/perl install-module.pl HTML::Parser
HTML-Scrubber: /usr/bin/perl install-module.pl HTML::Scrubber
Email-MIME-Attachment-Stripper: /usr/bin/perl install-module.pl Email::MIME::Attachment::Stripper
Email-Reply: /usr/bin/perl install-module.pl Email::Reply

To attempt an automatic install of every required and optional module
with one command, do:

/usr/bin/perl install-module.pl --all

从上面信息可以看出,缺少很多 perl 模块……

# 安装缺少的 Perl 模块
/usr/bin/perl install-module.pl --all
这里需要连网……你也可以下载我提供的包,在文章后面会给出链接。

安装到一定时候会提示:
*** Module::AutoInstall version 1.03
*** Checking for Perl dependencies...
[Core Features]
- Test::More ...loaded. (0.94)
- Mail::Header ...missing. (would need 1.01)
- Mail::Internet ...missing. (would need 1.0203)
- Mail::Field ...missing. (would need 1.05)
- MIME::Base64 ...loaded. (3.07 >= 2.2)
- IO::File ...loaded. (1.13 >= 1.13)
- IO::Handle ...loaded. (1.25)
- IO::Stringy ...missing. (would need 2.11)
- File::Spec ...loaded. (3.12 >= 0.6)
- File::Path ...loaded. (1.08 >= 1)
- File::Temp ...missing. (would need 0.18)
==> Auto-install the 5 mandatory module(s) from CPAN? [y]


从这里开始需要按回车确认一些东西,直到出现下面提示:

First, pick a nearby continent and country (you can pick several of
each, separated by spaces, or none if you just want to keep your
existing selections). Then, you will be presented with a list of URLs
of CPAN mirrors in the countries you selected, along with previously
selected URLs. Select some of those URLs, or just keep the old list.
Finally, you will be prompted for any extra URLs -- file:, ftp:, or
http: -- that host a CPAN mirror.

(1) Africa
(2) Asia
(3) Australasia
(4) Central America
(5) Europe
(6) North America
(7) Oceania
(8) South America
Select your continent (or several nearby continents) [] 2
Sorry! since you don't have any existing picks, you must make a
geographic selection.

(1) China
(2) Hong Kong
(3) India
(4) Indonesia
(5) Japan
(6) Kazakhstan
(7) Republic of Korea
(8) Russia
(9) Singapore
(10) Taiwan
(11) Thailand
(12) Turkey
Select your country (or several nearby countries) [] 1
Sorry! since you don't have any existing picks, you must make a
geographic selection.

(1) http://cpan.wenzk.com/
Select as many URLs as you like (by number),
put them on one line, separated by blanks, e.g. '1 4 5' [] 1


以上几个需要手动输入,后面再碰到需要确认的东西直接回车确认即可。

# 第二次检测,其实这个意义不大……
./checksetup.pl --check-modules
* This is Bugzilla 3.2.5 on perl 5.8.8
* Running on Linux 2.6.18-164.el5 #1 SMP Thu Sep 3 03:33:56 EDT 2009

Checking perl modules...
Checking for CGI.pm (v3.21) ok: found v3.48
Checking for TimeDate (v2.21) ok: found v2.23
Checking for PathTools (v0.84) ok: found v3.12
Checking for DBI (v1.41) ok: found v1.52
Checking for Template-Toolkit (v2.15) ok: found v2.22
Checking for Email-Send (v2.00) ok: found v2.198
Checking for Email-MIME (v1.861) ok: found v1.902
Checking for Email-MIME-Encodings (v1.313) ok: found v1.313
Checking for Email-MIME-Modifier (v1.442) ok: found v1.902

Checking available perl DBD modules...
Checking for DBD-Pg (v1.45) not found
Checking for DBD-mysql (v4.00) ok: found v4.013
Checking for DBD-Oracle (v1.19) not found

The following Perl modules are optional:
Checking for GD (v1.20) ok: found v2.44
Checking for Chart (v1.0) ok: found v2.4.1
Checking for Template-GD (any) ok: found v1.56
Checking for GDTextUtil (any) ok: found v0.86
Checking for GDGraph (any) ok: found v1.44
Checking for XML-Twig (any) ok: found v3.32
Checking for MIME-tools (v5.406) ok: found v5.427
Checking for libwww-perl (any) ok: found v5.834
Checking for PatchReader (v0.9.4) ok: found v0.9.5
Checking for PerlMagick (any) ok: found v6.2.8
Checking for perl-ldap (any) ok: found v0.39
Checking for Authen-SASL (any) ok: found v2.13
Checking for RadiusPerl (any) ok: found v0.15
Checking for SOAP-Lite (any) ok: found v0.710.10
Checking for HTML-Parser (v3.40) ok: found v3.64
Checking for HTML-Scrubber (any) ok: found v0.08
Checking for Email-MIME-Attachment-Stripper (any) ok: found v1.316
Checking for Email-Reply (any) ok: found v1.202
Checking for mod_perl (v1.999022) ok: found v2.000004

我们可以看到,所有模块都已经安装完成。

# 设置 MySQL 数据库
在 /etc/my.cnf 文件的 [mysqld] 中添加
# Allow packets up to 4MB
max_allowed_packet=4M
# Allow small words in full-text indexes
ft_min_word_len=2

注意,配置文件在修改后需要重启 MySQL 数据库服务。

# 创建数据库用户:
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, INDEX, ALTER, CREATE, LOCK TABLES, CREATE TEMPORARY TABLES, DROP, REFERENCES ON bugs.* TO bugs@localhost IDENTIFIED BY '密码';
mysql> FLUSH PRIVILEGES;

# 创建数据库:
mysql> create database bugs;

# 开始安装过程
./checksetup.pl

# 修改 localconfig 文件:
修改 /usr/local/src/bugzilla-3.2.5/localconfig 文件,在 $db_pass = ''; 中设置上面创建数据库用户时所设置的密码

# 开始安装:
./checksetup.pl
请在这一步执行之前启动 MySQL 数据库服务,因为需要往数据库中写入数据。

最后提示:
Looks like we don't have an administrator set up yet.
Either this is your first time using Bugzilla, or your
administrator's privileges might have accidentally been deleted.


Enter the e-mail address of the administrator:
输入邮箱,登录时将使用这个进行登录。
Enter the real name of the administrator:
Enter a password for the administrator account: 输入密码
Please retype the password to verify: 确认密码

# 创建一个软链接到 web 目录:
ln -s /usr/local/src/bugzilla-3.2.5 /var/www/html/bugzilla

# 修改 Apache 的配置文件 /etc/httpd/conf/httpd.conf :
cat >> /etc/httpd/conf/httpd.conf << "EOF"

# BugZilla
Alias /bugzilla/ "/var/www/html/bugzilla/"
<Directory "/var/www/html/bugzilla/">;
AddHandler cgi-script .cgi
Options +ExecCGI
DirectoryIndex index.cgi
AllowOverride Limit
</Directory>
EOF


# 调整数据库:
mysql> use bugs
mysql> ALTER TABLE attachments AVG_ROW_LENGTH=1000000, MAX_ROWS=20000;


# 访问你的 BugZilla 吧~
访问之前当然要先启动你的 Apache 服务,浏览器访问 http://IP地址/bugzilla/ 就能看到你的 BugZilla 页面了~

  关于前面提到的CPAN的包,下载地址为:http://cid-bace553dcea1dbb1.skydrive.live.com/self.aspx/Blog%e7%9b%b8%e5%85%b3%e6%96%87%e4%bb%b6/bugzilla%5E_cpan.tar.bz2
  由于我整个安装过程都使用的 root 用户,这个包直接解压到 /root/ 目录即可,在安装过程中就不需要联网下载软件包了。

编译安装 ClamAV

  Clam AntiVirus(ClamAV)是免费而且开放源代码的防毒软件,软件与病毒码的的更新皆由社群免费发布。
  官方网站:http://www.clamav.net/

  这里我主要说明一下在 Linux 系统环境下 ClamAV 源代码包的编译安装方法。使用源代码包编译安装,依赖于以下软件:zlib, zlib-devel, gcc, bzip2, bzip2-devel 。

  ClamAV需要一个特定用户,从系统安全角度,我们也应该避免使用特权用户来运行程序。我们可以通过下面的命令创建这个用户:
  groupadd clamav
  useradd -g clamav -M -s /bin/false -c "Clam AntiVirus" clamav

  下面解压源代码包,开始进行编译。源代码安装的话,大多数人都有自己的习惯,我习惯于解压到 /usr/local/src/ 这个目录中。
  tar -xvzf clamav-x.xx.x.tar.gz -C /usr/local/src/
  cd /usr/local/src/clamav-x.xx.x
  注意,上面的 x.xx.x 代表你所使用的版本,不要直接复制我的命令……
  ./configure
  make
  make install

  默认安装的路径为 /usr/local/ 我没有特别指定路径。配置文件路径为 /usr/local/etc/ ,相关配置文件为 clamd.conf 和 freshclam.conf 。

  配置文件 clamd.conf 为主配置文件,里面设定和扫描相关的东西。我一般使用下面内容:
# egrep -v '^#|^$' clamd.conf
LogFile /var/log/clamd.log
LogFileMaxSize 2M
LogTime yes
LogFacility LOG_MAIL
LogVerbose yes
PidFile /var/run/clamav/clamd.pid
TemporaryDirectory /var/tmp
DatabaseDirectory /var/lib/clamav
LocalSocket /var/run/clamav/clamd.socket


  配置文件 freshclam.conf 为更新配置文件,病毒数据库的更新需要在这里进行设置。我一般使用下面内容:
# egrep -v '^#|^$' freshclam.conf
DatabaseDirectory /var/lib/clamav
UpdateLogFile /var/log/freshclam.log
LogFileMaxSize 2M
LogTime yes
LogVerbose yes
LogFacility LOG_MAIL
PidFile /var/run/clamav/freshclam.pid
DatabaseOwner clamav
DatabaseMirror db.cn.clamav.net
DatabaseMirror database.clamav.net


  配置文件中对于各个参数都有很详细的描述,具体参数的意义请自行参考。

  在不修改配置文件的情况下,默认病毒数据库存放在 /usr/local/share/clamav/ 。

  根据我修改的配置文件,需要做下面的操作,因为我把数据库放到了 /var/lib/clamav/
  mkdir /var/lib/clamav
  mv /usr/local/share/clamav/*.cvd /var/lib/clamav
  chown -R clamav:clamav /var/lib/clamav
  上面的 *.cvd 其实就是离线病毒库,在官方网站也能下载到,方便那些不能使用在线更新的用户。将你下载到的 *.cvd 文件放到 /var/lib/clamav/ 目录下即可,呃,文件权限的话,我没具体测试,还是改一下比较好吧~这个问题我看看再更新文章。

  在我的配置文件中设置了日志的路径,但受权限影响,clamav 用户无法在 /var/log/ 下自行创建日志文件,使用下面命令:
  touch /var/log/{clamd,freshclam}.log
  chmod 600 /var/log/{clamd,freshclam}.log
  chown clamav /var/log/{clamd,freshclam}.log

  套接字和PID文件的目录也需要创建一下……
  mkdir /var/run/clamav
  chown clamav /var/run/clamav/

  关于病毒数据库的自动更新:我们可以使用命令 freshclam 来手动更新数据库,但这明显很麻烦,当然你也可以通过 cron 的计划任务来解决这个问题,不过 ClamAV 自身就能实现后台自动更新,我们只需要通过下面命令的方式启动更新:
  freshclam -d
  这个更新的频率是受 freshclam.conf 配置文件中的参数影响的:
  # Number of database checks per day.
  # Default: 12 (every two hours)
  #Checks 24
  默认是每2小时更新一次。

  最后说一下怎么扫描吧……用命令 clamscan 就能对当前所在路径进行扫描。更具体的参数,man 去吧,也许某天我会在这更新……本文以编译安装为主……

  关于扫描进行一下补充:使用 clamscan 进行扫描的时候,在对文件访问权限判断时,使用的是当前执行命令用户的权限。比如我现在使用 root 用户执行 clamscan 命令,那么当前的权限为 root 即任何文件都可以正常访问。但如果使用 clamdscan 进行扫描的话,使用的是 clamav 这个用户权限,比如扫描 /sbin 目录时,必定会碰到 Access denied. ERROR 这样的报告,因为 other 组没有读取权限……

  你能通过 man 查到以下资料:
  clamconf,clamdscan,clamdtop,clamscan,freshclam,clamd.conf,freshclam.conf,clamav-milter,clamd

关于 Linux 系统分区

  今天在群里讨论到 Linux 的系统分区,想起自己原来做过一个测试,把结果发在这里吧~

Linux 安装分区研究资料

  CentOS 5.2 完整安装,使用自定义安装 全部勾选其默认包,不再深入添加,语言好多……没有了 4 里的完整安装选项,勾语言相当郁闷……

虚拟机测试情况:25G 硬盘空间分配如下:

SWAP          2G      sda5
/             1G      sda7
/boot       100M      sda1
/home       100M      sda10
/tmp          2G      sda3
/usr        8.5G      sda2
/var          1G      sda6
/usr/local  100M      sda9
/opt        100M      sda8

完整安装的情况下,需要有 6376MB 的空间(还不确定是 / 还是 /usr)
  如果给 / 和 /usr 分配 7G 空间进行安装时会报以下错误:
You need more space on the following file systems: 853M on /mnt/sysimage/usr

进行空间调整测试:
  根据上条系统的反馈信息,判断系统的安装过程类似于 LFS 的构建,所以 /mnt/sysimage/usr 应该是对应以后真正的 /usr 目录。因此,调整 / 目录大小为 5G,因为/目录下东西并不多。调整 /usr 目录大小为 8G,系统很多文件都是存放在这里。
结果系统再次提示:
You need more space on the following file systems: 39M on /mnt/sysimage/usr
  由此可以看出,之前的判断是正确的,继续调整 /usr 文件系统大小既可。

  根据原来安装好的系统进行研究,发现系统所使用的空间主要还是集中在 /usr 这个目录上,其实 / 目录基本就占不了什么空间,所以最后这次调整只分配给 / 目录 1G 的空间,分给 /usr 目录8.5G空间。

终于开始正常的系统安装过程……
15:43开始
16:43结束

安装完成后的结果如下:
# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda7             996M  290M  655M  31% /
/dev/sda10             99M  5.6M   89M   6% /home
/dev/sda8              99M  5.6M   89M   6% /opt
/dev/sda6             996M  152M  793M  17% /var
/dev/sda3             2.0G   36M  1.9G   2% /tmp
/dev/sda2             8.3G  6.9G  959M  89% /usr
/dev/sda9              99M  5.6M   89M   6% /usr/local
/dev/sda1              99M   18M   77M  19% /boot
tmpfs                 506M     0  506M   0% /dev/shm

/目录下,各个文件夹的大小如下:
/bin         7.1M
/dev         132K
/misc           0
/lost+found   16K
/net            0
/proc           0
/sbin         35M
/srv         8.0K
/etc         120M
/lib         122M
/media       8.0K
/mnt         8.0K
/root        684K
/selinux     8.0K
/sys            0

恢复 Linux 的满屏乱码

  在使用 Linux 的过程中,我们可能会碰到这样的情况:不小心用 cat 打开了一个二进制文件后,出现满屏的乱码,无法恢复,这时我们可以通过下面的一个命令来恢复屏幕:
  reset
  由于屏幕乱码,所以敲的时候只能盲打了,你没法在屏幕确认自己到底打的什么。打命令之前,先按 Ctrl + C 防止命令执行时出现问题。

列出 Apache 目录内容

  在 Apache 中要列出目录内容需要 mod_autoindex 模块的支持。

  配置文件的设置方法:

 打开列目录功能:
<Directory /path/to/directory>
Options +Indexes
</Directory>

 关闭列目录功能:
<Directory /path/to/directory>
Options -Indexes
</Directory>


  在使用如 RHEL 或 CentOS 发行版自带 Apache 的朋友可能会碰到这样的问题,无法列出网站根目录下面的内容。其实问题原因很简单,因为 Apache 除了会读取 /etc/httpd/conf/httpd.conf 配置文件外,还会读取 /etc/httpd/conf.d/ 下以 .conf 结尾的文件。
  在 /etc/httpd/conf.d/ 下有一个名为 welcome.conf 的文件,这文件的内容如下:
#
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL.  To disable the Welcome page, comment
# out all the lines below.
#
<LocationMatch "^/+$">
    Options -Indexes
    ErrorDocument 403 /error/noindex.html
</LocationMatch>
  我们可以看到文件中去掉了目录的Indexes属性,这导致无法列出根目录的内容。可以通过更改这个文件的后缀名或者注释掉选项并重新加载配置文件解决该问题。
下一页