ただの作業メモです。過度な期待はしないでください。
2011-08-09
lxcメモ
linux |
#サーバ設定
http://wiki.debian.org/LXC
apt-get install lxc bridge-utils debootstrap
echo "cgroup /cgroup cgroup defaults 0 0" >> /etc/fstab
mkdir /cgroup
mount /cgroup
#ブリッジ設定
--- /etc/network/interfaces.orig 2011-08-06 23:55:49.557820366 +0900
+++ /etc/network/interfaces 2011-08-09 00:23:13.390802682 +0900
@@ -6,8 +6,17 @@
iface lo inet loopback
# The primary network interface
-allow-hotplug eth0
-iface eth0 inet dhcp
+#allow-hotplug eth0
+#iface eth0 inet dhcp
+iface eth0 inet manual
+
+auto br0
+iface br0 inet static
+bridge_ports eth0
+address 192.168.0.100
+network 192.168.0.0
+netmask 255.255.255.0
+broadcast 192.168.0.255
#allow-hotplug eth1
#iface eth1 inet dhcp
#設定を有効にするために再起動
reboot
######
# LXC
######
#テンプレート
http://lxc.git.sourceforge.net/git/gitweb.cgi?p=lxc/lxc;a=tree;f=templates;h=3a46924833a886e74cf4d5f7cfe4b50bcf5f30f6;hb=HEAD
http://en.gentoo-wiki.com/wiki/LXC#Gentoo
#lxc作成 (Debian)
cd ~/
wget -O ~/lxc-debian.sh "http://lxc.git.sourceforge.net/git/gitweb.cgi?p=lxc/lxc;a=blob_plain;f=templates/lxc-debian.in;hb=HEAD"
export MIRROR=http://cdn.debian.or.jp/debian
export TARGET="debian"
mkdir -p /etc/lxc
mkdir -p /lxc/${TARGET}
bash ~/lxc-debian.sh -n ${TARGET} -p /lxc/${TARGET}
cp /lxc/${TARGET}/config /etc/lxc/${TARGET}.conf
設定ファイルにネットワーク情報/lxcコンテナ名を追加
nano -w /etc/lxc/debian.conf
#lxc.network.type=macvlan
lxc.network.type=veth
lxc.network.link = br0
lxc.network.flags = up
lxc.network.ipv4 = 192.168.0.111/24
lxc.network.name = eth0
lxc.utsname = debian
#lxc起動
lxc-start -n debian -f /etc/lxc/debian.conf -d
#もしうまく起動しなければ-dを外して起動してみる
#起動がうまくいけばps aux | grep lxc-startで何か出る
#lxc操作
lxc-console -n debian
user:root
pass:root
で入れる
#lxc終了
lxc-consoleやsshで入った環境下でshutdown -h now
ホストでlxc-stop -n debian
Gentoo試してみたいです…
cd ~/
wget https://raw.github.com/globalcitizen/lxc-gentoo/master/lxc-gentoo
bash ~/lxc-gentoo create
mkdir -p /lxc/gentoo
mv gentoo /lxc/gentoo/
mv /lxc/gentoo/gentoo /lxc/gentoo/rootfs
mv gentoo.conf /etc/lxc
nano -w /etc/lxc/gentoo.conf
===
lxc.rootfs = /lxc/gentoo/rootfs
===
lxc-start -n gentoo -f /etc/lxc/gentoo.conf -d
#Q&A
メモリ制限をかけたい
設定ファイルに
lxc.cgroup.memory.limit_in_bytes = 2G
を追加。(この例は2Gが制限)
ホスト起動時にLXCを開始してほしい!(Debian)
--- /etc/default/lxc.orig 2010-08-05 02:23:58.000000000 +0900
+++ /etc/default/lxc 2011-08-09 01:56:26.038425182 +0900
@@ -1,9 +1,9 @@
# Comment out to run the lxc init script
-#RUN=yes
+RUN=yes
# Directory containing the container configurations
CONF_DIR=/etc/lxc
# Start /etc/lxc/example.conf, /etc/lxc/autostart.conf, etc.
-CONTAINERS="example autostart container"
+CONTAINERS="debian gentoo"
USBプリンタをlxcで使いたい!
設定ファイルに
lxc.cgroup.devices.allow = c 180:* rwm
を追加
LXC内で次の2行を実行
apt-get install makedev
cd /dev ; MAKEDEV usb
bindを使ってホストのディレクトリをlxc内で使いたい!
設定ファイルのlxc.mount.entryをすべてコメント(例)
#lxc.mount.entry=proc /lxc/debian/rootfs/proc proc nodev,noexec,nosuid 0 0
#lxc.mount.entry=sysfs /lxc/debian/rootfs/sys sysfs defaults 0 0
代わりに設定ファイルに追加
lxc.mount = /etc/lxc/fstab/debian.fstab
次にfstabファイルを作成
mkdir -p /etc/lxc/fstab
nano -w /etc/lxc/fstab/debian.fstab
#===
proc /lxc/debian/rootfs/proc proc nodev,noexec,nosuid 0 0
devpts /lxc/debian/rootfs/dev/pts devpts defaults 0 0
sysfs /lxc/debian/rootfs/sys sysfs defaults 0 0
/home /lxc/debian/rootfs/home none bind,rw 0 0
#===
最後にマウント先のディレクトリを作成
mkdir -p /lxc/debian/rootfs/home
Ubuntu固有の問題
アップデート後コンソールに接続できなくなったのですが…
perl -pe 'if (m/\s+\/dev\s+/ | m/\s+\/dev\/shm\s+/ | m/\s+\/var\/run\s+/ ){s/^/\#/}' lib/init/fstab > lib/init/fstab.perl.tmp
mv lib/init/fstab.perl.tmp lib/init/fstab
sed -i 's:and stopped udevtrigger::g' etc/init/networking.conf
sed -i 's:and net-device-up IFACE=lo::g' etc/init/rc-sysinit.conf
http://ubuntuforums.org/showthread.php?t=1382823&page=4
1. uncomment /dev, /dev/shm, and /var/run in /lib/init/fstab
2. (re)move /etc/init/udev* and /etc/init/upstart-udev-bridge.conf
3. remove "and started udev" condition from /etc/init/module-init-tools.conf (although this is probably moot... i'm pretty sure you cant modprobe from inside a container)
4. remove "and stopped udevtrigger" condition from /etc/init/networking.conf
5. remove "and net-device-up IFACE=lo" condition from /etc/init/rc-sysinit.conf
perl -ne 'print if (m/\/dev/)'
if (m/\s+\/var\/run\s+/)
udevのアップグレードに失敗するのですが…
cd /var/lib/dpkg/info
nano -w udev.postinst
create_devices()
{
# in a vserver environment, mknod will fail; cf. LP: #144685
if grep -q ^VxID /proc/self/status; then
return
fi
return
}
2011-04-28
またやった! うっかりdd
ddで書き込み先を間違ってマウント中のデータの入ったディスクに書き込んじゃったよ。
手遅れ過ぎる。でも見てくれ。FreeBSDはマウントしてあればそんな操作許可してねえと止めてくれるんだ。Linux? 気にせず書き込んでこの様さ。
# uname -a FreeBSD freebsd-i386 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Sat Nov 21 15:48:17 UTC 2009 root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386 # newfs -U /dev/ad1 /dev/ad1: 1024.0MB (2097152 sectors) block size 16384, fragment size 2048 using 6 cylinder groups of 183.77MB, 11761 blks, 23552 inodes. with soft updates super-block backups (for fsck -b #) at: 160, 376512, 752864, 1129216, 1505568, 1881920 # mount /dev/ad1 /mnt # dd if=/dev/zero of=/dev/ad1 bs=1M dd: /dev/ad1: Operation not permitted
# uname -a Linux nigoro-virtual-machine 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:34:50 UTC 2010 i686 GNU/Linux # mkfs.ext4 /dev/sdb mke2fs 1.41.12 (17-May-2010) /dev/sdb is entire device, not just one partition! Proceed anyway? (y,n) y Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 65536 inodes, 262144 blocks 13107 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 27 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. # mount /dev/sdb /mnt # dd if=/dev/zero of=/dev/sdb bs=1M dd応答無し # dmesg [ 1737.556470] EXT4-fs (sdb): delayed block allocation failed for inode 18 at logical offset 0 with max blocks 1 with error -5 [ 1737.556501] This should not happen!! Data will be lost [ 1737.556872] attempt to access beyond end of device [ 1737.556878] sdb: rw=0, want=4194312, limit=2097152 [ 1737.556884] EXT4-fs error (device sdb): ext4_read_block_bitmap: Cannot read block bitmap - block_group = 1, block_bitmap = 524288 [ 1737.567640] EXT4-fs (sdb): delayed block allocation failed for inode 19 at logical offset 0 with max blocks 1 with error -5 [ 1737.567876] This should not happen!! Data will be lost [ 1737.567959] attempt to access beyond end of device [ 1737.567964] sdb: rw=0, want=4194312, limit=2097152 [ 1737.567969] EXT4-fs error (device sdb): ext4_read_block_bitmap: Cannot read block bitmap - block_group = 1, block_bitmap = 524288 [ 1737.568555] EXT4-fs (sdb): delayed block allocation failed for inode 20 at logical offset 0 with max blocks 1 with error -5
2011-03-27
FreeBSD SU+J fsck
いつの間にかHDDのケーブルが抜け応答不能になっていたFreeBSDマシンの電源を強制的に落としケーブルを刺し直して電源を入れたときのメモ。
FreeBSD 8.2でSoft-Updates Journalingを有効にした環境だったのでfsckも早いに違いないと思って期待していた。しかし、実際はこんな感じで結局full fsckしている。まあ、Journal timestampが適切だった他の/、/usr、/var、/tmpはジャーナルから復旧してたけど。
full fsckは残念だけど、FSの健全性を考えるとこっちの方がいいのかもしれない。
** /dev/ufs/home USE JOURNAL? yes ** SU+J Recovering /dev/ufs/home Journal timestamp does not match fs mount time ** Skipping journal, falling through to full fsck ** Last Mounted on /home ** Phase 1 - Check Blocks and Sizes ** Phase 2 - Check Pathnames ** Phase 3 - Check Connectivity ** Phase 4 - Check Reference Counts ** Phase 5 - Check Cyl groups 2737127 files, 124432658 used, 315240968 free (41856 frags, 78799778 blocks, 0.0% fragmentation) ***** FILE SYSTEM MARKED CLEAN ***** ***** FILE SYSTEM WAS MODIFIED *****
2011-02-15
不良セクタテスト
ただのメモ。ZFSでもUFS2並にデータ回復できればいいんだが…。今度recordsizeいじってみるか。
これ以外のZFSメモ
http://d.hatena.ne.jp/nigoro_0x100/20110207/1297080675
準備
host # dd if=/dev/zero of=disk1.img bs=1M count=1000
host # dd if=/dev/zero of=disk2.img bs=1M count=1000
host # dd if=/dev/zero of=disk3.img bs=1M count=1000
host # dd if=/dev/zero of=disk4.img bs=1M count=1000
ZFS
host # kvm -drive file=fbsd82-boot.img,cache=writeback,boot=on -drive file=disk1.img,cache=writeback -drive file=disk2.img,cache=writeback -boot c -m 1024 -monitor stdio -usb -usbdevice mouse -name fbsd-zfs -cpu qemu64,+aes -localtime -smp 2,sockets=1,cores=1,threads=2
# zpool create tank /dev/ad1
# cd
# zfs umount /tank
# gnop create -v -r 2 ad1 && ddrescue --force /dev/ad1.nop /dev/ad2
# ddrescue --force /dev/ad1.nop /dev/ad2
ddrescue: warning: Preallocation not available. Press Ctrl-C to interrupt rescued: 1028 MB, errsize: 20492 kB, current rate: 590 kB/s ipos: 1048 MB, errors: 39204, average rate: 594 kB/s opos: 1048 MB, time from last successful read: 0 s Finished
# shutdown -p now
host # cp -rp disk2.img disk2-errdisk.img
host # kvm -drive file=fbsd82-boot.img,cache=writeback,boot=on -drive file=disk2-errdisk.img,cache=writeback -drive file=disk2.img,cache=writeback -boot c -m 1024 -monitor stdio -usb -usbdevice mouse -name fbsd-zfs -cpu qemu64,+aes -localtime -smp 2,sockets=1,cores=1,threads=2
# zfs mount tank
# zpool status
pool: tank
state: ONLINE
status: One or more devices has experienced an unrecoverable error. An
attempt was made to correct the error. Applications are unaffected.
action: Determine if the device needs to be replaced, and clear the errors
using 'zpool clear' or replace the device with 'zpool replace'.
see: http://www.sun.com/msg/ZFS-8000-9P
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
tank ONLINE 0 0 0
ad1 ONLINE 0 0 2
errors: No known data errors
# cp -rp /tank/src1 /tmp
<snip> cp: /tmp/src1/usr.bin/mklocale/yacc.y: Bad address cp: /tmp/src1/usr.bin/mklocale/lex.l: Bad address cp: /tmp/src1/usr.bin/vgrind/vgrind.1: Bad address cp: /tmp/src1/usr.bin/vgrind/vfontedpr.c: Bad address cp: /tmp/src1/usr.bin/du/du.1: Bad address cp: /tank/src1/usr.bin/talk: Illegal byte sequence cp: /tank/src1/usr.bin/tabs: Illegal byte sequence cp: /tank/src1/usr.bin/tail: Illegal byte sequence cp: /tmp/src1/UPDATING: Bad address cp: /tmp/src1/Makefile.inc1: Bad address cp: /tmp/src1/Makefile: Bad address cp: /tmp/src1/ObsoleteFiles.inc: Bad address
# dmesg
<snip> vm_fault: pager read error, pid 1090 (cp) vm_fault: pager read error, pid 1090 (cp) vm_fault: pager read error, pid 1090 (cp) vm_fault: pager read error, pid 1090 (cp) vm_fault: pager read error, pid 1090 (cp) vm_fault: pager read error, pid 1090 (cp) vm_fault: pager read error, pid 1090 (cp) vm_fault: pager read error, pid 1090 (cp) vm_fault: pager read error, pid 1090 (cp) vm_fault: pager read error, pid 1090 (cp)
# zpool status
pool: tank
state: ONLINE
status: One or more devices has experienced an error resulting in data
corruption. Applications may be affected.
action: Restore the file in question if possible. Otherwise restore the
entire pool from backup.
see: http://www.sun.com/msg/ZFS-8000-8A
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
tank ONLINE 0 0 9.37K
ad1 ONLINE 0 0 20.5K
errors: 8729 data errors, use '-v' for a list
# du -s /usr/src
549610 /usr/src
# du -s /tmp/src1
191314 /tmp/src1
UFS2+SU
host # kvm -drive file=fbsd82-boot.img,cache=writeback,boot=on -drive file=disk3.img,cache=writeback -drive file=disk4.img,cache=writeback -boot c -m 1024 -monitor stdio -usb -usbdevice mouse -name fbsd-zfs -cpu qemu64,+aes -localtime -smp 2,sockets=1,cores=1,threads=2
# newfs -U /dev/ad1
# mount /dev/ad1 /mnt
# cd
# umount /mnt
# gnop create -v -r 2 ad1 && ddrescue --force /dev/ad1.nop /dev/ad2
ddrescue: warning: Preallocation not available. Press Ctrl-C to interrupt rescued: 1027 MB, errsize: 20871 kB, current rate: 598 kB/s ipos: 1048 MB, errors: 39981, average rate: 579 kB/s opos: 1048 MB, time from last successful read: 0 s Finished
# mount /dev/ad2 /mnt
# cp -rp /mnt/src2 /tmp
cp: /mnt/src2/release/scripts/ports-install.sh: Bad file descriptor cp: /mnt/src2/release/doc/de_DE.ISO8859-1/relnotes/alpha/Makefile: Bad file descriptor cp: /mnt/src2/release/doc/de_DE.ISO8859-1/relnotes/alpha/article.sgml: Bad file descriptor cp: /mnt/src2/release/doc/en_US.ISO8859-1/Makefile: Bad file descriptor cp: /mnt/src2/release/doc/fr_FR.ISO8859-1: Bad file descriptor cp: /mnt/src2/release/picobsd/mfs_tree/etc/gettytab: Bad file descriptor cp: /mnt/src2/release/picobsd/mfs_tree/etc/motd: Bad file descriptor cp: /mnt/src2/release/picobsd/mfs_tree/etc/protocols: Bad file descriptor cp: /mnt/src2/release/picobsd/mfs_tree/etc/termcap: Bad file descriptor
# du -s /tmp/src2
491774 /tmp/src2
2011-02-07
ZFS メモ
FreeBSD |
この項目はZFS関係で気づいたことがあれば随時更新します。twilogもどうぞ。
4KB/セクタ HDDでパフォーマンスが出ない
- ZFS write performance issues with WD20EARS
- http://forums.freebsd.org/archive/index.php/t-15402.html
- 紹介されたパッチ
- http://lists.freebsd.org/pipermail/freebsd-fs/2010-October/009706.html
FreeBSD 8.2でZFS v15になります。kern/146410: [zfs] [patch] bad file copy performance from UFS to ZFSが修正されています。
http://www.freebsd.org/cgi/query-pr.cgi?pr=146410
http://people.freebsd.org/~mm/patches/zfs/v28/
不良セクタテスト
http://d.hatena.ne.jp/nigoro_0x100/20110215/1297769116
# Solaris 11
ZFS Pool Version 30で暗号化に対応した模様。
http://hub.opensolaris.org/bin/view/Community+Group+zfs/30
RAID-Zでシーケンシャル書き込みのパフォーマンスが悪い
特に大きなファイルを書き込もうとすると、キャッシュが大きすぎて計算に時間がかかり、実際にHDDに書き込む動作と計算する動作が交互に行われるような状態になる。計算中はCPUがほぼ100%となり、データの転送が止まってしまうため思ったほどパフォーマンスが出ない原因となる。
キャッシュサイズを変更することである程度解決できる。デフォルトは30秒分の書き込みをメモリに置いておくようだが、これを5秒に設定する。それでも、期待通りに動作しなければ0に設定してみる。
echo 'vfs.zfs.txg.timeout="5"' >> /boot/loader.conf
さらにシーケンシャル書き込みのためにできることは、次の2項目の数値を減らすこと。書き込み中にいきなりガクッと転送速度が落ちる場合は減らしてみる。(両方とも最小の値は1)
#/boot/loader.conf vfs.zfs.vdev.min_pending="2" vfs.zfs.vdev.max_pending="8"
物理メモリどころかスワップまで使い始めた、助けて!
下記4項目の数値を適切に設定することでスワップすることは無くなります。
#/boot/loader.conf vm.kmem_size_max="2048M" vm.kmem_size="1536M" vfs.zfs.arc_max="512M" vfs.zfs.vdev.cache.size="100M"