CentOS環境自動構築サーバーの実験
自動構築サーバVM構築
VM定義
※isoファイルにcentos65のminiを設定してインストールする
↓
※ネットワークは上記のとおり
↓
※インストール完了
iptables無効化
chkconfig iptables off
パッケージインストール
yum install dhcp httpd tftp-server syslinux createrepo -y chkconfig dhcpd on chkconfig httpd on chkconfig tftp on chkconfig xinetd on
マウント
mkdir /mnt/cdrom mount /dev/cdrom /mnt/cdrom >mount: ファイルシステムタイプを指定する必要があります mount /dev/cdrom /mnt/cdrom
↓
リスト確認
[root@localhost ~]# ll /mnt/cdrom/ 合計 82 -r--r--r-- 1 root root 14 11月 29 20:52 2013 CentOS_BuildTag dr-xr-xr-x 3 root root 2048 11月 29 21:05 2013 EFI -r--r--r-- 1 root root 212 11月 28 04:12 2013 EULA -r--r--r-- 1 root root 18009 11月 28 04:12 2013 GPL dr-xr-xr-x 2 root root 40960 11月 29 21:14 2013 Packages -r--r--r-- 1 root root 1354 11月 28 04:13 2013 RELEASE-NOTES-en-US.html -r--r--r-- 1 root root 1706 11月 28 04:12 2013 RPM-GPG-KEY-CentOS-6 -r--r--r-- 1 root root 1730 11月 28 04:12 2013 RPM-GPG-KEY-CentOS-Debug-6 -r--r--r-- 1 root root 1730 11月 28 04:12 2013 RPM-GPG-KEY-CentOS-Security-6 -r--r--r-- 1 root root 1734 11月 28 04:12 2013 RPM-GPG-KEY-CentOS-Testing-6 -r--r--r-- 1 root root 3380 11月 29 21:14 2013 TRANS.TBL dr-xr-xr-x 3 root root 2048 11月 29 21:14 2013 images dr-xr-xr-x 2 root root 2048 11月 29 21:04 2013 isolinux dr-xr-xr-x 2 root root 4096 11月 29 21:14 2013 repodata [root@localhost ~]#
Webサーバディレクトリへ配置
cp -r /mnt/cdrom /var/www/html/centos65
DHCPサーバ設定(/etc/dhcp/dhcpd.conf)
# # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.sample # see 'man 5 dhcpd.conf' # subnet 192.168.51.0 netmask 255.255.255.0 { default-lease-time 21600; max-lease-time 43200; option routers 192.168.51.2; option subnet-mask 255.255.255.0; range 192.168.51.100 192.168.51.150; } host client01 { hardware ethernet 00:0c:29:1a:79:22; fixed-address 192.168.51.100; filename "/pxeboot_cent65/pxelinux.0"; next-server 192.168.51.50; }
※hardware ethernetはあとで変更することになるので注意
DHCP起動
service dhcpd configtest > Syntax: OK service dhcpd restart > dhcpd を起動中: [ OK ]
TFTPサーバーの設定
cd /var/lib/tftpboot/ mkdir pxeboot_cent65 cp /mnt/cdrom/isolinux/{initrd.img,vmlinuz} /var/lib/tftpboot/pxeboot_cent65/ cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/pxeboot_cent65/ touch /var/lib/tftpboot/pxeboot_cent65/boot.msg mkdir /var/lib/tftpboot/pxeboot_cent65/pxelinux.cfg
/var/lib/tftpboot/pxeboot_cent65/pxelinux.cfg/default
prompt 0 default menu.c32 timeout 300 menu title === PXE Boot Menu === menu tabmsg Please Select a Number ontimeout centos65_core label centos65_core menu label ^1 CentOS 6.5 core kernel vmlinuz append initrd=initrd.img ks=http://192.168.51.50/ks/default.cfg ksdevice=bootif ipappend 2
rootpwでパスワード設定
# grub-crypt --sha-512 Password: Retype password: $6$N/fZJZDQbhrUMzdH$dV6AxBS2D9H3z9bAgMLssWzMM0vfT455A8VHbqrxC8IOWwGnqJJwukV2q5yWNEq8XJ9Fuk2.rKNRuJ.ZGkDG7/ #
※作成先のサーバでのrootパスワード
※ここで表示されたハッシュキーを自動作成用のrootパスワードとして使用する
Kickstartのファイル
mkdir /var/www/html/ks touch /var/www/html/ks/default.cfg chmod 777 /var/www/html/ks/default.cfg
/var/www/html/ks/default.cfg
# Kickstart file automatically generated by anaconda. #version=DEVEL install url --url http://192.168.51.50/centos65 lang ja_JP.UTF-8 keyboard jp106 network --bootproto=dhcp --onboot=yes rootpw --iscrypted $6$N/fZJZDQbhrUMzdH$dV6AxBS2D9H3z9bAgMLssWzMM0vfT455A8VHbqrxC8IOWwGnqJJwukV2q5yWNEq8XJ9Fuk2.rKNRuJ.ZGkDG7/ selinux --disabled authconfig --enableshadow --passalgo=sha512 timezone Asia/Tokyo bootloader --location=mbr --driveorder=sda zerombr clearpart --all part /boot --fstype=ext4 --asprimary --size=128 part / --fstype=ext4 --grow --size=1 part swap --size=1024 reboot repo --name="DVD" --baseurl=http://192.168.51.50/centos65 --cost=100 %packages --nobase @core %end %post --log=/root/install-post.log echo "192.168.51.50 puppet" | cat >> /etc/hosts %end
※/root/anaconda-ks.cfgを元に作成する
httpd
service httpd start
再起動
reboot
※もしかしたら「/etc/init.d/xinetd restart 」でもいいかも…
/var/log/messagesで監視
[root@localhost tftpboot]# tail -f /var/log/messages
別サーバで起動
vm設定
起動
/var/log/messagesを確認
Jul 20 12:41:57 localhost dhcpd: DHCPDISCOVER from 00:0c:29:be:0a:91 via eth0 Jul 20 12:41:58 localhost dhcpd: DHCPOFFER on 192.168.51.100 to 00:0c:29:be:0a:91 via eth0 Jul 20 12:41:59 localhost dhcpd: DHCPDISCOVER from 00:0c:29:be:0a:91 via eth0 Jul 20 12:41:59 localhost dhcpd: DHCPOFFER on 192.168.51.100 to 00:0c:29:be:0a:91 via eth0 Jul 20 12:42:03 localhost dhcpd: DHCPDISCOVER from 00:0c:29:be:0a:91 via eth0 Jul 20 12:42:03 localhost dhcpd: DHCPOFFER on 192.168.51.100 to 00:0c:29:be:0a:91 via eth0
自動起動サーバのmacアドレスを修正して再起動
# # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.sample # see 'man 5 dhcpd.conf' # subnet 192.168.51.0 netmask 255.255.255.0 { default-lease-time 21600; max-lease-time 43200; option routers 192.168.51.2; option subnet-mask 255.255.255.0; range 192.168.51.100 192.168.51.150; } host client01 { hardware ethernet 00:0c:29:be:0a:91; fixed-address 192.168.51.100; filename "/pxeboot_cent65/pxelinux.0"; next-server 192.168.51.50; }
↓
# service dhcpd restart dhcpd を停止中: [ OK ] dhcpd を起動中: [ OK ] #
メッセージ監視
[root@localhost ~]# tail -f /var/log/messages Jul 20 12:50:51 localhost dhcpd: Sending on Socket/fallback/fallback-net Jul 20 12:57:59 localhost dhcpd: DHCPDISCOVER from 00:0c:29:be:0a:91 via eth0 Jul 20 12:57:59 localhost dhcpd: DHCPOFFER on 192.168.51.100 to 00:0c:29:be:0a:91 via eth0 Jul 20 12:58:01 localhost dhcpd: Dynamic and static leases present for 192.168.51.100. Jul 20 12:58:01 localhost dhcpd: Remove host declaration client01 or remove 192.168.51.100 Jul 20 12:58:01 localhost dhcpd: from the dynamic address pool for 192.168.51.0/24 Jul 20 12:58:01 localhost dhcpd: DHCPREQUEST for 192.168.51.100 (192.168.51.50) from 00:0c:29:be:0a:91 via eth0 Jul 20 12:58:01 localhost dhcpd: DHCPACK on 192.168.51.100 to 00:0c:29:be:0a:91 via eth0 Jul 20 12:58:01 localhost xinetd[1041]: START: tftp pid=1256 from=192.168.51.100 Jul 20 12:58:01 localhost in.tftpd[1257]: tftp: client does not accept options
自動インストール開始
↓
↓
まとめ
macアドレスを指定しないといけないけどある程度は自動化できている感じ。
役に立つかは分からないけどなんか便利な感じがしたのでやってみた。
会社で仕事をしていたりする場合にはなにも情報が入ってこないのでいろいろモチベが下がり気味だけどこんなことでもできると
次への作業や勉強へのやる気へつながるのは面白い。