-
Notifications
You must be signed in to change notification settings - Fork 23
第二步‐开始部署LXC环境以及mihomo、openwrt
cooip-jm edited this page Aug 7, 2024
·
3 revisions

apt-get install lxc
lxc-checkconfig
nano /etc/lxc/default.conf
nano /etc/default/lxc-net
lxc-create --name mihomo --template download -- --dist debian --release bookworm --arch arm64 --server mirrors.bfsu.edu.cn/lxc-images
nano /var/lib/lxc/mihomo/config
使用宿主系统网桥

apt install -y openssh-server nano curl wget git apt-transport-https ca-certificates


exitnano /etc/systemd/network/eth0.network[Match]
Name=eth0
[Network]
Address=10.10.10.10/24
DNS=10.10.10.1
IPForward=yes
IPv6AcceptRA=true
[Route]
Gateway=10.10.10.1# 查看网络服务的状态
systemctl status systemd-networkd
# 启动网络服务
systemctl start systemd-networkd
# 停止网络服务
systemctl stop systemd-networkd
# 重启网络服务
systemctl restart systemd-networkd
# 设置开机启动网络服务
systemctl enable systemd-networkd
# 禁止开机启动网络服务
systemctl disable systemd-networkdapt install curl nano wget git apt-transport-https ca-certificates apt-utils -y
wget https://github.com/MetaCubeX/mihomo/releases/download/Prerelease-Alpha/mihomo-linux-arm64-alpha-6399347.gz
gzip -d mihomo-linux-arm64-alpha-6399347.gz
chmod 777 mihomo-linux-arm64-alpha-6399347
mv mihomo-linux-arm64-alpha-6399347 /usr/local/bin/mihomo
mkdir /etc/mihomo
nano /etc/mihomo/config.yaml ## 使用官方推荐配置或者自己按照官方例子填写
git clone https://github.com/metacubex/metacubexd.git -b gh-pages /etc/mihomo/ui
nano /etc/systemd/system/mihomo.service ###官方文档填写
systemctl daemon-reload
systemctl enable mihomo
systemctl start mihomo或者自行了解
https://wiki.metacubex.one/https://github.com/MetaCubeX
https://t.me/openwrt_flippy/4924解压到
tar -zxf openwrt_lxc_template_R24.01.26-flippy-87+-rootfs.tar.gz -C /var/lib/lxc/openwrt/rootfs/
nano /var/lib/lxc/openwrt/config # Distribution configuration
lxc.include = /usr/share/lxc/config/common.conf
lxc.arch = aarch64
# Container specific configuration
lxc.apparmor.profile = generated
lxc.apparmor.allow_nesting = 1
lxc.rootfs.path = dir:/var/lib/lxc/openwrt/rootfs
lxc.uts.name = openwrt
# Network configuration eth0
lxc.net.0.type = veth
lxc.net.0.link = vmbr0
lxc.net.0.flags = up
# Network configuration eth1
lxc.net.1.type = veth
lxc.net.1.link = vmbr0
lxc.net.1.flags = up
# PPPoe
lxc.cgroup2.devices.allow = c 108:0 rwm
lxc.mount.entry = /dev/ppp dev/ppp none bind,create=file
# TUN
lxc.cgroup2.devices.allow = c 10:200 rwm
lxc.mount.entry = /dev/net/tun dev/net/tun none bind,create=file
# 启用N1 的无线网卡
lxc.net.2.type = phys
lxc.net.2.link = wlan0
lxc.net.2.flags = up
lxc.net.2.name = wlan0
启动openwrt
lxc-start openwrt进入
lxc-attach openwrt退出
exit###openwrt内配置网络
nano /etc/config/network
配置好后
输入修改后的IP 地址




# 启用N1 的无线网卡
lxc.net.2.type = phys
lxc.net.2.link = wlan0
lxc.net.2.flags = up
lxc.net.2.name = wlan0
以官方openwrt举例
https://openwrt.org/

下载rootfs
wget https://downloads.openwrt.org/releases/23.05.2/targets/armsr/armv8/openwrt-23.05.2-armsr-armv8-rootfs.tar.gz解压到lxc目录内,oWrt自己手动创建
tar -xzf openwrt-23.05.2-armsr-armv8-rootfs.tar.gz -C /var/lib/lxc/oWrt/rootfs增加配置文件
nano /var/lib/lxc/oWrt/config
# Distribution configuration
lxc.include = /usr/share/lxc/config/common.conf
lxc.arch = aarch64
# Container specific configuration
lxc.apparmor.profile = generated
lxc.apparmor.allow_nesting = 1
lxc.rootfs.path = dir:/var/lib/lxc/oWrt/rootfs
lxc.uts.name = openwrt
# Network configuration eth0
lxc.net.0.type = veth
lxc.net.0.link = vmbr0
lxc.net.0.flags = up
# Network configuration eth1 根据自身需求决定是否添加该项
lxc.net.1.type = veth
lxc.net.1.link = vmbr0
lxc.net.1.flags = up
# PPPoe 根据自身需求决定是否添加该项
lxc.cgroup2.devices.allow = c 108:0 rwm
lxc.mount.entry = /dev/ppp dev/ppp none bind,create=file
# TUN 根据自身需求决定是否添加该项
lxc.cgroup2.devices.allow = c 10:200 rwm
lxc.mount.entry = /dev/net/tun dev/net/tun none bind,create=file
lxc-start oWrt
lxc-attach oWrtpasswdvi /etc/config/network/etc/init.d/network restart





我仓库里写了三个非常简陋的基础脚本,凑合用用。
你们有更好的,欢迎PR
wget -O - https://raw.githubusercontent.com/cooip-jm/About-openwrt/main/bash.sh | sh -s -- -v
运行完后

wget -O - https://raw.githubusercontent.com/cooip-jm/About-openwrt/main/install-passwall.sh | sh -s -- -v

wget -O - https://raw.githubusercontent.com/cooip-jm/About-openwrt/main/openclash-install.sh | sh -s -- -v

opkg update && opkg list-upgradable | cut -f 1 -d ' ' | xargs opkg upgradelxc.start.auto = 1nano /etc/systemd/system/lxc-start.service[Unit]
Description="LXC autostart for lxc user"
[Service]
ExecStartPre=/bin/sleep 15
ExecStart=/usr/bin/lxc-autostart --all
[Install]
WantedBy=default.target
systemctl daemon-reload
systemctl enable lxc-start.service
systemctl start lxc-start.service
systemctl status lxc-start.service
journalctl --disk-usagejournalctl --vacuum-time=2d
journalctl --vacuum-size=500Msystemctl kill --kill-who=main --signal=SIGUSR2 systemd-journald.serviceSystemMaxUse=16M
ForwardToSyslog=nosystemctl restart systemd-journald.service