Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build a lightweight Linux server

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to build a lightweight Linux server. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

This article only covers the part of building a basic server. I chose Ubuntu for the distribution, and although I know that CentOS or RHEL may have better performance, it is easier to be familiar with Ubuntu after all. Ubuntu itself has a Server version, and you can install a LAMP Server almost without intervention, but Linux itself is fun, and I prefer to know what is running on the server, so I decided to start by building a clean basic system. After some Google, I found an almost "perfect" tutorial: Minimal Ubuntu 8.04Server Install, the following installation process is basically based on this tutorial, a little improvement to meet the actual needs.

Back to the point, let's get into the installation. First of all, boot the server with Ubuntu 8.04 Desktop Live CD and open a Terminal to start work.

The first step is to start the partition tool to partition the hard disk. I also use cfdisk here (the reason I don't use GPart is because the server doesn't have a mouse-_-b) and partitions the 500g hard drive. The command is as follows:

Sudo su

Cfdisk / dev/sda

First, the 60MB primary partition is used as the / boot, then the 50GB logical partition is used as the root partition, the 4GB logical partition is used as the swap partition, and the remaining partition is used as / home. Don't forget to write in the partition table after sorting.

After completing the partition, I began to format each partition. For convenience, I only used the format ext3:

Mkfs.ext3 / dev/sda1

Mkfs.ext3 / dev/sda5

Mkfs.ext3 / dev/sda6

Mkswap / dev/sda7

After completing the partition, you can install the basic system. You need to use debootstrap here. The specific commands are as follows:

Mkdir / min

Mount / dev/sda5 / min

Mkdir / min/boot

Mount / dev/sda1 / min/boot

Mkdir / min/home

Mount / dev/sda6 / min/home

Apt-get install debootstrap

Before performing debootstrap, it is recommended that you do some source settings. Because this step requires a large number of software downloads, it is necessary to choose the fastest source. Here I am using the source of cn99:

Nano / usr/share/debootstrap/scripts/hardy

Find a paragraph similar to the following (default_mirror) and change it to the source you need:

Case $ARCH in amd64 | i386 | sparc)

Default_mirror http://ubuntu.cn99.com/ubuntu

And then start installing the minimum system.

Debootstrap hardy / min

When we are done, we need to set up the system to make it available. First of all, we can copy some setting information directly to the target system:

Cp / etc/hosts / min/etc/

Cp / etc/network/interfaces / min/etc/network/

Cp / etc/bash_completion / min/etc/

Cp / etc/bash.bashrc / min/etc/

In addition, we need to make some settings for the optical drive:

Mkdir-p / min/media/cdrom0

Ln-s cdrom0 / min/media/cdrom

Establish a fstab:

Nano / etc/fstab

The contents of the fstab file are roughly as follows:

Proc / proc proc defaults 0 0 / dev/sda5 / ext3 relatime 0 1 / dev/sda1 / boot ext3 relatime 0 1 / dev/sda6 / home ext3 relatime 0 1 / dev/sda7 none swap sw 0 0 / dev/cdrom / media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0

After this step, my system is basically installed, and now we can chroot in for further configuration:

Mount-bind / dev / min/dev

Mount-t proc proc / min/proc

Mount-t sysfs sysfs / min/sys

Chroot / min

Set the time zone:

Cp / usr/share/zoneinfo/Asia/Shanghai / etc/localtime

Install a text editor, I personally prefer nano, of course, you can also install vim:

Apt-get install nano

Create a list of sources, or fill in the fastest source:

Nano / etc/apt/sources.list

The content is as follows, using the source of cn99 (the speed at which I can get to 1M/s on Education Network)

Deb http://ubuntu.cn99.com/ubuntu hardy main restricted universe multiverse deb http://ubuntu.cn99.com/ubuntu hardy-updates main restricted universe multiverse deb http://ubuntu.cn99.com/ubuntu hardy-security main restricted universe multiverse

Update the source and upgrade the existing software:

Apt-get update

Apt-get dist-upgrade

Set the root user password, create a new user, and give it sudo privileges:

Passwd

Adduser liuyang

Addgroup admin

Adduser liuyang admin

Echo "admin ALL= (ALL) ALL" > > / etc/sudoers

Install grub so that the target system can boot:

Apt-get install linux-image-server grub

Mkdir / boot/grub

Update-grub

Update-initramfs-u

The target system has been set up, now launch chroot, and complete the final operation-install grub on the MBR of / dev/sda:

Exit

Grub-install-root-directory=/min-no-floppy-recheck / dev/sda

Restart the system, exit Live CD, and if all goes well, you should be able to boot your server with a "clean" Ubuntu.

This is the end of the article on "how to build a lightweight Linux server". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report