最小化安装Ubuntu Server 22.04

声明:

​ 本篇图片引用了csdn作者杨小羊《最小化安装Ubuntu Server 22.04(图文详解版本)》,自己在其基础上额外归纳了一些系统优化内容,仅供学习使用,如若侵权联系删除

0.Ubuntu Server下载

1
https://ubuntu.com/download/server

1、自定义安装虚拟机

centos ubuntulinux

02

03

04

这里的cpu内存等硬件自定义设置,博主比较喜欢的配置是 2核2内核2G内存,后面其他的没有提及的都默认配置

05

这里最好使用NAT网络,方便后面远程连接

06

完成配置后点击下面的CD,开始设置IOS路径

07

完成后确认,开机

2、Ubuntu Server最小化安装

08

选择第一个

09

这里由于没有中文,只能选择英文

10

选择第二个,不更新

11

这里直接回车,默认配置

12

按上下键,到最小化安装那,按回车,等最小化安装前面括号有一个x时候,,下键到Done,回车

13

Luay_20241203_164511

这里上下键,选择静态ip,设置ens33和ens34,ip和网关根据你的实际修改

14

Configure proxy配置页面的Proxy address无需配置,直接回车

15

这里设置云源,自己输入以下阿里云的源

阿里云源地址:https://mirrors.aliyun.com/ubuntu

16

选择安装磁盘,直接回车默认自动分配,需要手动分区的话选择 [custom storage layout]

17

检查磁盘分区是否符合你的要求,回车继续

18

再次确认 Continue 继续

19

设置计算机名、用户名及密码

20

按空格键或者回车 选择安装 OpenSSH Server 服务

21

选择预置环境,按需选取,自由而定,不需要则直接选择Done回车继续,

22

开始安装,这个环节有点慢,需要有点耐心,下面那个小横再转就说明在安装,博主也安装了十几分钟

23

这里可以取消更新,直接重启,我们可以后续再更新,也可以等他更新完,博主建议等他更行完

24

重启重启过程中可能有的地方会卡一下,你按一下回车就好

3、服务器配置

(1)设置root密码

重启后,开启root用户的设置,设置root用户密码:sudo passwd root

需要先输入当前用户密码,再输入需要设置的root用户密码

(2)安装需要的工具

1
2
sudo apt install -y vim zip net-tools iptables
sudo apt-get install inetutils-*ping*

(3)设置静态ip

①获取当前ip ip addr

②编辑网络文件:sudo vim /etc/netplan/00-installer-config.yaml

25

1
2
3
4
5
6
7
8
9
10
11
12
# This is the network config written by 'subiquity'
network:
ethernets:
ens33:
addresses:
- 192.168.10.133/24
nameservers:
addresses: [114.114.114.114, 8.8.8.8]
routes:
- to: default
via: 192.168.10.2
version: 21.2.3.4.5.6.7.8.9.10.11.12.

③配置生效: sudo netplan apply

更新

登录后复制

1
2
3
sudo apt-get update

sudo apt-get dist-upgrade

(4)root远程登录

默认不支持root远程登录,如果你需要就操作

1
2
3
4
5
6
7
1.编辑ssh配置文件
root@luay:~# vim /etc/ssh/sshd_config
···
PermitRootLogin .* ==》PermitRootLogin yes

2.重启服务
root@luay:~# systemctl restart sshd

4、优化

修改网卡为eth0

修改与否看你,不强制

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
sudo nano /etc/default/grub
找到GRUB_CMDLINE_LINUX=""
改为GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
然后sudo grub-mkconfig -o /boot/grub/grub.cfg

重启系统

#配置文件里名字修改为eth0,eth1(如果你有第二块网卡)
root@luay:~# vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
ens33: #==>eth0
addresses:
- 10.0.0.243/24
nameservers:
addresses:
- 223.5.5.5
search:
- 114.114.114.114
routes:
- to: default
via: 10.0.0.254
ens34: #==>eth1
addresses:
- 172.16.1.243/24
nameservers:
addresses: []
search: []
routes:
- to: default
via: 10.0.0.254

完成上述配置后执行指令 sudo netplan apply 重启网卡

A start job is running for wait for network

1
2
3
4
5
6
7
[root@luay ~]# vim /etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service 
···
[Service]
# 设置超时2s
TimeoutStartSec=2sec

重启reboot

命令自动补全

1
2
3
4
5
6
# 安装bash-completion包
sudo apt-get update
sudo apt-get install bash-completion

# 启用bash-completion
source /usr/share/bash-completion/bash_completion

iptables

如果部署docker应用,需要用到iptables,否则会网络控制器初始化失败

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
× docker.service - linux Docke Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2025-01-16 03:21:02 UTC; 9s ago
Docs: https://docs.docker.com
Process: 2301 ExecStart=/usr/bin/dockerd (code=exited, status=1/FAILURE)
Main PID: 2301 (code=exited, status=1/FAILURE)
CPU: 149ms

Jan 16 03:21:01 worker233 dockerd[2301]: time="2025-01-16T03:21:01.641966036Z" level=info msg="Loading containers: start."
Jan 16 03:21:01 worker233 dockerd[2301]: time="2025-01-16T03:21:01.643510915Z" level=warning msg="failed to find iptables" error="exec:
\"iptables\": executable file not found in $PATH"
Jan 16 03:21:01 worker233 dockerd[2301]: time="2025-01-16T03:21:01.643999117Z" level=info msg="stopping event stream following graceful
shutdown" error="context canceled" module=libcontainerd namespace=moby
Jan 16 03:21:01 worker233 dockerd[2301]: time="2025-01-16T03:21:01.644115308Z" level=info msg="stopping healthcheck following graceful s
hutdown" module=libcontainerd
Jan 16 03:21:01 worker233 dockerd[2301]: time="2025-01-16T03:21:01.644136371Z" level=info msg="stopping event stream following graceful
shutdown" error="context canceled" module=libcontainerd namespace=plugins.moby
Jan 16 03:21:02 worker233 dockerd[2301]: time="2025-01-16T03:21:02.646850683Z" level=warning msg="grpc: addrConn.createTransport failed
to connect to {unix:///var/run/docker/containerd/containerd.sock <nil> 0 <nil>}. Err :connection error: desc = \"transport: Error while
dialing dial unix:///var/run/docker/containerd/containerd.sock: timeout\". Reconnecting..." module=grpc
Jan 16 03:21:02 worker233 dockerd[2301]: failed to start daemon: Error initializing network controller: error obtaining controller insta
nce: failed to create NAT chain DOCKER: Iptables not found
1
2
sudo apt update
sudo apt install iptables