proxmox ve - qingzhiku/MicroService GitHub Wiki
PVE实操过程实录
物理机安装pve pve install in hardware pc
1、下载镜像文件 / download image
2、写盘 / write diver image with ultralISO
// 步骤 step:
-> open ultraliso
-> start
-> write diver image
3、连接USB镜像与设置bios / insert usb & bios set
enable vt or vt-d
select boot
4、启动电脑 / start pc
5、选择安装install proxmox ve / select first option " install proxmox ve "
6、一直下一步 / next-> -> -> ->
7、目标选硬盘 / target harddisk
8、国家选中国 / country->china
time zone -> shanghai
keyboard layout -> u.s.
9、设置密码与邮箱 / set password and e-mail(can custom)
10、设置主机名与网络ip / set hostname (eg.pve1.xxx.com) and set network and ip -> next
11、一直下一步 / next-> -> -> -> wait....
12、打开web控制台 / open web console
# 查看web地址
cat /etc/issue
# result
------------------------------------------------------------------------------
Welcome to the Proxmox Virtual Environment. Please use your web browser to
configure this server - connect to:
https://192.168.1.8:8006/
------------------------------------------------------------------------------
url段 | 值 |
---|---|
schemas | https |
port | 8006 |
一般安装时已经选择,无需再设置
1、 查看当前系统时间
date -R
2、 如果不是东八区,那么就接着要调整时区
tzselect
3、 过程略
# 选择 Asia=>中国(China)=>北京(Beijing)
4、 拷贝配置生效
sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
5、检查生效情况
date -R
# 修改日期
sudo date -s MM/DD/YY
# 修改时间
sudo date -s hh:mm:ss
# 非常重要,如果没有这一步的话,后面时间还是不准
sudo hwclock --systohc
apt install ntpdate -y
ntpdate 210.72.145.44 # 中国国家时间服务器: 210.72.145.44
# ntp.ntsc.ac.cn
1、使用Linux crontab 用来定期执行更新时间
参数 | 作用 |
---|---|
-u | 用户(eg. root / user) |
-r | 删除时程表 |
-l | 列出时程表 |
-e | 执行文本任务(eg. -e ntpdate ntp.ntsc.ac.cn) |
2、Crontab表达式补充 2.1 Cron-Expressions的各个子表达式含义
* * * * *
- - - - -
| | | | |
| | | | +----- 星期中星期几 (0 - 6) (星期天 为0)
| | | +---------- 月份 (1 - 12)
| | +--------------- 一个月中的第几天 (1 - 31)
| +-------------------- 小时 (0 - 23)
+------------------------- 分钟 (0 - 59)
2.2 Crontab特殊字符含义
符号 | 含义 |
---|---|
/ | 每又,(eg. 2/5 * * * *) 表示:每5分钟又2分,等于0+2,5+2... |
- | 在*与*之间每,(eg. 2-5 * * * *)表示:在2与5之间每分钟 |
, | *和*的时候(eg. 2,5 * * * *)表示:在2和5的时候 |
2.3 举一些完整的Crontab表达式例子: 注意看大单位定位小单位读法
表达式 | 含义 |
---|---|
* * * * * | 每天每小时每隔 1 分钟执行一次计划任务 |
0 * * * * | 每天每小时整点执行一次计划任务 |
15 10 * * * | 每天 10:15 执行一次计划任务 |
5 12 1 * * | 每个月 1 号的 12:05 执行一次计划任务 |
10 15 20 3 * | 每年 3 月 20 日 15:10 执行一次计划任务 |
10 15 * 3 0 | 每年 3 月的每个周日 15:10 执行一次计划任务 |
* 14 * * * | 每天从 14:00 到 14:59 每隔 1 分钟执行一次触发 |
0/5 14 * * * | 每天从 14:00 到 14:59 每个 5 分钟执行一次触发 |
0/5 14,18 * * * | 每天从 14:00 到 14:59 和 18:00 到 18:59 每隔 5 分钟执行一次触发 |
0-5 14 * * * | 每天从 14:00 到 14:05 每隔 1 分钟执行一次触发 |
10,44 14 * 3 WED | 3 月的每个星期 3 的 14:10 和 14:44 分别执行一次触发 |
0 0 1 * * | 每月的第一天执行一次触发 |
2.4 添加定时网络校时任务
# 编辑时程表
crontab -e
# 追加以下内容,每周0点0分0时
0 0 * * 1 ntpdate ntp.ntsc.ac.cn
1、安装chrony一般已经安装
apt install chrony
2、配置chrony.conf
nano /etc/chrony/chrony.conf
#添加
#中国国家授时中心
server ntp.ntsc.ac.cn iburst
server ntp1.aliyun.com
3、重启chrony
systemctl restart chronyd
4、chronyd正在访问的当前时间源的信息
chronyc sources
5、查看chrony状态,如果查到无需安装
systemctl status chronyd
6、验证自动同步 通过减少一天时间,等待5分钟查看是否自动同步
date -s "-1 day"
设置debian软件源时需要,下面以 (debian11(bullseye)) 为例设置
# 第一种
cat /etc/debian_version
# 第二种
uname -a
# 第三种
hostnamectl
--------------------------------------------------------------------------
#返回
Static hostname: pve1
Icon name: computer-desktop
Chassis: desktop
Machine ID: ec6d71b0fd6d435aab17f4fce710ed2f
Boot ID: f6d78431aa27454baaffc981e2c2eac1
Operating System: Debian GNU/Linux 11 (bullseye)
Kernel: Linux 5.13.19-2-pve
--------------------------------------------------------------------------
# 第四种
cat /etc/os-release
有2种软件仓库构成
- Debian的软件源
- Proxmox VE专用软件源
- 企业源
- 无订阅源
- 测试源
PVE软件源的配置文件:
# Debian系统源和proxmox源
/etc/apt/sources.list
# Proxmox企业仓库更新源
/etc/apt/sources.list.d/pve-enterprise.list
# 创建五订阅更新源
touch /etc/apt/sources.list.d/pve-no-subscription.list
# 清华开源镜像站
https://mirrors.tuna.tsinghua.edu.cn/
# 使用帮助 https://mirrors.tuna.tsinghua.edu.cn/help/proxmox/
# wget https://mirrors.ustc.edu.cn/proxmox/debian/proxmox-release-bullseye.gpg -O /etc/apt/trusted.gpg.d/proxmox-release-bullseye.gpg
# 中科大学开源软件镜像
https://mirrors.ustc.edu.cn/
## 阿里云(没找到pve的源)
http://mirrors.aliyun.com/debian/
# 使用帮助 https://developer.aliyun.com/mirror/debian
1、注释掉Proxmox企业版更新源source list
# 方法一:注释掉(推荐)
vi /etc/apt/sources.list.d/pve-enterprise.list
# nano /etc/apt/sources.list.d/pve-enterprise.list
# 然后用 '#' 注释掉其中的地址
# deb https://enterprise.proxmox.com/debian/pve buster pve-enterprise
# 方法二:删除
rm -rf /etc/apt/sources.list.d/pve-enterprise.list
# 方法二:更改为备份
mv /etc/apt/sources.list.d/pve-enterprise.list /etc/apt/sources.list.d/pve-enterprise.list.bak
2、设置Debian系统源(阿里云源)和proxmox源
nano /etc/apt/sources.list
# vi /etc/apt/sources.list
修改为:
# deb http://ftp.debian.org/debian bullseye main contrib
# deb http://ftp.debian.org/debian bullseye-updates main contrib
# security updates
# deb http://security.debian.org bullseye-security main contrib
# debian aliyun source(apt install apt-transport-https -y)
deb http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb http://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src http://mirrors.aliyun.com/debian-security/ bullseye-security main
deb http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
# # debian 清华大学 source,默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
# deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# proxmox source
# deb http://download.proxmox.com/debian/pve bullseye pve-no-subscription
# deb https://mirrors.ustc.edu.cn/proxmox/debian/pve bullseye pve-no-subscription
# deb https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian bullseye pve-no-subscription
使用nano编辑完之后,使用组合键 Ctl+O 保存,使用组合键 Ctl+X 退出
3、添加无订阅更新源
# 可以放到文件中/etc/apt/sources.list
echo 'deb https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian bullseye pve-no-subscription' >> /etc/apt/sources.list.d/pve-no-subscription.list
# echo 'deb https://mirrors.ustc.edu.cn/proxmox/debian/pve buster pve-no-subscription' >> /etc/apt/sources.list.d/
4、Ceph源
vi /etc/apt/sources.list.d/ceph.list
# nano /etc/apt/sources.list.d/ceph.list
修改为:
# deb http://download.proxmox.com/debian/ceph-pacific bullseye main
deb https://mirrors.ustc.edu.cn/proxmox/debian/ceph-pacific bullseye main
5、执行更新源
apt update #更新源
apt upgrade #更新已安装的包
注:下面命令请根据自己情况选择执行,可以定期执行升级操作
apt update && apt dist-upgrade -y #如需升级pve,则执行该命令
6、删除不订阅情况下不弹窗
nano /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
Ctrl + W 搜索 "No valid subscription"
将所在代码块的判断语句从
if (res === null || res === undefined || !res || res.data.status.toLowerCase() !== ‘active’)
改为
if (false)
最后注销重新登陆
7、设置CT Templates 需要使用 Proxmox 网页端下载 CT Templates,可以替换 CT Templates 的源
- 方法一: 将 /usr/share/perl5/PVE/APLInfo.pm 文件中默认的源地址 http://download.proxmox.com 替换为 https://mirrors.tuna.tsinghua.edu.cn/proxmox 即可
- 方法二: 将 /usr/share/perl5/PVE/APLInfo.pm 文件中默认的源地址 http://download.proxmox.com 替换为 https://mirrors.ustc.edu.cn/proxmox 即可
使用命令操作
cp /usr/share/perl5/PVE/APLInfo.pm /usr/share/perl5/PVE/APLInfo.pm.back
sed -i 's|http://download.proxmox.com|https://mirrors.tuna.tsinghua.edu.cn/proxmox|g' /usr/share/perl5/PVE/APLInfo.pm
apt-get install task-kde-desktop
查看内核开启ipv6自动配置:
cat /proc/sys/net/ipv6/conf/vmbr0/accept_ra
# 返回
1
cat /proc/sys/net/ipv6/conf/vmbr0/autoconf
# 返回
1
查看已开启ipv6转发:
cat /proc/sys/net/ipv6/conf/vmbr0/forwarding
# 返回
1
需要将accept_ra值改成2才能自动配置SLAAC ipv6地址:
nano /etc/sysctl.conf
# 在文件中追加
net.ipv6.conf.all.accept_ra=2
net.ipv6.conf.default.accept_ra=2
net.ipv6.conf.vmbr0.accept_ra=2
net.ipv6.conf.all.autoconf=1
net.ipv6.conf.default.autoconf=1
net.ipv6.conf.vmbr0.autoconf=1
重启网络服务
service networking restart
nano /etc/sysctl.conf
# 在文件中追加/修改为 = 1
net.ipv6.conf.all.disable_ipv6 = 1 #禁用整个系统所有接口的IPv6
net.ipv6.conf.default.disable_ipv6 = 1
# 使生效
sysctl -p /etc/sysctl.conf
1、交换机802.1Q VLAN设置 关闭交换机中二层交换的DHCP侦听 假设交换机是5口
port: 。 。 。 。 。
num: 1 2 3 4 5
划分方案:
vlan | 成员端口 | Tagged端口 | Untagged端口 | 用于 |
---|---|---|---|---|
1 | 1 | 1 | 主干 | |
10 | 1-2 | 1 | 2 | wan1 |
20 | 1,3-5 | 1 | 3-5 | lan1 |
2、PVE桥接vlan
桥接步骤:
位置:节点 -> 系统 -> 网络 网卡(eg.enp1s0) 创建 Linux Bridge 命名(格式:[名称(vmbr[n])].[pvid]) eg.:vmbr2.10/vmbr3.20 保存
1、查看当前系统的网络接口
cat /etc/network/interfaces
返回:
auto lo
iface lo inet loopback
iface enp1s0 inet manual
auto vmbr0
iface vmbr0 inet static
address 192.168.1.9/24
gateway 192.168.1.1
bridge-ports enp1s0
bridge-stp off
bridge-fd 0
iface wlp3s0 inet manual
2、配置无线网卡
apt install net-tools wireless-tools wpasupplicant
# 查看,如不出现,重启再试
iwconfig
lo no wireless extensions.
enp4s0 no wireless extensions.
wlp5s0 IEEE 802.11 ESSID:off/any
Mode:Managed Access Point: Not-Associated Tx-Power=0 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Encryption key:off
Power Management:on
vmbr0 no wireless extensions.
3、配置无线网络
# 启动网卡
ifconfig wlp3s0 up
# 搜索无线网络
iwlist wlp5s0 scan
# 生成网络配置
wpa_passphrase <WIFI_NAME> <WIFI_PASSWORD> > /etc/wpa_supplicant/wpa_supplicant.conf
# 添加到当前的系统网络接口
echo 'auto wlp3s0
iface wlp5s0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf' >> /etc/network/interfaces
# 重启系统网络服务
service networking restart
# 查看网络接口
iwconfig
# 查看无线网络都连上了网
ifconfig
挂载磁盘方式:
本地磁盘:目录(常用)、LVM、ZFS
网络存储:ceph、iscsi、nfs、cifs
1、查看磁盘
fdisk -l
# pve-root 作为根目录
# pve-swap 作为虚拟内存
# pve-data 作为磁盘镜像储存
LVM还建了一个thinpool,名为data
从运维的角度,建议直接不使用lvm-thin(pve节点-磁盘-lvm-thin),并且将所有空间给到pve-root
*PVE删除Local-lvm(实际是lvm-thin)存储空间并合并到local中
1、删除local-lvm存储空间
lvremove pve/data
# or lvremove /dev/pve/data
2、再将lvm-thin的空间转移到pve-root
lvextend -l +100%FREE -r pve/root
# or lvextend -L +100%FREE -r /dev/pve/root
3、使用resize2fs调整文件系统大小
resize2fs /dev/mapper/pve-root
4、查看大小/dev/mapper/pve-root
df -Th
5、修改一下储存配置:删除web界面local-lvm(即lvm-thin)
// 路径
数据中心 -> 存储-local -> lvm -> 删除
//编辑local
目录 -> 内容 -> 添加 -> 磁盘映像和容器
1、查看选磁盘列表
graph LR
a1(插入磁盘/USB) -.->
a2(选节点上的磁盘选项) -.->
a3(磁盘设备列表)
2、使用GPT初始化磁盘
graph LR
a1(磁盘设备列表) -.->
a2(选择设备) -.->
a3(擦除磁盘) -.->
a4(使用GPT初始化磁盘)
3、挂载磁盘,推荐目录
graph LR
a1(选中节点磁盘选项)
b1(LVM)
c1(LVM-Thin)
d1(目录<推荐>)
e1(ZFS)
a1-.->b1
a1-.->c1
a1-.->d1
a1-.->e1
b2(创建:Volume Group)
b1-.->b2
c2(创建:Thinpool)
c1-.->c2
d2(创建:创建目录)
d1-.->d2
e2(创建:ZFS)
e1-.->e2
a2(填写磁盘名称等信息)
b2-.->a2
c2-.->a2
d2-.->a2
e2-.->a2
a3(创建)
a2-.->a3
4、再次查看磁盘状态
可以看到磁盘已经挂载就绪了
利用虚拟的备份功能,对备份文件进行导入导出
通过虚拟机的备份功能,备份虚拟机到磁盘,在虚拟机备份或者磁盘备份中,可以看到已经备份的vma文件
备份过程:
graph TB
1(登录后切到pve节点) -.->
2(选择要备份的虚拟机) -.->
3(切换到虚拟机备份选项卡)-.->
4(点击右侧上方的立即备份)-.->
5(备份参数设置 <br/> 存储:local <br/>模式:停止 <br/> 压缩:无 <br/> 发送邮件至:无)-.->
6(点击备份)-.->
7(等待完成)
说明:
备份存储参数:
如果存储选local,备份位置一般在/var/lib/vz/dump 如果存储在其他位置,如usb16g,备份位置一直在/mnt/pve/usb16g/dump/
利用Ftp工具导出vma文件到本地
导出过程:
graph TB
1(Ftp工具登录PVE)-.->
2(找到备份文件目录) -.->
3(找到备份vma文件) -.->
4(下载到本地)
通过Ftp工具把vma备份文件导入到pve备份文件目录,上传以后,通过pve备份选项卡可以查看到上传的备份文件。
导入过程:
graph TB
1(Ftp工具登录PVE)-.->
2(找到备份文件目录)-.->
3(上传vma备份文件到该目录)-.->
4(等待上传完毕)
在存储备份选项卡找到备份的文件,点击还原/恢复,就可以恢复虚拟机
graph TB
1(在存储上找到备份文件)-.->
2(点击还原/恢复按钮)-.->
3(设置还原/恢复到的存储和VM ID)-.->
4(点击恢复按钮开始恢复)-.->
5(等待恢复完毕)
最后测试启动导入的虚拟机
# 数据中心 -> 集群 -> 创建集群
# 数据中心 -> 集群 -> 创建集群
1、在待隔离节点上停止 pve-cluster 服务
systemctl stop pve-cluster.service
systemctl stop corosync.service
2、 将待隔离节点的集群文件系统设置为本地模式
pmxcfs -l
3、 删除corosync 配置文件
rm /etc/pve/corosync.conf
rm -rf /etc/corosync/*
4、 重启cluster集群文件系统服务
killall pmxcfs
systemctl start pve-cluster.service
5、 离线节点删除 WEB-UI 上的除当前 node 外的 node
cd /etc/pve/nodes
rm -rf ***
# or
# rm -rf node_name(eg.pve2)
6、清理集群残留信息(正常的节点)
cd /etc/pve/nodes
rm -rf ***
pvecm delnode NodeName(eg.pve2)
1、Proxmox服务器SSH可以登录但WebUI无法访问
# 重启网页服务
systemctl restart pveproxy pvedaemon