Ubuntu 10.04 LTS (Lucid Lynx) AMI
雑多なメモ
長い間、Ubuntu 8.04.4 LTS (Hardy Heron) と付き合って、Lucid Lynx はまだ性格がよくわからない事が多いので、癖をメモ
はじめの第一歩
echo "Asia/Tokyo" | sudo tee /etc/timezone
sudo dpkg-reconfigure --frontend noninteractive tzdata
sudo service rsyslog restart
sudo service cron restart
sudo aptitude update
sudo aptitude -y safe-upgrade
# reboot
# edit .screenrc
# screen -xRR
# edit .bashrc
# unset command_not_found_handle
# mkfs.ext3 /dev/sdf
# mkdir /opt
# tune2fs -c -1 -i 0 /dev/sdf
# mount -o defaults,relatime /dev/sdf /opt
# vi /etc/fstab
# umount /opt
# mount /opt
sudo aptitude install libperl5.10
sudo aptitude install sysstat
sudo aptitude install sqlite3
sudo aptitude install binutils
sudo aptitude install sharutils
sudo aptitude install traceroute
sudo aptitude -y install dump
sudo aptitude -y install bind9
sudo aptitude -y install emacs23-nox
sudo aptitude install s3cmd
sudo aptitude -y install git-core
sudo aptitude install python-ipy
CloudFormation example for ubuntu
/etc/hosts.allow
書いておくほうが無難
sshd : .jp (ここは実情に合わせて) : allow sshd : localhost 127.0.0.1 : allow sshd : ALL : deny #ALL : PARANOID : RFC931 20 : deny ALL : localhost 127.0.0.1 : allow ALL : [::1] : allow rpcbind : ALL : deny
cloud-init
- ec2-init から cloud-init になって戸惑い
調査中...
古い ec2-init からいただき
メールサーバとかで必要になる 内部 IP address と論理ホスト名との整合性を取る仕掛け Split DNS (基本的にこの設定をしておくと、EC2 の IP address の差異を気にしなくて良くなる)
/usr/local/etc/init に修正して配置
ec2-set-hosts
#!/usr/bin/python
#
# Set up the hostname for ec2.
# Copyright 2008 Canonical Ltd.
#
# Author: Chuck Short <chuck.short@canonical.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import urllib
import os
from Cheetah.Template import Template
api_ver = '2011-01-01'
metadata = None
base_url = 'http://169.254.169.254/%s/meta-data' % api_ver
my_hostname = urllib.urlopen('%s/local-hostname/' % base_url).read()
my_ip = urllib.urlopen('%s/local-ipv4/' % base_url).read()
my_fqdn = os.popen("/bin/cat /etc/hostname").read().rstrip()
# replace the ubuntu hostname in /etc/hosts
mp = {'localipv4' : my_ip, 'hostname' : my_hostname, 'fqdn' : my_fqdn}
t = Template(file="/usr/local/etc/bind/templates/hosts.tmpl", searchList=[mp])
os.system("rm -f /etc/hosts")
f = open("/etc/hosts", "w")
f.write('%s' %(t))
f.close()
/usr/local/etc/bind/templates/hosts.tmpl
127.0.0.1 localhost #127.0.1.1 $hostname $localipv4 $fqdn # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
ec2-set-dns-zone (内部 DNS 設定用)(aptitude install python-ipy で IPy 導入前提)
#!/usr/bin/python
#
# Set up the hostname for ec2.
# Copyright 2008 Canonical Ltd.
#
# Author: Chuck Short <chuck.short@canonical.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import urllib
import os
from Cheetah.Template import Template
from IPy import IP
api_ver = '2011-01-01'
metadata = None
base_url = 'http://169.254.169.254/%s/meta-data' % api_ver
my_ip = urllib.urlopen('%s/local-ipv4/' % base_url).read()
my_fqdn = os.popen("/bin/cat /etc/hostname").read().rstrip()
ip = IP(my_ip)
my_arpa = ip.reverseName().rstrip('.')
# replace the Split DNS host ip address in /etc/bind/db.myzone
mp = {'localipv4' : my_ip}
t = Template(file="/usr/local/etc/bind/templates/zone.tmpl", searchList=[mp])
os.system("rm -f /etc/bind/db.myzone")
f = open("/etc/bind/db.myzone", "w")
f.write('%s' %(t))
f.close()
# replace the Split DNS host ip address in /etc/bind/db.myarpa
mp = {'fqdn' : my_fqdn}
t = Template(file="/usr/local/etc/bind/templates/arpa.tmpl", searchList=[mp])
os.system("rm -f /etc/bind/db.myarpa")
f = open("/etc/bind/db.myarpa", "w")
f.write('%s' %(t))
f.close()
# replace the Split DNS host ip address in /etc/bind/myzone.conf
mp = {'fqdn' : my_fqdn, 'arpa' : my_arpa}
t = Template(file="/usr/local/etc/bind/templates/conf.tmpl", searchList=[mp])
os.system("rm -f /etc/bind/myzone.conf")
f = open("/etc/bind/myzone.conf", "w")
f.write('%s' %(t))
f.close()
/usr/local/etc/bind/templates/zone.tmpl
; ; BIND data file for Split DNS ; @ 604800 IN SOA localhost. root.localhost. ( 2 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ 604800 IN NS localhost. @ 604800 IN A $localipv4 @ 604800 IN MX 10 @
/usr/local/etc/bind/templates/arpa.tmpl
; ; BIND data file for Split DNS ; @ 604800 IN SOA localhost. root.localhost. ( 2 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ 604800 IN NS localhost. @ 604800 IN PTR $fqdn.
/usr/local/etc/bind/templates/conf.tmpl
zone "$fqdn" { type master; file "/etc/bind/db.myzone"; }; zone "$arpa" { type master; file "/etc/bind/db.myarpa"; };
/etc/bind/named.conf.local に以下を追加する
include "/etc/bind/myzone.conf";
/etc/bind/named.conf.options の forwarders を EC2 の内部 DNS サーバに設定
forwarders { 172.16.0.23; };
/etc/bind/named.conf.options の listen address 制限しておく
// listen-on-v6 { any; }; listen-on { 127.0.0.1; }; listen-on-v6 { ::1; };
起動スクリプトとしてリンク
sudo ln -s /usr/local/etc/init/ec2-set-hosts /etc/rc2.d/S12ec2-set-hosts sudo ln -s /usr/local/etc/init/ec2-set-dns-zone /etc/rc2.d/S13ec2-set-dns-zone
IPv4 only にするために /etc/default/bind9 を変更
OPTIONS="-4 -u bind"
dhcp client が自動生成する /etc/resolv.conf に反映する為に、/etc/dhcp3/dhclient.conf のコメントを外す
prepend domain-name-servers 127.0.0.1;
hostname を設定する。
echo "host.example.com" | sudo tee /etc/hostname sudo /bin/hostname -F /etc/hostname
EIPをアサインして、公開 DNS に登録する。
hostname
- /bin/hostname
いろいろかわってる感じ
hostname --fqdn について
See the warnings in section THE FQDN above, and avoid using this option; use hostname --all-fqdns instead.
とある。'THE FQDN' セクションには
THE FQDN このコマンドでFQDN(hostname --fqdnで返される)やDNSドメイン名(dnsdomainnameで返される)を 変更することはできません。システムのFQDNはresolver(3)でホスト名として返す名前です。 技術的背景:FQDNはgethostname(2)で返されたホスト名をgetaddrinfo(3)に渡して得られた名前です。 DNSドメイン名は最初のドット以後の部分です。 したがって、名前解決の優先度を指定するコンフィグレーション(通常 /etc/host.conf)に依存します。 通常は(hostsファイルがDNSやNISに優先されているので) /etc/hosts を変更します。 もしマシンに複数のネットワークインターフェイスやアドレスがある場合、もしくはモバイル環境で使用されている場合は、 FQDNとドメイン名を複数を持っている場合や、全く無いといった可能性があります。 したがって、hostname --fqdn, hostname --domain, dnsdomainnameコマンドは使用すべきではありません。 hostname --ip-addressも同様の制限があり使用すべきではありません。
ソースコード : hostname.c
したがって、hostname を明示的に変更している場合の (/etc/hostname を自分のホスト名にしている場合)
% hostname --fqdn hostname: Name or service not known
は無視すれば良い。
でも、気になる場合は環境に合わせて、resolver 系コンフィグレーションを変更すれば良い。
EC2 では /etc/resolv.conf の domain と search 行を消すか、/etc/hostname のドメイン名を指定すれば良い。
ec2 の dhcp 環境では、
指定する場合
/etc/dhcp3/dhclient.conf で
supersede domain-name "ドメイン名";
削除する場合
(というよりも resolv.conf を dhclient3 に自動生成させない)
/etc/dhcp3/dhclient-enter-hooks.d/ で hack するべし 以下の内容のファイルをお好きな名前で作成する。
#!/bin/bash make_resolv_conf(){ : }
motd
- motd
upgrade したはずなのに、
A newer build of the Ubuntu lucid server image is available. It is named 'release' and has build serial 'XXXXXXXX.X'.
と表示される。 known bug らしい。優先度 low で fix 予定
Bug #653220 in cloud-init (Ubuntu): “remove updates-check from cloud-init”
- 2重 motd 問題は
mv /etc/motd.tail /etc/motd.tail.old
sysctl
/etc/sysctl.d/ なるものが出来てる。 READMEによると 60-*.conf でホゲリなさいとの事。
60-my-tuning.conf てな名前で最低限の指定など
vm.swappiness=0 kernel.panic_on_oops=1 kernel.panic=1 # Disable IPv6 net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1 net.ipv6.conf.lo.disable_ipv6=1
どうも、/etc/sysctl.d/ に配置しても、ipv6 系は反映されないようだ。なので kernel option で殺す。
大規模サーバの都市伝説 ;)
kernel.sem=250 32000 128 1024 kernel.msgmni=256 kernel.shmmax=268435456 fs.file-max=6815744 net.ipv4.ip_local_port_range=9000 65500 # net.core.rmem_max=16777216 net.core.wmem_max=16777216 net.ipv4.tcp_rmem=4096 87380 16777216 net.ipv4.tcp_wmem=4096 65536 16777216 net.core.rmem_default=262144 net.core.wmem_default=262144 # net.core.netdev_max_backlog=30000 net.core.somaxconn=262144 net.ipv4.tcp_max_orphans=262144 net.ipv4.tcp_max_syn_backlog=262144 net.ipv4.tcp_fin_timeout=3 net.ipv4.tcp_no_metrics_save=1 net.ipv4.tcp_synack_retries=2 net.ipv4.tcp_syn_retries=2 net.ipv4.tcp_tw_reuse=1 net.ipv4.tcp_tw_recycle=1
kernel options
grub-legacy-ec2 なので いろいろ違う。
/etc/default/grub は /usr/sbin/update-grub-legacy-ec2 で読み込んでいるが、GRUB2 用がインストールされているので無視
grub legacy では '# ' に仕込むという変な仕様
/boot/grub/menu.lst を変更
# defoptions=xencons=hvc0 console=hvc0 | # defoptions=xencons=hvc0 console=hvc0 ipv6.disable=1
sudo update-grub-legacy-ec2
で反映
☆注意☆
menu.lst を書き換えた後、debconf が対話メニューを出す場合
install the package maintainer's version
を選択すること。(でないと、これからの update の際に menu.lst が更新されない)
メモ
/var/cache/debconf/config.dat
Name: grub/update_grub_changeprompt_threeway Template: grub/update_grub_changeprompt_threeway Value: install_new Owners: grub, grub-legacy-ec2 Flags: seen Variables: BASENAME = menu.lst FILE = /var/run/grub/menu.lst
# debconf-show grub-legacy-ec2 * grub/update_grub_changeprompt_threeway: install_new
man 1 ucf
定番パッケージ
cron-apt
sudo aptitude install cron-apt
edit .....
いろいろ
sudo aptitude install php-pear
sudo aptitude install apache2-prefork-dev
sudo aptitude install php5-dev
# sudo pecl upgrade -f apc-3.1.7
# sudo pecl upgrade -f memcache-3.0.6
# sudo /etc/init.d/apache2 restart
Zimbra 系メモ
Sending Mail from Terminal (optional)
wget http://ubuntu.lnix.net/misc/mta-dummy/mta-dummy_1.0_all.deb
dpkg -i mta-dummy_1.0_all.deb
aptitude install bsd-mailx
Add the following to /etc/mail.rc:
set sendmail=/opt/zimbra/postfix/sbin/sendmail
WordPress 系メモ
とりあえずパッケージでいれて設定だけいただく
sudo aptitude -y install wordpress
sudo /bin/bash /usr/share/doc/wordpress/examples/setup-mysql -n WORDPRESSDBNAME HOSTNAME
# 消す前に /usr/share/doc/wordpress 固めて保存しておく
sudo apt-get -y remove wordpress
sudo aptitude keep-all
未整理
お手軽 計測・可視化
node
sudo aptitude install munin-node
sudo aptitude install munin-plugins-extra
sudo aptitude install libcache-cache-perl
sudo aptitude install libcache-memcached-perl
sudo aptitude install libtext-csv-xs-perl
server
sudo aptitude install munin
お手軽 サービス・死活監視
sudo aptitude install monit
.screenrc
defutf8 on defkanji utf-8 encoding utf-8 utf-8 defencoding utf-8 # vbell off autodetach on startup_message off altscreen on # for Emacsian escape ^Tt # defhstatus "^En:^Et" hardstatus on hardstatus alwayslastline "screen |%c %m/%d | %w" # for Macintosh delete key bindkey -k kD stuff \177 # for MacOSX Terminal.app termcapinfo xterm* ti@:te@ # avoid angerous key bind bind x bind ^x bind k bind ^k bind . bind ^\ bind \\ bind ^h bind h
~/.ssh/config
Host * #ForwardAgent yes TCPKeepAlive yes ServerAliveInterval 15 ServerAliveCountMax 60
varnishd
Installation on Ubuntu
echo "deb http://repo.varnish-cache.org/ubuntu/ lucid varnish-2.1" | sudo tee /etc/apt/sources.list.d/varnish.list
wget -qO - http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-key add -
sudo aptitude update
sudo aptitude install varnish
あんちょくな daily backup script
#!/bin/sh
if [ "`/bin/cat /proc/partitions | /bin/fgrep sdp`" ]; then
/sbin/tune2fs -c -1 -i 0 /dev/sdp > /dev/null 2>&1
/sbin/e2label /dev/sda1 uec-rootfs
if [ "`/bin/cat /proc/mounts | /bin/fgrep sdp`" ]; then
echo "Warn: /dev/sdp is already mounted."
else
if [ ! -e /backup ]; then
/bin/mkdir /backup
fi
/bin/mount -t ext3 /dev/sdp /backup
/bin/sleep 5
fi
# check twice
if [ "`/bin/cat /proc/mounts | /bin/fgrep sdp`" ]; then
if [ -c /backup/dev/null ]; then
# FULL BACKUP
# cd /backup
# /sbin/dump 0uf - /dev/sda1 | /sbin/restore rf -
# /usr/bin/nice -n 19 /usr/bin/rsync -ax -e /usr/bin/ssh --delete / /backup/
/bin/sync; /bin/sync; /bin/sync
/bin/sleep 5
/usr/bin/nice -n 19 /usr/bin/rsync -ax --delete / /backup/
/bin/sync; /bin/sync; /bin/sync
/bin/sleep 5
/bin/umount /backup
else
echo "Error: /backup is unexpected volume."
fi
else
echo "Error: something failure happens. mount error?"
fi
else
echo "Error: /dev/sdp is not attached."
fi
- このあと snapshopt をとる
botoを使ってEBSをバックアップ(世代管理つき) - インフラエンジニアway
ubuntu AMI は boto 1.9b が標準ではいっているので管理プログラムは boto を使うのがよさそう。
管理作業用の credential は IAM で権限を制限したものを利用する。
Snapshot 運用に制限する場合の Policy
{ "Statement": [ { "Action": [ "ec2:CreateSnapshot", "ec2:DeleteSnapshot", "ec2:DescribeRegions", "ec2:DescribeSnapshotAttribute", "ec2:DescribeSnapshots", "ec2:ModifySnapshotAttribute", "ec2:ResetSnapshotAttribute" ], "Effect": "Allow", "Resource": "*" } ] }
MySQL を noninteractive でインストール。(対話型でパスワードを聞かれるのを自動設定する)
echo 'mysql-server-5.1 mysql-server/root_password password PASSWORD' | sudo debconf-set-selections
echo 'mysql-server-5.1 mysql-server/root_password seen true' | sudo debconf-set-selections
echo 'mysql-server-5.1 mysql-server/root_password_again password PASSWORD' | sudo debconf-set-selections
echo 'mysql-server-5.1 mysql-server/root_password_again seen true' | sudo debconf-set-selections
echo 'mysql-server-5.1 mysql-server/start_on_boot boolean true' | sudo debconf-set-selections
sudo aptitude -y install mysql-server
NICのアクセラレーション設定を無効にする
/etc/network/interfaces に追加
post-up /usr/sbin/ethtool -K eth0 sg off post-up /usr/sbin/ethtool -K eth0 tso off
root device 問題
boot する root device の指定が LABEL=uec-rootfs になっている。 想定している boot device 以外に DISK LABEL が uec-rootfs の volume が attach されている場合に不具合が起きる可能性があります。 ☆環境により boot しない場合有り 注意☆
sudo e2label /dev/sda1
ls -al /dev/disk/by-label
sudo e2label /dev/sda1 uec-rootfs
sudo e2label /dev/sdp copy-of-uec-rootfs
という手もあるんだが... root device = boot device = /dev/sda1 に単純化したほうが事故が少ないと思う。
EC2 の環境では、ディスクドライブが明示的に指定でき、明示的にそのドライブ名にボリュームをアサインできるので、Disk Label にたよる必要はない。
Ubuntu で LABEL=uec-rootfs にしている意味・意義がなくなるが、EBS backed AMI での運用の利便性(instance stop して volume 挿げ替え)と確実性を考えから root=/dev/sda1 固定にすべきに参萬点
/etc/fstab
LABEL=uec-rootfs を /dev/sda1 に変更
/boot/grub/menu.lst
root=LABEL=uec-rootfs を root=/dev/sda1 に変更
# kopt=root=LABEL=uec-rootfs ro | # kopt=root=/dev/sda1 ro
Bug #665235 in Ubuntu on EC2: “grub-legacy-ec2: attaching a volume to maverick instance may boot off it”
いろんな議論があるようですが、私は現在の変化しつつある状況では保守的な選択をしますね。つまり、root=/dev/sda1 決めうち。
todo
echo 'deb http://apt.opscode.com/ lucid-0.10 main' | sudo tee /etc/apt/sources.list.d/opscode.list
wget -qO - http://apt.opscode.com/packages@opscode.com.gpg.key | sudo apt-key add -
sudo aptitude update
sudo aptitude -y install chef
limit 系
startup script にキッチリ ulimit を書くのが本道
ウッカリを防ぐために pam 系で制限解除
/etc/security/limits.d/mylimits.conf
* - stack -1 root - nofile 524288