1. 网络配置

Key Value

IP Address

Subnet

192.168.1.0/24

Address

192.168.1.120

Gateway

192.168.1.1

NameServer

114.114.114.114,8.8.8.8

Account

Name

Noble

Server Name

noble-docker

UserName

noble

Password

elf

Confirm Password

elf

apt install net-tools -y

vim /etc/netplan/00-installer-config.yaml

netplan apply
network:
  ethernets:
    eth0:
      addresses:
      - 192.168.1.120/24
      nameservers:
        addresses:
        - 114.114.114.114
        - 8.8.8.8
        search: []
      routes:
      - to: default
        via: 192.168.1.1
  version: 2

2. 账户设置

  • 不要安装非LTS版本,如Ubuntu Server 23.04,
    否则可能登录后SSH服务都找不到

  • 安装成功后重启,使用noble - elf登录

  • root密码修改

sudo -s

sudo passwd root

elf - elf

sudo reboot now

3. SSH设置

vim /etc/ssh/sshd_config

PermitRootLogin yes

systemctl restart sshd
systemctl enable ssh

systemctl daemon-reload
systemctl restart ssh.socket

systemctl status ssh

# ufw allow 22
ufw allow ssh

ufw enable

# ssh noble@192.168.0.12345 -p 22
ssh userName@serverIpOrHostname

4. Mirror Source

Ubuntu Version Command

Ubuntu 24.04 Noble

vim /etc/apt/sources.list.d/ubuntu.sources

Ubuntu 22.04 Jammy

vim /etc/apt/sources.list

5. Ubuntu Jammy

  • vim /etc/apt/sources.list

deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

deb http://mirrors.163.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse

deb http://cn.archive.ubuntu.com/ubuntu jammy main restricted
deb http://cn.archive.ubuntu.com/ubuntu jammy-updates main restricted
deb http://cn.archive.ubuntu.com/ubuntu jammy universe
deb http://cn.archive.ubuntu.com/ubuntu jammy-updates universe
deb http://cn.archive.ubuntu.com/ubuntu jammy-updates multiverse
deb http://cn.archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu jammy-security main restricted
deb http://cn.archive.ubuntu.com/ubuntu jammy-security universe
deb http://cn.archive.ubuntu.com/ubuntu jammy-security multiverse

6. Ubuntu Noble

  • vim /etc/apt/sources.list.d/ubuntu.sources

Types: deb deb-src
URIs: https://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-backports noble-security noble-proposed
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb deb-src
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu/
Suites: noble noble-updates noble-backports noble-security noble-proposed
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb deb-src
URIs: http://mirrors.163.com/ubuntu/
Suites: noble noble-updates noble-backports noble-security noble-proposed
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb deb-src
URIs: https://mirrors.ustc.edu.cn/ubuntu/
Suites: noble noble-updates noble-backports noble-security noble-proposed
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb
URIs: http://cn.archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

6.1. Type

  • 指定存储库的格式;

Entry Memo

deb

预编译并准备安装的二进制包

deb-src

需编译的源码包

6.2. URI

Entry Memo

cn.*

指向Ubuntu包归档的中国镜像

security.*

专门用于安全更新

6.3. Suite

  • 指与Ubuntu发布周期的不同版本或Stage对齐的特定软件包集

Entry Memo

noble

初始版本包

noble-updates

更新包

noble-backports

向后移植backport

noble-security

安全漏洞

6.4. Component

  • 存储库中按支持状态或许可组织包的类别

Entry Memo

main

拥有Ubuntu支持的免费和开源软件

restricted

包含Ubuntu支持的专有驱动程序和软件

universe

包括community-maintained免费和开源软件

multiverse

软件可能非免费或非开源,且不受Ubuntu官方团队支持

6.5. Sign By

  • 指向包含用于验证软件包真实性的公钥的密钥环文件,官方的Ubuntu存档签名密钥

  • /usr/share/keyrings/ubuntu-archive-keyring.gpg

7. 时间同步

  • 一般涉及容器会涉及到时间同步,如ntp,timezone等,解决方案有很多,
    如启动容器时指定或构建镜像时设置或从设定好的主机复制,
    此处采用主机和构建镜像时独立设置,如Aisa/Shanghai

# Ubuntu 24.04
timedatectl set-timezone Asia/Shanghai && \
	timedatectl set-local-rtc 1 && \
	systemctl restart rsyslog && timedatectl status

# Ubuntu 22.04
timedatectl set-timezone Asia/Shanghai && \
	timedatectl set-local-rtc 1 && \
	hwclock --localtime --systohc && \
	systemctl restart rsyslog && timedatectl status

# timedatectl list-timezones | grep keyword
# timedatectl list-timezones | grep Asia/Shanghai

# timedatectl set-timezone Region/Location
# timedatectl set-timezone Asia/Shanghai

# timedatectl set-time YYYY-MM-DD
# timedatectl set-time 2022-09-01

# timedatectl set-time HH:MM:SS
# timedatectl set-time 14:38:30

# apt install ntpdate
# ntpdate ​​time.windows.com​​

# 设置硬件时间为本地时间
# timedatectl set-local-rtc 1

# 设置硬件时间为UTC时间
# timedatectl set-local-rtc 0

# 本地时间更新到硬件
# hwclock --localtime --systohc

# 启动ntp时间同步
# timedatectl set-ntp true

# 禁用ntp时间同步
# timedatectl set-ntp false

date +"%Z %z" && cat /etc/timezone && \
	ls -l /etc/localtime && timedatectl status

tzselect => Asia => China => BeiJing => Yes
	cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
	=> date -R

8. 语言环境

  • https://help.ubuntu.com/community/Locale

  • 查询当前设定及已安装Locale: locale && locale -a

  • Linux语系通过变量来设置,其它变量会通过LANG和LC_ALL传递变化,
    LANG是定义系统主语系的变量,LC_ALL是定义整体语系的变量,
    另需通过/etc/sysconfig/i18n定义系统默认语系

  • 修改/etc/default/locale

  • 特定于用户的$HOME/.pam_environment

  • gnome-language-selector

$ vim /etc/default/locale

LANG=zh_CN.UTF-8
LANGUAGE=zh_CN:zh
LC_ALL=zh_CN.UTF-8

$ locale-gen zh_CN.UTF-8

$ reboot now

$ echo $LANG && locale

# 容器设置语言环境:apt install -y language-pack-zh-hans
RUN  locale-gen && update-locale LANG=zh_CN.UTF-8 && \
	localedef -c -f UTF-8 -i zh_CN zh_CN.utf8 && \
	localectl set-locale LANG=zh_CN.UTF-8

ENV LC_ALL zh_CN.UTF-8
  • Microsoft Wsl方案:

    • vim /etc/default/locale

    • LANG=C.UTF-8LANG=zh_CN.UTF-8

    • apt install -y language-pack-zh-hans

    • 退出终端并重新登录

9. 系统与硬件

# 系统信息
cat /etc/issue && uname -omr

# 系统更新
apt update -y && apt upgrade -y && apt list --upgradable

# 硬件信息:查看内存,磁盘及cpu信息
free -hm && df / -h | tail -1 && grep -cE 'cpu[0-9]+' /proc/stat