Greetings! Today, we’re diving into essential system administration tasks in Linux. Our comprehensive guide covers a range of crucial operations that every system administrator should be familiar with:
- Disk Space Management: We’ll explore important Linux commands used to display and analyze disk space usage. These tools are vital for monitoring your system’s storage health and identifying potential issues before they become critical.
- Disk Space Extension: Learn step-by-step procedures for extending disk space in both standard filesystems and mixed environments using LVM (Logical Volume Management). This knowledge is crucial for adapting to growing storage needs without system downtime.
- PostgreSQL Database Management: We’ll walk through the process of upgrading PostgreSQL from version 8 to 16, including how to perform database dumps and restorations. This is essential knowledge for maintaining and upgrading your database systems.
- FTP Server Setup: Discover how to install and configure Pure-FTPd, a popular FTP server. We’ll cover installation, user management, and troubleshooting common authentication issues.
By mastering these skills, you’ll be well-equipped to handle a variety of system administration tasks, from routine maintenance to critical system upgrades. Whether you’re a seasoned sysadmin or just starting out, this guide will provide valuable insights and practical knowledge to enhance your Linux administration capabilities.
Let’s get started with our deep dive into these essential Linux operations!
Disk Space
Firstly, the most common daily commands are used for checking disk space.
- df
I normally use this to check disk space. Adding the option ‘-h’ with this command makes the data easier to read(human-readable).
df -h :
Another option is ‘-T’, this will give the filesystem type as such:
df -Th :
- du
This command provides the disk usage within directories and files and can be used to analyse them more easily.
The best use case is as such:
du -hax | sort -hr | less |
Personally, I like to add the partition name also:
du -hax /opt | sort -hr | less |
Where in:
- du -hax /opt
- -h displays human-readable format
- -a includes hidden files
- -x excludes files that are outside of /opt
- /opt is to target only this directory
- sort -hr
- -h displays human-readable format
- -r shows the largest directory/file first
- less will display the output one page at a time. This is useful when the output is bigger than the terminal window.
I don’t have much in /opt so it shows like this:
- lsblk
This command will display all the filesystems that are connected to the machine. For example, it will show the disk /dev/sda and all the partitions under it:
Common commands to add disk space in:
- Standard filesystem
A step-by-step guide to adding disk space with parted:
- Find where you want to add the disk space. For this example let’s say in /dev/sda3
- Add your disk space whether on VMware or manually onto a disk which is /dev/sda.
- Rescan the disk(sda) using this command:
echo “1” > /sys/class/block/sda/device/rescan |
- Now to display information about all the partitions in /dev/sda and the free space, use this command:
parted /dev/sda print free |
- After finding the correct information on /dev/sda and the free space, we will need to resize the partition /dev/sda3:
parted /dev/sda resizepart 3 |
You need to provide the new ‘end’ of the disk.
- After that, it says that you will need to update the fstab. You can do it like this:
resize2fs /dev/sda3 |
And it’s done! You can verify your updated disk with df or lsblk.
- Mix filesystem (standard and LVM)
A step-by-step guide to adding disk space with parted and LVM:
- Find where you want to add the disk space. For this example let’s say in /dev/sdb1
- Add your disk space whether on VMware or manually onto a disk which is /dev/sdb.
- Rescan the disk(sdb) using this command:
echo “1” > /sys/class/block/sdb/device/rescan |
- Now to display information about all the partitions in /dev/sdb and the free space, use this command:
parted /dev/sdb print free |
- After finding the correct information on /dev/sdb and the free space, we will need to resize the partition /dev/sdb1:
parted /dev/sdb resizepart 1 |
You need to provide the new ‘end’ of the disk.
- After that, we need to resize the physical volume:
pvresize /dev/sdb1 |
- The last step is to extend the logical volume of the /opt partition.
lvextend -l +100%FREE -r /dev/vg_opt/lv_opt |
If you want to list all logical volumes, you can use lvdisplay.
And it’s done! You can verify your updated disk with df or lsblk.
Additional Notes
- Always backup important data before modifying disk partitions.
- The examples use /dev/sda and /dev/sdb, but your device names may differ.
- For LVM operations, ensure you’re familiar with your volume group and logical volume names.
PostgreSQL Upgrade and Restoration Guide
Part 1: PostgreSQL Upgrade from 8 to 16 and Database Dump
- Install PostgreSQL 16:
sudo apt install postgresql-16 postgresql-contrib-16
- Switch to the postgres user:
sudo su - postgres
- List all PostgreSQL clusters:
pg_lsclusters
This will show you the version, cluster name, and port number for each PostgreSQL installation. - Connect to the new PostgreSQL 16 instance:
psql -p 5432
(Replace 5432 with the actual port number if different) - Exit psql:
\q
- List clusters again to verify:
pg_lsclusters
- Remove the old PostgreSQL 8 cluster:
pg_dropcluster 8 main
- Start a screen session for the dump:
screen -S pg_dump
- Perform a full dump of all databases:
pg_dumpall | gzip > db_all.sql.gz
- Detach from the screen session: Press Ctrl+A, then D
- To restore this dump (if needed on the same server):
screen -S pg_restore
gunzip -c db_all.sql.gz | psql
Then detach from the screen session: Press Ctrl+A, then D
Part 2: Database Restoration into a New Server
- On the source server, dump the specific database:
nohup pg_dump -Fc database_name | gzip > database_name_dump.sql.gz &
Note: We’re using nohup here as screen didn’t work on an old server. - Transfer the dump file to the target server:
scp database_name_dump.sql.gz user@target_server:/path/to/destination
- On the target server, switch to the postgres user:
sudo su - postgres
- Connect to PostgreSQL:
psql
- Terminate active connections to the target database:
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'database_name';
- Drop the existing database (if it exists):
DROP DATABASE database_name; - Exit psql:
\q - Start a screen session for restoration:
screen -S pg_restore
- Restore the database:
gunzip -c database_name_dump.sql.gz | pg_restore -d postgres -C
- Detach from the screen session: Press Ctrl+A, then D
- Verify the restoration:
- Connect to PostgreSQL: psql
- List all databases: \l
- Connect to the restored database: \c database_name
- Check table contents and perform necessary verifications.
Remember to replace database_name with your actual database name throughout these instructions.
Pure-FTPd Installation and Configuration Guide
1. Installation
- Update your package list:
sudo apt update - Install Pure-FTPd:
sudo apt install pure-ftpd
Adding a User
- Create a new system user (replace username with desired username):
sudo adduser ftpuser
- Create a directory for FTP:
sudo mkdir /home/ftpuser/ftp
- Set ownership:
sudo chown nobody:nogroup /home/ftpuser/ftp
- Set permissions:
sudo chmod a-w /home/ftpuser/ftp
- Create a directory for file transfers:
sudo mkdir /home/ftpuser/ftp/files
- Set ownership for the new directory:
sudo chown ftpuser:ftpuser /home/ftpuser/ftp/files
- Add the Pure-FTPd user:
sudo pure-pw useradd ftpuser -u ftpuser -d /home/ftpuser/ftp/files
- Update the Pure-FTPd database:
sudo pure-pw mkdb
3. Configuring Pure-FTPd
- Create a symlink to enable virtual users:
sudo ln -s /etc/pure-ftpd/conf/PureDB /etc/pure-ftpd/auth/60puredb - Restart Pure-FTPd:
sudo systemctl restart pure-ftpd
4. Troubleshooting: Failed Authentication
If you encounter a “530 Login authentication failed” error, follow these steps:
- Add a symlink in the auth directory:
cd /etc/pure-ftpd/auth/
sudo ln -s ../conf/PureDB 50PureDB
- Verify the symlink order:
ls -l
You should see something like:50PureDB -> ../conf/PureDB
65unix -> ../conf/UnixAuthentication
70pam -> ../conf/PAMAuthentication
- Update the Pure-FTPd database:
sudo pure-pw mkdb - If the issue persists, restart the Pure-FTPd service:
sudo systemctl restart pure-ftpd.service
5. Logging
- Pure-FTPd logs can be found in /var/log/pure-ftpd/ or /var/log/syslog
- To view logs in real-time:
sudo tail -f /var/log/syslog | grep pure-ftpd
6. Additional Security Measures (Optional)
- Enable TLS support:
sudo echo 1 > /etc/pure-ftpd/conf/TLS - Generate SSL certificate:
sudo mkdir -p /etc/ssl/private/
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem
- Set proper permissions:
sudo chmod 600 /etc/ssl/private/pure-ftpd.pem - Restart Pure-FTPd:
sudo systemctl restart pure-ftpd
Remember to replace username and ftpuser with your desired username throughout these instructions.