Adachinですっ。
KVM内でゲストサーバ構築時(CentOS7)に、kickstartファイルがCentOS6と若干違うため、
OSインストールできず、フリーズしたりするのでメモしときます。
CentOS8とか出たらまた考えないといけないパターン(汗)
■kvm-cent7.cfg
環境によって違うと思いますが、毎回変更する部分は固定IPアドレスとホスト名くらいです。
%endを入れないとOSインストール時にフリーズします。bootdriveはvdaに。
それ以下はユーザー作成とか自動化してます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version=RHEL7 | |
# System authorization information | |
auth –enableshadow –passalgo=sha512 | |
# Use network installation | |
url –url="http://xxx.xxx.xxx.xxx/os/7/os/x86_64/" | |
# Run the Setup Agent on first boot | |
firstboot –enable | |
ignoredisk –only-use=vda | |
# Keyboard layouts | |
keyboard –vckeymap=us –xlayouts='us' | |
# System language | |
lang en_US.UTF-8 | |
#text | |
autostep | |
reboot | |
# Network information | |
network –bootproto=static –device=eth0 –gateway=xxx.xxx.xxx.xxx –ip=xxx.xxx.xxx.xxx –nameserver=8.8.8.8 –netmask=255.255.255.0 –noipv6 –activate | |
network –hostname=cent7 | |
# Root password | |
adachinpw –iscrypted $1$adachin$xxxxxxxxxxxxxxxxx/ | |
# System timezone | |
timezone Asia/Tokyo –isUtc –ntpservers=ntp-b2.nict.go.jp,ntp-a2.nict.go.jp,ntp-b3.nict.go.jp,ntp-a3.nict.go.jp | |
# System bootloader configuration | |
bootloader –location=mbr –boot-drive=vda | |
# Partition clearing information | |
clearpart –drives=vda –all | |
# Disk partitioning information | |
part / –fstype="xfs" –ondisk=vda –grow –size=0 | |
part swap –fstype="swap" –ondisk=vda –size=1024 | |
part /boot –fstype="xfs" –ondisk=vda –size=500 –asprimary | |
%packages | |
@core | |
%end | |
%post | |
## add user ### | |
groupadd -g 601 adachingrp && \ | |
adduser -m -d /home/adachin -g 601 -u 601 adachingrp && \ | |
echo 'adachin:$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | chpasswd -e | |
## add pub-keys ## | |
mkdir /home/adachin/.ssh | |
echo 'ssh-rsa xxxxxxxxxxxxxxxxxxx== adachin@localhost.localdomain' >> /home/adachin/.ssh/authorized_keys | |
chmod 600 /home/adachin/.ssh/authorized_keys | |
chmod 700 /home/adachin/.ssh | |
chown -R adachin.adachingrp /home/adachin/.ssh | |
## set sudo ## | |
echo 'adachin ALL=(ALL) ALL' > /etc/sudoers.d/00_base | |
chmod 0440 /etc/sudoers.d/00_base | |
## change sshd config ## | |
cp /etc/ssh/sshd_config /var/tmp/sshd_config_org | |
cat << EOF >> /etc/ssh/sshd_config | |
### change sshd settings ##### | |
AddressFamily inet | |
UseDNS no | |
PermitRootLogin no | |
PubkeyAuthentication yes | |
AuthorizedKeysFile .ssh/authorized_keys | |
EOF | |
sed -i -e "s/PasswordAuthentication\ yes/PasswordAuthentication\ no/g" /etc/ssh/sshd_config | |
/sbin/service sshd restart | |
%end |
■kvm-cent7.txt
あとは上記のkickstartファイルをkvmコマンドで当てればOKです。
Cent6と変わらないはず。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 1. make Disk Imange | |
qemu-img create -f qcow2 /var/lib/libvirt/images/cent7.qcow2 20G | |
### 2. install and boot guest server | |
virt-install \ | |
–connect qemu:///system \ | |
–name cent7 \ | |
–vcpus=2 \ | |
–ram=2048 \ | |
–hvm \ | |
–disk path=/var/lib/libvirt/images/cent7.qcow2 \ | |
–network bridge=br219 \ | |
–nographics \ | |
–os-type=Linux \ | |
–os-variant=virtio26 \ | |
–location='/var/tmp/CentOS-7-x86_64-DVD-1511.iso' \ | |
–initrd-inject=/var/tmp/cent7.cfg \ | |
–extra-args='ks=file:/cent7.cfg console=tty0 console=ttyS0,115200n8' | |
## delete guestSV | |
virsh destroy cent7; virsh undefine cent7 |
■まとめ
最近dockerばかり触っているので、KVMのサーバ管理のめんどくささに唖然とした….
0件のコメント