hnakamur’s blog

ものすごい勢いで忘れる私のために未整理でもいいからとりあえずメモ

ラベル Linux の投稿を表示しています。 すべての投稿を表示
ラベル Linux の投稿を表示しています。 すべての投稿を表示

2011-03-25

ls -lRの出力に合わせてパーミション設定を行う

ls -lRの出力に合わせてパーミション設定を行うためのスクリプトを作りました。

使い方
./ls-lR_to_chmod.pl < ls-lRの結果 > setperm.sh

ls-lR_to_chmod.plの内容
#!/usr/bin/perl

sub to_chmod_perm_chunk {
   my $perm = shift;
   $perm =~ tr/-//d;
   if ($perm eq '') {
     $perm = '-';
   } elsif ($perm =~ /[ST]$/) {
     $perm =~ tr/ST/st/;
   } elsif ($perm =~ /[st]$/) {
     $perm =~ s/([st])$/x$1/;
   }
   return $perm;
}

sub to_chmod_perm {
  my $perm = shift;
  return 'u=' . to_chmod_perm_chunk(substr($perm, 1, 3)) .
         ',g=' . to_chmod_perm_chunk(substr($perm, 4, 3)) .
         ',o=' . to_chmod_perm_chunk(substr($perm, 7, 3));
}

use constant FIELD_COUNT => 9;
my $dir;
while (<>) {
    chomp;
    if (/^[d-]/) {
        my @fields = split(/\s+/, $_, FIELD_COUNT);
        my $perm = @fields[0];
        my $file = @fields[FIELD_COUNT - 1];
        print 'chmod ' . to_chmod_perm($perm), ' ', $dir . '/' . $file, "\n";
    } elsif (/(.*):$/) {
        $dir = $1;
    }
}

出力されたシェルスクリプトを実行はrootで行ってください。
ls -lRを相対パス指定で実行したときは、出力されたシェルスクリプトを実行するときも同じディレクトリに移動してください。
つまり↓こんな感じです。
sudo -s
cd 【ls -lRを実行したディレクトリ】
sh 【上記で出力したsetperm.shのフルパス】

LinuxのパーミションのSとTの大文字小文字の違い

実験してみたところ実行パーミション(x)がついているときは小文字、ついていないときは大文字になるようです。
sとtについてはLinux Files and File Permissionsを参照。

chmodで指定するときは以下のようにします。
$ chmod o=rxt hoge
$ ls -l hoge
-rw-r--r-t 1 user1 group1 0 Mar 25 11:19 hoge
$ chmod o=rt hoge
$ ls -l hoge
-rw-r--r-T 1 user1 group1 0 Mar 25 11:19 hoge

2011-02-02

nslookupでquerytypeを全てにするオプション

-querytype=anyならWindowsでもLinuxでも使えます。-qと省略可能なので、
nslookup -q=any example.com
という感じです。

Linuxならdigコマンドという手もあります。
dig example.com

2009-08-25

QEMU WikiのSlirpやTapについての解説がわかりやすい

QemuNetwork - #qemu WikiからたどれるSlirpやTapの解説が非常に分かりやすかったです。後から読み返すこともありそうなのでメモ。

  • Slirpについての説明
    • ルート権限が無くても使えます。→Slirpによるネットワークはuser mode networkingあるいは略してuser networkingとかuser-netとも呼ばれます。
    • Slirp自体はダイアルアップの時代にSLIP接続とのやりとりをソケットに見せかけるために作られたプログラムのことです。
    • KVMのネットワークページのUser Networkingセクションに対応します。
  • Tapに付いての説明
    • The 'tap' deviceの項とNote5:によると、Tapはホスト・ゲスト間の通信に使われるそうです。LinuxやBSDのカーネルでは直接eth0にパケットを送るということはできないので、間にtap0を挟む必要があるということです。で、tap0からホストを宛先にして送ればホストのeth0に届くということになります。
    • Possibility 2: NAT routing with one "external" net, and one "virtual internal" LANsがKVMのネットワークページのprivate virtual bridgeセクションに対応します。
    • Possibility 3: NO routing, one LAN made up of real and virtual devicesがKVMのネットワークページのpublic bridgeセクションやKVM Networking - Community Ubuntu DocumentationのCreating a network bridge on the hostセクションに対応します。

WiresharkのCLI版tsharkのインストール

Wiresharkとは

WiresharkはネットワークプロトコルアナライザEtherealの後継にあたるらしい。

インストール

リモートのサーバーにsshで入って使うことを想定しているのでGUI版ではなくCLI版を使います。CLI版のコマンドはtsharkです。

CentOS 5.2の場合

# yum install wireshark

ちなみにGUI版のパッケージ名はwireshark-gnome

Ubuntu 9.04の場合

$ sudo aptitude install tshark

ちなみにGUI版のパッケージ名はwireshark

テスト

CLI版のコマンドはtsharkです。

# tshark -n -i br0 tcp port 80

別の端末で以下のコマンドを実行。

$ telnet 192.168.11.241 80
GET /

tsharkの端末で^Cを入力。出力結果はこんな感じ。

# tshark -n -i br0 tcp port 80
Running as user "root" and group "root". This could be dangerous.
Capturing on br0
  0.000000 192.168.11.102 -> 192.168.11.241 TCP 36674 > 80 [SYN] Seq=0 Win=5840 Len=0 MSS=1460 TSV=1738335 TSER=0 WS=6
  0.000905 192.168.11.241 -> 192.168.11.102 TCP 80 > 36674 [SYN, ACK] Seq=0 Ack=1 Win=5792 Len=0 MSS=1460 TSV=3965771 TSER=1738335 WS=4
  0.000978 192.168.11.102 -> 192.168.11.241 TCP 36674 > 80 [ACK] Seq=1 Ack=1 Win=5888 Len=0 TSV=1738335 TSER=3965771
  1.362928 192.168.11.102 -> 192.168.11.241 HTTP GET /
  1.363635 192.168.11.241 -> 192.168.11.102 TCP 80 > 36674 [ACK] Seq=1 Ack=8 Win=5792 Len=0 TSV=3967134 TSER=1738471
  1.364764 192.168.11.241 -> 192.168.11.102 HTTP Continuation or non-HTTP traffic 
  1.364829 192.168.11.102 -> 192.168.11.241 TCP 36674 > 80 [ACK] Seq=8 Ack=22 Win=5888 Len=0 TSV=1738471 TSER=3967135
  1.364852 192.168.11.241 -> 192.168.11.102 TCP 80 > 36674 [FIN, ACK] Seq=22 Ack=8 Win=5792 Len=0 TSV=3967136 TSER=1738471
  1.365315 192.168.11.102 -> 192.168.11.241 TCP 36674 > 80 [FIN, ACK] Seq=8 Ack=23 Win=5888 Len=0 TSV=1738471 TSER=3967136
  1.366978 192.168.11.241 -> 192.168.11.102 TCP 80 > 36674 [ACK] Seq=23 Ack=9 Win=5792 Len=0 TSV=3967138 TSER=1738471
^C10 packets captured

ちなみにtcpdumpの場合はこんな感じ。

# tcpdump -n -i br0 tcp port 80
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on br0, link-type EN10MB (Ethernet), capture size 96 bytes
11:49:01.942466 IP 192.168.11.102.36673 > 192.168.11.241.80: S 3722872408:3722872408(0) win 5840 <mss 1460,sackOK,timestamp 1722908 0,nop,wscale 6>
11:49:01.943604 IP 192.168.11.241.80 > 192.168.11.102.36673: S 1321486056:1321486056(0) ack 3722872409 win 5792 <mss 1460,sackOK,timestamp 3811486 1722908,nop,wscale 4>
11:49:01.943673 IP 192.168.11.102.36673 > 192.168.11.241.80: . ack 1 win 92 <nop,nop,timestamp 1722909 3811486>
11:49:04.794205 IP 192.168.11.102.36673 > 192.168.11.241.80: P 1:8(7) ack 1 win 92 <nop,nop,timestamp 1723194 3811486>
11:49:04.795714 IP 192.168.11.241.80 > 192.168.11.102.36673: . ack 8 win 362 <nop,nop,timestamp 3814337 1723194>
11:49:04.795782 IP 192.168.11.241.80 > 192.168.11.102.36673: P 1:22(21) ack 8 win 362 <nop,nop,timestamp 3814338 1723194>
11:49:04.795818 IP 192.168.11.102.36673 > 192.168.11.241.80: . ack 22 win 92 <nop,nop,timestamp 1723194 3814338>
11:49:04.795838 IP 192.168.11.241.80 > 192.168.11.102.36673: F 22:22(0) ack 8 win 362 <nop,nop,timestamp 3814339 1723194>
11:49:04.796667 IP 192.168.11.102.36673 > 192.168.11.241.80: F 8:8(0) ack 23 win 92 <nop,nop,timestamp 1723194 3814339>
11:49:04.798567 IP 192.168.11.241.80 > 192.168.11.102.36673: . ack 9 win 362 <nop,nop,timestamp 3814341 1723194>
^C
10 packets captured
10 packets received by filter
0 packets dropped by kernel

2009-01-20

Linux Virtual Server (LVS)



[24時間365日] サーバ/インフラを支える技術 ?スケーラビリティ、ハイパフォーマンス、省力運用 (WEB+DB PRESS plusシリーズ)を見ながら、まずは仮想IPアドレスを追加してみた。[24時間365日] サーバ/インフラを支える技術 ?スケーラビリティ、ハイパフォーマンス、省力運用 (WEB+DB PRESS plusシリーズ)


その後send_arpコマンドを試そうと思ったが、見当たらない。本はdebianが対象なのでCentOSだと違うようだ。ググってみるとLinux Virtual Server Administrationというのを発見。まずはじっくり読んでみよう。





2008-12-17

OpenVZでCentOS5をゲストOSとしてセットアップの続き



昨日の記事の続きです。


検索してみると



というページを発見。


まねしてやってみる。



# vi /vz/template/centos/5/x86_64/config/install-post
===================================================================
--- /vz/template/centos/5/x86_64/config/install-post 2008/12/17 15:14:07 1.1
+++ /vz/template/centos/5/x86_64/config/install-post 2008/12/17 15:25:17 1.4
@@ -35,10 +35,10 @@
$VZCTL exec2 $VEID sed -i -e '/getty/d' /etc/inittab

# Disable klogd
-$VZCTL exec2 $VEID \
- "sed -i -e 's/daemon\\ klogd/passed\\ klogd\\ skipped/' \
- -e 's/killproc\\ klogd/passed\\ klogd\\ skipped/' \
- /etc/init.d/syslog"
+#$VZCTL exec2 $VEID \
+# "sed -i -e 's/daemon\\ klogd/passed\\ klogd\\ skipped/' \
+# -e 's/killproc\\ klogd/passed\\ klogd\\ skipped/' \
+# /etc/init.d/syslog"
# FIXME: fix '/etc/init.d/syslog status' to return 0
# even if klogd is not running

@@ -55,7 +55,7 @@
# Disable fsync() in syslog
$VZCTL exec2 $VEID \
'sed -i -e s@\\\([[:space:]]\\\)\\\(/var/log/\\\)@\\\1-\\\2@' \
- /etc/syslog.conf
+ /etc/rsyslog.conf

# Disable X11Forwarding by default
$VZCTL exec2 $VEID \
@@ -85,3 +85,5 @@
#echo "Rebuilding RPM DB ..."
#$RPM --root $VE_ROOT --rebuilddb
#rm -f $VE_ROOT/var/lib/rpm/__db.0*
+
+mkdir -p $VE_ROOT/var/lib/yum || abort "Can't create /var/lib/yum"
===================================================================
# vzpkgcache -f centos-5-x86_64-minimal
...


しかし、やはり



could not open ts_done file: [Errno 2] No such file or directory: '/vz/root/100001/var/lib/yum/transaction-done.2008-12-18.00:31.05'


のようなエラーが連発しているので、別の端末から手動で



# mkdir -p /vz/root/100001/var/lib/yum


として作成。


その後



...
Complete!
chmod: cannot access `/etc/cron.daily/slocate.cron': No such file or directory
chmod: cannot access `/etc/cron.daily/makewhatis.cron': No such file or directory
Packing cache file centos-5-x86_64-minimal.tar.gz ...
Cache file centos-5-x86_64-minimal.tar.gz [129M] created.
#


となって一応終了。cron.dailyでエラーが出てますがInstall OpenVZ on a x86 64 system Centos-Fedora - OpenVZ Wikiにも



It finishes with complaints about cron.daily, but don't worry about it.



と書いてあるので気にしないことにします。


で、そのページの続きに従って実行。あとBasic operations in OpenVZ environment - OpenVZ Wikiも見つつ。



# vzpkgls -c
centos-5-x86_64-minimal
# vzctl create 200 --ostemplate centos-5-x86_64-minimal
Creating container private area (centos-5-x86_64-minimal)
Performing postcreate actions
Container private area was created



# vzctl create 200 --ostemplate centos-5-x86_64-minimal
# vzctl start 200


パッケージインストールのテスト。fastestmirrorが効いてなくて遅いミラーを選んでしまったようで1分程度かかったが成功。



# vzyum 200 install nano
# vzrpm 200 -qa



# vzctl set 200 --ipadd 192.168.1.101 --save
# vzctl set 200 --nameserver 192.168.1.1.1 --save
# vzctl stop 200
# vzctl start 200
# vzctl exec 200 ps ax
PID TTY STAT TIME COMMAND
1 ? Ss 0:00 init [3]
9513 ? Ss 0:00 /usr/sbin/sshd
9524 ? Rs 0:00 ps ax
# vzctl enter 200
# ps ax
PID TTY STAT TIME COMMAND
1 ? Ss 0:00 init [3]
9513 ? Ss 0:00 /usr/sbin/sshd
9526 ? Ss 0:00 vzctl: pts/0
9527 pts/0 Ss 0:00 -bash
9542 pts/0 R+ 0:00 ps ax
# exit
# vzctl stop 200


てなわけでとりあえず動きました!





2008-12-16

OpenVZを試す、が、まだうまくいかない



Linux-VServerはバニラカーネルへのパッチとして提供されていて、パッチあたりまくりのCentOSだとうまく当たらないし、そうかといってバニラカーネル+Linux-VServerにしてしまうとCentOSとは別物になってしまってCentOSの検証環境としては使えないなあと悩んでいて以下のページを見つけました。



そうかOpenVZならCentOSのカーネルにも対応していたのか(もっと早く気付けよ>私)。ということでトライしてみました。



# cd /etc/yum.repos.d/
# wget http://download.openvz.org/openvz.repo
# rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
# yum search ovzkernel
# yum install ovzkernel.x86_64
# vi /etc/sysctl.conf
===================================================================
RCS file: /etc/sysctl.conf,v
retrieving revision 1.1
diff -u -r1.1 /etc/sysctl.conf
--- /etc/sysctl.conf 2008/12/16 16:13:56 1.1
+++ /etc/sysctl.conf 2008/12/16 16:15:34
@@ -4,15 +4,19 @@
# sysctl.conf(5) for more details.

# Controls IP packet forwarding
-net.ipv4.ip_forward = 0
+net.ipv4.ip_forward = 1
+net.ipv4.conf.default.proxy_arp = 0

# Controls source route verification
+net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
+net.ipv4.conf.default.send_redirects = 1
+net.ipv4.conf.all.send_redirects = 0

# Do not accept source routing

# Controls the System Request debugging functionality of the kernel
-kernel.sysrq = 0
+kernel.sysrq = 1

# Controls whether core dumps will append the PID to the core filename
# Useful for debugging multi-threaded applications
===================================================================
# sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
kernel.sysrq = 1
kernel.core_uses_pid = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_syncookies = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.eth0.accept_redirects = 0
net.ipv4.conf.lo.accept_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.eth0.accept_source_route = 0
net.ipv4.conf.lo.accept_source_route = 0

# reboot
uname -r
2.6.18-92.1.13.el5.028stab059.6
# yum install vzctl vzctl-lib vzpkg vzquota vzyum vzrpm43 vzrpm43-python vzrpm44 vzrpm44-python
oading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
* addons: ftp2.riken.jp
* extras: ftp2.riken.jp
* base: ftp2.riken.jp
* openvz-kernel-rhel5: ftp.iij.ad.jp
* openvz-utils: ftp.iij.ad.jp
* updates: ftp2.riken.jp
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package vzctl.i386 0:3.0.23-1 set to be updated
---> Package vzpkg.noarch 0:2.7.0-18 set to be updated
---> Package vzrpm44-python.i386 0:4.4.1-22.5 set to be updated
---> Package vzquota.i386 0:3.0.12-1 set to be updated
---> Package vzyum.noarch 0:2.4.0-11 set to be updated
--> Processing Dependency: cElementTree.so for package: vzyum
---> Package vzrpm43-python.i386 0:4.3.3-7_nonptl.6 set to be updated
---> Package vzrpm44.i386 0:4.4.1-22.5 set to be updated
---> Package vzctl.x86_64 0:3.0.23-1 set to be updated
---> Package vzquota.x86_64 0:3.0.12-1 set to be updated
---> Package vzrpm43.i386 0:4.3.3-7_nonptl.6 set to be updated
---> Package vzctl-lib.i386 0:3.0.23-1 set to be updated
---> Package vzctl-lib.x86_64 0:3.0.23-1 set to be updated
--> Finished Dependency Resolution
Error: Missing Dependency: cElementTree.so is needed by package vzyum


おおっとなんかエラーが。


で、検索したら本家のドキュメントに行き着く(最初からこちらを見ようね>私)。



というわけで続き。



# yum install vzctl vzquota
# /sbin/service vz start
# /sbin/chkconfig --list vz
# wget http://linux.carreira.com.pt/ovzutils/setx86_64-0.3.tar.gz
# tar zxf setx86_64-0.3.tar.gz
# sh setx86_64
# vi /vz/template/centos/5/x86_64/config/.rpmmacros
===================================================================
RCS file: /vz/template/centos/5/x86_64/config/.rpmmacros,v
retrieving revision 1.1
diff -u -r1.1 /vz/template/centos/5/x86_64/config/.rpmmacros
--- /vz/template/centos/5/x86_64/config/.rpmmacros 2008/12/16 16:34:18 1.1
+++ /vz/template/centos/5/x86_64/config/.rpmmacros 2008/12/16 16:34:35
@@ -1 +1 @@
-%_install_langs C
+%_install_langs C:ja_JP.UTF-8
===================================================================

# vzpkgls | grep x86_64
fedora-7-x86_64-small
fedora-7-x86_64-default
fedora-7-x86_64-minimal
fedora-core-5-x86_64-default
fedora-core-5-x86_64-minimal
fedora-core-3-x86_64-default
fedora-core-3-x86_64-minimal
fedora-core-6-x86_64-default
fedora-core-6-x86_64-minimal
fedora-core-4-x86_64-default
fedora-core-4-x86_64-minimal
centos-5-x86_64-default
centos-5-x86_64-minimal
centos-4-x86_64-default
centos-4-x86_64-minimal
# vzpkgcache -f centos-5-x86_64-minimal
...
Installing: libgcc ####################### [ 1/87]
could not open ts_done file: [Errno 2] No such file or directory: '/vz/root/100001/var/lib/yum/transaction-done.2008-12-17.01:43.38'
Installing: setup ####################### [ 2/87]
could not open ts_done file: [Errno 2] No such file or directory: '/vz/root/100001/var/lib/yum/transaction-done.2008-12-17.01:43.38'
...
Complete!
sed: can't read /etc/init.d/syslog: No such file or directory
ERROR: Script install-post failed


途中で/vz/root/100001/var/lib/yum/というディレクトリが無いっぽいエラー連発。最後にもエラーが。なんか間違えたかな。


調べてみると/vz/root/まではあるがその下はないようだ。/etc/init.d/syslogのほうはあるんだけどな。続きはまた今度。





2008-12-05

bcapabilitiesにSYS_CHROOTを追加したらホストからゲストにsshできた



ホストからゲストにsshできないの続きです。


util-vserver:Capabilities and Flags - Linux-VServerを見て



SYS_CHROOT


という内容で/etc/vservers/vserver1/bcapabilitiesファイルを作成してからvserver1起動して、ホストからゲストにsshしてみるといけましたよ!


util-vserver:Capabilities and Flags - Linux-VServerのページはここ数日何回か見てたんだけどdefault bcaps are:というところにSYS_CHROOTが含まれているし、/etc/vservers/vserver1/bcapabilitiesファイルは無いからデフォルトになってるんだろうな、と思って試してなかったのですが、明示的に指定すれば行けたってことですね。


となるとreducecap --showで表示された情報ってのもなんだったのか。あれはホストで実行するとホストのcapabilitiesを表示しているのかな?これも要調査。というかまだまだ基本的なところがわかってないな。


まあ何はともあれ一歩前進。





2008-12-04

ホストからゲストにhttpではアクセスできた







guest# yum install httpd
guest# /etc/init.d/httpd start
guest# echo 'It works' > /var/www/html/index.html
guest# wget http://192.168.0.3/


でまず自分自身では取得できた(192.168.0.3はguestのIPアドレス。lo(loopback)が無い状態なのでlocalhostとは指定できない状況)


次にホストから



host$ wget http://192.168.0.3/


でも取得できた。





ホストからゲストにsshできない




  • ホスト: Debian etch

  • ゲスト: CentOS 5.2


ホストからゲストにsshで入ろうとすると



$ ssh 192.168.0.3
Read from socket failed: Connection reset by peer
$


となってしまいます。


ゲストの/var/log/secureには



Dec 3 16:58:51 vserver1 sshd[4587]: fatal: chroot("/var/empty/sshd"): Operation not permitted


という行ができてた。


Capabilities and Flags - Linux-VServerのSystem capabilities (bcaps) のSYS_CHROOTが無いのかなと思ったけどutil-vserver:Capabilities and Flags - Linux-VServerを見てもデフォルトで入ってるらしい。/etc/vservers/vserver1/にbcapabilitiesというファイルは無い状態なのでデフォルト値になってるはず。


vserver development mailing list: [Vserver] "Defaults Caps of chcontext" and whish listというページでreducecapというコマンドの存在を知り(dpkg -S /usr/sbin/reducecapによるとutil-vserverパッケージに含まれる)、ホストで実行してみると



# reducecap --show
Capability Effective Permitted Inheritable
...
CAP_SYS_RAWIO X X


となるので、やはり許可されているようだ。


今後さらに調査が必要ということで一旦棚上げ。





2008-12-03

Debianにはデフォルトではwheelグループが無い



新山 祐介さん著の入門OpenSSHサポートページ)で/etc/sudoersでwheelグループに対して許可を与える設定を使っているというのを呼んでまねしようとしたのですが(私はそれまでは直接ユーザーに許可を与えていた)、CentOSではwheelグループがあるのにDebianには無いことに気づきました。


検索するとDebian referenceに9.2.2 "Why GNU su does not support the wheel group"という節があることを発見。じゃあadmグループで代用するのかと思いきや、Securing Debian Manualに4.10 Providing secure user accessという節があり、wheelグループを追加するのがもっともきれいな方法だとされている。


で、/etc/pam.d/suを見ると以下のようなセクションがある。



# Uncomment this to force users to be a member of group root
# before they can use `su'. You can also add "group=foo"
# to the end of this line if you want to use a group other
# than the default "root" (but this may have side effect of
# denying "root" user, unless she's a member of "foo" or explicitly
# permitted earlier by e.g. "sufficient pam_rootok.so").
# (Replaces the `SU_WHEEL_ONLY' option from login.defs)
# auth required pam_wheel.so


とりあえず



auth required pam_wheel.so group=wheel


と書き換えた後、



# addgroup --gid 11 wheel
# usermod -a -G wheel root
# usermod -a -G wheel rails # railsはsudoを許可したい一般ユーザー


を実行して(wheelのgidはCentOS5では10だが/etc/groupを見るとuucpにとられていて10の次は12だったので11にしてみた)



# su - rails
$ sudo whoami
Password:
rails is not in the sudoers file. This incident will be reported.


と試してみたがエラーになった。


/etc/sudoersへの追加は結局必要らしい(というかPAMのことがよくわかっていないことに今気づいた。後日勉強すること)。



# visudo




%wheel ALL=(ALL) ALL


という行を追加して再度sudoを試すと今度はできた。


その後再度/etc/pam.d/suを見てたら、さっきの節の前に



# This allows root to su without passwords (normal operation)
auth sufficient pam_rootok.so


と書かれていることを発見。rootユーザーをwheelグループに追加するというのは不要でした。





2008-11-29

時計のずれを修正



Debian FAQ - Silicon Linux Wikiを参考にしました。



# vi /etc/default/rcS




UTC=no


に修正。



# tzconfig


で反映しようと思ったら



WARNING: the tzconfig command is deprecated, please use:
dpkg-reconfigure tzdata


と言われたので



# dpkg-reconfigure tzdata


と実行し、CUIでのタイムゾーンで[Asia]/[Tokyo]を選択。


すると



Current default timezone: 'Asia/Tokyo'
Local time is now: Sat Nov 29 10:21:38 JST 2008.
Universal Time is now: Sat Nov 29 01:21:38 UTC 2008.


と表示されて正しくなりました。





2008-11-25

一部のパッケージだけ手動でtestingレポジトリから取得する




/etc/apt/source.listに以下の内容を追加。



# testing
deb http://cdn.debian.or.jp/debian/ testing main contrib non-free
deb http://security.debian.org/ testing/updates main contrib non-free


apt-pin止め(apt-pinning)。/etc/apt/preferencesを以下の内容で作成。



ackage: *
Pin: release a=testing
Pin-Priority: 90


aptitude updateで以下のようなエラーが発生するので



# aptitude update
...
Reading package lists... Error!
E: Dynamic MMap ran out of room
E: Error occurred while processing tkman (NewVersion1)
E: Problem with MergeList /var/lib/apt/lists/cdn.debian.or.jp_debian_dists_testing_main_binary-i386_Packages
E: The package lists or status file could not be parsed or opened.
E: Couldn't rebuild package cache


以下のような内容で/etc/apt/apt.confを作成して



APT::Cache-Limit "100000000";
APT::Default-Release "stable";


再度実行して今度はOK。



# aptitude update
...
Reading package lists... Done


aptitude upgradeで何もアップグレードされないことも確認。


testingのutil-vserverパッケージのバージョン確認。



# aptitude -t testing show util-vserver
Package: util-vserver
State: not installed
Automatically installed: no
Version: 0.30.216~r2772-4
...


testingのutil-vserverパッケージのバージョンインストール。



# aptitude -t testing install util-vserver
Reading package lists... Done
Building dependency tree... Done
Reading extended state information
Initializing package states... Done
Building tag database... Done
The following packages are BROKEN:
libc6 libc6-dev libncurses5-dev
The following packages have been kept back:
adduser apt apt-utils aptitude base-files base-passwd bash binutils bison
bsdmainutils bsdutils busybox bzip2 coreutils cpio cpp cpp-4.1 cron dctrl-tools
debconf debconf-i18n debian-archive-keyring debianutils debootstrap dhcp3-client
dhcp3-common dialog diff dpkg dpkg-dev e2fslibs e2fsprogs ed exim4 exim4-base
exim4-config exim4-daemon-light file findutils flex gcc gcc-4.1 gcc-4.1-base
gettext gettext-base gnupg gpgv grep groff-base gzip hostname ifupdown info
initramfs-tools initscripts iproute iproute-doc iptables iputils-ping
kernel-package klibc-utils klogd less libacl1 libatm1 libattr1 libbeecrypt6
libblkid1 libbz2-1.0 libcomerr2 libcompress-zlib-perl libdb4.2 libedit2 libexpat1
libgcc1 libgcrypt11 libgpg-error0 libklibc libkrb53 liblocale-gettext-perl
liblockfile1 libmagic1 libmail-sendmail-perl libmudflap0 libmudflap0-dev
libncursesw5 libneon25 libpam-modules libpam-runtime libpam0g libpcre3 libpopt0
libreadline5 libsasl2-2 libsepol1 libsigc++-2.0-0c2a libsqlite0 libsqlite3-0 libss2
libssl0.9.8 libstdc++6 libtasn1-3 libtext-charwidth-perl libtext-iconv-perl
libtext-wrapi18n-perl libusb-0.1-4 libuuid1 libvolume-id0 libwrap0 libxml2 login
logrotate lsb-base lvm2 m4 mailx make makedev man-db mawk mime-support mktemp
module-init-tools mount nano ncurses-base ncurses-bin net-tools netbase
openbsd-inetd openssh-blacklist openssh-client openssh-server passwd patch perl
perl-base perl-doc perl-modules po-debconf procps psmisc python python-celementtree
python-central python-elementtree python-libxml2 python-minimal python-rpm
python-sqlite python-support python-urlgrabber python2.4 python2.4-minimal
python2.5 python2.5-minimal readline-common rpm screen sed sharutils ssh sudo
sysklogd sysv-rc sysvinit sysvinit-utils tar tcpd telnet texinfo tzdata udev unzip
update-inetd vim vim-common vim-runtime wget xml-core yum zlib1g
The following packages will be upgraded:
libncurses5 libselinux1 libslang2 util-linux util-vserver
The following packages are RECOMMENDED but will NOT be installed:
libgpm2 libpng12-0
6 packages upgraded, 0 newly installed, 0 to remove and 184 not upgraded.
Need to get 6376kB of archives. After unpacking 811kB will be used.
The following packages have unmet dependencies:
libc6-dev: Depends: libc6 (= 2.3.6.ds1-13etch7) but 2.7-16 is to be installed.
libncurses5-dev: Depends: libncurses5 (= 5.5-5) but 5.6+20080830-1 is to be installed.
libc6: Conflicts: tzdata-etch which is a virtual package.
Resolving dependencies...
The following actions will resolve these dependencies:

Remove the following packages:
linux-kernel-headers

Install the following packages:
libgpm2 [1.20.4-3 (testing)]
libpng12-0 [1.2.27-2 (testing)]
linux-libc-dev [2.6.26-10 (testing)]

Upgrade the following packages:
binutils [2.17-3 (stable, now) -> 2.18.1~cvs20080103-7 (testing)]
libc6-dev [2.3.6.ds1-13etch7 (stable, now) -> 2.7-16 (testing)]
libncurses5-dev [5.5-5 (stable, now) -> 5.6+20080830-1 (testing)]
tzdata [2008e-1etch3 (stable, now) -> 2008h-2 (testing)]

Score is -226

Accept this solution? [Y/n/q/?]


libc6-devとかあがって大丈夫なのかわからないがとりあえずYで行ってみた。





Linux-VServerのゲストOSとしてCentOSをインストール



Building Guest Systems - Linux-VServerを読みながらトライ中。


まずは、yumを入れておく。



# aptitude install yum


Howtos Linux-Vserver With LVM And Quotas - 5dollarwhitebox.org Media Wikiというページを見つけたのでこれに従ってやってみる。



# aptitude update && aptitude upgrade
# aptitude install lvm2 util-vserver coreutils


NTFSのsparse fileの手順に沿ってcentos5guest.ext3という名前で8Gのsparse fileを作り、coLinuxを以下のような設定で再起動。



kernel=C:\coLinux\coLinux_VServer\vmlinux-2.6.22.18-vs2.2.0.6-co-0.7.3
hda1=c:\coLinux\etch.ext3
hdb1=c:\coLinux\swap.img
hdc1=c:\coLinux\centos5guest.ext3
root=/dev/hda1
initrd=C:\coLinux\coLinux_VServer\initrd.img-2.6.22.18-vs2.2.0.6-co-0.7.3
mem=512
eth0=slirp
eth1=tuntap


物理ボリューム、ボリュームグループ、論理ボリューム作成



# pvcreate /dev/hdc1
Physical volume "/dev/hdc1" successfully created
# vgcreate vg0 /dev/hdc1
Volume group "vg0" successfully created
# lvcreate -L1024 -n vserver1 vg0
Logical volume "vserver1" created


ファイルシステム作成とマウント



# mke2fs -j /dev/vg0/vserver1
...
# mkdir /var/lib/vservers/vserver1
# mount -t ext3 /dev/vg0/vserver1 /var/lib/vservers/vserver1


仮想サーバー作ろうとしたらエラー。



# vserver vserver1 build -m yum --context 42 --hostname vserver1.local \
--interface eth0:192.168.1.11/24 -- -d centos5
ERROR: Can not find configuration for the distribution 'centos5';
please read http://linux-vserver.org/HowToRegisterNewDistributions
for information how to add support for your own distribution.



# dpkg -L util-vserver | lv


で確認してみると、確かにcentos5の設定は無かった(centos4ならあったけど)。検索してみるとvserver development mailing list: Re: [Vserver] CentOS 5 building guest machineで、util-vserverのバージョンを0.30.213にあげれば入っているとのこと。dpkg -l util-vserverしてみると手元のは0.30.212-1。Debian -- パッケージ検索結果 -- util-vserverを見るとtestingレポジトリにはもっと新しいのが登録されているそうだ。


tesingからutil-vserverをインストールしたときの手順は一部のパッケージだけ手動でtestingレポジトリから取得するに書きました。


というわけでもう一度やってみると今度は別のエラー発生。



# vserver vserver1 build -m yum --context 42 --hostname vserver1.local \
--interface eth0:192.168.1.11/24 -- -d centos5
mount: mount point /etc/rpm does not exist
rm: cannot remove directory `/etc/vservers/.defaults/vdirbase/vserver1': Device or resource busy


#444224 - util-vserver: please include /etc/rpm and suggest:yum - Debian Bug report logsという記事を見て



# mkdir -p /etc/vservers/vserver1/rpmetc
# vserver vserver1 build -m yum --context 42 --hostname vserver1.local \
--interface eth0:192.168.1.11/24 -- -d centos5
vserver-topdirectory '/etc/vservers/.defaults/vdirbase/vserver1' and/or configuration at '/etc/vservers/vserver1'
exist already; please try to use '--force', or remove them manually.


とやってみたらまたエラーに。


ここは素直に/etc/rpmを作るほうがよさそうと思いやってみると



# rm -r /etc/vservers/vserver1/
# mkdir /etc/rpm
# vserver vserver1 build -m yum --context 42 --hostname vserver1.local \
--interface eth0:192.168.1.11/24 -- -d centos5
You are using a version of yum which is insecure and broken in chroot
related operations; either apply the patches shipped in the 'contrib/'
directory of util-vserver, or ask the author of yum to apply them
(preferred).

In the meantime, 'vyum' will continue with dirty hacks which might not
work when the vserver is running and local DOS attacks are possible.

Execution will continue in 5 seconds...


と出て固まった。と思ったのは間違いで別の端末でps見たら起動してるようです。しばらく待っているとyumでインストールするときのリストが出てきたのでゲストOS用にパッケージをインストールしているようです。


待ってる間に別の端末でyumをtestingからインストール。かなりいろいろつられてバージョンアップするそうだが気にせずGO!



# aptitude show yum | grep Version:
Version: 2.4.0-3.1
# aptitude show yum -t testing | grep Version:
Version: 3.2.12-1.2
# aptitude install yum -t testing


長くなってきたので続きは別エントリにします。





2008-11-24

Linux-VServerのゲストOSとしてCentOSをインストール(続き)



Linux-VServerのゲストOSとしてCentOSをインストールの続き


ゲストOSのインストールが遅いのはyumのダウンロードのミラーが遅いことに気づき、/usr/lib/util-vserver/distributions/centos5/yum.repo.d/CentOS-Base.repoを書き換えたら、よくなった。


しかし、次の問題が発生。



# vserver vserver1 build -m yum --context 42 --hostname vserver1.local \
--interface eth0:192.168.1.11/24 -- -d centos5
You are using a version of yum which is insecure and broken in chroot
related operations; either apply the patches shipped in the 'contrib/'
directory of util-vserver, or ask the author of yum to apply them
(preferred).

In the meantime, 'vyum' will continue with dirty hacks which might not
work when the vserver is running and local DOS attacks are possible.

Execution will continue in 5 seconds...
Traceback (most recent call last):
File "/usr/bin/yum", line 29, in ?
yummain.user_main(sys.argv[1:], exit_code=True)
File "/usr/share/yum-cli/yummain.py", line 236, in user_main
errcode = main(args)
File "/usr/share/yum-cli/yummain.py", line 152, in main
(result, resultmsgs) = base.buildTransaction()
File "/var/lib/python-support/python2.4/yum/__init__.py", line 626, in buildTransaction
(rescode, restring) = self.resolveDeps()
File "/var/lib/python-support/python2.4/yum/depsolve.py", line 663, in resolveDeps
CheckDeps, checkinstalls, checkremoves, missing = self._resolveRequires(errors)
File "/var/lib/python-support/python2.4/yum/depsolve.py", line 746, in _resolveRequires
thisneeds = self._checkInstall(txmbr)
File "/var/lib/python-support/python2.4/yum/depsolve.py", line 788, in _checkInstall
provs = self.tsInfo.getProvides(*req)
File "/var/lib/python-support/python2.4/yum/transactioninfo.py", line 428, in getProvides
result = self.getOldProvides(name, flag, version)
File "/var/lib/python-support/python2.4/yum/transactioninfo.py", line 421, in getOldProvides
for pkg, hits in self.rpmdb.getProvides(name, flag, version).iteritems():
File "/var/lib/python-support/python2.4/yum/rpmsack.py", line 397, in getProvides
pkgs = self.searchProvides(name)
File "/var/lib/python-support/python2.4/yum/rpmsack.py", line 156, in searchProvides
return self.searchPrco(name, 'provides')
File "/var/lib/python-support/python2.4/yum/rpmsack.py", line 139, in searchPrco
mi = ts.dbMatch(tag, name)
TypeError: unknown key type


testingのyumを入れたのは失敗でしたよ。というわけでstableのに戻します(もっといいやり方があるかもしれないけどとりあえずこれで)。



# aptitude uninstall yum
# aptitude install yum


vyumがyumについてエラーを言うのはYum-patch - Linux-VServerで対応するようだ。これは後日やってみよう。


とりあえず今度こそvserverのbuildはエラーなく終わりました。


Building Guest Systems - Linux-VServerに従って動作確認。



root@debian:~# vserver vserver1 start
Starting system logger: [ OK ]
Starting kernel logger: [ OK ]
root@debian:~# vserver vserver1 enter
bash-3.2# pwd
/
bash-3.2# ifconfig
eth0 Link encap:Ethernet HWaddr 00:FF:2A:6F:C4:80
inet addr:192.168.1.11 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:468 (468.0 b)
Interrupt:2

bash-3.2# logout
root@debian:~#


おー、動きましたよ。


停止と状態確認はこれで。



root@debian:~# vserver vserver1 stop
Shutting down kernel logger: [FAILED]
Shutting down system logger: [ OK ]
Starting killall: [ OK ]
root@debian:~# vserver vserver1 status
Vserver 'vserver1' is stopped


上のFAILEDのときにコンソールでは以下のようなメッセージが表示されてた。



vxW: [xid #0] !!! limit: de75704c[VM,9] = 75 on exit.
vxW: [xid #0] !!! limit: dd34b04c[VM,9] = 76 on exit.
vxW: [xid #0] !!! limit: dd3a904c[VM,9] = 153 on exit.
vxW: [xid #0] !!! limit: dd11704c[VM,9] = 29 on exit.


これもおいおい調べよう。





イメージファイルの拡大



新規に大きいサイズでイメージファイルを作ってそこにコピーし、その後resize2fsを使う。


/dev/cobd0から/dev/cobd1 (4G)にコピーする例。



# dd if=/dev/cobd0 of=/dev/cobd1
# e2fsck -f /dev/cobd1
# resize2fs /dev/cobd1 4G





CentOS5のカスタムインストールCD作成



Build a custom CentOS 5 install CD « Nootech Notes


以下はVirtualBox上にインストール済みのCentOS5.2上で実行した。


インストールCD1枚目の内容を展開



# mkdir -p /media/centos
# mount -o loop /mnt/coLinux/iso/CentOS-5.2-i386-bin-1of6.iso /media/centos/
# mkdir -p ~/build/c5disc1
# cd ~/build/c5disc1
# (cd /media/centos/; tar cf - .) | tar xpf -
# umount /media/centos/


パッケージ追加



# yum -y install anaconda anaconda-help anaconda-runtime
# yum install 適宜必要なパッケージ ...


レポジトリ作成



# discinfo=`head -1 .discinfo`
# createrepo -u "media://$discinfo" -g repodata/comps.xml ~/build/c5disc1


ISOイメージ作成



# isofilename=~/build/c5-custom.iso
# mkisofs -r -R -J -T -v -no-emul-boot -boot-load-size 4 -boot-info-table \
-V "My Custom Linux 1.0" -p "Cool Dude" -A "My Custom Linux 1.0 - 2008/11/23" \
-b isolinux/isolinux.bin -c isolinux/boot.cat -x "lost+found" \
-o $isofilename ~/build/c5disc1
# /usr/lib/anaconda-runtime/implantisomd5 $isofilename





2008-11-23

CentOS5のカスタムインストールCD作成

Build a custom CentOS 5 install CD « Nootech Notes 以下はVirtualBox上にインストール済みのCentOS5.2上で実行した。 インストールCD1枚目の内容を展開
# mkdir -p /media/centos
# mount -o loop /mnt/coLinux/iso/CentOS-5.2-i386-bin-1of6.iso /media/centos/
# mkdir -p ~/build/c5disc1
# cd ~/build/c5disc1
# (cd /media/centos/; tar cf - .) | tar xpf -
# umount /media/centos/
パッケージ追加
# yum -y install anaconda anaconda-help anaconda-runtime
# yum install 適宜必要なパッケージ ...
レポジトリ作成
# discinfo=`head -1 .discinfo`
# createrepo -u "media://$discinfo" -g repodata/comps.xml ~/build/c5disc1
ISOイメージ作成
# isofilename=~/build/c5-custom.iso
# mkisofs -r -R -J -T -v -no-emul-boot -boot-load-size 4 -boot-info-table \
-V "My Custom Linux 1.0" -p "Cool Dude" -A "My Custom Linux 1.0 - 2008/11/23" \
-b isolinux/isolinux.bin -c isolinux/boot.cat -x "lost+found" \
-o $isofilename ~/build/c5disc1
# /usr/lib/anaconda-runtime/implantisomd5 $isofilename

ブログ アーカイブ