Introduction
Recently, my server experienced some hardware issues, so I took the opportunity to reinstall the Linux server. This article will introduce how to install Ubuntu as your work server.
Having a Linux server allows you to do many things, such as:
- DNS server: Used for blocking ads and related applications.
- Remote development: Allows continuous development on trusted computers.
- Web server: Set up websites using Nginx or Apache, along with database services.
- Proxy server: For bypassing restrictions or NAT traversal.
- Simple file server: Not recommended as a standard NAS, as data maintenance costs are high. It’s better to use a ready-made NAS solution.
Determine the server’s performance based on your personal needs. For example, if you want to set up a web server, consider firewall and other security factors.
There are some ready-made virtual hosting solutions on the market, where the services are already set up, and users only need to upload files. Most are configured through pre-written programs on the web, making them very user-friendly for those who do not understand systems at all.
For more advanced needs, there are virtual private servers (VPS), which are hosted on trusted third-party providers. These hosts might have Linux or Windows installed, and users can connect remotely via SSH to set up services or reset remotely.
Common third-party providers include:
- Amazon Web Services (AWS)
- Google Cloud Platform (GCP)
- Microsoft Azure
- DigitalOcean
- Vultr
- Linode
These services are billed based on usage or on a monthly basis. The cost is around USD $0.15 per hour or USD $30 per month.
Choosing a Linux Distribution
Since I mainly use it for service, web hosting, and development, I chose to install Ubuntu Server 24.04. However, some SDKs require the development environment to use Ubuntu 18.04. When choosing a distribution, you should decide based on your personal development needs and environment.
Comparing different distributions, such as Ubuntu, Debian, Fedora, CentOS, here are their characteristics:
Distribution | Characteristics |
---|---|
Ubuntu | Suitable for beginners, provides an intuitive installation process and default configurations. |
Ubuntu Server | Designed for servers, no graphical interface, includes server-related tools, supports remote management. |
Debian | Stable and secure, suitable for environments requiring high stability. |
Fedora | Cutting-edge technology, suitable for developers wanting to experience the latest software. |
CentOS | Enterprise-grade distribution, suitable for server deployments in corporate environments. |
The main reason for using Ubuntu is its friendliness to beginners, avoiding many difficulties encountered by professionals. Additionally, most tasks can be developed normally on any distribution. Therefore, when choosing a distribution, you don’t need to be overly concerned, just choose the one you like.
As of June 2024, if you want to develop the NVIDIA Optimized Deep Learning Framework, the official support is only for Ubuntu 22.04, so be sure to check if the framework you want to develop supports your expected Linux distribution.
Disk Partitioning During Ubuntu Server 24.04 Installation
During the installation of Ubuntu Server 24.04, the interface mainly relies on keyboard interaction, making the operation relatively simple.
The installation process involves disk partitioning, which can be referenced from Ubuntu Disk Space Recommendations and Strategies.
Partition | Size | My Partition |
---|---|---|
/ | At least 15 GB | 30 GB, ext4 |
/boot | 250 MB ~ 1 GB | 500 MB, ext4 |
/var | 2 GB | 2 GB, ext4 |
swap | Size of RAM | 8 GB, ext4 |
/home | Remaining space | 151.34 GB, ext4 |
/ is the root partition. The official recommendation is to allocate at least 15 GB. Due to log files, temporary files, and installation packages, the root partition may gradually fill up, causing partial system operation errors. To prevent such situations, I used twice the size to reduce errors. It is still recommended to regularly clean up the root partition files or adjust the root partition size when space is insufficient.
/boot for most UEFI systems is 500 MB ~ 1 GB.
For general desktop systems, allocating 1-2 GB for /var is sufficient. For server systems, especially those generating a lot of system logs (such as web servers), it is recommended to allocate 5 GB or more to the /var partition to prevent log files from filling up the root directory. When using Docker, it is recommended to allocate at least 20 to 50 GB of disk space for /var. If the initial space planning is too small, you can modify /etc/docker/daemon.json to change the default path /var/lib/docker/ to another directory or use symbolic links to solve the problem.
Swap should be configured to 1.5 ~ 2 times the system RAM, for example, if you have 4 GB of RAM, set SWAP to 6 GB. If you have more than 8 GB of RAM, 1x SWAP is sufficient.
Leave the remaining space for /home, or plan other partitions as needed.
System Configuration and Installation
Network Configuration
⚠️ It’s challenging to perform remote operations without network connectivity, so the first task is to ensure the network is working properly.
|
|
In the output, you can see that the device name for the wired network is enp8s0
:
|
|
Since Ubuntu 17.10, the network management tool has been unified to netplan. You can check the configuration file using ls /etc/netplan
, usually named 01-netcfg.yaml
or 50-cloud-init.yaml
. Among them, 01-netcfg.yaml
has higher configuration priority and will be prioritized if it exists.
On my server, there is only the 50-cloud-init.yaml
configuration file. Use sudo nano /etc/netplan/50-cloud-init.yaml
to edit this file, fill in the wired network device name, and set it to obtain an IP automatically or use a static IP. In my configuration, I use a dynamic IP and set the DNS servers.
Here is an example configuration, adjust it according to your network environment:
|
|
This configuration makes the network device enp8s0
obtain an IP automatically via DHCP and use 1.1.1.1
and 8.8.8.8
as DNS servers.
If you use a static IP, refer to the following configuration:
|
|
After confirming the configuration file is correct, execute the following command to apply the settings:
|
|
This command will reload netplan and apply the new settings, ensuring the network configuration is effective.
Next, you can check if the network is functioning properly using the ping
command:
|
|
The output will be as follows:
|
|
By following the above steps, you can confirm whether the network connection is functioning properly.
Setting System Time and Date
Change the timezone to Asia/Taipei
|
|
Setting Chinese Language Environment
Edit the locale configuration file for language settings.
|
|
After adding the following content inside, save and exit:
|
|
Execute the following command to update the language configuration:
|
|
Ensure that the system’s software and packages are up to date.
|
|
Install Tailscale
If there is a need to access this computer externally, it is strongly recommended to install Tailscale instead of exposing the server directly to the entire Internet.
For detailed installation instructions, please refer to: Using Tailscale to Easily Create Secure and Private Tunnels
|
|
At this point, a URL will be displayed. Visit this URL on your smartphone or another device and log in.
Linux will automatically retrieve the Token and join your personal Tailscale network.
After installing Tailscale, some users may experience issues such as network interface names changing or DNS conflicts that prevent outbound pings.
It is recommended to reboot your system after installing Tailscale to ensure normal internet connectivity. If necessary, update your network configuration files again.
Configure SSH
You can refer to Using SSH Keys for Password-Free Remote Connections.
Install Net-tools
Net-tools provides a suite of network management and troubleshooting tools, although some commands have been replaced by more modern tools like ip
.
Install network management and troubleshooting tools:
|
|
Install Build Essentials
Some development tools depend on the following packages. It is recommended to install them to have a basic build environment:
|
|
Configure Ubuntu Pro Security
Enabling Ubuntu Pro allows for real-time system vulnerability fixes, enhancing system security and stability.
First, register and obtain a free Ubuntu Pro subscription from the Ubuntu official website. You can register at Ubuntu Pro.
After registration, subscribe to Ubuntu Pro using sudo pro attach <YOUR_TOKEN>
:
|
|
The output:
|
|
Install ble.sh
ble.sh is a script that provides real-time syntax highlighting and powerful features (such as auto-completion) for Bash.
|
|
Install Homebrew
Homebrew provides a faster way to install software packages on macOS, allowing convenient installation, updates, and management of packages. It also supports other Linux systems like Ubuntu.
|
|
After installation, you will need to execute an additional two commands to automatically load Homebrew’s installation directory into Bash.
|
|
Install fzf
fzf is a command-line fuzzy finder tool that efficiently searches through files, command history, Git commits, and more using fuzzy search techniques. It significantly enhances developers’ productivity on the command line.
|
|
Install Node.js
Node.js is a JavaScript runtime environment used for both front-end and back-end development.
The official installation guide provides clear instructions. It is recommended to use nvm for installation.
|
|
Install tldr
tldr provides concise and practical command-line tool explanations and examples, offering a more intuitive alternative to the man
command on Linux.
|
|
To use tldr, simply type tldr <command>
.
|
|
Update Git to the Latest Version
Updating Git to the latest version is not always necessary. Some tools may require older versions of Git, and installing the latest version could lead to compatibility issues.
The git-core/ppa
is a Personal Package Archive (PPA) maintained by the Git community, providing the latest versions of Git software.
|
|
Configure Git User
To set up your Git user information, use the following commands:
|
|
Conclusion
Once the above basic environment configurations are set up, you can happily proceed with remote development 🥳.