Tracの導入@Debian etch

Tracはメジャーなオープンソースのバグトラッキングシステム。

Subversionと連携させるために、事前にリポジトリを作っておくこと。(ここでは省略します)
ここでは/home/svnに作っているとします。
さらに、revision 1がないと、Trac初期化時に以下のエラーになるので注意。

~省略~
Failed to initialize environment. ('No such revision 1', 160006)
raceback (most recent call last):
File "/var/lib/python-support/python2.4/trac/scripts/admin.py", line 628, in do_initenv
repos = self.__env.get_repository()Failed to initialize environment. ('No such revision 1', 160006)
Traceback (most recent call last):
File "/var/lib/python-support/python2.4/trac/scripts/admin.py", line 628, in do_initenv
repos = self.__env.get_repository()
~省略~

インストール

まずは

# apt-get install trac

次にtrac-adminコマンドで初期化

# mkdir /home/trac
# trac-admin /home/trac
...
Project Name [My Project]> ←プロジェクト名を入力
...
Database connection string [sqlite:db/trac.db]> ←デフォルトのsqliteを使用するのでそのままリターン
...
Repository type [svn]> ←リターン
...
Path to repository [/path/to/repos]> /home/svn ←入力
...
Templates directory [/usr/share/trac/templates]> ←リターンCreating and Initializing Project …..省略
Congratulations!

起動確認

tracには簡易的なWebサーバが付属しています。これを使って起動確認をしてみます。

# tracd --port 80 /home/trac

これでブラウザからアクセスできればOK

Apacheとの連携

アクセスユーザの設定

# htpasswd パスワードファイル名(/etc/apache/passwdなど) ユーザ名

tracをapacheに追加してあげます。

# vi /etc/apache2/sites-available/trac

アクセスはポート8080にしています。
ファイル内容

Listen 8080
<VirtualHost *:8080>
ServerAdmin webmaster@localhost
DocumentRoot /usr/share/trac/htdocs/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/httpd/root/>
AllowOverride AuthConfig Limit
</Directory>ScriptAlias /trac /usr/share/trac/cgi-bin/trac.cgi
<Location “/trac”>
SetEnv TRAC_ENV “/home/trac”
</Location>
<LocationMatch “/trac/login”>
AuthType Basic
AuthName “Trac”
AuthUserFile パスワードファイル名
Require valid-user
</LocationMatch>
ServerSignature Off
</VirtualHost>

Pluginの導入

チケットのタイプとかコンポーネントとかの管理がコマンドラインからしかできません。
なので、WebAdminというプラグインを導入します。
プラグインのeggファイルを扱うためにpythonのツールをインストール

# apt-get install python-setuptools
# wget http://trac.edgewall.org/attachment/wiki/WebAdmin/TracWebAdmin-0.1.2dev_r4240-py2.4.egg.zip?format=raw
# mv TracWebAdmin-0.1.2dev_r4240-py2.4.egg.zip?format=raw /home/trac/plugin/TracWebAdmin-0.1.2dev_r4240-py2.4.egg

/home/trac/conf/trac.iniに以下のように記述

[components]
webadmin.* = enabled

サーバ再起動は必要ないはずですが、アクセスすると以下のようなエラーになります。

(抜粋)

ExtractionError: Can't extract file(s) to egg cache
The following error occurred while trying to extract file(s) to the Python egg cache:
[Errno 13] Permission denied: '/var/www/.python-eggs'
The Python egg cache directory is currently set to:
/var/www/.python-eggs

これはeggファイルキャッシュディレクトリにアクセス権限がないからです。
なので、apacheの設定でキャッシュディレクトリを以下のように設定してあげます。

<Location "/trac">
SetEnv TRAC_ENV "/home/trac"
SetEnv PYTHON_EGG_CACHE /tmp/traceggcache ★追加
</Location>

そして、以下を実行

# mkdir /tmp/traceggcache
# chown www-data:www-data /tmp/traceggcache
# /etc/init.d/apache reload

あと、デフォルトだとADMIN権限を持っていませんので、ADMIN権限を与えます。

# trac-admin /home/trac permission add ユーザ名 TRAC_ADMIN

これで正常にadminとう項目がTrac上に出てきます。

DBについて

デフォルトではSQLiteが使用されます。Debian etchのsqliteはバージョン2系で、sqliteコマンドでは以下のようなエラーになります。

Unable to open database "tracbak.db": file is encrypted or is not a database

3系をインストールしてアクセスしましょう。

# apt-get install sqlite3
# sqlite3 dbファイル名

mod_pythonの導入

デフォルトのcgiモードだと、だんだんと動作が鈍くなってきます。
以下の通りmod_pythonを入れると速くなります。

# apt-get install libapache2-mod-python

apacheの設定ファイル tracを編集

<Location "/trac">
#SetEnv TRAC_ENV "/home/trac"
SetEnv PYTHON_EGG_CACHE /tmp/traceggcache
SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonOption TracEnv /home/trac
</Location>

LDAPサーバ構築 その2 - Sambaサーバとの連携 @ Debian etch

LDAP+SambaでPDCを構築する方法です。

 # apt-get install samba-doc smbldap-tools 

設定は基本的には/usr/share/doc/smbldap-tools/README.Debian.gzに書かれています。

LDAPのSamba用スキーマをインストールします。

 # zcat /usr/share/doc/samba-doc/examples/LDAP/samba.schema.gz > /etc/ldap/schema/samba.schema

samba.schemaを/etc/ldap/slapd.confに追記します。

include       /etc/ldap/schema/samba.schema

性能向上のために、ldapのDBにインデックスをはります。同様にslapd.confに追記。

 index         uid,uidNumber,gidNumber,memberUid       eq index         cn,mail,surname,givenname               eq,subinitial

index sambaSID eq
index sambaPrimaryGroupSID eq
index sambaDomainName eq

パスワードへのアクセスを変更

 access to attribute=userPassword

 access to attrs=userPassword,sambaNTPassword,sambaLMPassword

に変更

で、LDAPサーバを再起動します。

# /etc/init.d/slapd restart

Sambaの設定です。
/etc/samba/smb.confのすでにある設定項目を変更

...

 passdb backend = ldapsam:ldap://127.0.0.1/

obey pam restrictions = no
passwd program = /usr/sbin/smbldap-passwd %u
passwd chat = *New*password* %n\n *Retype*new*password* %n\n

さらに以下をGlobalの最後に追記

 os level = 64preferred master = Yes

domain master = Yes

ldap suffix = dc=hoge,dc=net

ldap machine suffix = ou=Computers

ldap user suffix = ou=Users

ldap group suffix = ou=Groups

ldap admin dn = cn=admin,dc=hoge,dc=net

ldap passwd sync = Yes

ldap ssl = No

*all*authentication*tokens*updated*

add user script = /usr/sbin/smbldap-useradd -m "%u"

ldap delete dn = Yes

delete user script = /usr/sbin/smbldap-userdel "%u"

add machine script = /usr/sbin/smbldap-useradd -w "%u"

add group script = /usr/sbin/smbldap-groupadd -p "%g"

delete group script = /usr/sbin/smbldap-groupdel "%g"

add user to group script = /usr/sbin/smbldap-groupmod -m "%u" "%g"

delete user from group script = /usr/sbin/smbldap-groupmod -x "%u" "%g"

set primary group script = /usr/sbin/smbldap-usermod -g "%g" "%u"

#======================= Share Definitions =======================

次にsmbldap-toolsの設定。これはsambaのユーザ管理などのツールで、パスワードをUnixユーザと同期させたりできます。
まずは設定

# zcat /usr/share/doc/smbldap-tools/examples/smbldap.conf.gz > /etc/smbldap-tools/smbldap.conf
# cp /usr/share/doc/smbldap-tools/examples/smbldap_bind.conf /etc/smbldap-tools/smbldap_bind.conf

/etc/smbldap-tools/にできたファイルを適宜変更します。
smbldap.confのSIDは

 # net getlocalsid

コマンドで取得できます。(Sambaを起動しておく必要あり?)
あと、ldapTLSは、今回はTLSを使用しないので”0″にします。
smbldap_bind.confにはadminのdnとパスワードを記述します。
最後に初期データ投入

 # smbldap-populate -u 2000 -g 2000

-u -g でUID,GIDのスタート値を設定できます。
ユーザの追加は

 # smbldap-useradd -a -N "hoge name" -u 2001 hogehoge

といった感じ

暗号化パスワードの生成

LDAPブラウザなどで直接ユーザのパスワードを変更したい場合、暗号化したパスワードが必要になるときがあります。

暗号化パスワードを生成したい場合は以下のようにして生成できます。

# slappasswd -h {CRYPT}

{CRYPT}は{md5}や{SMD5}などを指定。


LDAPサーバ構築 @ Debian etch

まずはapt-getでインストールします

# apt-get install slapd ldap-utils

インストールすると、自動的にホストのDNSからBaseDNが設定されます。
また、cn=adminというadmin権限ユーザも登録されます。

たとえば、hoge.netというホストならば、

# ldapsearch -W -x -Lb "dc=hoge,dc=net" -D "cn=admin,dc=hoge,dc=net"

とすれば、LDAP検索できます。

設定ファイルをいじってもいいですが、

# dpkg-reconfigure slapd

とすると対話形式でも設定できます。


デフォルトサーバ証明書の更新 @ CentOS 4

インストール時に自動的にインストールされるApacheのSSLの証明書を更新する方法。

# openssl req -new -key /etc/httpd/conf/ssl.key/server.key -x509 -days 365 -out /etc/httpd/conf/ssl.crt/server.crt

もちろん俺々証明書です。-daysの部分が有効期限の日数なので、期限長くしたい場合はここの数字を変えてください。


WordPress プラグイン - Stat Traq導入

アクセス統計をとってくれるプラグインStat TraqをWordPressに導入しました。

Downloadはこちらから。

インストールはサイトに載っている通りなのですが、一応メモとして残しておきます。

  • 上記サイトからプラグインをダウンロード
    • ファイル名 : StatTraq_V1-1-1.zip
  • zipファイルを展開したらwp-contentとwp-stattraqというディレクトリが現れます。wp-content/plugins/stattraq.php をWordPressインストールディレクトリのwp-content/pluginsディレクトリへコピー。
  • wp-stattraqディレクトリはWorldPressインストールディレクトリの直下に置きます。
  • WordPressの管理ページのプラグインにStatTraqが現れるので有効にします。
  • ブラウザでhttp://blogのURL/wp-stattraq/stattraq-install.phpにアクセスし、”Create the StatTraq Table for version 1.1″をクリックするとデータベースにテーブルが作成され準備完了。

あとは管理画面からStatTraqからアクセスすれば統計情報が見られます。

統計情報例として、ページ毎のアクセス数、アクセス元のIP、リンク元などが取得できます。