如何映射hyper-v的端口?

把Hyper-v虚拟机端口映射到localhost上,以便开发

Hyper-v虚拟机管理器要添加一个内部交换机(switch),以便固定虚拟机ip地址。这里设置为10.10.10.8。

centos上装好1panel,并把redis启动好。

用下面命令,将centos虚拟机的redis映射到本地localhost:6379

1
netsh interface portproxy add v4tov4 listenport=6379 listenaddress=127.0.0.1 connectaddr=10.10.10.8 connectport=6379

用下面命令解绑映射

1
netsh interface portproxy delete v4tov4 listenaddr=127.0.0.1 listenport=6379
Dashboard Template for Bootstrap

Section title

# Header Header Header Header
1,001 Lorem ipsum dolor sit
1,002 amet consectetur adipiscing elit
1,003 Integer nec odio Praesent
1,003 libero Sed cursus ante
1,004 dapibus diam Sed nisi
1,005 Nulla quis sem at
1,006 nibh elementum imperdiet Duis
1,007 sagittis ipsum Praesent mauris
1,008 Fusce nec tellus sed
1,009 augue semper porta Mauris
1,010 massa Vestibulum lacinia arcu
1,011 eget nulla Class aptent
1,012 taciti sociosqu ad litora
1,013 torquent per conubia nostra
1,014 per inceptos himenaeos Curabitur
1,015 sodales ligula in libero
Dashboard Template for Bootstrap

1 创建脚本,并运行它

1
2
3
4
5
6
7
8
docker pull registry:latest
# 检查
docker images | grep -aiE registry
# 构建容器
docker run -itd --name=huage-registry -p 5000:5000 registry:latest
sleep 5
# 检查是否成功
docker ps | grep -aiE registry

2 演示步骤

2.1 拉取nginx
1
2
3
docker pull nginx

docker images | grep nginx
2.2 改tag
1
2
3
docker tag nginx:latest me6:5000/nginx:latest

docker images | grep nginx
2.3 上传
1
2
docker push me6:5000/nginx:latest
#报错,因为没有改https为http
2.4 其它机器改daemon.json
1
"insecure-registries":["192.168.66.86:5000"]

1.常规配置(lvm分区,调整swap,更改源,删除订阅弹窗)

参考:PVE虚拟化(Proxmox Virtual Environment)安装以及常规配置(lvm分区,调整swap,更改源,删除订阅弹窗)-腾讯云开发者社区-腾讯云 (tencent.com)

1移除pve里的local-lvm分区

1
2
lvremove pve/data
lvextend -l +100%FREE -r pve/root

提示是否移除卷[y/n] 输入 y

然后在网页中,点击数据中心 - 存储 - local-lvm 点击移除并确认

2移除pve自带的swap分区

由于默认swap分区建立在系统盘中,会影响系统盘运行,且消耗系统盘寿命,建议删除。

进入shell输入如下命令

1
2
3
swapoff -a
lvremove /dev/pve/swap
lvresize -l +100%FREE /dev/pve/root

创建swap分区

想自定义swap分区大小的小伙伴可以按照以下步骤操作

1
2
3
4
5
6
7
8
9
#创建一个16G的swap,bs * count =16G   count代表你想创建的swap分区的大小单位为g 
dd if=/dev/zero of=/swapfile bs=1G count=16
#配置安全的权限
chmod 0600 /swapfile
#格式化成swap
mkswap /swapfile
#挂载swap
swapon /swapfile
#验证 free -h

开机自动挂载swap分区

打开shell继续输入如下命令

代码语言:bash

复制

1
2
nano /etc/fstab       
/swapfile swap swap defaults 0 0

注意:要注释掉原来的swap那一行,不然会很慢!

更改国内源删除订阅弹窗

代码语言:bash

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 将此文件的中的所有内容注释掉
nano /etc/apt/sources.list.d/pve-enterprise.list

# 下载中科大的GPG KEY
wget https://mirrors.ustc.edu.cn/proxmox/debian/proxmox-release-bookworm.gpg -O /etc/apt/trusted.gpg.d/proxmox-release-bookworm.gpg

# 使用Proxmox非企业版源
echo "deb https://mirrors.ustc.edu.cn/proxmox/debian bookworm pve-no-subscription" > /etc/apt/sources.list.d/pve-no-subscription.list

# 将Debian官方源替换为中科大源
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

# 替换Ceph源
echo "deb https://mirrors.ustc.edu.cn/proxmox/debian/ceph-quincy bookworm no-subscription" > /etc/apt/sources.list.d/ceph.list

# 替换CT镜像下载源
sed -i 's|http://download.proxmox.com|https://mirrors.ustc.edu.cn/proxmox|g' /usr/share/perl5/PVE/APLInfo.pm

#删除订阅弹窗
sed -Ezi.bak "s/(Ext.Msg.show\(\{\s+title: gettext\('No valid sub)/void\(\{ \/\/\1/g" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js && systemctl restart pveproxy.service
# 执行完成后,浏览器Ctrl+F5强制刷新缓存

编辑/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

执行sysctl -p

2、创建LXC容器

进入容器shell

1
apt install curl sudo

要先换源/etc/apt/source.list

deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib

查看这个安装docker教程:Debian 12 / Ubuntu 22.04 安装 Docker 以及 Docker Compose 教程 - 烧饼博客

然后安装portainer(参考Docker)

安装npm(nginx-proxy-manager)

1
docker run -d --name npm --restart always --network host -v /home/docker/npm/data:/data -v /home/docker/npm/letsencrypt:/etc/letsencrypt jc21/nginx-proxy-manager:latest

默认端口是81,默认用户密码:admin@example.com changme

改为了admin@qq.co, aosite007008, admin

LTAI5t87HKTEqYxY29qVTjse

UHR57DVL4twERQAIq4tqtX9bXJODCE

000300010011329e1775

listen [::]:21443 ssl;

【PVE8.0保姆级教程(06) IPV6+Nginx Proxy Manager反向代理和转发本地服务】 https://www.bilibili.com/video/BV1VN411x7UN/?share_source=copy_web&vd_source=635462a67c7c18600ca16e3d8c372abe

安装

安装完毕,由于使用两块硬盘,要将第二硬盘挂载,下面命令是执行自动挂载

1
echo /dev/sda /mnt/ssd1t/ ext4 defaults 1 >> /etc/fstab

无效订阅去除命令

1
sed -i.backup -z "s/res === null || res === undefined || \!res || res\n\t\t\t.data.status.toLowerCase() \!== 'active' /false/g" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js && systemctl restart pveproxy.service

03 导入虚拟机(ova)

1 将ova传入pve中

2 解压

tar xvf ubuntu.ova

得到两个文件

ubuntu.ovf
ubuntu-disk1.vmdk

3 导入

qm importdisk 106 ubuntu-disk1.vmdk local-lvm -format qcow2

4 pve界面添加该磁盘