一键脚本使用的Ubuntu24和Debian12(本文使用)
检测环境是否符合要求:
bash <(wget -qO- --no-check-certificate https://raw.githubusercontent.com/oneclickvirt/incus/main/scripts/pre_check.sh)
开启虚拟内存(swap)
#国际线路
curl -L https://raw.githubusercontent.com/spiritLHLS/addswap/main/addswap.sh -o addswap.sh && chmod +x addswap.sh && bash addswap.sh
#国内线路
curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/spiritLHLS/addswap/main/addswap.sh -o addswap.sh && chmod +x addswap.sh && bash addswap.sh
选择2,先移除默认的swap,然后重新执行脚本,选择1,添加swap,我的内存是2G,这里SWAP我就直接给4GB(4096MB)
PS:内存看你开多少服务器,这里如果要开8个,换算需要2G内存,实际内存如果是512MB内存,还需要开1.5G,保守点开2G虚拟内存即可(实际swap开的虚拟内存应该是实际内存的2倍,也就是开1G是合理的)
incus主体安装(一键脚本)
#国际
curl -L https://raw.githubusercontent.com/oneclickvirt/incus/main/scripts/incus_install.sh -o incus_install.sh && chmod +x incus_install.sh && bash incus_install.sh
#国内
curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/incus/main/scripts/incus_install.sh -o incus_install.sh && chmod +x incus_install.sh && bash incus_install.sh
执行以上任一脚本后等待一会
如果不需要指定非系统盘的路径做默认存储池,那么选择是否自定义存储池路径时直接回车或输入n即可,不需要指定路径。
如果需要指定非系统盘的路径做默认的存储池,那么需要选择y,然后输入对应的路径(你挂载的盘的实际的绝对路径)。
如果对应的盘除去已占用空间还有18G硬盘空余,想要开设15G的存储池,按照命令行的提示则输入15
这里我选择n,默认即可
我的硬盘默认是30GB,这里我给23GB,剩下7GB,系统和SWAP,在预留一点给镜像使用
PS:选择配置物理盘大小,一般填空闲磁盘大小减去内存大小后乘以0.95并向下取整,这里我填了10GB
出现以上提示,那就reboot 重启下,然后再次输入上面的一键脚本重新安装,依次重复上面的步骤
安装过后会自动重启,等待一会重新连接服务器
一键安装开incus宿主机所需要的带vnstat环境的常用预配置环境(非必须,该脚本仅仅是为了站点对接监控方便,不装的也没问题,因为这里我需要对接whmcs,就装了)
#国际
curl -L https://raw.githubusercontent.com/oneclickvirt/incus/main/scripts/backend.sh -o backend.sh && chmod +x backend.sh && bash backend.sh
#国内
curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/incus/main/scripts/backend.sh -o backend.sh && chmod +x backend.sh && bash backend.sh
安装incus的官方可视化控制面板(非必须,只是为了方便可视化操作,没有也没问题,如果你想面板管理,这里建议安装)
apt-get install -y incus-ui-canonical
incus config set core.https_address [::]
然后你可以在浏览器中输入:https://你的公网IPV4地址:8443
点击高级->继续前往,这时候弹窗需要选择证书,这里选择一个常用的,下次登录就选择这个证书(这里可能需要开启下魔法,有可能无法访问)
点击Generate->skip(如果你需要用密码生成,输入个密码也行),生成过后下载crt证书,点击download crt(这个证书上传到这台服务器里,然后输入下方提示的命令)
incus config trust add-certificate incus-ui.crt
接下来点击第二步-Trust token,首先在刚刚安装的incus服务器上执行下面的命令,会生成一个token,生成过后填入到import里,点击导入即可,填入过后就会自动进入面板后台
自定义批量生成版本(本文主要介绍自定义批量生成)
#国际
curl -L https://github.com/oneclickvirt/incus/raw/main/scripts/add_more.sh -o add_more.sh && chmod +x add_more.sh && bash add_more.sh
#国内
curl -L https://cdn.spiritlhl.net/https://github.com/oneclickvirt/incus/raw/main/scripts/add_more.sh -o add_more.sh && chmod +x add_more.sh && bash add_more.sh
#查看已批量开设的信息
cat log
这里我准备分配23台1核128m内存1GB硬盘无ipv6的容器,限速这里自己自定义,镜像这里我选择alpine3.1(这里会下载3.18版本最新的镜像,尝试输入3.18会报错,输入3.1就可以)
全部创建完成之后输入cat log即可看到所有创建好的容器信息
格式为:容器名称 ssh端口 root密码 端口开始 端口结束
部分常用incus命令
#查看所有容器
incus list
#查看单个容器
incus info 容器名字
#启动单个容器
incus start 容器名字
#停止单个容器
incus stop 容器名字
#删除单个容器
incus delete -f 容器名字
#进入容器
incus exec 容器名字 /bin/bash
#删除所有LXC容器
incus list -c n --format csv | xargs -I {} incus delete -f {}
#在容器内执行删除无用日志
sudo apt-get autoremove
sudo apt-get clean
sudo find /var/log -type f -delete
sudo find /var/tmp -type f -delete
sudo find /tmp -type f -delete
sudo find /var/cache/apt/archives -type f -delete
其他一键脚本:
单独生成一个NAT容器
#国际
curl -L https://raw.githubusercontent.com/oneclickvirt/incus/main/scripts/buildct.sh -o buildct.sh && chmod +x buildct.sh && dos2unix buildct.sh
#国内
curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/incus/main/scripts/buildct.sh -o buildct.sh && chmod +x buildct.sh && dos2unix buildct.sh
使用方法:
./buildct.sh 容器名称 CPU核数 内存大小 硬盘大小 SSH端口 外网起端口 外网止端口 下载速度 上传速度 是否启用IPV6(Y or N) 系统(留空则为debian11)
./buildct.sh test 1 256 2 20001 20002 20025 500 500 N debian11
普通版本批量生成
#国际
curl -L https://raw.githubusercontent.com/oneclickvirt/incus/main/scripts/init.sh -o init.sh && chmod +x init.sh && dos2unix init.sh
#国内
curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/incus/main/scripts/init.sh -o init.sh && chmod +x init.sh && dos2unix init.sh
参考来源:https://dwz.dk/cryvk
2 条评论
向佬友請教一下,我遇到如下錯誤提示:
每个容器的系统是什么?(注意传入参数为系统名字+版本号,如:debian11、ubuntu20、centos7):alpine3.1
add_more.sh: line 203: incus: command not found
No matching image found, please execute
incus image list images:system name/version number
Check if the corresponding image exists
未找到匹配的镜像,请执行
incus image list images:系统名字/版本号
查询是否存在对应镜像
输入无效,请输入一个存在的系统
What is the system of each container? (Note that the incoming parameter is the system name + version number, e.g. debian11, ubuntu20, centos7):
每个容器的系统是什么?(注意传入参数为系统名字+版本号,如:debian11、ubuntu20、centos7):
每次選了系統,都遇到這樣的提示。如何查詢可以用的系統類型和版本號的標準輸入方法?
debian10,debian11,debian12, debian13
ubuntu18,ubuntu20,ubuntu22
centos8,centos9 (实际开设出来都是Stream版本)
alpine3.15,alpine3.16,alpine3.17,alpine3.18
openwrt21,openwrt22,fedora37,fedora38,fedora39
rockylinux8,rockylinux9,oralce8,oracle9
oralce7,centos7 (都需要在GRUB中启用CGroupV1否则无法启动,详细介绍见常见问题答疑)
kali,archlinux