Ubuntu 20.04 LTS (Focal Fossa) 安装笔记

Posted by sysin on 2020-05-15
Estimated Reading Time 10 Minutes
Words 2.2k In Total
更新日期:Fri May 15 2020 10:10:00 GMT+0800,阅读量:

请访问原文链接:Ubuntu 20.04 LTS (Focal Fossa) 安装笔记,查看最新版。原创作品,转载请保留出处。

作者主页:sysin.org


无耻抄袭者 Yu Tao,请立遁!!!

Ubuntu 20.04 新特性

Updated Packages

Linux Kernel 5.4.

Toolchain Upgrades 🛠️:

Ubuntu 20.04 LTS comes with refreshed state-of-the-art toolchain including new upstream releases of glibc 2.31, ☕ OpenJDK 11, rustc 1.41, GCC 9.3, 🐍 Python 3.8.2, 💎 ruby 2.7.0, php 7.4, 🐪 perl 5.30, golang 1.13.

Ubuntu Desktop:

Network configuration

With this Ubuntu release, netplan.io has grown multiple new features, some of which are:

  • Basic support for configuring SR-IOV network devices. Starting with netplan.io 0.99, users can declare Virtual Functions for every SR-IOV Physical Function, configure those as any other networking device and set hardware VLAN VF filtering on them.
  • Support for GSM modems via the NetworkManager backend via the modems section.
  • Adding WiFi flags for bssid/band/channel settings.
  • Adding ability to set ipv6-address-generation for the NetworkManager backend and emit-lldp for networkd.

Storage/File Systems

ZFS 0.8.3

Other base system changes since 18.04 LTS

  • Python3 by default(Python 3.8. Python 2.7 已经移除)

  • Snap Store replaces ubuntu-software

Ubuntu Server

  • Installer

    The live server installer is now the preferred media to install Ubuntu Server on all architectures.

  • QEMU

    QEMU was updated to 4.2 release.

  • libvirt

    libvirt was updated to version 6.0.

  • dpdk

    Ubuntu 20.04 LTS includes the latest stable release 19.11.1 of the latest LTS series 19.11.x. The very latest (non-stable) version being 20.02 was not chosen for downstream projects of DPDK (like Open vSwitch) not being compatible yet.

  • Open vSwitch

    Open vSwitch has been updated to 2.13.

  • Chrony

    Chrony been updated to version 3.5.

  • cloud-init

    Cloud-init was updated to version 20.1-10.

  • PHP 7.4

  • Ruby 2.7

  • Ruby on Rails 5.2.3

  • Ubuntu HA/Clustering

    Kronosnet
    Corosync 3.0
    Pacemaker 2.0
    Resource Agents
    Fence Agents
    keepalived

  • isc-kea 1.6 stable track(dhcp server)

  • Bind 9.16

  • OpenSSH updates with U2F Support

  • HAProxy 2.0

  • Apache, TLSv1.3, client cert auth

  • Samba 4.11

  • PostgreSQL 12

  • nginx

    Starting in Focal Fossa, nginx-core no longer ships with the legacy geoip module enabled by default. If you are using the legacy geoip module in nginx, you may run into upgrade issues if you do not deactivate the geoip module in your configuration. This was done as part of the deprecation of GeoIP legacy support.

  • Squid 4.x

  • s390x

  • OpenStack Ussuri

  • Ceph was updated to the 15.2.1 release

完整更新内容请查阅发行说明

1. 安装摘要

18.04:安装界面变化比较大,参看截图,默认 SSH Server 已经安装(测试 18.04.3 修改为需要手动勾选),没有时区选择界面

20.04:安装界面少了步骤的数字提示,参看截图,SSH Server 需要勾选安装,没有时区选择界面

注意:分区如果选择 LVM,默认 / 目录只使用了 4G,需要编辑使用全部容量

2. 格式化网卡名称

1
2
3
4
5
6
7
8
9
10
类似 CentOS 7,及 Ubuntu 16.04 开始,安装好后网卡名称变成 ens160 类似名称了
# 编辑 grub 配置文件
sudo vi /etc/default/grub
修改 GRUB_CMDLINE_LINUX=""为 GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"

# 直接使用 sed 编辑
sudo sed -i "/^GRUB_CMDLINE_LINUX=""/c GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"" /etc/default/grub
# 更新 grub 配置文件
sudo update-grub
# 然后下一节编辑配置文件并重启生效

3. 网络配置

查看 IP 地址信息

1
2
3
ip address
# 简写 ip a
# ifconfig 也支持

通过 netplan 管理网络

18.04:
cat /etc/network/interfaces
ifupdown has been replaced by netplan
默认使用 netplan 管理网络

18.04 默认配置文件:/etc/netplan/50-cloud-init.yaml

20.04:
cat /etc/network/interfaces
cat: /etc/network/interfaces: No such file or directory

20.04 默认配置文件:/etc/netplan/00-installer-config.yaml

配置静态 IP 地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sudo vim /etc/netplan/00-installer-config.yaml
# 格式如下:
network:
version: 2
ethernets:
eth0: #ens160 修改为 eth0
addresses:
- 10.19.190.5/24
gateway4: 10.19.190.1
nameservers:
addresses:
- 10.19.190.11
- 10.19.190.12
search:
- sysin.org
1
2
3
4
5
# 运行以下命令使配置生效
sudo netplan apply

# 重启系统后彻底生效
sudo reboot

配置为 DHCP

1
2
3
4
5
6
7
8
echo '
network:
version: 2
ethernets:
eth0:
dhcp4: yes
dhcp6: yes
' > /etc/netplan/00-installer-config.yaml

恢复传统的网络配置方式

1
2
3
# 可以恢复原有配置方式
sudo apt install net-tools #ifconfig、netstat、route 等命令集
sudo apt install ifupdown #模板未执行该命令

补充:yaml 基础

1
2
3
4
大小写敏感
使用缩进表示层级关系
缩进时不允许使用 Tab 键,只允许使用空格
缩进的空格数目不重要,只要相同层级的元素左侧对齐即可

缩进建议使用 2 个空格,使用短横线 “-” 表示列表时,”- “后面的条目需要对齐,如果使用超过 2 个空格缩进,格式将有误。

配置静态路由示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
network:
version: 2
ethernets:
eth0:
addresses:
- 10.19.190.5/24
#gateway4: 10.19.190.254
nameservers:
addresses:
- 10.19.190.11
- 10.19.190.12
search:
- sysin.org
routes:
- to: 0.0.0.0/0
via: 10.19.190.254
metric: 100
- to: 10.19.177.0/24
via: 10.19.190.1
metric: 100

4. 修改主机名

设置主机名

1
2
3
vim /etc/hostname
# 修改为主机名 ubuntu01
ubuntu01

添加 domain name

1
2
3
4
5
vi /etc/hosts
# 添加一行
127.0.0.1 ubuntu01.sysin.org ubuntu01
# 注意这里的格式,IP 后面先写 FQDN 再写主机名,与 CentOS 相同
# 先写主机名后写 FQDN 不影响解析,但是'hostname -f'命令无法只能显示主机名

查看 FQDN

1
2
3
hostname -f
# 正确显示如下
ubuntu01.sysin.org

5. 设置时区

1
sudo timedatectl set-timezone Asia/Shanghai

6. 修改国内镜像源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 模板使用 aliyun

# 备份
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 替换为阿里云镜像源
sudo sed -i 's/cn.archive.ubuntu.com/mirrors.aliyun.com/' /etc/apt/sources.list
# 提示:-i 写入文件,s 替换命令

选择时区后镜像地址为 cn.archive.ubuntu.com,注意修改替换命令

# 根据实际网络情况选择镜像,可以 Ping 镜像地址查看延迟
# 网易 163
sudo sed -i 's/cn.archive.ubuntu.com/mirrors.163.com/' /etc/apt/sources.list
# 中科大
sudo sed -i 's/cn.archive.ubuntu.com/mirrors.ustc.edu.cn/' /etc/apt/sources.list
# 清华
sudo sed -i 's/cn.archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/' /etc/apt/sources.list

更新

1
2
3
4
sudo apt update #更新源
sudo apt upgrade #更新已安装的包
sudo apt dist-upgrade #升级系统
sudo apt clean && sudo apt autoclean #清理下载文件的存档

7. 安装 SNMP(模板未配置)

1
sudo apt install snmpd snmp

8. 配置 NTP

(1) 默认使用 systemd-timesyncd(NTP Client)进行时间同步

适用于 Ubuntu 18.04、20.04 和 22.04。

配置文件默认如下:
vi /etc/systemd/timesyncd.conf

1
2
3
4
5
6
[Time]
#NTP=
#FallbackNTP=ntp.ubuntu.com
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048

默认 NTP 服务器使用 ntp.ubuntu.com

如果使用其他的服务器,增加一行,多个地址用空格分隔:

1
NTP=ntp1.aliyun.com ntp2.aliyun.com

重启服务生效:
systemctl restart systemd-timesyncd

手动同步(sudo atp install ntpdate):
ntpdate -s ntp1.aliyun.com

查看同步状态:

timedatectl timesync-status

(2) 配置使用 chrony

也可以禁用默认的 NTP Client(命令:sudo timedatectl set-ntp off),使用 chrony 进行时间同步。

安装

1
2
3
4
5
6
7
8
sudo apt install chrony

sudo systemctl enable chrony
sudo systemctl start chrony
sudo systemctl status chrony

# 查看配置文件,暂使用默认配置
cat /etc/chrony/chrony.conf

chrony 自带一个交互式工具 chronyc,在配置文件中指定了时间服务器之后,如果想查看同步状态,可以进入这个交互式工具的交互界面。

1
2
3
4
5
chronyc 有很多的子命令,可以输入 help 来查看
chronyc> help
选项:
sources [-v] 显示关于当前来源的信息
sourcestats [-v] 显示时间同步状态(如时间偏移了多少之类)

9. 虚机安装 VMware Tools

1
2
3
# Ubuntu 16.04 在 ESXi 中安装系统时已经自动安装了 vm-tools(18.04、20.04 相同)
# 20.04 自带 vm-tools 版本为 11.0.5,与 ESXi 7.0.0 匹配
sudo apt install open-vm-tools

10. 安装必备工具

1
2
3
4
5
6
7
8
9
10
11
sudo apt install zip unzip
sudo apt install lrzsz
sudo apt install htop #20.04 已默认安装(18.04 已默认安装)
sudo apt install lnav
sudo apt install fd-find #fd 命令,20.04 已经收录
sudo apt install ripgrep #rg 命令,20.04 已经收录
sudo apt install tree
sudo apt install build-essential #Following command will install essential commands like gcc, make etc.
sudo apt install net-tools #ifconfig、netstat、route 等命令集
sudo apt install ntp ntpdate ntpstat #可选,模板未安装
# nc lsof pstree 系统自带 (sysin)

11. 开启 root 账号登录

Ubuntu 默认禁用 root SSH 密码登录(Pubkey 认证不受此限,默认启用),安装时候创建特定用户作为管理员帐号(通过 sudo 执行特权命令),启用 root 用户步骤如下:

  • 修改 root 密码(控制台可以登录)
1
sudo passwd root
  • 修改配置文件(SSH 密码登录)
1
2
3
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

sudo vi /etc/ssh/sshd_config

找到下面相关配置:

1
2
3
4
5
6
7
8
9
10
11
12
# Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2

修改如下

1
2
3
4
5
增加一句
PermitRootLogin yes

快速配置:
sudo sed -i "/^#PermitRootLogin/c"PermitRootLogin""yes"" /etc/ssh/sshd_config

补充

1
2
PermitRootLogin prohibit-password  #允许 root 登录,但禁止使用密码认证
可以配合使用 Pubkey 认证,修改 PubkeyAuthentication yes
  • 重启服务生效
1
sudo systemctl restart ssh

下载 OVF

虚拟机模板下载:


捐助本站 ❤️ Donate

点击访问官方网站


文章用于推荐和分享优秀的软件产品及其相关技术,所有软件默认提供官方原版(免费版或试用版),免费分享。对于部分产品笔者加入了自己的理解和分析,方便学习和测试使用。任何内容若侵犯了您的版权,请联系作者删除。如果您喜欢这篇文章或者觉得它对您有所帮助,或者发现有不当之处,欢迎您发表评论,也欢迎您分享这个网站,或者赞赏一下作者,谢谢!

支付宝赞赏 微信赞赏

赞赏一下


☑️ 评论恢复,欢迎留言❗️
敬请注册!点击 “登录” - “用户注册”(已知不支持 21.cn/189.cn 邮箱)。请勿使用联合登录(已关闭)