{{tag>[centos installation]}}
=====CentOS 7 - installation and configuration=====
This page describes the installation of a CentOS 7 virtual machine. Using Qemu/KVM/Libvirt.
====Install CentOS 7====
===Install script===
#!/bin/bash
# Note: this script uses writeback cache, make sure host has UPS.
VMNAME="vmname"
VMMEM="1024"
VMCPU="2"
DEFBRIDGE="br50"
IMAGEPOOL="/var/lib/libvirt/images"
DISKSIZE="16G"
IMAGEFILE="$IMAGEPOOL/$VMNAME.qcow2"
if [ ! -f $IMAGEFILE ]; then
/usr/bin/qemu-img create -f qcow2 $IMAGEFILE $DISKSIZE
fi
virt-install --connect qemu:///system \
--name $VMNAME \
--ram $VMMEM \
--vcpus $VMCPU \
--disk path=$IMAGEFILE,format=qcow2,bus=virtio,cache=writeback \
--network bridge:$DEFBRIDGE \
--nographics \
--os-type=linux \
--os-variant=rhel7 \
--location=http://repo/centos/7/CentOS7-base/ \
--initrd-inject=/root/vmks-centos7.cfg \
--extra-args="ks=file:/vmks-centos7.cfg console=tty0 console=ttyS0,115200" \
--autostart
===Kickstart script===
install
text
skipx
# Base repo
url --url=http://repo/centos/7/CentOS7-base/
# Updates repo
repo --name="updates" --baseurl=http://repo/centos/7/CentOS7-updates/
# Prevent the Setup Agent from running on first boot
firstboot --disable
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --ipv6 auto --activate
rootpw --iscrypted
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
timezone Europe/Amsterdam --isUtc
# Create non administrative user
user --name=username --homedir=/home/username --password= --iscrypted
ignoredisk --only-use=vda
bootloader --location=mbr --driveorder=vda --boot-drive=vda --append="crashkernel=auto console=tty0 console=ttyS0,115200"
# Any disks whose formatting is unrecognized are initialized.
zerombr
# Erases all partitions from the system.
clearpart --all --drives=vda --initlabel
# Initialize boot partition.
part /boot --fstype=xfs --fsoptions="defaults,noatime" --size=512 --asprimary
# Create LVM pv and vg.
part pv.01 --size=1000 --grow --asprimary
volgroup vg pv.01
# Create lv's, set noatime and commit time. Leave some space left in the VG for later use.
logvol swap --vgname=vg --size=512 --name=lv_swap --fstype=swap
logvol / --vgname=vg --size=4096 --name=lv_root --fstype=xfs --fsoptions="defaults,noatime"
logvol /var --vgname=vg --size=4096 --name=lv_var --fstype=xfs --fsoptions="defaults,noatime"
logvol /home --vgname=vg --size=512 --name=lv_home --fstype=xfs --fsoptions="defaults,noatime"
reboot
%packages
@base
@core
%end
====Configure CentOS7====
===Hostname===
* Set hostname:hostnamectl set-hostname
===Configure static networking===
* Show connections: nmcli c show
* Edit connection
su - root
nmcli c edit
# set ipv4 address and gateway
nmcli> set ipv4.addresses 1.2.3.4/24 2.3.4.5
# set DNS
nmcli> set ipv4.dns 4.5.6.7 5.6.7.8
nmcli> set ipv4.dns-search yourdomain.com
# set autoconnect
nmcli> set connection.autoconnect yes
# save and activate
nmcli> save
nmcli c up 'System p4p1'
===Configure timekeeping===
* Configure ntp servers in /etc/chrony.conf
* Start Chrony:systemctl enable chronyd.service
systemctl restart chronyd.service
* Check Chrony status: chronyc sources
* Check settings: timedatectl