Linux Service Management: Starting, Stopping, and Checking Status
Linux services are background-running programs with specific functionalities. Managing services is fundamental to system operations and requires administrative privileges (e.g., `$ sudo`). Core operations are implemented via the `systemctl` command: `systemctl status [service_name]` checks the status (e.g., `active (running)`); `start/stop/restart` are used to start, stop, and restart services respectively; `list-units --type=service` lists all services, and `is-active [service_name]` quickly determines the running status. For enabling/disabling services at boot, use `enable/disable`, and verify with `is-enabled`. When services fail, `journalctl -u [service_name]` checks logs (e.g., port conflicts, configuration errors). Mastering these commands fulfills most service management requirements.
Read MoreBeginner's Must-Know: Linux Log File Viewing Commands
This article introduces 5 essential log viewing commands for Linux server beginners, applicable to daily problem diagnosis and monitoring. The core commands and their uses are as follows: 1. **tail**: View the end of a file. Use `-n 数字` to specify the number of lines, `-f` for real-time monitoring (e.g., website access logs), and `-q` to suppress the filename display. 2. **head**: View the start of a file. The `-n 数字` parameter specifies the number of lines, suitable for initial logs (e.g., system startup logs). 3. **cat**: Quickly view the entire content of small files. Use `-n`/`-b` to display line numbers. Not recommended for large files (risk of screen overflow). 4. **less**: Page through large files. Supports up/down navigation, search (`/关键词`), and `+G` to jump to the end. 5. **grep**: Filter content by keyword. Use `-n` to show line numbers, `-i` for case-insensitive matching, and `-v` for inverse filtering. Often combined with `tail` (e.g., `tail -f log | grep error`). Combination tips: For example, `tail -n 100 log | grep error` quickly locates errors, and `less +G log` jumps to the end of the log.
Read MoreSystem Monitoring Tools: A Guide to Linux Server Performance Viewing
This article introduces 6 essential performance monitoring tools for Linux server beginners, helping them quickly grasp the "health status" of servers. System monitoring is crucial for ensuring service stability, requiring regular checks of CPU, memory, disk, and other resources. Core tools include: `top` for real-time monitoring of CPU, memory, and processes; sort by P/M to quickly identify high resource-consuming processes. `vmstat` analyzes overall system performance, focusing on the number of runnable processes (r), IO blocking processes (b), and swap partition usage (swpd). `iostat` specializes in disk IO, using tps and %util to determine bottlenecks. `free -h` provides a quick view of memory usage and available space. `df -h` and `du -sh` monitor disk partition space and directory/file sizes respectively. Tool selection scenarios: Use `top` for a quick overview, `free` when memory is tight, `iostat` to diagnose disk IO bottlenecks, `df` when space is insufficient, and `du` to locate large files. Mastering these tools enables timely detection and resolution of resource issues through targeted monitoring, ensuring stable server operation.
Read MoreA Comprehensive Guide to Starting and Stopping Linux Services
This article introduces the core methods for managing Linux services. Services are background - running programs, and management is fundamental to system maintenance. Modern Linux uses the systemctl tool of systemd for management. The core operations include: starting a service with `sudo systemctl start <service name>`, stopping it with `stop`, restarting with `restart`, and checking the status with `status`; setting it to start automatically at boot with `enable` and disabling it with `disable`. The self - starting status can be viewed through `list - unit - files`. Practical operations include: reloading the configuration (without restarting) with `reload` and viewing logs with `journalctl -u <service name>`. Precautions: `sudo` privilege elevation is required, the service name must be accurate (e.g., Nginx is `nginx`), and ensure the service is installed before operation. `stop` will forcefully terminate the service and may lose data; `restart` or `reload` (safer) is preferred. Mastering these can meet basic operation and maintenance needs.
Read More