Kevin Ashcraft

Linux & Radio Tutorials

Install CentOS 7.4

CentOS 7.4 is a distribution of Linux built from the same sources as Red Hat Linux. It's a server operating system ready for enterprise-level services. This is a walkthrough covering how to install CentOS in just a few steps (it really is quite straight-forward).

In this tutorial we'll walk through the basics of installing CentOS, starting with downloading the ISO, and then setting the keyboard/language, destination drive, network configuration, and users.

For a bonus, the entire process can be automated with kickstart.

Download CentOS

Download an image of the most recent version by going to centos.org and clicking on the Get CentOS Now button and then clicking on the Minimal ISO button on the next page. This will take you to a bunch of links (mirrors) for the image; click any one. There are several other image types and download methods available, including a long list of mirrors, and in the future I recommend using a torrent option as it's often the fastest.

Once you've obtained the image, copy it onto a cd or usb drive with dd, and then boot it up on your soon-to-be server.

dd if=CentOS-7-x86_64-Minimal-1708.iso of=/dev/$usb_device

Set Keyboard/Language

The selection you'll need to make is for the language and keyboard layout. This one is straight-foward, just select your language, and is written here soley for the purpose of thoroughness.

Set Destination Drive

To set the destination drive click on the drive icon and a new window will appear showing the different configuration options. I recommend selecting "do it yourself" so you can confirm the partitions that are made (since CentOS will often make a large /home partition that I'd prefer to be all allocated to /).

On the drive partition window, click "automatically create partitions", and then reallocate the home partition's space if necessary by removing the home partition and increasing the / partition by the newly available space.

Configure the Network

To configure the network click on the network icon and a new window will open showing the devices. Click on the one that's connected to enable it, and then set the hostname and ip addresses (if it's not dhcp). This step is not absolutely necessary, but makes the initial login and basic configuratio (/basic config) much easier since the system will be connected to the network and you'll already know the ip address.

If you do not enable the card here it will not be start automatically when the system boots (and you'll need to start it with commands like 'ip link set enp2s0 up' and get an address with 'dhcpcd'.

Create Users

While the system is being installed you're able to create the root password and a new user. Type the root password twice, and then while you're making the user click the "make admin user" button.

Kickstart Automated Install

A file was created in the /root directory named 'anaconda.ks.cfg' and has all of the settings you just selected. It can be used to launch additional systems automatically so you can quickly create many servers at a time.

There are two steps you need to take to automatically install CentOS via kickstart. First: update the file with additional settings for the drive size. Second: when booting the CentOS minimal image, press the 'tab' key at the grub screen and edit the init line, adding 'ks=http://10.10.10.10/anaconda.ks.cfg'

anaconda.ks.cfg

#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# 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

# Network information
network  --bootproto=dhcp --device=eth0 --ipv6=auto --activate

# Root password
rootpw --iscrypted $6$5tNvDS1mBrDzA6LA$gLtZWPlQM3y/Nv0yrPEus4uSIlYLn/FYhervFpncBruoZv404PB6m/
# System services
services --enabled="chronyd"
# System timezone
timezone America/New_York --isUtc
user --groups=wheel --name=kevin --password=$6$hFPODGxyNnmk/.5H$/Xj2SKR.GXfOV7lC1ICfZhf55C3YKdm1m8vsLQY6wGJ0 --iscrypted --gecos="kevin"
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=vda
# Partition clearing information
clearpart --none --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --ondisk=vda --size=1024
part pv.156 --fstype="lvmpv" --ondisk=vda --size=1 --grow
volgroup centos --pesize=4096 pv.156
logvol /  --fstype="xfs" --grow --size=1 --name=root --vgname=centos
logvol swap  --fstype="swap" --size=2048 --name=swap --vgname=centos

%packages
@^minimal
@core
chrony
kexec-tools
epel-release
%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

%post
/bin/yum update -y
/bin/yum install -y puppet
/bin/puppet agent --test --waitforcert 300
/bin/mkdir /etc/facter/facts.d -p
/bin/echo "---
puppet_network=virtual_k4k
puppet_os=centos
" > /etc/facter/facts.d/external_facts.yaml
%end