2007/07/24

PXEでCentOSをネットワークインストールする


新しく用意したマシンにCentOSをインストールしようとしたのだけれど、なんとこのマシンにはCDDもFDDもついてなかった!

というわけで、PXEネットーワークブートを使用してCentOSをインストールすることにしました。


PXEネットワークブート用サーバを構築



まずは、PXEネットワークブート用のサーバを構築します。

「@IT:PXEネットワークブート用サーバを構築するには」

「PXEを使ったネットワークブート」

を参考にしました。

開発用のサーバとして使用しているCentOS4.4マシンをPXEサーバにすることにします。



TFTPサーバを構築

tftp-serverをインストール
# rpm -qa | grep tftp
# yum install tftp-server
Installed: tftp-server.i386 0:0.39-2
Complete!

/etc/xinetd.d/tftpを編集し、サービスを有効にする
# vi /etc/xniinetd.d/trftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
# service xinetd restart
xinetd を停止中: [ OK ]
xinetd を起動中: [ OK ]

PXE用ブートイメージを取得
# mkdir /tftpboot/pxe_centos4.5
# cd /tftpboot/pxe_centos4.5
# wget ftp://ftp.riken.jp/Linux/centos/4.5/os/i386/images/pxeboot/vmlinuz
# wget ftp://ftp.riken.jp/Linux/centos/4.5/os/i386/images/pxeboot/initrd.img
# ls
initrd.img vmlinuz


DHCPサーバを構築

dhcpをインストール
# rpm -qa | grep dhcp
dhcpv6_client-0.10-14_EL4
# yum install dhcp
Installed: dhcp.i386 7:3.0.1-59.EL4
Complete!

設定ファイルを編集 ※ 不要な行は削除しています
# cp /usr/share/doc/dhcp-3.0.1/dhcpd.conf.sample  /etc/dhcpd.conf
# vi /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;

subnet 192.168.0.0 netmask 255.255.255.0 {
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;
option domain-name "r-stone.net";
option domain-name-servers 192.168.0.2;
option time-offset -18000; # Eastern Standar
d Time
filename "/pxe_centos4.5/pxelinux.
0";
range dynamic-bootp 192.168.0.250 192.168.0.254;
default-lease-time 21600;
max-lease-time 43200;
}
# mkdir /var/lib/dhcpd
# touch /var/lib/dhcpd/dhcpd.leases
# service dhcpd start
dhcpd を起動中: [ OK ]


PXEサーバを構築

syslinux(pxelinux)のインストール (既にインストール済みでした)
# rpm -qa | grep syslinux
syslinux-2.11-1

ブートローダの準備
# cp /usr/lib/syslinux/pxelinux.0 /tftpboot/pxe_ccentos4.5/

設定ファイルの作成
# mkdir /trftpboot/pxe_centos4.5/pxelinux.cfg
# vi /tftpboot/pxe_centos4.5/pxelinux.cfg/default
default centos4

label centos4
kernel vmlinuz
append load initrd=initrd.img devfs=nomount


ファイアウォールの設定

これまで構築したサーバで使用するポートを開放














サーバポートプロトコル
DHCP67UDP
TFTP69UDP
PXE4011UDP

###
# DHCP
###
iptables -A INPUT -p udp -s 192.168.0.0/24 --dport 67 -j ACCEPT

###
# TFTP
###
iptables -A INPUT -p udp -s 192.168.0.0/24 --dport 69 -j ACCEPT

###
# PXE
###
iptables -A INPUT -p udp -s 192.168.0.0/24 --dport 4011 -j ACCEPT


CentOSのイメージをマウント&HTTP公開


ISOイメージをマウント
# mkdir /mnt/iso
# mount -t iso9660 -o loop /home/r-stone/iso/CentOS-4.5-i386-binDVD.iso /mnt/iso

Apatchで公開
# vi /usr/local/apache2/conf/httpd.conf
Alias /centos4.5 "/mnt/iso"
<Directory /mnt/iso>
Options MultiViews Indexes FollowSymLinks
Order deny,allow
Deny from all
Allow from 192.168.0.0/24 127.0.0.1
</Directory>
# /usr/local/apache2/bin/apachectl restart



PXEネットワークブートでCentOSをインストール


いよいよCentOSをネットワークインストールします。

こちらは、

「@IT:PXEネットワークブートでLinuxをインストールするには」

を参考にしました。



インストール方法の設定


PXEブートよりインストーラが起動してしまえば、あとは通常のインストールと同じです。

ただ、パッケージの転送はHTTPを使用するようにしましたので、インストール方法の画面では「HTTP」を選択し、HTTPの設定を行います。

インストール後


PXEサーバ側:

念のため使用後はサービスを停止しておきます

  • HTTP公開の停止

  • イメージのアンマウント

  • TFTPサーバの停止

  • DHCPサーバの停止


クライアント側:


  • BIOSのPXEを無効に





CDDがなかったのは焦りましたが、結局CDDなんてインストール時にしか使わないわけで、消費電力を抑えるためにもPXEでのネットワークインストールも良いかなと思います。

2007/07/20

Bloggerのクラシックテンプレート(FTP公開)でもラベル一覧を表示したい


07/12/11追記:下記スクリプトに不具合が見つかりました。こちらの記事を参照してください。



弊社Official Blogでは、Bloggerのクラシックテンプレート(FTP公開)でブログを公開しています。

記事の投稿時には、「この投稿のラベル」というところでラベルを設定できるのですが、設定したラベルの一覧をサイドバーに表示するタグは無いようなのです。


クリボウの Blogger Tips: ラベル一覧にフィードアイコン

クラシックテンプレートは…


クラシックテンプレートの利用者は、上に示したようなカスタマイズができません。というより、それ以前にブログにラベル一覧を表示する方法が用意されていません。




(クラシックテンプレートには、)サイドバーに全てのラベルを表示するタグはありません。サイドバーのラベルウィジェットを使う場合には、レイアウトテンプレートに変更する必要があります。
(クリボウ訳)



レイアウトテンプレートを使えない身(FTP 公開ブログ)としては、非常に残念です…。


なにか他の方法で表示できないかと調べていると、Javascriptでサイドバーにラベル一覧を表示する方法を発見しました!


phydeaux3: Automatic List of Labels for Blogger Classic Templates / FTP


Caveats - this only works for blogs that have their admin profile publicly available, and the blog must be publicly listed in that profile (this is as it should, if you haven't announced your blog publicly, then your metafeed shouldn't be public). It also does NOT return the number of posts in each label. Just the list of all the ones used.



Ok, you need two pieces of information for it to work. Your Blogger UserID number, and your Blogs ID number. Both of these you can get via your dashboard. For the USERID, click on the View Profile link and it's the long number at the end of that url. For the Blog ID number, again from the dashboard if you click on any links to change settings or create a post for that blog, all links will have blogID=XXXXXXX at the end where the X's will be that particular blog's ID number. Once you have that, here is code that will fetch and display the labels for your blog.




どうやら、プロフィールを公開している状態で、UserIDとBlogIDがあれば可能なようです。

上記サイトより早速コードを拝借して試してみると、日本語のラベルページにジャンプできません!

Bloggerより生成されたラベルページのファイル名を良く見てみると、なんと日本語が混じるとBase64でエンコードされたファイル名になっています。ですが、上記コードでは単純にencodeURIComponentしているだけのようです。海外ではこれでOKですが、日本ではちょっとまずいです。

というわけで、前置きが長くなりましたが、以下が改造後のソースです。

※Base64のエンコードには、Free code and tutorialsにある、Javascript base64 encodingを使用しています。

このファイルを予め読み込んでおく必要があります。


<div id="labelList"></div> <script type="text/javascript">
//<![CDATA[
function listLabels(root){
var baseURL = '/blog/labels/';
var baseHeading = "ラベル";
var isFTP = true;
var llDiv = document.getElementById('labelList');
var entry = root.entry;
var h2 = document.createElement('h2');
h2.className = 'sidebar-title';
var h2t = document.createTextNode(baseHeading);
h2.appendChild(h2t);
llDiv.appendChild(h2);
var ul = document.createElement('ul');
ul.id = 'label-list';
var category = entry.category;
labelSort = new Array();
for(p in category){
labelSort[labelSort.length] = [category[p].term];
}
labelSort.sort();
for (var r=0; r < labelSort.length; r++){
var li = document.createElement('li');
var a = document.createElement('a');
if(isFTP){
var l = encodeURIComponent(labelSort[r]);
if (l.indexOf('%', 0) >= 0) {
var reg1=/\//g;
l = Base64.encode(new String(labelSort[r]));
l = l.replace(reg1, "__");
}
a.href = baseURL + l +'.html';
}
else {
a.href = baseURL + encodeURIComponent(labelSort[r]);
}
a.innerHTML = labelSort[r] + ' ';
li.appendChild(a);
ul.appendChild(li);
abnk = document.createTextNode(' ');
ul.appendChild(abnk);
}
llDiv.appendChild(ul);
}
//]]>
</script>
<!--
The script source URL must be
http://www.blogger.com/feeds/<UserID>/blogs/<BlogID>?alt=json-in-script&callback=bloggerLabels
You can get your <UserID> at the end of your profile view URL.
And you can get your <BlogID> at the end of URL in your blog editor (and blog setting)
like http://www.blogger.com/posts.g?blogID=xxxxx, in this case xxxxx is your <BlogID>.
-->
<script type="text/javascript" src="http://www.blogger.com/feeds/UserID/blogs/BlogID?alt=json-in-script&callback=listLabels" ></script>


baseURLや、baseHeading等の値は環境に合わせて変更します。

詳しくは元記事をご覧下さい。

2007/07/17

Getting Realでいこう!


2ヶ月くらい前に、はてなブックマークより[Getting Real by 37signals]というページを発見しました。



Getting Real は、より速く、よりよいソフトウェア構築のための方法です。またその主要なアイディアは多くのビジネス・クリエイティビティの現場でも採用できるものです。


とても身にしみる内容で、非常に参考になりました。頭のなかにあった漠然としたもやもやが、一気に吹き飛んだ感じでした。とってもすっきりします。

読んでるとなんだかモチベーションがあがってきて、不思議な癒しを感じられますw。まだ読んでいない方は、是非一読することをお勧めします。

これからは、「Getting Realでいこう!」ですね。



37signalsといえば、ruby on railsの作者であるDHH氏がおられるところです。また、Basecamp(プロジェクト管理アプリケーション)等のメジャーなWebサービスも提供しています。