ご連絡



地味にリンクはってたのですが勤務している会社のページが大幅リニューアル
したのでリンク張っておきます。


ビットスター株式会社



サイトみてもらうとわかりますが、サーバーハウジングなどのデータセンター事業、
Webシステム構築事業、仮想化事業(このブログもある意味仕事の一部!?)を
やってます。


興味、お問い合わせある方は気軽に連絡してください。

Xen + Asterisk1.6 構築編

オープンソースIP-PBXで有名なAsterisk1.6をXen上に構築。


[domu]# yum install -y gcc
[domu]# yum install -y openssl*
[domu]# yum install -y libtermcap*
[domu]# yum install -y kernel-xen*
[domu]# reboot


[domu]# wget http://downloads.digium.com/pub/asterisk/releases/asterisk-1.6.1.0.tar.gz
[domu]# tar xzvf asterisk-1.6.1.0.tar.gz
[domu]# cd asterisk-1.6.1.0
[domu]# ./configure
[domu]# make
[domu]# make install


インストール自体は特に問題なく完了。
ちなみにXen+Asterisk1.4の場合はztdummy.cの以下を編集しないとインストールできなかった
はずなので(日本語の文献・サイトが少なくかなりはまった)ものすごく楽になりました。

[ztdummy.c]
#undef USE_RTC の1行を追加

次回以降はAsterisk1.6でいろいろ遊びます。

NFSとiSCSIの性能差

Xenを構築時、Domain-Uのイメージファイルの置き場所として安価に構築しようとした場合
・ローカルのHDD
NFS接続された領域
iSCSI接続された領域
が考えられる。
それぞれのRead/Write性能を比較し、RW性能以外の長所/短所を踏まえた上で決定すべき。


で、今回はRW性能比較について検証。


<前提条件>
ServerA <-- 100Mbps --> ServerB
ServerB上にiSCSI接続用のイメージファイルとNFS接続用のディレクトリを作成
約1GBのファイルをWrite/Read
NFSiSCSI、ローカルHDD(SATA/7200回転)


まずはiSCSINFSをマウントし以下のコマンドでファイルの書き込みを行う。
[ServerA #] time dd if=/dev/zero of=/mnt/iscsi-vol/testfile bs=128k count=8192
8192+0 records in
8192+0 records out
1073741824 bytes (1.1 GB) copied, 29.4537 seconds, 36.5 MB/s
real 0m29.457s
user 0m0.008s
sys 0m2.540s




NFS

iSCSI

ローカルHDD

Write1回目

1073741824 bytes (1.1 GB) copied, 107.903 seconds, 10.0 MB/s

1073741824 bytes (1.1 GB) copied, 29.4537 seconds, 36.5 MB/s

1073741824 bytes (1.1 GB) copied, 7.62334 seconds, 141 MB/s

Write2回目

1073741824 bytes (1.1 GB) copied, 161.972 seconds, 6.6 MB/s

1073741824 bytes (1.1 GB) copied, 29.9452 seconds, 35.9 MB/s

1073741824 bytes (1.1 GB) copied, 7.45572 seconds, 144 MB/s

Write3回目

1073741824 bytes (1.1 GB) copied, 163.577 seconds, 6.6 MB/s

1073741824 bytes (1.1 GB) copied, 29.8378 seconds, 36.0 MB/s

1073741824 bytes (1.1 GB) copied, 7.36467 seconds, 146 MB/s

Read1回目

1073741824 bytes (1.1 GB) copied, 66.9923 seconds, 16.0 MB/s

1073741824 bytes (1.1 GB) copied, 53.7887 seconds, 20.0 MB/s

1073741824 bytes (1.1 GB) copied, 15.4124 seconds, 69.7 MB/s

Read2回目

1073741824 bytes (1.1 GB) copied, 35.1438 seconds, 30.6 MB/s

1073741824 bytes (1.1 GB) copied, 0.816578 seconds, 1.3 GB/s

1073741824 bytes (1.1 GB) copied, 0.931104 seconds, 1.2 GB/s

Read3回目

1073741824 bytes (1.1 GB) copied, 3.01381 seconds, 356 MB/s

1073741824 bytes (1.1 GB) copied, 0.790862 seconds, 1.4 GB/s

1073741824 bytes (1.1 GB) copied, 0.914567 seconds, 1.2 GB/s
Readについてはキャッシュの影響が大きいためあまり参考にならないがWriteについてはNFSiSCSIの間で3倍〜5倍程度の差が生じている。
転送速度をみてもネットワーク環境がGBネットワークであればiSCSIとローカルHDDはほとんど速度を意識することなく使えそう。

Xen Domain-Uバックアップ(3)

Xen Domain-Uバックアップ(2)でLVMスナップショットを利用したバックアップ方法を記載したが、以下の課題点があった。
・すでに構築済みの場合、LVMスナップショットで使用する容量を確保するために論理ボリュームのサイズ変更が必要。(サーバを停止、再起動する必要がある。)
・XenDomain-Uが大きいほど+数が多いほどLVMスナップショット領域が必要となり、そのための容量が通常時は使用できない。


これらを解決するためのオンラインバックアップ方法として前回のエントリで使用したiSCSIを利用してNW上の他のサーバー上にLVMスナップショット領域を作成し、取得する方法を紹介。
以下の手順で作業を行う。


1)iSCSI target(スナップショット用領域)を作成
2)iSCSIを接続しPVを作成→VGに追加
3)スナップショット領域を作成し、マウント
4)XenDomain-Uのバックアップ
5)スナップショット領域をアンマウント
6)スナップショット領域を削除
7)VGからiSCSI領域を切り離し
8)iSCSIを切断


iSCSI targetの作成は前回のエントリを参照
[root@iscsi-target ~]# dd if=/dev/zero of=/tmp/iscsi-test.img bs=1G count=24 (24Gのスナップショット用領域を作成)
[root@iscsi-target ~]# vi /etc/ietd.conf
以下を編集
#Target iqn.2001-04.com.example:storage.disk2.sys1.xyz
Target iqn.2009-04.iscsi.sample:storage.sample
Lun 0 Path=/tmp/iscsi-test.img,Type=fileio


[root@iscsi-target ~]# /etc/rc.d/init.d/iscsi-target start


iSCSI clientの作成は前回のエントリを参照
[root@xen-dom0 ~]# vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2

Act PV 1
VG Size 145.91 GB
PE Size 32.00 MB
Total PE 4669
Alloc PE / Size 4669 / 145.91 GB
Free PE / Size 0 / 0 空き容量なし


[root@xen-dom0 ~]# iscsiadm -m node --targetname iqn.2009-04.iscsi.sample:storage.sample --portal :3260 -l (iSCSIに接続)
[root@xen-dom0 ~]# fdisk -l (iSCSI領域の確認)
Disk /dev/sda: 158.9 GB, 158999773184 bytes
255 heads, 63 sectors/track, 19330 cylinders
Units = シリンダ数 of 16065 * 512 = 8225280 bytes


バイス Boot Start End Blocks Id System
/dev/sda1 * 1 8 64228+ de Dell ユーティリティ
/dev/sda2 9 270 2104515 c W95 FAT32 (LBA)
/dev/sda3 271 283 104422+ 83 Linux
/dev/sda4 284 19330 152995027+ 5 拡張領域
/dev/sda5 284 19330 152994996 8e Linux LVM


↓ここiSCSI領域
Disk /dev/sdc: 25.7 GB, 25769803776 bytes
64 heads, 32 sectors/track, 24576 cylinders
Units = シリンダ数 of 2048 * 512 = 1048576 bytes


[root@xen-dom0 ~]# pvcreate /dev/sdc
[root@xen-dom0 ~]# vgextend VolGroup00 /dev/sdc ※VGに/dev/sdcを追加
[root@xen-dom0 ~]# vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2

Act PV 2
VG Size 169.88 GB
PE Size 32.00 MB
Total PE 5436
Alloc PE / Size 4669 / 145.91 GB
Free PE / Size 767 / 23.97 GB 追加した分空き容量が増えてる


空き容量ができたのであとはXen Domain-Uバックアップ(2)の方法でオンラインバックアップ
[root@xen-dom0 ~]# lvcreate -s -L 20G -n snap-vol /dev/VolGroup00/LogVol00
[root@xen-dom0 ~]# mount /dev/VolGroup00/snap-vol /mnt/snapshot/
[root@xen-dom0 ~]# rsync -av /mnt/snapshot/var/lib/xen/images/***.img /バックアップ先
[root@xen-dom0 ~]# umount /mnt/snapshot/
[root@xen-dom0 ~]# lvremove /dev/VolGroup00/snap-vol
[root@xen-dom0 ~]# vgreduce VolGroup00 /dev/sdc ※VGからiSCSI領域を切り離す
[root@xen-dom0 ~]# iscsiadm -m node --targetname iqn.2009-04.iscsi.sample:storage.sample --portal :3260 --logout (iSCSIを切断)

CentOS+iSCSI設定

iSCSIを使って論理ボリューム上で使用できる容量アップを行う。


iSCSI targetの作成
1)必要なパッケージのインストール(gcc/OpenSSL-devel/kernel-devel)
2)iSCSI targeのインストール
3)iSCSI設定ファイルの編集
4)iSCSI接続先ファイルの作成
5)サービスの起動


iSCSI clientの作成
1)iSCSI initisatorのインストール
2)接続設定
3)ファイル領域の作成


iSCSI target
[root@iscsi-target ~]# yum install -y gcc
[root@iscsi-target ~]# yum install -y openssl-devel
[root@iscsi-target ~]# yum install -y kernel-* (kernel-xenの場合は lernel-xen-*)
[root@iscsi-target ~]# reboot
※rebootできない環境の場合は
uname -r -m で使用しているカーネルを特定しそれに対応したkernel-develをインストール(バージョン違いに注意)
ちなみに私の環境では
[root]# uname -r -m
2.6.18-92.1.10.el5xen i686
[root]# wget ftp://mirror.switch.ch/pool/3/mirror/centos/5.2/updates/i386/RPMS/kernel-xen-devel-2.6.18-92.1.10.el5.i686.rpm
[root]# rpm -ivh kernel-xen-devel-2.6.18-92.1.10.el5.i686.rpm
で環境を作成しました。


[root@iscsi-target ~]# wget http://jaist.dl.sourceforge.net/sourceforge/iscsitarget/iscsitarget-0.4.15.tar.gz
[root@iscsi-target ~]# tar xzvf iscsitarget-0.4.15.tar.gz
[root@iscsi-target ~]# cd iscsitarget-0.4.15
[root@iscsi-target ~]# make
[root@iscsi-target ~]# make install
[root@iscsi-target ~]# vi /etc/ietd.conf
以下を編集
#Target iqn.2001-04.com.example:storage.disk2.sys1.xyz
Target iqn.2009-04.iscsi.sample:storage.sample
Lun 0 Path=/tmp/iscsi-test.img,Type=fileio


[root@iscsi-target ~]# dd if=/dev/zero of=/tmp/iscsi-test.img bs=256M count=8 (2Gの領域を作成)
[root@iscsi-target ~]# /etc/rc.d/init.d/iscsi-target start
ここでエラーの場合kernelとkernel-develのバージョンにずれがないか確認


[root@iscsi-target ~]# chkconfig iscsi-target on


iSCSI client
[root@iscsi-client ~]# yum -y install iscsi-initiator-utils
[root@iscsi-client ~]# /etc/init.d/iscsi start
[root@iscsi-client ~]# iscsiadm -m discovery -t sendtargets -p (iSCSI接続先情報の表示)
[root@iscsi-client ~]# iscsiadm -m node --targetname iqn.2009-04.iscsi.sample:storage.sample --portal :3260 -l (iSCSIに接続)
[root@iscsi-client ~]# fdisk -l (iSCSI領域の確認)
この後は通常のHDDとして使用できるためfdiskでパーティション作成、pvcreate、vgcreate、lvcreate等で
ファイル領域として使用できる

Xen Domain-Uの時刻について

Xen上で動くDomain-Uの時刻はホストOSから取得しているようでDomain-U上でntpdateを使用して時刻合わせをしようとしても変更されない。
なのでホストOSを作成の際には必ずntpdateを使用して時刻同期をしてからDomain-Uを作成すること。
やむを得ずDomain-Uか稼働している状態で時刻同期をする場合はDomain-Uの時刻が止まったり、飛んだりするのでcronなどの動作に注意して設定すること。
念のため時刻同期の方法は以下。


1)ホストOS上でntpdateで時刻同期
2)ntpd もしくは cron で定期的に時刻同期を行う。


[root@host~] ntppdate ntp.nict.jp
[root@host~] vi /etc/ntp.conf
以下を編集
server ntp.nict.jp
server ntp1.jst.mfeed.ad.jp


[root@host~] service ntpd start
[root@host~] chkconfig ntpd on


もしくは
[root@host~] crontab -e
以下を追加
0 0 * * * /usr/sbin/ntpdate ntp.nict.jp 毎日0時に時刻同期


※その他
一部の環境でDomain-U上で
[root@domu~] ntpdate -B ntp.nict.jp
を行った後に yum list などを行うと


[root@domu~]# yum list
浮動小数点演算例外です


などと意味のわからないエラーが発生。
とりあえずは
[root@domu~] ntpdate -b ntp.nict.jp
とするとエラーは発生しなくなる模様。
詳細は調査中です。

CentOS+OpenSSL(自己署名証明書)

OpenSSLを使って秘密鍵と証明書を作成しhttps通信を行う。
社内サイトなどの暗号化したいけど認証機関の証明書は必要ないというときに利用。
(いわゆるオレオレ証明書)


1)秘密鍵の作成(openssl genrsa)
2)RSA秘密鍵パスフレーズ削除(openssl in out)
3)証明書要求(CSR)の作成(openssl req)
4)10年間有効な自己署名証明書の作成(openssl x509)
5)httpd.confの編集してapacheの再起動


[root@centos ~]# yum -y install mod_ssl
[root@centos ~]# openssl genrsa -des3 1024 > /etc/pki/tls/private/server.key


Generating RSA private key, 1024 bit long modulus
.................++++++
...................................................++++++
e is 65537 (0x10001)
Enter pass phrase for server.key: パスフレーズ
Verifying - Enter pass phrase for server.key: パスフレーズ


[root@centos ~]# openssl rsa -in /etc/pki/tls/private/server.key -out /etc/pki/tls/private/server.key
Enter pass phrase for server.key: パスフレーズ
writing RSA key


[root@centos ~]# chmod 400 /etc/pki/tls/private/server.key
[root@centos ~]# openssl req -new -key /etc/pki/tls/private/server.key -out /etc/pki/tls/certs/server.csr


Enter pass phrase for server.key: パスフレーズ
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.

        • -

Country Name (2 letter code) [AU]: JP
State or Province Name (full name) [Some-State]: Tokyo
Locality Name (eg, city) : Chuo-ku
Organization Name (eg, company) [Internet Widgits Pty Ltd]: hogehoge.inc
Organizational Unit Name (eg, section)
: hogehoge
Common Name (eg, YOUR name) : hogehoge.com
Email Address
: admin@hogehoge.com


Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password :
An optional company name
:


[root@centos ~]# openssl x509 -in /etc/pki/tls/certs/server.csr -out /etc/pki/tls/certs/server.crt -req -signkey /etc/pki/tls/private/server.key -days 3650


Enter pass phrase for server.key: パスフレーズ
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.

        • -

Country Name (2 letter code) [AU]: JP
State or Province Name (full name) [Some-State]: Tokyo
Locality Name (eg, city) : Chuo-ku
Organization Name (eg, company) [Internet Widgits Pty Ltd]: hogehoge.inc
Organizational Unit Name (eg, section)
: hogehoge
Common Name (eg, YOUR name) : hogehoge.com
Email Address
: admin@hogehoge.com


[root@centos ~]# vi /etc/httpd/conf.d/ssl.conf
以下を編集
SSLCertificateFile /etc/pki/tls/certs/server.crt
SSLCertificateKeyFile /etc/pki/tls/private/server.key


[root@centos ~]# service httpd restart