跳转至

Ubuntu 20.04 Server 安装教程

在 VMware 虚拟机上安装 Ubuntu 20.04 Server Version

如何安装系统

选择 ubuntu server iso

来到 Ubuntu Server 20.04 Image

选择 ubuntu-20.04.6-live-server-amd64.iso

Danger

注意,一定是 Server 版本,而不是 Desktop 版

因为 Server 更加轻量化

虚拟机配额

新建虚拟机,选 recommended

alt text

将刚才下载好的镜像文件导入

alt text

设置虚拟机名(在vmware中的显示名,而不是主机名 host name)

alt text

设置主机名, host name

alt text

disk分配,保持默认不变

alt text

配置 CPU/Memory/Network Adaptor: 点击 Customize Hardware

alt text

  • 2' CPU
  • 2048 Memory
  • Network Adaptor: 保持默认,是NAT
  • Network Adaptor 2: 点击Add新建一个,选择模式host-only

alt text

结束配置,点击finish

alt text

系统安装

现在进入系统安装阶段,选择语言为English

alt text

跟图示一样即可

alt text

跟图示一样即可

alt text

跟图示一样即可, 不用动

alt text

跟图示一样即可, 不用动

alt text

跟图示一样即可, 不用动

alt text

跟图示一样, 取消勾选 Set up this disk as an LVM group

alt text

跟图示一样即可, 不用动

alt text

跟图示一样即可, continue

alt text

设置你的用户名(username)和密码

alt text

理论上现在你就是 username@hostname(hostname 在上面设置中提到过了)

勾选 Install OpenSSH Server: 自动配置SSH相关的内容,便于远程操控

alt text

啥也不选,直接 Done

alt text

现在就是系统安装的阶段了, 显示 Installing System

alt text

显示 Installing Complete! 后, 选择 Reboot Now!

alt text

现在输入完login的username和passwd, 就顺利进来了 :))

alt text

如何实现服务器端的“翻墙”

在 Server 端 “翻墙” 可没那么容易

  1. Server端 没有 Desktop端 的图形化界面
  2. Desktop端 如何“翻墙”? 传送门
  3. 需要打破翻墙的“自环” (传送门提到过👆)
  4. 需要深刻理解“配置文件”是什么?

这里借鉴了参考文档: linux server 翻墙教程

具体的原理我在这里就忽略了,我们只讲解如何做

Note

我们的默认是, 你的 物理机(宿主机) 已经成功翻墙

现在 VMware 上的 Ubuntu20.04 还没翻墙

打开 linux 命令行,依次执行下列命令

Bash
1
2
3
mkdir  ~/.config/
mkdir  ~/.config/mihomo/
cd     ~/.config/mihomo/

在宿主机上下载 clash-linux / Country.mmdb / GeoSite.dat

Bash
1
2
3
4
5
cd ~/Downloads
# clash-linux
wget -O clash-linux.gz https://github.com/MetaCubeX/mihomo/releases/download/v1.17.0/mihomo-linux-amd64-v1.17.0.gz
# Country.mmdb
wget -O Country.mmdb https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb

来到 v2ray-规则文件下载地址

选择 GeoSite.dat的任一链接 下载

在CLI中开设两个窗口

  1. Win1: 远程连接上 ubuntu server
  2. Win2: 本机传送scp指令
    Bash
    1
    2
    3
    4
    cd ~/Downloads
    scp ./clash-linux.gz [email protected]:~/.config/mihomo/
    scp ./Country.mmdb [email protected]:~/.config/mihomo/
    scp ./geosite.dat [email protected]:~/.config/mihomo/
    
如何使用SSH连接到Ubuntu VM
Bash
1
2
sudo apt install net-tools
ifconfig

找对应的端口IP即可

比如笔者的是, 下面的172.16.122.129:

Bash
 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
ubuntu@ubuntu:~$ ifconfig
  ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
          inet 172.16.162.132  netmask 255.255.255.0  broadcast 172.16.162.255
          inet6 fe80::20c:29ff:fe57:d10f  prefixlen 64  scopeid 0x20<link>
          ether 00:0c:29:57:d1:0f  txqueuelen 1000  (Ethernet)
          RX packets 3590  bytes 1806912 (1.8 MB)
          RX errors 0  dropped 0  overruns 0  frame 0
          TX packets 3234  bytes 400532 (400.5 KB)
          TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

  ens34: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
          inet 172.16.122.129  netmask 255.255.255.0  broadcast 172.16.122.255
          inet6 fe80::20c:29ff:fe57:d119  prefixlen 64  scopeid 0x20<link>
          ether 00:0c:29:57:d1:19  txqueuelen 1000  (Ethernet)
          RX packets 34899  bytes 48328921 (48.3 MB)
          RX errors 0  dropped 0  overruns 0  frame 0
          TX packets 6066  bytes 1072881 (1.0 MB)
          TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

  lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
          inet 127.0.0.1  netmask 255.0.0.0
          inet6 ::1  prefixlen 128  scopeid 0x10<host>
          loop  txqueuelen 1000  (Local Loopback)
          RX packets 137  bytes 12033 (12.0 KB)
          RX errors 0  dropped 0  overruns 0  frame 0
          TX packets 137  bytes 12033 (12.0 KB)
          TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  1. inet 对应的
  2. host-only 的 interface 对应的 IP
  3. 笔者处: ens34host-only; ens33NAT

从梯子下载配置文件

参考 这里

alt text

做法: 点击 Clash 的订阅链接

这是一个URL,将这个URL复制到浏览器搜索栏,就会自动下载一份文件

这个文件本质上是一个 .yaml 配置文件, 类似于:

alt text

在本机保存好,待会要复制并覆盖 config.yaml

现在本机的使命达成,后面我们聚焦于ubuntu server窗口:

ubuntu server clash 运行配置

现在你的~/.config/mihomo应该包含以下成分:

Bash
1
2
ubuntu@ubuntu:~/.config/mihomo$ ls
Country.mmdb  clash-linux.gz  geosite.dat

解压到当前文件夹:

Bash
1
gzip -f clash-linux.gz -d 

授权可执行权限:

Bash
1
chmod +x clash-linux

初始化执行 clash:

Bash
1
./clash-linux 

发生了点笔误,我们要修复下 :-(

跟刚才一样,我们回到Win2上,进行如下操作:

Bash
1
2
3
cd ~/Downloads
scp ./Country.mmdb [email protected]:~/.config/mihomo/
scp ./geosite.dat [email protected]:~/.config/mihomo/

现在来修改配置文件~/.config/mihomo/config.yaml:

Bash
1
2
3
ubuntu@ubuntu:~/.config/mihomo$ ls
Country.mmdb  cache.db  clash-linux  config.yaml  geosite.dat
ubuntu@ubuntu:~/.config/mihomo$ vim config.yaml

将之前拉到本地的配置文件(上面展示的那种,从梯子下载的)中的文本复制粘贴到config.yaml

然后,再次启动clash

Bash
1
./clash-linux

alt text

看见这样的结果,就知道已经稳了 :)

基于上述,日常开发如何使用梯子
  1. 在本机开两个CLI窗口连接ubuntu server
  2. 其中一个窗口进入 ~/.config/mihomo 运行: ./clash-linux
  3. 相当于后台进程
  4. 另一个窗口做开发