Managing systemd effectively is a crucial skill for any system administrator. This tutorial provides step-by-step instructions for services configuration, along with best practices for production environments.
Prerequisites
- A registered domain name (for public-facing services)
- Basic familiarity with the Linux command line
- SSH client on your local machine
- Root or sudo access to the server
Initial Setup
After applying these changes, monitor the server's resource usage for at least 24 hours to ensure stability. Tools like htop, iostat, and vmstat can provide real-time insights into system performance.
# Systemd service management
sudo systemctl status nginx
sudo systemctl enable --now nginx
sudo systemctl restart nginx
# View service logs
sudo journalctl -u nginx -f --since "10 minutes ago"
# List all running services
systemctl list-units --type=service --state=running
The configuration above sets the recommended values for a VPS with 2-4GB of RAM. Adjust the memory-related settings proportionally if your server has different specifications.
Configuration Steps
After applying these changes, monitor the server's resource usage for at least 24 hours to ensure stability. Tools like htop, iostat, and vmstat can provide real-time insights into system performance.
# Server resource monitoring
htop # Interactive process viewer
iostat -x 1 5 # Disk I/O stats (5 samples)
vmstat 1 5 # Virtual memory stats
ss -tlnp # Open listening ports
netstat -an | wc -l # Total connections
These commands should be run as root or with sudo privileges. If you're using a non-root user, prefix each command with sudo.
Security Implications
Security should be a primary consideration when configuring systemd. Always use strong passwords, keep software updated, and restrict network access to only the necessary ports and IP addresses.
Common Issues and Solutions
- High memory usage: Review the configuration for memory-related settings. Reduce worker counts or buffer sizes if running on a low-RAM VPS.
- Slow performance: Check for disk I/O bottlenecks with
iostat -x 1and network issues withmtr. Review application logs for slow queries or requests.
Conclusion
This guide covered the essential steps for working with systemd on a VPS environment. For more advanced configurations, refer to the official documentation. Don't hesitate to reach out to our support team if you need help with your specific setup.