Introduction¶
In the internet era, servers are the core infrastructure supporting websites, applications, and data storage. As a representative of open-source operating systems, Linux has become the preferred choice for server environments due to its stability, security, and powerful scalability. Unlike desktop Linux, server-oriented Linux versions focus more on performance optimization and service stability. This article will guide you from scratch to master Linux server installation and basic service deployment, making it suitable for beginners with no prior experience.
1. Linux Server Installation Preparation and Basic Setup¶
1.1 Pre-Installation Requirements¶
- Hardware Requirements: Servers generally have lower hardware requirements than ordinary PCs (but stability is crucial). A minimum configuration includes 1 CPU core, 2GB RAM, and 20GB storage (SSD is recommended). For basic services (e.g., web, FTP), even lower configurations may suffice.
- Distribution Selection: Beginners are recommended to start with these two mainstream options:
- CentOS: Enterprise-grade stability, ideal for production environments with a mature software repository.
- Ubuntu Server: Ubuntu’s server edition, beginner-friendly, with simple installation and rapid software updates.
1.2 Installation Steps (CentOS 7 Example)¶
- Download the ISO Image: Visit the CentOS official website to download the latest ISO image. Choose “Minimal Install” to minimize resource usage.
- Start Installation: Mount the ISO in a virtual machine or physical server, select “Install CentOS 7”, and follow the prompts.
- Key Configuration:
- Language: Chinese or English (based on preference).
- Installation Location: Use “Automatic Partitioning” or manually configure/boot(200MB),swap(2GB), and/(remaining space).
- Root Password: Set a secure password (critical for server access).
- Post-Installation: Reboot and select the CentOS system to start.
2. Post-Installation Basic Configuration¶
2.1 Network Configuration (Critical! Servers Must Connect to the Internet)¶
- Check IP Address: Run
ip addrto find the network interface (e.g.,eth0orens33) and verify theinetaddress (e.g.,192.168.1.100). - Set Static IP (to avoid IP changes):
- CentOS: Edit the network configuration file:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
Modify the following parameters:
BOOTPROTO=static # Static IP mode
IPADDR=192.168.1.100 # Server IP
NETMASK=255.255.255.0 # Subnet mask
GATEWAY=192.168.1.1 # Gateway (router IP)
DNS1=8.8.8.8 # DNS server (Google DNS example)
ONBOOT=yes # Enable network interface at boot
- Restart the network service:
systemctl restart network, then confirm withip addr.
2.2 User and Permission Management (Security First! Disable Root Direct Login)¶
- Create a Non-Root User:
adduser zhangsan # Create user
passwd zhangsan # Set password
usermod -aG sudo zhangsan # Grant sudo privileges (Ubuntu uses the same command)
- Disable Root SSH Login:
Edit the SSH configuration:
vi /etc/ssh/sshd_config
Change:
PermitRootLogin yes # Modify to: PermitRootLogin no
Restart SSH service: systemctl restart sshd.
2.3 Firewall Configuration (Only Open Necessary Ports)¶
- Why Firewalls: Servers have unnecessary ports open by default. Restrict access to only ports required for business operations (e.g., 80/443 for HTTP/HTTPS, 21 for FTP).
- CentOS (firewalld):
systemctl start firewalld # Start firewall
systemctl enable firewalld # Enable at boot
firewall-cmd --add-port=80/tcp --permanent # Open HTTP port
firewall-cmd --reload # Apply changes
- Ubuntu (ufw):
ufw allow 80/tcp # Open HTTP port
ufw enable # Activate firewall
3. Practical Core Service Deployment¶
3.1 Web Server (Nginx)¶
Nginx is a lightweight, high-performance web server suitable for beginners.
- Installation:
- CentOS: sudo yum install nginx -y
- Ubuntu: sudo apt install nginx -y
- Start and Enable:
sudo systemctl start nginx
sudo systemctl enable nginx # Auto-start at boot
- Verification: Access the server IP (e.g.,
192.168.1.100) in a browser. The default Nginx page confirms successful installation.
3.2 FTP Server (vsftpd)¶
FTP facilitates file transfer and data sharing.
- Installation: sudo yum install vsftpd -y (CentOS) or apt install vsftpd -y (Ubuntu).
- Start and Enable:
sudo systemctl start vsftpd
sudo systemctl enable vsftpd
- Create FTP User:
sudo useradd ftpuser -d /home/ftpfiles # Set home directory
sudo passwd ftpuser # Set password
sudo chown -R ftpuser:ftpuser /home/ftpfiles # Adjust permissions
- Testing: Use FTP clients like FileZilla with the server IP and credentials to upload/download files.
3.3 Database Server (MariaDB)¶
MariaDB (a MySQL fork) is used for data storage.
- Installation:
- CentOS: sudo yum install mariadb-server -y
- Ubuntu: sudo apt install mariadb-server -y
- Start and Secure Setup:
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation # Initialize: set root password, remove anonymous users, etc.
- Test Login:
mysql -u root -pand enter the password to execute SQL commands.
Conclusion¶
The core workflow of Linux server setup and basic service deployment can be summarized as: Minimal Installation → Network/Security Configuration → Core Service Deployment. Linux’s strength lies in its open-source ecosystem and flexible configuration, but continuous learning is essential (e.g., log management, performance monitoring, containerization). Remember: stability and security are critical for servers. Hands-on practice (e.g., deploying Python services, configuring SSL certificates) accelerates skill acquisition.
As you progress, explore advanced architectures (LAMP/LNMP, load balancing), but always prioritize foundational knowledge.