hollyさんのwiki

本物のサーバを立てる前によくvmwareである程度構築手順を試してやるので、その時のメモ。といってもvmware playerでやっているので、他のツールはいろいろと自分で揃えておくこと。vmwareじゃなくても構築手順はそれなりに使えたりする。
これをもとにその後の用途に応じたサーバを構築すればいいかなと

OS

とりあえずよく使うCentOSで。isoファイルをダウンロードするなり、CD or DVDに焼くなりして準備しておく

設定ファイル

とりあえずこれ使う

centos-vm-master.vmx

仮想ディスク作成

qemu

http://www.h7.dion.ne.jp/~qemu-win/index-ja.html
開発は停止している。大容量の仮想できない(実際はsparseファイル)も作成できるがIDEしか無理
# 10Gの仮想ディスクファイルを作成する例
qemu-img create -f vmdk image.vmdk 10G

nhc

http://www.geocities.co.jp/SiliconValley/2994/tool...
SCSIも対応しているが、大容量の仮想ディスクが作成できない。とりあえず画面にそって作るだけなのでこっちを使う

インストール

HDD

20GB

言語

Japanese

キーボード

jp106

network

dhcp + auto

hostname

auto

timezone

Asia/Tokyo。UTCは使わない

rootパスワード

n********a

パーティション

/dev/sda
devicemount pointfile systemspace
sda1/bootext3100MB
sda2/ext3のこり
sda3/varext38192MB
sda4-extended-
sda5-swap1024MB

boot loader

そのままで次

インストールするソフト

  • development tool
  • editor
  • base

最低限の設定

基本的にすべてrootの作業。patchの当て方は以下を参考にする
# patchあて対象ファイルがあるディレクトリに移動
cd /path/to
# patchをあてる
patch < /patch_file/path/to/foo.patch

システムの言語設定

基本的にインストール時の言語設定に依存する。設定ファイルは/etc/sysconfig/i18nに記述されている
# 英語でインストール作業をしていたのでこのようになっている
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
変更したい場合はLANGを他の言語に設定する(日本語ならja_JP.UTF-8など。とりあえずCにする)
sed -i.org -e 's/^\(LANG\)=.*$/\1=C/' /etc/sysconfig/i18n

LABEL指定をdevice指定に変更

fstabとgrub.confを編集する
/etc/fstab
--- fstab.org	2009-12-19 00:55:23.000000000 +0900
+++ fstab	2009-12-19 01:16:36.000000000 +0900
@@ -1,7 +1,7 @@
-LABEL=/                 /                       ext3    defaults        1 1
-LABEL=/var              /var                    ext3    defaults        1 2
-LABEL=/boot             /boot                   ext3    defaults        1 2
+/dev/sda2               /                       ext3    defaults        1 1
+/dev/sda3               /var                    ext3    defaults        1 2
+/dev/sda1               /boot                   ext3    defaults        1 2
 tmpfs                   /dev/shm                tmpfs   defaults        0 0
 devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
 sysfs                   /sys                    sysfs   defaults        0 0
 proc                    /proc                   proc    defaults        0 0
-LABEL=SWAP-sda5         swap                    swap    defaults        0 0
+/dev/sda5               swap                    swap    defaults        0 
/boot/grub/grub.conf
--- grub.conf	2009-12-19 01:02:35.000000000 +0900
+++ grub.conf	2009-12-19 01:16:53.000000000 +0900
@@ -13,5 +13,5 @@
 hiddenmenu
 title CentOS (2.6.18-164.el5)
 	root (hd0,0)
-	kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/
+	kernel /vmlinuz-2.6.18-164.el5 ro root=/dev/sda2
 	initrd /initrd-2.6.18-164.el5.img

macアドレス情報を削除する

/etc/sysconfig/network-scripts/ifcfg-eth0 のHWADDRの項目は削除する

sshd

sshd_config設定
パスワード認証は不可、root以外はとりあえずログインできないように/etc/ssh/sshd_configを変更する
--- sshd_config.org	2009-09-04 03:12:38.000000000 +0900
+++ sshd_config	2009-12-21 00:01:02.000000000 +0900
@@ -57,7 +57,7 @@
 # To disable tunneled clear text passwords, change to no here!
 #PasswordAuthentication yes
 #PermitEmptyPasswords no
-PasswordAuthentication yes
+PasswordAuthentication no
 
 # Change to no to disable s/key passwords
 #ChallengeResponseAuthentication yes
@@ -71,9 +71,9 @@
 
 # GSSAPI options
 #GSSAPIAuthentication no
-GSSAPIAuthentication yes
+GSSAPIAuthentication no
 #GSSAPICleanupCredentials yes
-GSSAPICleanupCredentials yes
+GSSAPICleanupCredentials no
 
 # Set this to 'yes' to enable PAM authentication, account processing, 
 # and session processing. If this is enabled, PAM authentication will 
@@ -84,7 +84,7 @@
 # session checks to run without PAM authentication, then enable this but set 
 # ChallengeResponseAuthentication=no
 #UsePAM no
-UsePAM yes
+UsePAM no
 
 # Accept locale-related environment variables
 AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES 
@@ -106,7 +106,7 @@
 #ClientAliveInterval 0
 #ClientAliveCountMax 3
 #ShowPatchLevel no
-#UseDNS yes
+UseDNS no
 #PidFile /var/run/sshd.pid
 #MaxStartups 10
 #PermitTunnel no
@@ -117,3 +117,6 @@
 
 # override default of no subsystems
 Subsystem	sftp	/usr/libexec/openssh/sftp-server
+
+# only root
+AllowUsers root
公開鍵登録
mkdir ~/.ssh
echo "ssh-dss AAAAB3NzaC1kc3MAAACBAMWmPi/Qkh1PsoosvPPngmWdiDyVT5TQJmkPxvUzQnjJaEKYeC3xjUr0xystPYbQ7CnUkOvajuFQ+pSZPqAbYM23QyXfVYQ84ba2hKWxjEQe8Fg08COLIGcQEIklLZss54hsQlcBYfVN1BjBRmhPCQAc+LL2NisStlbh0kfh+Xi1AAAAFQDspHXE2/8hI3iPxPwaUFx2sdr0TQAAAIBeJO/yKgo90bz1it0XwordAyT4Ah+zVMZD8vPPN0dHxpzdbBkqDXQp77f4REXMOvtdLVaSZCX6Jujjp+DEsp5wYWE6L2IYXvgyy6lklylifqtIQqorraoYTuOh+2oe5y0irSdlYI/VGIPSGB5Z0zTXNc+7MtWv7286t8l2W21pTgAAAIAMX/bJ/Cv8q2uQhZQNo/vjVIT78LBUI9aPh1qS21nQv377wF6a469CNaJRSRrxD4kT0lnwUpQMPEvOdEpodVi5VP0c+IjHZEOVaXoXVbJH0k30E226j6j99865hTUF34RvYf4AE62TQysHgp4t0/D7EMW+FF3nTuLeFXeHdKBr1g== admin@fedora8" > ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
再起動
変更後、再起動する
/etc/rc.d/init.d/sshd restart

yumレポジトリ参照先追加

rpmforge
バージョンはその都度確認すること
wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -ivh rpmforge-release-0.3.6-1.el5.rf.i386.rpm
sed -i.org -e 's/^\(enabled\) = 1/\1 = 0/' /etc/yum.repos.d/rpmforge.repo
epel
wget http://download.fedora.redhat.com/pub/epel/5/$(uname -i)/epel-release-5-3.noarch.rpm
rpm -ivh epel-release-5-3.noarch.rpm
sed -i.org -e "s/^\(enabled\)=1/\1=0/" /etc/yum.repos.d/epel.repo
atrpms
cat <<EOL > /etc/yum.repos.d/atrpms.repo
[atrpms]
name=Redhat Enterprise Linux \$releasever - \$basearch - ATrpms
baseurl=http://dl.atrpms.net/el\$releasever-\$basearch/atrpms/stable
enabled=0
gpgcheck=1
gpgkey=http://atrpms.net/RPM-GPG-KEY.atrpms
EOL
# GPGkeyを取り込む
rpm --import http://atrpms.net/RPM-GPG-KEY.atrpms
livna
wget http://rpm.livna.org/livna-release.rpm
rpm -ivh livna-release.rpm
sed -i.org -e "s/^\(enabled\)=1/\1=0/" /etc/yum.repos.d/epel.repo

packageの整理

不要なpackageの削除
yum -y remove bluez-gnome bluez-libs bluez-utils cvs talk yp-tools ypbind yum-updatesd subversion lftp postgresql-libs apr-util
screen
何かと便利なのでインストールしておく
yum -y install screen
設定は~/.screenrcを設置する
autodetach on
bell_msg "^G"
defkanji utf-8
defencoding utf-8
encoding utf-8 utf-8
defscrollback 10000
startup_message off
vbell off
#caption always "%{= wb} %-w%{=bu dr}%n %t%{-}%+w %= %{=b wk} [%l] %{=b wb}%y/%m/%d(%D) %{=b wm}%c"
caption always "%{= wb} %-w%{=bu dr}%n %t%{-}%+w %= %{=b wk} [%l] %{=b wb}%Y/%m/%d %{=b wm}%c:%s"
# デフォルトの設定をはずしたい場合は以下のコメントをはずす
escape ^Jj
yum-security
yum -y install yum-security
yum-cron
yum-updatesdの代替
yum -y install yum-cron
yum-utils
yum -y install yum-utils
ntp
vmwareの場合はvmware-toolsで行うので必要なし。vmware以外であればいれること(というか入れておかないとだめ)
yum -y install ntp
rsyslog
syslogの代替
yum -y install rsyslog
postfix
sendmailの代替
yum -y install postfix

daemonの整理

不要なdaemonの停止
以下を実行する

chkconfig-off-daemon.sh

postfixをデフォルトのMTAに変更する
alternatives --config mta
There are 2 programs which provide 'mta'.

Selection Command
-----------------------------------------------
*+ 1 /usr/sbin/sendmail.sendmail
2 /usr/sbin/sendmail.postfix

Enter to keep the current selection[+], or type selection number: <- 2を入力
postfix設定ファイルを変更
/etc/postfix/main.cfを変更する
--- main.cf	2008-08-15 06:06:30.000000000 +0900
+++ main.cf	2009-12-19 02:20:33.000000000 +0900
@@ -68,6 +68,7 @@
 #
 #myhostname = host.domain.tld
 #myhostname = virtual.domain.tld
+myhostname = localhost.localdomain
 
 # The mydomain parameter specifies the local internet domain name.
 # The default is to use $myhostname minus the first component.
@@ -75,6 +76,7 @@
 # parameters.
 #
 #mydomain = domain.tld
+mydomain = localdomain
 
 # SENDING MAIL
 # 
@@ -91,6 +93,7 @@
 #
 #myorigin = $myhostname
 #myorigin = $mydomain
+myorigin = $myhostname
 
 # RECEIVING MAIL
 
@@ -152,10 +155,11 @@
 #
 # See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
 #
-mydestination = $myhostname, localhost.$mydomain, localhost
+#mydestination = $myhostname, localhost.$mydomain, localhost
 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
 #	mail.$mydomain, www.$mydomain, ftp.$mydomain
+mydestination = $myhostname, localhost
 
 # REJECTING MAIL FOR UNKNOWN LOCAL USERS
 #
@@ -408,6 +412,7 @@
 #
 #home_mailbox = Mailbox
 #home_mailbox = Maildir/
+home_mailbox = Maildir/
  
 # The mail_spool_directory parameter specifies the directory where
 # UNIX-style mailboxes are kept. The default setting depends on the
必要な追加daemonを起動
chkconfig yum-cron on
chkconfig rsyslog on
chkconfig postfix on
# 停止と起動
/etc/rc.d/init.d/syslog stop && /etc/rc.d/init.d/rsyslog start
/etc/rc.d/init.d/sendmail stop && /etc/rc.d/init.d/postfix start

IPv6の無効化

使うのならやる必要はないけど
# IPV6関係が存在する場合は実行
sed -i -e "s/^\(IPV6INIT\)/#\1/" -e "s/^\(IPV6_AUTOCONF\)/#\1/" /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i -e "s/^\(NETWORKING_IPV6\)/#\1/" /etc/sysconfig/network

# これを記述していれば確実
cat <<EOL >> /etc/sysconfig/network
NETWORKING_IPV6=no
IPV6INIT=no
IPV6_AUTOCONF=no
EOL
/etc/rc.d/init.d/network restart

# IPv6関係のkernelモジュールも読み込まれないようにしておく。5.4以前はoptions ipv6 disable=1の代わりにinstall ipv6 /bin/true
cp -p /etc/modprobe.conf /etc/modprobe.conf.org
cat <<EOL >> /etc/modprobe.conf
alias net-pf-10 off
options ipv6 disable=1
EOL
次回起動後、netstat -anで
::ffff:192.168.1.203:22
このような表示がされていなければよい

yum update

実行後、再起動する
yum clean all
yum -y --enablerepo=rpmforge --enablerepo=epel --enablerepo=atrpms --enablerepo=livna update
shutdown -r now

vmware-tools

このあたりでそろそろインストールする。VMware Serverの付属品として入っているのでhttp://www.vmware.com/jp/products/server/ から最新版をダウンロードする
共有フォルダの設定
vmware playerのVMware Player>共有フォルダを選択して常に有効を選択しておく。これで起動後、自動的に/mnt/hgfsとsharedFolder0.hostPathで設定されているフォルダがmountされる
インストール
# versionはその都度確認
tar xvfz VMware-server-2.0.2-203138.i386.tar.gz
mount -t iso9660 -r -o loop /root/vmware-server-distrib/lib/isoimages/linux.iso /mnt
rpm -ivh /mnt/VMwareTools-7.7.6-203138.i386.rpm
Preparing...                ########################################### [100%]
   1:VMwareTools            ########################################### [100%]

The installation of VMware Tools 7.7.6 for Linux completed successfully.
You can decide to remove this software from your system at any time by
invoking the following command: "rpm -e VMwareTools".

Before running VMware Tools for the first time, you need to
configure it for your running kernel by invoking the
following command: "/usr/bin/vmware-config-tools.pl".

Enjoy,

    --the VMware team
umount /mnt
初期設定
vmware-config-tools.plを実行するといろいろ質問されるので、基本すべてyesにする
It looks like you are trying to run this program in a remote session. This
program will temporarily shut down your network connection, so you should only
run it from a local console session. Are you SURE you want to continue?
[no] <- yes


Stopping VMware Tools services in the virtual machine:
   Guest operating system daemon:                          [  OK  ]
The bld-2.6.18-8.el5-i686smp-RHEL5 - vmmemctl module loads perfectly into the
running kernel.

The bld-2.6.18-8.el5-i686smp-RHEL5 - vmhgfs module loads perfectly into the
running kernel.

The bld-2.6.18-8.el5-i686smp-RHEL5 - vmxnet module loads perfectly into the
running kernel.

The bld-2.6.18-8.el5-i686smp-RHEL5 - vmblock module loads perfectly into the
running kernel.

[EXPERIMENTAL] The VMware FileSystem Sync Driver (vmsync) is a new feature that
creates backups of virtual machines. Please refer to the VMware Knowledge Base
for more details on this capability. Do you wish to enable this feature?
[no] <- yes。いれておくと時刻同期とかホストOSとmountできたりする

The bld-2.6.18-8.el5-i686smp-RHEL5 - vmsync module loads perfectly into the
running kernel.

The bld-2.6.18-8.el5-i686smp-RHEL5 - vmci module loads perfectly into the
running kernel.

The bld-2.6.18-8.el5-i686smp-RHEL5 - vsock module loads perfectly into the
running kernel.

No X install found.

Starting VMware Tools services in the virtual machine:
   Switching to guest configuration:                       [  OK  ]
   Guest filesystem driver:                                [  OK  ]
   Mounting HGFS shares:                                   [  OK  ]
   Guest memory manager:                                   [  OK  ]
   VM communication interface:                             [  OK  ]
   VM communication interface socket family:               [  OK  ]
   Blocking file system:                                   [  OK  ]
   File system sync driver:                                [  OK  ]
   Guest operating system daemon:                          [  OK  ]

The configuration of VMware Tools 7.7.6 build-203138 for Linux for this running
kernel completed successfully.

You must restart your X session before any mouse or graphics changes take
effect.

You can now run VMware Tools by invoking the following command:
"/usr/bin/vmware-toolbox" during an X server session.

You will need to either manually start /usr/bin/vmware-user or log out and log
back in to this desktop session to obtain the following features: guest
resolution fit, drag and drop, and file and text copy/paste.  vmware-user is
configured to automatically start at a graphical login, but that won't take
effect until the next login.

Enjoy,

--the VMware team
終了後、/etc/fstabに
# Beginning of the block added by the VMware software
.host:/                 /mnt/hgfs               vmhgfs  defaults,ttl=5     0 0
# End of the block added by the VMware software
が追記され、dfを行うと
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2             19187244   3094420  15102420  18% /
/dev/sda1               101086     17703     78164  19% /boot
tmpfs                   257664         0    257664   0% /dev/shm
.host:/              202186024  56695244 145490780  29% /mnt/hgfs
とmountされていることが確認できる。yum updateでkernelがバージョンアップした場合は必ずvmware-config-tools.plを実行すること

起動時サービス確認

anacron         0:off   1:off   2:on    3:on    4:on    5:on    6:off
auditd          0:off   1:off   2:on    3:on    4:on    5:on    6:off
crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off
iptables        0:off   1:off   2:on    3:on    4:on    5:on    6:off
irqbalance      0:off   1:off   2:on    3:on    4:on    5:on    6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off
rawdevices      0:off   1:off   2:off   3:on    4:on    5:on    6:off
rsyslog         0:off   1:off   2:on    3:on    4:on    5:on    6:off
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
vmware-tools    0:off   1:off   2:on    3:on    4:off   5:on    6:off
yum-cron        0:off   1:off   2:on    3:on    4:on    5:on    6:off

cron

hwclock <-> sysclock同期
*/10 * * * * /sbin/hwclock --systohc >/dev/null 2>&1

vmware server

最近、なんだかんだいれておくほうが便利そうなのでいれた

インストール

ライセンスは事前に入手しておくこと

tomcatをとめる

毎回決まったVMしか使わないし、tomcatが起動しているのもちょっとうざいのでとめておく
ショートカット作成
選択したVMのsummary > console にGenerate Virtual Machine Shortcutという項目があるので、これでデスクトップにお目当てのVMのショートカットを作成
VMWare Server Web Accessを停止
サービスからこれを探し出して、自動起動しないようにしておく。あとはショートカットをクリックすればそのVMだけが起動する。ID/PASSを聞かれるので、VMWare Server Web Accessにログインする時と同じID/PASSを入力する
タグ

Wiki内検索

Menu

ここは自由に編集できるエリアです。

管理人/副管理人のみ編集できます