This is step-by-step guide for a basic CentOS 8 or CentOS Stream server setup including all instructions as well as a fully automated script for your convenience.

If you would like to try this out directly on your computer without any additional hardware, please use a virtual machine e.g. Oracle VM VirtualBox.

Following you find the step-by-step guide for a basic CentOS 8 server setup.

Downloading the CentOS 8 ISO image

  1. Visit the official website: https://www.centos.org/download/
  2. Either click on the download link for your preferred platform or directly download the ISO for the x86 64-bit platform via this link: http://isoredirect.centos.org/centos/8/isos/x86_64/

Initial setup procedure

After powering up your computer resp. virtual machine, copy the following lines of code into the respective files and folders.

Alternatively you can download the latest version of the script from my GitHub Repository.

File: centos_server_setup.sh


#!/bin/sh

# reference to the config and helper scripts
source ./centos_setup_resources/centos_config.sh
source ./centos_setup_resources/centos_helper.sh

centos_version=$(get_centos_version)

# Equality Comparison
if [ "$centos_version" == "$CENTOS_822004" ]
then
	echo "Start installation CentOS 822004"
elif [ "$centos_version" == "$CENTOS_832011" ]
then
	echo "Start installation CentOS 832011"
elif [ "$centos_version" == "$CENTOS_STREAM8" ]
then
	echo "Start installation CentOS Stream release 8"
else
    echo "Setup cancelled by user"
    exit 0
fi

#TODO: check if commands have been actually performed

########### START Install Cockpit on CentOS 8 ###########

print_setup_start_information "CentOS 8 - Cockpit Web Console will get installed"

# install cockpit
dnf -y install cockpit

# start and enable the service
systemctl enable --now cockpit.socket

# activated firewalld service, allow Cockpit port to be accessed from machines within the network
firewall-cmd --add-service=cockpit --permanent
firewall-cmd --reload

# access Cockpit Web Console on CentOS 8
print_setup_finish_information "Cockpit Web Console on CentOS 8 is enabled\nVisit - https://$(get_local_ipv4_address):9090 - to access it"

########### END Install Cockpit on CentOS 8 ###########

######### START install further tools and repos ###########

print_setup_start_information "Install software: vim, htop net-tools nload vnstat\nInstall repository: epel-release"

# install vim
dnf install -y vim

# add PowerTools repository
dnf config-manager --set-enabled powertools

# install development tools
dnf -y groupinstall 'Development Tools'

# enable EPEL (Extra Packages for Enterprise Linux) repository
dnf install -y epel-release

# install additional software (to check load and network)
dnf install -y htop net-tools nload vnstat

# install language packs
dnf install -y langpacks-en glibc-all-langpacks

print_setup_finish_information "Additional software and programs are installed"

########### END install further tools and repos ###########

######### START perform full system update ###########

print_setup_start_information "Performing full system update"

# perform a full system update
dnf -y  update

print_setup_finish_information "Full system update performed\n-- Rebooting the system is recommended"

######### END perform full system update ###########

########### START disabling SELinux ###########

print_setup_start_information "Settings SELinux to Permissive Mode"

# set SELinux to Permissive mode during this session
setenforce 0

# set SELINUX for the time of configuration to permissive
# in this stage, SELINX is active but only logs instead of enforces the settings
# this makes debugging during setup much easier as errors are not caused by SELINUX
sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/sysconfig/selinux

print_setup_finish_information "SELinux is now in Permissive Mode.\nThis Permissve Mode will be persistent after reboot."
print_notification_information "SELinux is now in Permissive Mode!\nPlease install the right policies and set SELinux to Enforcing after setup!"

########### END disabling SELinux ###########

# reboot in case of a new kernel
#reboot

 

Now create a folder with the name: centos_setup_resources
And save the following files inside the newly created folder.

File: centos_helper.sh


#!/bin/sh

# reference to the config and helper scripts
source ./centos8_config.sh

get_centos_version()
{
	local centos_version
	centos_version=$(cat /etc/centos-release | sed -nre 's/^[^0-9]*(([0-9]+\.)*[0-9]+).*/\1/p')
	# Equality Comparison
	if [ "$centos_version" == "8" ]
	then
		if [[ "$(cat /etc/centos-release)" == *"Stream"* ]]; then
			centos_version="Stream release 8"
		fi	
	fi
	echo "$centos_version"
}

print_setup_start_information()
{
	local start_header
	local start_footer
	start_header="\n\n${CYAN}################## Installation Start ##################\n"
	start_footer="\n########################################################\n\n${NC}"
	echo -e "${start_header}${1}${start_footer}"
	sleep 5s
}

print_setup_finish_information()
{
	local finish_header
	local finish_footer
	finish_header="\n\n${GREEN}################## Installation Finished ##################\n"
	finish_footer="\n###########################################################\n\n${NC}"
	echo -e "${finish_header}${1}${finish_footer}"
	sleep 5s
}

print_notification_information()
{
	local notification_header
	local notification_footer
	notification_header="\n\n${ORANGE}################## IMPORTANT NOTIFICATION ##################\n"
	notification_footer="\n###########################################################\n\n${NC}"
	echo -e "${notification_header}${1}${notification_footer}"
	sleep 5s
}

get_local_ipv4_address()
{
	local local_ipv4_address
	# SOURCE (20201122): https://stackoverflow.com/a/13322549
	# getting the actual IP address of the network interface and format output
	local_ipv4_address=$(ip a | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
	echo $local_ipv4_address
}

 

File: centos_config.sh


#!/bin/sh

########### START Color definitions for script ###########
# SOURCE (20201124): https://stackoverflow.com/a/5947802/2749755
# color outputs for shell scripts

BLACK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
LIGHT_GRAY='\033[0;37m'
DARK_GRAY='\033[0;30m'
LIGHT_RED='\033[0;31m'
LIGHT_GREEN='\033[0;32m'
YELLOW='\033[0;33m'
LIGHT_PURPLE='\033[0;34m'
LIGHT_CYAN='\033[0;36m'
WHITE='\033[0;37m'
NC='\033[0m' # No Color

########### END Color definitions for script ###########

########### START CentOS 8 version definitions ###########

CENTOS_822004="8.2.2004"
CENTOS_832011="8.3.2011"
CENTOS_STREAM8="Stream release 8"

########### START CentOS 8 version definitions ###########

Now make the centos_server_setup.sh file execute able and run it as either root user or with the sudo command.

 


chmod +x centos_server_setup.sh
./centos_server_setup.sh

No thoughts on “CentOS 8 and CentOS Stream Basic Server Setup - Automated Script”

Leave your comment

In reply to Some User