Files
pve_toss_notes/PVE初始化配置.md
T

193 lines
5.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 1.更换系统软件源
在上一篇文章中,我们从刚装好的 PVE 系统中获取了系统的一些参数:
![PVE系统信息](img/pve_sys_info.png)
此处显示出 PVE 底层使用的是 Debian的 系统,代号为 “bullseye”。
为了后续能够对 PVE 系统进行升级,需要更换其镜像仓库,也就是大家熟知的软件源。
由于我们目前处于“离线”安装状态,因此更换完软件源后,在没有网络的情况下无法对系统更新。
### 1.1.系统软件源替换
首先对现有的软件源配置进行备份:
```bash
## 进入系统软件源配置文件目录
cd /etc/apt
## 将默认软件源配置文件进行备份
cp sources.list sources.list.bak
```
这里我将使用中国科技大(USTC)的镜像仓库进行替换,使用如下命令:
**注意:该命令为两行,在输入时请逐行输入并回车执行**
```bash
## 替换系统软件仓库
sed -i 's|^deb http://ftp.debian.org|deb https://mirrors.ustc.edu.cn|g' /etc/apt/sources.list
sed -i 's|^deb http://security.debian.org|deb https://mirrors.ustc.edu.cn/debian-security|g' /etc/apt/sources.list
```
执行完成后,检查是否执行正确:
```bash
## 输出系统源配置文件,检查是否正确
cat /etc/apt/sources.list
```
如果输出结果中有 USTC 的镜像地址,则表示命令已经正确执行:
```bash
## 输出内容参考:
deb https://mirrors.ustc.edu.cn/debian bullseye main contrib
deb https://mirrors.ustc.edu.cn/debian bullseye-updates main contrib
# security updates
deb https://mirrors.ustc.edu.cn/debian-security bullseye-security main contrib
```
此处我放出 Debian Bullseye 的完整镜像源以供参考, **非常不建议** 将 PVE 的系统源替换成完整的 Debian 源,以避免出现问题。
```bash
## Debian Bullseye 完整源 USTC
deb https://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free
#deb-src https://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free
#deb-src https://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free
#deb-src https://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib non-free
#deb-src https://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib non-free
```
可以看到,PVE 的系统源和 Debian 完整源的差异在于 “non-free” 和 “bullseye-backports”。
如果小伙伴在一些软件或者驱动(比如闭源 GPU 驱动)上遇到问题,可以尝试将 PVE 的系统源替换成 Debian 的完整源来尝试解决问题。
### 1.2.PVE 订阅源替换
默认情况下,PVE 启用了一个官方的源,而该源为订阅制收费,我们需要替换为免费的源。
进入订阅源的目录:
**注意:rm 命令为高危险操作命令,请正确使用,请勿手抖,请勿手抖**
```bash
## 进入订阅源目录
cd /etc/apt/sources.list.d
## 删除该目录下的所有配置
rm -rvf *.list
```
创建PVE免费源:
**注意:该命令为两行,在输入时请逐行输入并回车执行**
```bash
## 创建PVE免费源
source /etc/os-release
echo "deb https://mirrors.ustc.edu.cn/proxmox/debian/pve $VERSION_CODENAME pve-no-subscription" > /etc/apt/sources.list.d/pve-no-subscription.list
```
创建完成后对其进行检查:
```bash
## 检查PVE免费源
cat /etc/apt/sources.list.d/pve-no-subscription.list
```
如果输出结果中有 USTC 的镜像地址,则表示命令已经正确执行:
```bash
## 输出内容参考:
deb https://mirrors.ustc.edu.cn/proxmox/debian/pve bullseye pve-no-subscription
```
### 1.3.PVE CT Templates 替换
如果需要使用 Proxmox 网页端下载 CT Templates,可以替换 CT Templates 的源。
该功能我未使用,因此只做记录:
```bash
## 替换 CT Templates 源
cp /usr/share/perl5/PVE/APLInfo.pm /usr/share/perl5/PVE/APLInfo.pm.bak
sed -i 's|http://download.proxmox.com|https://mirrors.ustc.edu.cn/proxmox|g' /usr/share/perl5/PVE/APLInfo.pm
```
### 1.4.替换后操作
更换完成系统源之后,需要更新系统源的同步:
```bash
## 清理
apt clean && apt autoclean
## 同步
apt update
```
考虑到“离线”安装时无法同步系统源,因此该步骤可以等到 PVE 中安装好了 RouterOS 软路由或其他路由系统并正确连接 Internet 后再执行。
或者家庭网络环境中还有一个 172.16.1.0/24 网段的,已经连接 Internet 的路由器 A。将路由器 A 的LAN 口与 PVE 的管理网口连接,此时 PVE 可访问外网。
## 2.安装必要软件
安装软件前,同样要让 PVE 能够访问外网。
```bash
## 同步镜像仓库
apt update
## 安装系统软件
apt install htop lm-sensors neofetch fail2ban vim tmux unattended-upgrades powermgmt-base
## 安装网络工具
apt install iperf iperf3 iftop net-tools ethtool
## 安装CPU调度调整工具
apt install cpufrequtils
```
其中 “fail2ban” 和 “unattended-upgrades” 为两个服务,后续会对其进行配置。
“cpufrequtils” 为 CPU 调度器的配置工具,后续会对 CPU 调度算法进行调整。
## 3.配置PVE网桥和管理网口
设置电脑的 IP 地址为静态 IP ,IP 地址段与 PVE 的 IP 地址段保持一致。
用网线将电脑的网口与 PVE 的管理网口,此时应该为编号最小的第一个网口,相连接。
访问 PVE 的 WEB 管理界面,对 PVE 的网络进行一些调整。
![PVE网络规划](img/pve_net_schematization.png)
在设置 PVE 的网络之前,需要对网络内部结构做一个规划。
在前篇的网络地址段规划时,我们有如下规划内容:
- PVE IP172.16.1.250/24
- PVE 网关:172.16.1.1
- PVE DNS172.16.1.1