PVE LXC 运行 CLASH
date
Jan 21, 2024
slug
pre-lxc-clash
status
Published
tags
PVE
lxc
clash
alpine
summary
openwrt 总是用一段时间就耗尽内存,用 lxc 实现一个更纯粹的网关
type
Post
LXC 模板选择 alpine
创建好容器后做如下的设置
- 把TUN/TAP支持打开。
- 对指定LXC容器开启tun/tap,需要修改/etc/pve/lxc/[ID].conf ##[ID]为你的容器编号
vi /etc/pve/lxc/[ID].conf Proxmox7.0之前的版本添加: lxc.cgroup.devices.allow: c 10:200 rwm lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file
如果你在使用Proxmox7.0之后的版本:
lxc.cgroup2.devices.allow: c 10:200 rwm lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file
- 配置 alpine
- 开启内核转发
- alpine安装ssh
在alpine中编辑/etc/sysctl.conf,添加一行[net.ipv4.ip_forward = 1],然后运行[sysctl -p]。如果sysctl不会在开机时启动,则需要运行[rc-update add sysctl]。
apk add openssh-server rc-update add sshd service sshd start
如果要通过root用户来登录ssh,则还需要在/etc/ssh/sshd_config中加入[PermitRootLogin yes],再重启sshd。
- 添加自启动脚本
~ # cat /etc/init.d/mihomo #!/sbin/openrc-run command="/usr/local/bin/mihomo" command_args="-d /etc/mihomo" command_background="yes" command_user="root" respawn="true" pidfile="/var/run/mihomo.pid" depend() { need net } ~ # chmod +x /etc/init.d/mihomo ~ # rc-update add mihomo default
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F28f08778-28f0-4b0b-969c-a90c545f3b27%2Ff9f2151b-2f79-4cdb-8952-fe00fed33976%2FUntitled.png?table=block&id=b8d4859c-1aad-4cac-a50e-001c5b2c9295&cache=v2)
~ # chmod +x /etc/init.d/mihomo
~ # rc-update add mihomo default
~ # chmod +x /etc/init.d/mihomo
~ # rc-update add mihomo default
参考资料