Top Command You Must Know to Manage Linux Web Server
As a software engineer, you might expect that your main responsibilities is to just code and produce a great product. However, to really understand how a product work you ought to have the curiosity to dive deep & explore the infrastructure that support your product. This means there will be a time where you have to manage your own server.
This guide is meant to be an introduction to how you can manage your own Linux Web Server. The specification of web server that I use daily is :
- CentOS 8 or Rocky Linux for the OS
- Using NGINX for the web server
- Using AzAgent (Azure Devops Agent) for CI/CD
So, here are the top command that you must know to manage your own linux web server
1. Accessing your server via SSH
Secure Socket Shell is the main network protocol that provides a secure way to access a computer over an unsecured network. To access remote linux server you can use this command :
ssh <username>@<IP Address> -p <Port Number>
Example : ssh jonathan@10.240.100.30 -p 67895
, Then you can enter your account password.
NOTES :
- Terminal and powershell by default doesn’t show your password when you are typing or pasting it. So, don’t be confused. Your password is there but you can’t just see it
- To paste in terminal just right-click or Ctrl + Shift + V on your mouse. Ctrl + V doesn’t work here.
2. List of Important Folders
Sweet now you’re in the remote server! But now where do I need to go? 😖Here’s some important folders that host the important settings to your web server :
- Root Folder
cd /
- NGINX
- Settings :cd /etc/nginx
- Proxy Pass Configuration :cd /etc/nginx/conf.d
- Running Service
cd /etc/systemd/system
3. Check the status of a service
Hey I couldn’t deploy this API service, could you check what happen in the server?
If you happen to be asked to checked the service, here’s the command you can use to accomplished your task :
- Check service status
systemctl status <Nama Service>
- Restart service
systemctl restart <Nama Service>
- Stop service
sudo systemctl stop <Nama Service>
Notes :sudo
command means you run the command as superuser - List All Service
systemctl list-units --type=service
- List All Service based on state
systemctl list-units — type=service — state=<running | active | inactive>
- View service’s overall history
journalctl -u <Nama Service>
- Check service’s history over period of time
journalctl -u <Nama Service> -S “5 hour ago”
4. Check Server Storage and Memory
When managing a server, often times you will encounter situation where your server run into low storage or memory because of limited capacity or bugged service. The command that you need to master to be able to analyze this condition are :
For Storage
- Check Overall Server’s Storage
df -lh
- Check Current Directory Storage
sudo du -lh — max-depth=1
- Check Current Directory Storage & Sort by Size
sudo du -lh — max-depth=1 | sort -hr
- Display all file + human readable size + sorted by
ls -ahlS
- Count size of files with certain extension
find . -type f -name ‘*.json.gz’ -exec du -ch {} + | grep total$
- Delete all files with certain string
find . -type f -name ‘gc.log.*’ -delete
For Memory
I highly recommend to install htop (human interactive top) as the go to monitoring tools for your server. You can refer to this article to install it on CentOS 8 server.
Htop has some cool features such as :
- Colored output resource usage statistics.
- The ability to end or kill processes without typing their PIDs.
- Htop allows mouse usage, unlike top which doesn’t support it.
- Better performance than top command.
- Filter only the service we want to see.
- Interactive & Live feedback
So there are the top commands that I consider every software engineer must know when dealing with Linux server. These list are just the tip of the iceberg and only serve as a basic knowledge. You can have Google as your best friend when you want to explore other command. I hope you learn something new & gain new insight.