Ubuntu 12.04 (Precise Pangolin) server editionの初期設定メモ。
- このメモの目的と内容
- kvm仮想マシンを各種サーバとして使うための自分用メモ
- インストールにはubuntu-12.04-server-i386.iso.torrentを使用
- インストールするマシンとして、192MBのメモリと10GBのストレージ(qcow2/virtio)2台が接続されている仮想マシンを使用
最新バージョンでの初期設定内容はUbuntuにて掲載しています。
仮想マシンの作成
仮想マシンマネージャーで仮想マシンを作成する。 作成後、すぐにはインストールを開始せず、VNCサーバーのキーマップをjaにしておく。
インストール手順
ブート画面
- F2 Language: [English]を選択
- F3 Keymap: [Japan]を選択
- [Install Ubuntu Server]を選択
Select a language
- Language: [English - English]を選択
Select your location
- Country, territory or area: [other] → [Asia] → [Japan]の順に選択
Configure locales
- Country to base default locale settings on: [United States - en_US.UTF-8]を選択
Loading additional components
- (インストールが終わるまで待つ)
Configure the network
(DHCPを無効にしている場合)
- Network configuration method: [Configure network manually]を選択
- (以下ダイアログに従ってIPアドレス等を入力)
Set up users and passwords
- (ダイアログに従ってユーザ名・パスワード等を入力)
- Encrypt your home directory?: <No>を選択
Configure the clock
- Is this time zone correct?: 適切なタイムゾーンが選択されていることを確認して<Yes>を選択
Partition disks
- Partitioning method: [Manual]を選択
- 以下のように設定
Virtual disk1 vda 10GB #1 primary 512M ext4 /boot Mount option: defaults #5 logical (max) ext4 /usr Mount option: defaults Virtual disk2 vdb 10GB #1 primary (max) ext4 / Mount option: defaults #5 logical 512M swap - - [Finish partitioning and write changes to disk]を選択
- Write the changes to disks?: パーティションのフォーマットを確認して<Yes>を選択
Installing the base system
- (インストールが終わるまで待つ)
Configure the package manager
- HTTP proxy information: 空欄のままもしくは必要に応じて適切なURLを入力
Configuring tasksel
- How do you want to manage upgrades on this system? [No automatic updates]を選択
Software selection
- (サーバの構成に従って適当なものを選択)
- [Mail server]の設定例
- Postfix Configuration
- General type of mail configuration: [Satellite system]を選択
- System mail name: 適当な名前を入力
- SMTP relay host: メール配送に用いるSMTPサーバのホスト名を入力
- Postfix Configuration
Install the GRUB boot loader on a hard disk
- Install the GRUB boot loader to the master boot record?: <Yes>を選択
Finish the installation
- Installation complete: ディスクを取り出して<Continue>を選択
- 再起動
インストール後の設定
デフォルトのエディタ変更
好みのエディタに変更する。
$ sudo update-alternatives --config editor There are 4 choices for the alternative editor (providing /usr/bin/editor). Selection Path Priority Status ------------------------------------------------------------ * 0 /bin/nano 40 auto mode 1 /bin/ed -100 manual mode 2 /bin/nano 40 manual mode 3 /usr/bin/vim.basic 30 manual mode 4 /usr/bin/vim.tiny 10 manual mode Press enter to keep the current choice[*], or type selection number: 3 update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in manual mode.
~/.vimrc
以下の内容で作成。
~/.vimrc
set encoding=utf-8
set fileencoding=utf-8
set fileencodings=utf-8,utf-16,japan
set backspace=2
set tabstop=2
set shiftwidth=4
set expandtab
highlight tabs ctermbg=green guibg=green
set list
set number
set ruler
set smartindent
~/.bashrc
以下の内容を追記。
~/.bashrc
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
PS1='\!> \[\033[0;33m\]\u\[\033[m\]@\[\033[0;36m\]\h\[\033[m\] [\[\033[0;32m\]\t\[\033[m\] \w]\$ '
case $TERM in
kterm|xterm|cygwin)
TITLEBAR="\u@\h:\w"
PS1="\[\033]0;${TITLEBAR}\007\]${PS1}"
;;
esac
/etc/aliases
root宛のメール送信先を変更する。
/etc/aliases
# 以下を追記
root: root@example.com
変更を反映する。
sudo newaliases
GRUB 2
起動時にGRUB 2のメニュー画面が表示されるようにする。 GRUB_HIDDEN_TIMEOUTをコメントアウトし、GRUB_TIMEOUTにタイムアウト秒数を指定する。
/etc/default/grub
#GRUB_HIDDEN_TIMEOUT=0
GRUB_TIMEOUT=5
変更内容を反映する。
$ sudo update-grub2 Generating grub.cfg ... Found linux image: /boot/vmlinuz-2.6.32-21-generic-pae Found initrd image: /boot/initrd.img-2.6.32-21-generic-pae Found memtest86+ image: /memtest86+.bin done
パッケージのインストールと設定
xineted + telnetd
sudo apt-get install xinetd telnetd
以下を追記。
/etc/hosts.allow
in.telnetd : 127.0.0.1 192.168.0.0/24
/etc/hosts.deny
ALL : PARANOID
/etc/xinetd.d/telnetを作成。
/etc/xinetd.d/telnet
service telnet
{
disable = no
flags = REUSE
socket_type = stream
user = telnetd
wait = no
server = /usr/sbin/in.telnetd
server_args = -h
only_from = 192.168.0.0/24 127.0.0.1
log_on_failure += USERID
}
xinetdを再起動。
sudo service xinetd restart
NFS
sudo apt-get install nfs-common
マウントポイントを作成。
sudo mkdir -p /srv/nfs
/etc/fstabを編集後、マウントする。
sudo vi /etc/fstab
sudo mount -a
マウントされたかどうか確認する。
cat /etc/mtab
ls -l /srv/nfs
NTP
sudo apt-get install ntp
適当なNTPサーバを設定、再起動。
sudo vi /etc/ntp.conf
sudo service ntp restart
Logwatch
sudo apt-get install logwatch
Munin
sudo apt-get install munin-node
/etc/munin/pluginsから必要なプラグインだけを残す。
sudo unlink xxx
sudo ln -s /usr/share/munin/plugins/xxx
データを収集するマシンのみからのアクセスを許可するように変更する。
/etc/munin/munin-node.conf
allow ^192\.168\.0\.10$
munin-nodeを再起動。
sudo service munin-node restart
データを収集するマシンからtelnetで接続できるか試す。
$ telnet server1.example.com 4949 Trying 192.168.0.20... Connected to server1.example.com. Escape character is '^]'. # munin node at server1.example.com nodes server1.example.com . quit Connection closed by foreign host.
AWStats
sudo apt-get install awstats
/etc/awstats以下の設定ファイルを編集後、ログが読み込まれデータが正しく収集されるかテストする。
sudo -u www-data /usr/share/doc/awstats/examples/awstats_updateall.pl now -awstatsprog=/usr/lib/cgi-bin/awstats.pl -confdir="/etc/awstats/"
ls /var/lib/awstats
必要に応じてcron(/etc/cron.d/awstats)の設定およびHTTPサーバの設定を更新したのち、「http://サーバ名/awstats/awstats.pl?config=設定ファイル名」を開いて収集されたデータが表示されるか確かめる。