CentOS5.3にpython2.5とmercurial1.3.1をインストール

はまったのでメモ。
CentOS5.3にpython2.6をインスコした状態でmercurial1.3.1をインストールする際の注意事項。
Pythonをソースからインスコして、mercurialもソースからインスコして使っていたら以下のようなエラーが出る。

[shohu@hoge]~/test/fuga% hg add test.txt
中断: モジュール _ssl の読み込みに失敗!

これはPythonの以下のような設定して、ソースインスコしないとNG。
_sslモジュールを入れる設定をしなければだめ。

$ wget http://python.org/ftp/python/2.5.2/Python-2.5.2.tgz
$ tar xvzf Python-2.5.2.tgz
$ cd Python-2.5.2
$ ./configure --enable-shared
$ vi Modules/Setup

    以下のファイルを有効にする

    zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

    SSL=/usr
    _ssl _ssl.c \
    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
    -L$(SSL)/lib -lssl -lcrypto


$ make
$ make install
$ ldconfig

DjangoでER図 in CentOS

Djangoのdjango-command-extensions で manage.py のコマンドを色々拡張することができる。
その中でも気にいっているのがgraph_models
モデルをER図のような画像で出力してくれる。
f:id:shohu33:20090907001148j:image
さっそく画像出力までを試してみた。

準備

Graphviz

グラフ表現を GIF や PNG などのファイルフォーマットに変換してくれるライブラリをインスコ

$ wget http://www.graphviz.org/graphviz-rhel.repo
$ cp graphviz-rhel.repo /etc/yum.repos.d/
$ sudo yum install graphviz
$ sudo yum install graphviz-devel graphviz-doc
pygraphviz

pythonからGraphvizを使うためのもの

$ wget http://pypi.python.org/packages/source/p/pygraphviz/pygraphviz-0.99.1.tar.gz#md5=5381633f9538804b24046eb96474668d
$ tar zxvf pygraphviz-0.99.1.tar.gz
$ cd pygraphviz-0.99.1
$ sudo python setup.py install 
django-command-extensions

拡張コマンド本体をインスコ
http://code.google.com/p/django-command-extensions/
からソースを落として以下でインスコ

python setup.py install

あとはsettings.pyのINSTALLED_APPSに以下を記載しておく

INSTALLED_APPS = (
    ...
    'django_extensions',
)

画像出力

djangoプロジェクトに移動して以下実行

$ python manage.py graph_models -a -g -o hoge.png

ホスト名の変更

以下URLから抜粋
http://www.searchman.info/tips/1360.html

Linuxサーバのホスト名を変更します。

一時的にホスト名を変更する場合

#hostname xxxx

これで、xxxxというホスト名に変更しました。
しかし、再起動すると、この変更は無効になります。


再起動しても有効になる変更は、
2箇所のファイルの変更が必要になります。

#vi /etc/hosts
127.0.0.1 xxxx localhost.localdomain localhost

#vi etc/sysconfig/network

NETWORKING=yes
HOSTNAME=xxxx
GATEWAY=192.168.0.1

※
ゲートウェイの設定もここで行います。

変更が終わった後は、ネットワークの再起動を行います。

# /etc/rc.d/init.d/network restart

SSL自己署名 CentOS4

WebArena の CentOS4上でのSSL自己認証。

# cd /etc/httpd/conf
# openssl genrsa 1024 > server.key
# openssl rsa -in server.key -out server.key ← サーバー用秘密鍵からパスワード削除
公開鍵の作成
# openssl req -new -key server.key -out server.csr
サーバー用証明書作成
# openssl x509 -in server.csr -out server.pem -req -signkey server.key -days 365
# chmod 400 server.*
# vi /etc/httpd/conf/httpd.conf
-----
Include conf/extra/httpd-ssl.conf
-----
# vi /etc/httpd/conf/extra/httpd-ssl.conf ← ApacheSSL設定ファイル編集
-----
SSLCertificateFile /etc/httpd/conf.d/server.pem ← サーバー用証明書を指定※CentOS5の場合
-----

iptablesの設定 CentOS5

最近の Linuxiptables がポートとパケットの管理をしています サーバーとして使用するため設定します。

Web.DNS.Mail.FTP.SSH,SSL を利用します

 iptables -A INPUT -p icmp -j ACCEPT
 iptables -A INPUT -p tcp -j ACCEPT
 iptables -A INPUT -p udp -j ACCEPT
 iptables -A INPUT -i lo -j ACCEPT
 iptables -A INPUT -p tcp --dport 80 -j ACCEPT
 iptables -A INPUT -p tcp --sport 80 -j ACCEPT     // #80 Web
 iptables -A INPUT -p tcp --dport 443 -j ACCEPT
 iptables -A INPUT -p tcp --sport 443 -j ACCEPT     // #443 SSL
 iptables -A INPUT -p tcp --dport 53 -j ACCEPT
 iptables -A INPUT -p tcp --sport 53 -j ACCEPT
 iptables -A INPUT -p udp --dport 53 -j ACCEPT
 iptables -A INPUT -p udp --sport 53 -j ACCEPT     // #53 DNS
 iptables -A INPUT -p tcp --dport 20 -j ACCEPT
 iptables -A INPUT -p tcp --sport 20 -j ACCEPT
 iptables -A INPUT -p tcp --dport 21 -j ACCEPT
 iptables -A INPUT -p tcp --sport 21 -j ACCEPT     // #20 #21 FTP

 iptables -A INPUT -p tcp --dport 110 -j ACCEPT
 iptables -A INPUT -p tcp --sport 110 -j ACCEPT    // #110 POP

 iptables -A INPUT -p tcp --dport 25 -j ACCEPT
 iptables -A INPUT -p tcp --sport 25 -j ACCEPT     // #25 SMTP
 iptables -P INPUT DROP
 /etc/rc.d/init.d/iptables save
 iptables -L INPUT --line-number
Chain INPUT (policy DROP)
num  target     prot opt source               destination
1    RH-Firewall-1-INPUT     all --  anywhere             anywhere
:
:
RH-Firewall-1-INPUTのルールを削除する。
 iptables -D INPUT 1