This commit is contained in:
SuperYuIuo
2023-08-16 13:34:29 +00:00
parent 2a50fe41e7
commit d7bc616ec0

View File

@@ -2,31 +2,31 @@
outline: deep
---
# LXC虚拟化
# LXC Virtualization
## 单独开设LXC虚拟化的CT
## Creating Individual LXC Containers for Virtualization
:::warning
初次使用前需要保证当前PVE纯净且宿主机未进行过任何端口映射否则设置冲突可能出现BUG
Before initial use, ensure that the current PVE (Proxmox Virtual Environment) is clean and the host machine has not undergone any port mapping, as conflicts in settings could lead to bugs.
:::
:::tip
开设前请使用screen挂起执行避免批量开设时间过长SSH不稳定导致中间执行中断
Before creating containers, use the 'screen' command to run them in the background. This helps to avoid extended creation times that might lead to interruptions due to unstable SSH connections.
:::
- 自动开设NAT服务器默认使用Debian11镜像,也可自定义系统
- 自动进行内外网端口映射含2280443端口以及其他25个内外网端口号一样的端口
- 生成后需要等待一段时间虚拟机内部配置好网络以及登陆信息大概需要3分钟
- 默认开设的网络配置为2280443端口及一个25个端口区间的内外网映射
- 可自定义开设的核心数,内存大小,硬盘大小,使用宿主机哪个存储盘,记得自己计算好空闲资源开设
- 可在命令中指定存储盘位置默认不指定时为local盘即系统盘可指定为PVE中显示的挂载盘
- 开设的CT默认已启用SSH且允许root登陆且已设置支持使用docker的嵌套虚拟化
- 容器的相关信息将会存储到对应的容器的NOTE中可在WEB端查看
- 如果宿主机自带IPV6子网将自动附加上IPV6网络但无公网IPV6地址
- Automatically create NAT servers using the default Debian 11 image, or customize the system image as needed.
- Automatically perform internal and external network port mapping, including ports 22, 80, 443, and 25 additional ports with identical numbers for both internal and external networks.
- After generation, allow some time for the virtual machine to configure its internal network and login information. This process takes approximately 3 minutes.
- The default network configuration includes port mappings for 22, 80, 443, and a range of 25 ports for both internal and external networks.
- Customize the number of cores, memory size, disk size, and the storage disk on the host machine for allocation. Ensure that you calculate available resources before creating containers.
- Optionally specify the storage disk location in the command. When not specified, it defaults to the local disk, which is the system disk. Alternatively, you can specify a mount disk as displayed in PVE.
- The created containers are enabled with SSH by default, allowing root login. They are also configured to support nested virtualization for Docker.
- Relevant container information will be stored in the respective container's notes, accessible through the web interface.
- If the host machine has an IPV6 subnet, IPV6 networking will be automatically attached, but no public IPV6 addresses will be provided.
### 使用方法
### Usage Instructions
下载脚本
Download the script
Command:
@@ -34,55 +34,57 @@ Command:
curl -L https://raw.githubusercontent.com/spiritLHLS/pve/main/scripts/buildct.sh -o buildct.sh && chmod +x buildct.sh
```
* 系统支持:
- debian10debian11
- ubuntu18ubuntu20ubuntu22
- centos8almalinux9
- 其他系统可能支持可能不支持,自行测试
* System Support:
- debian10, debian11
- ubuntu18, ubuntu20, ubuntu22
- centos8, almalinux9
- Other systems may or may not be supported, please test on your own.
:::tip
系统参数一律是小写的系统名字拼接版本号x86_64的具体可执行```pveam available --section system```查看可用的系统名字和版本号arm的可在[https://mirror.tuna.tsinghua.edu.cn/lxc-images/images/](https://mirror.tuna.tsinghua.edu.cn/lxc-images/images/)中查看支持的系统,版本号类同执行```pveam available --section system```查看到的版本号。
(注意脚本使用的参数只有小写的英文系统名字拼接版本号)
System parameters are always in lowercase, consisting of the system name concatenated with the version number. For x86_64 systems, you can check available system names and version numbers using ```pveam available --section system```. For ARM systems, you can check supported systems and version numbers at [https://mirror.tuna.tsinghua.edu.cn/lxc-images/images/](https://mirror.tuna.tsinghua.edu.cn/lxc-images/images/), similar to the version numbers obtained by executing ```pveam available --section system```.
(Please note that the parameters used in the script are only lowercase English system names concatenated with version numbers.)
:::
所有系统的CT默认用户名是root
The default username for all CTs is root.
```shell
./buildct.sh CTID 密码 CPU核数 内存 硬盘 SSH端口 80端口 443端口 外网端口起 外网端口止 系统 存储盘
./buildct.sh CTID Password Number_of_CPU_Cores Memory Disk SSH_Port Port_80 Port_443 Start_Public_Port End_Public_Port System Storage_Disk
```
### 测试示例
### Test Example
```shell
./buildct.sh 102 oneclick123 1 512 5 20001 20002 20003 30000 30025 debian11 local
```
开设完毕可执行```cat ct102```查看信息或在web端的NOTES查看
After setting up, you can execute `cat ct102` to view the information, or check the NOTES section on the web interface.
以下为开设的示例CT的信息
Here is the information for the created example CT:
| 属性 | 值 |
Please note that "CT" and other technical terms might have specific meanings in different contexts. If "CT" stands for something specific in your domain, you might want to provide additional context for accurate translation.
| Attribute | Value |
|---------------------------|-------------|
| VMID | 102 |
| SSH登录的用户名 | root |
| SSH登录的密码 | oneclick123 |
| CPU核数 | 1 |
| 内存大小 | 512MB |
| 磁盘大小 | 5G |
| SSH端口 | 20001 |
| 80端口 | 20002 |
| 443端口 | 20003 |
| 内外网映射端口一致的区间 | 3000030025|
| 系统 | debian11 |
| 宿主机的存储盘 | local |
| SSH Username | root |
| SSH Password | oneclick123 |
| Number of CPU Cores | 1 |
| Memory Size | 512MB |
| Disk Size | 5G |
| SSH Port | 20001 |
| Port 80 | 20002 |
| Port 443 | 20003 |
| Port Range for NAT | 30000 to 30025|
| Operating System | debian11 |
| Host Storage Disk | local |
### 删除示例
### Deletion Examples
- 停止CT
- 删除CT
- 删除端口映射
- 重启网络
- 删除log文件
- Stop CT
- Delete CT
- Delete Port Mapping
- Restart Network
- Delete Log Files
```shell
pct stop 102
@@ -94,22 +96,22 @@ service networking restart
systemctl restart networking.service
```
## 批量开设NAT的LXC虚拟化的CT
## Batch Creation of LXC Containers with NAT
:::warning
初次使用前需要保证当前PVE纯净且宿主机未进行过任何端口映射否则设置冲突可能出现BUG
Make sure the current Proxmox Virtual Environment (PVE) is clean and the host machine has not undergone any port mapping before the first use, as conflicting settings may result in bugs.
:::
:::tip
开设前请使用screen挂起执行避免批量开设时间过长SSH不稳定导致中间执行中断
Before initiating the creation process, it's recommended to use the 'screen' command to execute the batch creation. This will prevent interruptions due to potential instability in SSH during the extended creation time.
:::
- 可多次运行批量生成CT容器但需要注意的是母鸡内存记得开点swap免得机器炸了[开SWAP点我跳转](https://github.com/spiritLHLS/addswap)
- 每个容器创建之间有间隔等待60秒避免突发性能不足
- 可自定义批量开设的核心数,内存大小,硬盘大小,使用宿主机哪个存储盘,记得自己计算好空闲资源开设
- 开设的CT默认已启用SSH且允许root登陆且已设置支持使用docker的嵌套虚拟化
- 容器的相关信息将会存储到对应的容器的NOTE中可在WEB端查看
- 如果宿主机自带IPV6子网将自动附加上IPV6网络但无公网IPV6地址
- It is possible to run the batch container creation process multiple times. However, please be mindful of allocating enough memory to the host machine to prevent system crashes. For adding swap space, refer to [this link](https://github.com/spiritLHLS/addswap).
- There is a 60-second interval between creating each container to avoid sudden performance bottlenecks.
- Customization options include selecting the number of CPU cores, memory size, disk size, and the storage drive on the host machine. Ensure that you have calculated available resources appropriately before initiating the process.
- The created containers have SSH enabled by default, allowing root login. Additionally, they are configured to support nested virtualization for Docker usage.
- Relevant information about the containers will be stored in the corresponding container's notes, which can be viewed on the web interface.
- If the host machine has an IPv6 subnet, it will be automatically assigned to the containers. However, public IPv6 addresses will not be provided.
Command:
@@ -117,15 +119,14 @@ Command:
curl -L https://raw.githubusercontent.com/spiritLHLS/pve/main/scripts/create_ct.sh -o create_ct.sh && chmod +x create_ct.sh && bash create_ct.sh
```
开设完毕可执行```cat ctlog```查看信息或在web端的NOTES查看
After the setup is complete, you can execute ```cat ctlog``` to view the information, or check in the NOTES section on the web interface.
### Delete All CT
### 删除所有CT
- 删除所有CT
- 删除所有nat的端口映射
- 重启网络
- 删除log文件
- Delete all CTs
- Delete port mappings for all NATs
- Restart the network
- Delete log files
```shell
pct list | awk 'NR>1{print $1}' | xargs -I {} sh -c 'pct stop {}; pct destroy {}'
@@ -136,14 +137,14 @@ service networking restart
systemctl restart networking.service
```
## 开设纯IPV6地址的虚拟机
## Creating Virtual Machines with Pure IPv6 Addresses
前提是宿主机给的是IPV6子网而不是单独一个IPV6地址且宿主机未开启MAC地址校验
The premise is that the host provides an IPv6 subnet rather than a standalone IPv6 address, and the host does not have MAC address filtering enabled.
### 自动选择IPV6地址无需手动指定
### Automatic Selection of IPv6 Addresses, No Manual Configuration Needed
- 自动检测可用的IPV6区间对应容器编号的V6地址绑定到容器上
- 系统的相关信息将会存储到对应的容器的NOTE中可在WEB端查看
- Automatically detect available IPv6 ranges and bind the corresponding V6 address based on the container number to the container.
- Relevant system information will be stored in the NOTES of the corresponding container, accessible for viewing on the web interface.
Command:
@@ -151,31 +152,31 @@ Command:
curl -L https://raw.githubusercontent.com/spiritLHLS/pve/main/scripts/buildct_onlyv6.sh -o buildct_onlyv6.sh && chmod +x buildct_onlyv6.sh
```
#### 创建示例
#### Example Usage
```shell
./buildct_onlyv6.sh CTID 密码 CPU核数 内存大小以MB计算 硬盘大小以GB计算 系统 存储盘
./buildct_onlyv6.sh CTID Password Number_of_CPU_Cores Memory_Size_in_MB Disk_Size_in_GB Operating_System Storage_Disk
```
```shell
./buildct_onlyv6.sh 152 oneclick123 1 1024 10 debian12 local
```
上述命令意义为开设一个纯IPV6地址的容器
The above command signifies the creation of a container with a pure IPV6 address.
| 属性 | 值 |
|--------------|-----------------|
| 容器类型 | CT |
| Attribute | Value |
|------------ |-----------------|
| Container Type | CT |
| CTID | 152 |
| 用户名 | root |
| 密码 | oneclick123 |
| CPU核心数 | 1 |
| 内存 | 1024MB |
| 硬盘 | 10G |
| 系统 | debian12 |
| 存储盘 | local盘 (系统盘) |
| Username | root |
| Password | oneclick123 |
| CPU Cores | 1 |
| Memory | 1024MB |
| Disk | 10G |
| Operating System | debian12 |
| Storage Disk | Local Disk (System Disk) |
#### 删除示例
#### Deletion Example
```shell
rm -rf ct*