Provision a server end to end
Turn a fresh VM into a working web or file server with storage, users and services.
By Invicly Tech, , in Linux Administration (RHCSA-style). About 11 minutes to read.
In short
Bring everything together by turning a fresh VM into a useful server, such as a web server with its content on LVM and a nightly backup. Work in a sensible order: identity and network first, then accounts, storage, software, services and scheduling. Keep notes of every command so you could rebuild it from a script.
Explained simply
Provisioning means taking a brand new, empty machine and turning it into a server that does a real job. In this project, that job is a small web server: it has a name, a fixed address, admin accounts, its own storage for the website, and a nightly backup.
The order matters. If you break the network halfway through, you lose your remote connection and have to start over at the console. So you set up identity and network first, then people and access, then storage, software and services, and scheduling last.
Every step must survive a reboot. A setting that only lives in memory is a trap: it works today and disappears after the next kernel update. So each time you change something, use the command or file that makes it permanent.
Write every command into a notes file as you go. At the end, those notes are almost a script. Next time you can rebuild the same server in minutes instead of hours.
Press Play on a diagram to walk through it one step at a time.
- 1Identity and network
Hostname, static IP, DNS, chrony.
- 2Accounts
Admin group, users, sudo drop-in, SSH keys.
- 3Storage
PV, VG, LV, xfs, fstab entry for /srv.
- 4Software
Repositories, dnf install, updates.
- 5Services
Enable web server, firewall and SELinux labels.
- 6Scheduling
Backup service and timer, then reboot and verify.
- Identity
- /etc/hostname
- chronyd enabled
- Network
- NetworkManager profile
- autoconnect yes
- Storage
- fstab entry by UUID or LV path
- Services
- httpd enabled
- firewall --permanent rules
- SELinux fcontext rule
- Scheduling
- backup.timer enabled
- Persistent=true
In depth
Identity, time and name resolution
Set the full hostname with hostnamectl set-hostname web01.lab.example.com; it is stored in /etc/hostname. Add the server's own name and IP to /etc/hosts so local tools can resolve it even when DNS is down.
Correct time matters more than it seems: logs from several servers must line up, TLS certificates are checked against the clock, and Kerberos fails with more than five minutes of skew. On RHEL, chronyd keeps the clock in sync. Put your time source in /etc/chrony.conf with a line like server ntp.lab.example.com iburst or pool 2.rhel.pool.ntp.org iburst, restart chronyd, then check with chronyc sources -v. timedatectl set-timezone Europe/Berlin sets the zone, and timedatectl shows whether the clock is synchronized.
- hostnamectl shows static hostname and OS details
- chronyc sources: a * marks the source in use
- timedatectl list-timezones | grep -i berlin
Networking with NetworkManager
On RHEL 9, connection profiles are stored as files in /etc/NetworkManager/system-connections/ and managed with nmcli. nmcli con show lists profiles and the devices they use; the profile name is often not the same as the device name. A static setup needs four settings: ipv4.method manual, ipv4.addresses with a prefix such as 192.168.1.50/24, ipv4.gateway and ipv4.dns.
Changes made with nmcli con mod are saved at once but applied only when the connection is brought up again with nmcli con up NAME. Do this from the console, or as one command line, because the address may change under your SSH session. Make sure connection.autoconnect is yes so the profile comes up at boot. Verify with ip -br addr, ip route and getent hosts.
- 1nmcli con show
Find the profile for the device
- 2nmcli con mod
method, addresses, gateway, dns
- 3nmcli con up
Applies the saved profile
- 4Verify
ip -br addr, ip route, ping gateway
- 5Check boot
connection.autoconnect yes
Accounts and sudo for a team
Create a group for admins, put people in it, and give the group sudo rights in its own file. A file such as /etc/sudoers.d/admins containing %admins ALL=(ALL) ALL is clearer than adding everyone to wheel, and it is easy to remove later. Always check it with visudo -cf /etc/sudoers.d/admins; a syntax error in any sudoers file can break sudo for everyone.
Install each admin's SSH public key now, so you can turn off password logins during hardening. Create a separate system account for services, such as a backup user with no shell, so automated jobs do not run as a person or as root.
- groupadd admins; usermod -aG admins ana
- useradd --system --shell /sbin/nologin backup
- sudo -l -U ana shows what ana may run
Storage that can grow
Putting /srv on LVM (Logical Volume Manager) means you can add disk space later without moving data. The chain is: physical volume (pvcreate on the disk), volume group (vgcreate pools one or more PVs), logical volume (lvcreate carves out a piece), filesystem (mkfs.xfs), and mount point.
In /etc/fstab, refer to the filesystem by UUID (from blkid) or by its /dev/vgname/lvname path; never by /dev/sdb names, which can change between boots. Test with mount -a and findmnt --verify before rebooting, because a bad fstab line can drop the server into emergency mode. Later, lvextend -r -L +5G /dev/vgsrv/lvweb grows both the volume and the filesystem in one step. XFS can grow but cannot shrink.
- 1/srv/web
Mount point in /etc/fstab
- 2XFS filesystem
mkfs.xfs; grows with xfs_growfs or lvextend -r
- 3Logical volume lvweb
lvcreate -n lvweb -L 2G vgsrv
- 4Volume group vgsrv
Pool of space from one or more disks
- 5Physical volume /dev/vdb
pvcreate marks the disk for LVM
Software, services and the backup job
Install packages with dnf, then enable services with systemctl enable --now so they start now and at every boot. For a web root in /srv/web, three things must agree: Apache's config points to it, the firewall allows the http service permanently, and SELinux labels the folder httpd_sys_content_t through semanage fcontext and restorecon.
Finish with the nightly backup as a timer and service pair: a oneshot service running a tar or rsync script as the backup user, and a timer with OnCalendar=*-*-* 01:30 and Persistent=true. Then reboot and check everything from a second machine: the name resolves, the page loads, SSH works with keys, the mount is there, and systemctl list-timers shows the next backup.
Learn it in 5 short steps
About 1h each. Track them with a timer in your plan.
- 1Set hostname, network and time~1h
- 2Create users, groups and sudo rules~1h
- 3Build LVM storage mounted at /srv~1h
- 4Install and enable a web server~1h
- 5Schedule a nightly backup timer~1h
Key points
- Do network and access first, so a mistake later does not cut you off.
- Every change must survive a reboot; reboot at the end and re-check.
- Script the steps as you go; your notes become your next automation.
- Verify from a second machine, not just from localhost.
Key terms
Tap a card to flip it. 0/4 known
Examples
sudo hostnamectl set-hostname web01.lab.example.com
sudo nmcli con mod ens160 ipv4.method manual ipv4.addresses 192.168.1.50/24 ipv4.gateway 192.168.1.1 ipv4.dns 192.168.1.1 && sudo nmcli con up ens160
sudo pvcreate /dev/vdb && sudo vgcreate vgsrv /dev/vdb && sudo lvcreate -n lvweb -L 2G vgsrv
sudo mkfs.xfs /dev/vgsrv/lvweb && sudo mkdir -p /srv/web
echo "/dev/vgsrv/lvweb /srv/web xfs defaults 0 0" | sudo tee -a /etc/fstab && sudo mount -a
sudo dnf install -y httpd && sudo systemctl enable --now httpd
sudo firewall-cmd --permanent --add-service=http && sudo firewall-cmd --reload
sudo semanage fcontext -a -t httpd_sys_content_t "/srv/web(/.*)?" && sudo restorecon -Rv /srv/webCore provisioning steps; then point DocumentRoot at /srv/web and add a backup timer.
Time, admins and sudo in one pass
After the network works, set the time zone and time source, then create the admin team. Step 1: set the zone and point chrony at the lab time server. Step 2: confirm synchronisation. Step 3: create the admins group, add ana and give the group sudo rights in a drop-in. Step 4: check the drop-in syntax before you log out, and confirm ana's rights.
sudo timedatectl set-timezone Europe/Berlin
echo 'server ntp.lab.example.com iburst' | sudo tee -a /etc/chrony.conf
sudo systemctl enable --now chronyd && sudo systemctl restart chronyd
chronyc sources -v; timedatectl | grep synchronized
sudo groupadd -f admins && sudo usermod -aG admins ana
echo '%admins ALL=(ALL) ALL' | sudo tee /etc/sudoers.d/admins
sudo chmod 440 /etc/sudoers.d/admins
sudo visudo -cf /etc/sudoers.d/admins
sudo -l -U anaPoint Apache at the LVM volume and add the backup
The volume is mounted at /srv/web. Step 1: add a small Apache config that uses it as the document root. Step 2: test the config and restart. Step 3: create the backup service and timer. Step 4: reboot and verify from another machine with curl and from the server with list-timers and findmnt.
sudo tee /etc/httpd/conf.d/site.conf <<'EOF'
DocumentRoot "/srv/web"
<Directory "/srv/web">
Require all granted
</Directory>
EOF
echo '<h1>web01</h1>' | sudo tee /srv/web/index.html && sudo restorecon -Rv /srv/web
sudo apachectl configtest && sudo systemctl restart httpd
printf '[Service]\nType=oneshot\nExecStart=/usr/bin/tar czf /backup/web.tgz /srv/web\n' | sudo tee /etc/systemd/system/webbackup.service
printf '[Timer]\nOnCalendar=*-*-* 01:30\nPersistent=true\n[Install]\nWantedBy=timers.target\n' | sudo tee /etc/systemd/system/webbackup.timer
sudo mkdir -p /backup && sudo systemctl daemon-reload && sudo systemctl enable --now webbackup.timer
sudo systemctl reboot
# from another machine: curl http://web01/ then on web01: findmnt /srv/web; systemctl list-timers webbackup.timerQuick reference
- Order: identity and network, accounts and keys, storage, software, services, scheduling
- hostnamectl set-hostname FQDN; add the name and IP to /etc/hosts
- chronyc sources -v and timedatectl confirm the clock is synchronized
- nmcli con mod saves; nmcli con up applies
- Sudo for a group: %admins ALL=(ALL) ALL in /etc/sudoers.d/admins, check with visudo -cf
- Mount by UUID or LV path; test fstab with mount -a and findmnt --verify
- Web root needs three things: Apache config, firewall --permanent, SELinux label
- Reboot at the end and verify from a second machine
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Set the hostname to web01.lab.example.com and the time zone to UTC, and show proof of both.
- Exercise 2medium
Create a 1 GiB logical volume lvdata in a new volume group vgdata on /dev/vdc, format it as XFS and mount it at /data permanently.
- Exercise 3hard
Turn your provisioning notes into one script that can run twice without errors, covering hostname, the admins group with sudo, and enabling httpd.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Why configure networking before anything else?
- Everything else is easier over SSH, and a network mistake later could cut you off halfway. Getting it right first, from the console, removes that risk.
- Do I need LVM for a small server?
- Not strictly, but it lets you grow /srv later by adding a disk, without downtime or moving data. On the RHCSA, LVM tasks are expected.
- What is the difference between chrony and timedatectl?
- chronyd is the service that actually syncs the clock with time servers. timedatectl shows and changes time settings, such as the time zone, and whether sync is turned on.
- How do I know my server will come back after a reboot?
- Reboot it and check. Before that, mount -a, findmnt --verify, systemctl is-enabled for each service and firewall-cmd --list-all --permanent catch most problems.