<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/ DTD/wml_1.1.xml">

<wml>
<head>
<meta http-equiv="cache-control" content="max-age=180,private" />
</head>
<card title="PVE使用LXC跑openwrt的研究">
<p>
作者:<a href="index.php?action=showuser&amp;userid=1&amp;hash=">admin</a><br />时间:2024-02-28 20:09<br />分类:<a href="index.php?action=list&amp;cid=3&amp;hash=">电脑技术</a><br />内容:
PVE使用LXC跑openwrt的研究




PVE常用配置修改工具


使用脚本更新PVE源和修改PVE--pvetools


Github：https://github.com/ivanhao/pvetools


这是一个为proxmox ve写的工具脚本（理论上debian9+可以用）。包括配置邮件，samba，NFS，zfs，嵌套虚拟化，docker，硬盘直通等功能。


方式一：命令行安装


需要用root账号来运行


在终端中按行分别执行以下内容：


强烈建议先删除企业源：rm /etc/apt/sources.list.d/pve-enterprise.list




XML/HTML代码


    export LC_ALL=en_US.UTF-8

    apt update &amp;&amp; apt -y install git &amp;&amp; git clone https://mirror.ghproxy.com/https://github.com/ivanhao/pvetools.git

    cd pvetools

    ./pvetools.sh







一键无脑安装: 


XML/HTML代码


    echo &quot;nameserver  8.8.8.8&quot; &gt;&gt; /etc/resolv.conf &amp;&amp; rm -rf pvetools &amp;&amp; rm -rf /etc/apt/sources.list.d/pve-enterprise.list &amp;&amp; export LC_ALL=en_US.UTF-8 &amp;&amp; apt update &amp;&amp; apt -y install git &amp;&amp; git clone https://mirror.ghproxy.com/https://github.com/ivanhao/pvetools.git &amp;&amp; echo &quot;cd /root/pvetools &amp;&amp; ./pvetools.sh&quot; &gt; pvetools/pvetools &amp;&amp; chmod +x pvetools/pvetools* &amp;&amp; ln -s /root/pvetools/pvetools /usr/local/bin/pvetools &amp;&amp; pvetools





方式二：wget离线下载安装（或者下载后ssh传到PVE服务器）




XML/HTML代码


    wget --no-check-certificate https://mirror.ghproxy.com/https://github.com/ivanhao/pvetools/releases/download/pve8/pvetools-pve8.0.3.zip

    unzip pvetools-pve8.0.3.zip

    cd pvetools-pve8.0.3

    ./pvetools.sh







如果提示没有权限，输入 chmod +x ./*.sh


PVE一键换源、去订阅等（另外一个修改配置工具）


Github：https://github.com/iii80/pve-sh


首先安装curl、wget、squashfs-tools工具


以下请在PVE命令行中操作


使用root用户登录，执行以下命令




XML/HTML代码


    apt update &amp;&amp; apt install -y curl wget squashfs-tools




插件安装：


方式一：PVE中输入以下命令安装pve.sh，然后在PVE命令行中直接输入 pve 运行 推荐




XML/HTML代码


    wget https://gh-proxy.com/https://raw.githubusercontent.com/iii80/pve-sh/main/pve.sh -O /usr/bin/pve &amp;&amp; chmod +x /usr/bin/pve







在PVE命令行中输入 pve 即可运行脚本。


方式二：直接运行




XML/HTML代码


    bash -c  &quot;$(curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/iii80/pve-sh/main/pve.sh)&quot;







LXC容器OpenWrt安装、更新(原作者删库，已失效)


方式一：PVE中直接使用 openwrt 命令运行自动安装更新脚本 推荐




XML/HTML代码


    wget https://gh-proxy.com/https://raw.githubusercontent.com/iii80/pve-sh/main/openwrt.lxc.sh -O /usr/bin/openwrt &amp;&amp; chmod +x /usr/bin/openwrt




在PVE命令行中输入 openwrt 即可运行脚本，进行安装或更新操作。


方式二：直接运行




XML/HTML代码


    bash -c  &quot;$(curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/iii80/pve-sh/main/openwrt.lxc.sh)&quot; 







固件下载相关




XML/HTML代码


    选项          说明                        默认值  

    仓库地址       github用户名称/仓库名称      roacn/build-actions  

    TAG名称       所在release的tag名称         AutoUpdate-x86-lxc  

    API文件       所在release的附件api文件名称  zzz_api  

    固件格式       .tar.gz或.img.gz格式固件；  

    设置为default，默认获取云端两种格式固件；  

    设置为.tar.gz，则只获取云端.tar.gz格式固件；  

    设置为.img.gz，则只获取云端.img.gz格式固件   default  







OpenWrt容器相关




XML/HTML代码


    选项       说明                      默认值  

    容器ID     lxc容器id，需要&gt;=100       100  

    容器名称    lxc容器管理页面显示的名称    OpenWrt  

    CPU核心    lxc容器分配CPU核心数        4  

    内存大小    lxc容器分配内存大小，单位MB  2048  

    磁盘大小    lxc容器分配磁盘大小，单位GB  2  

    网络接口    lxc容器分配的网络接口数量    1  

    开机自启    是否启用开机自启动，1为开启，0为不开启    1  

    启动顺序    在所有PVE虚拟机的启动排序    1  







PVE  LXC容器开启TUN/TAP


openclash的tun模式必须修改配置文件，或者zerotier这些需要tun网卡的都必须设置。


假设openwrt的id是102,所以需要找到102的配置文件。




XML/HTML代码


    cd /etc/pve/lxc/

     

    cat &gt;&gt;102.conf&lt;&lt;EOF

    lxc.cgroup2.devices.allow: c 10:200 rwm

    lxc.hook.autodev = sh -c &quot;modprobe tun; cd ${LXC_ROOTFS_MOUNT}/dev; mkdir net; mknod net/tun c 10 200; chmod 0666 net/tun&quot;

    EOF







或者手动编辑lxc的配置文件，在最下面添加一下代码




XML/HTML代码


    lxc.cgroup2.devices.allow: c 10:200 rwm

    lxc.hook.autodev = sh -c &quot;modprobe tun; cd ${LXC_ROOTFS_MOUNT}/dev; mkdir net; mknod net/tun c 10 200; chmod 0666 net/tun&quot;







然后重启102容器就可以了。


OpenClash手动安装


Github：https://github.com/vernesong/OpenClash


ipk下载：https://github.com/vernesong/OpenClash/releases


提前安装好这些依赖：




XML/HTML代码


    #iptables

    opkg update

    opkg install coreutils-nohup bash iptables dnsmasq-full curl ca-certificates ipset ip-full iptables-mod-tproxy iptables-mod-extra libcap libcap-bin ruby ruby-yaml kmod-tun kmod-inet-diag unzip luci-compat luci luci-base





XML/HTML代码


    #nftables

    opkg update

    opkg install coreutils-nohup bash dnsmasq-full curl ca-certificates ipset ip-full libcap libcap-bin ruby ruby-yaml kmod-tun kmod-inet-diag unzip kmod-nft-tproxy luci-compat luci luci-base







然后手动上传安装luci-app-openclash_xxx_all.ipk，不管错误提示，刷新openwrt网页就出现openclash了。剩下的就是根据提示下载内核，配置上网。


PVE安装docker+docker-copmose+Portainer




XML/HTML代码


    bash &lt;(curl -sL https://iii80.com/sh/docker.sh)

    bash &lt;(curl -sL https://iii80.com/sh/docker-cn.sh)







删除local-lvm分区 （非必要可不修改）


因为local-lvm，占用空间大而且存储类型少，越到后期上面有大量的虚拟机需要迁移，删除会比较麻烦，如果lvm已经有了虚拟机需要将虚拟机磁盘迁移到local存储，再删除




XML/HTML代码


    lvremove pve/data  #local-lvm的挂载位置  

    lvextend -l +100%FREE -r pve/root  #将空闲的空间全部给local  







从页面将local-lvm删除，修改local卷的存储类型，防止后续有些类型的数据无法存储，全部加上， 勾选备份保留。


参考：https://blog.csdn.net/qq_32429805/article/details/135048004


</p><p>
<a href="index.php?action=login&amp;hash=">立即登陆发表评论</a><br />
</p>
<p><a href="index.php?action=list&amp;hash=">返回日志列表</a><br /><a href="index.php?action=index&amp;hash=">返回主页</a></p>
</card>
</wml>
