分类 日积月累 下的文章

pve网卡、核显直通,系统时间修正及自动同步

一、pve折腾遇到的问题

ventoy不支持pve8这个版本,更新ventoy即可!

二、网卡直通openwrt

为解决螃蟹网卡wan口虚拟化速度慢的问题,决定将螃蟹网卡直通openwrt,步骤命令如下:

打开shell输入

nano /etc/default/grub

在里面找到:GRUB_CMDLINE_LINUX_DEFAULT=”quiet”,修改为。

GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on"

ctrl+x保存。

更新一下

update-grub

重启系统

reboot

修改文件 /etc/modules

nano /etc/modules

加入如下内容,ctrl+x保存。

vfio
 vfio_iommu_type1
 vfio_pci
 vfio_virqfd

虚拟机中添加pci设备,选中螃蟹网卡

移除原来的虚拟wan口,重启虚拟机。搞定!

测速恢复正常

====================================================================

三、核显直通ubuntu虚拟机

1、启动内核IOMMU支持
打开PVE节点的shell,输入命令

nano /etc/default/grub

将GRUB_CMDLINE_LINUX_DEFAULT列改成如下:

GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt video=efifb:off,vesafb:off"

编辑完文件后按“Ctrl + X” > “Y” > “回车”,确认保存并退出,然后更新一下引导配置:

update-grub

2、加载硬件直通相关模块
在PVE的shell中输入:

nano /etc/modules

加入如下内容,ctrl+x保存。

vfio
 vfio_iommu_type1
 vfio_pci
 vfio_virqfd

3、添加驱动黑名单
编辑PVE系统的驱动黑名单配置文件:

nano /etc/modprobe.d/blacklist.conf

这个文件原来不存在,打开里面是空白的,添加以下内容:

blacklist snd_hda_intel
blacklist snd_hda_codec_hdmi
blacklist i915

这些是PVE系统核显相关的驱动,添加到“blacklist.conf”文件后,PVE系统将不加载核显的驱动,留给虚拟机用。

4、绑定核显到vfio模块
查看核显以及声卡的供应商和设备ID

lspci -n | grep -E "0300|0403"

输出如下:

00:02.0 0300: 8086:5917 (rev 07)
00:1f.3 0403: 8086:9d71 (rev 21)

其中“8086:5917”和“8086:9d71”分别就是核显和声卡的供应商ID和设备ID,把它们绑定到vifo模块:

echo "options vfio-pci ids=8086:5917,8086:9d71" > /etc/modprobe.d/vfio.conf

其他主板或CPU核显和声卡的硬件ID会不一样,请根据实际情况添加。

最后更新配置信息并重启PVE主机

update-initramfs -u
reboot

重启上来之后检查模块是否正常加载:

lsmod | grep vfio

有类似输出说明就是正常的:

vfio_pci               16384  3
vfio_pci_core          73728  1 vfio_pci
vfio_virqfd            16384  1 vfio_pci_core
irqbypass              16384  24 vfio_pci_core,kvm
vfio_iommu_type1       45056  2
vfio                   45056  10 vfio_pci_core,vfio_iommu_type1

进入虚拟机硬件设置,添加pci设备,选择核显、声卡如下图。重启虚拟机生效。

====================================================================

四、修改pve系统时间及自动更新

安装完pve遇到系统时间与实际不符,比实际晚两年多,用如下方法实测管用。

1、设置系统时间与硬件时间一致

#查看硬件的时间

hwclock --show

设置硬件时间

hwclock --set --date '2024-01-20 18:22:00' 

设置系统时间和硬件时间同步

hwclock --hctosys  

让系统时间和硬件时间保持一致

hwclock -s 

2、设置内网时间同步

安装时间同步插件

apt install systemd-timesyncd

修改时间服务器

nano /etc/systemd/timesyncd.conf

添加阿里时间同步服务器,将这行加到里面保存

NTP=ntp.aliyun.com

重启服务

systemctl restart systemd-timesyncd.service
systemctl enable systemd-timesyncd.service

系统必要性更新

apt update 
apt install curl unzip -y
# 修改时间
timedatectl set-timezone Asia/Shanghai

echo "zh_CN.UTF-8 UTF-8" >> /etc/locale.gen
# 修改中文

dpkg-reconfigure locales
# 指定本地语言
reboot


apt update
# 验证中文设置是否生效

修改固定ip
进入/etc/netplan文件夹

network:
  ethernets:
    ens192:
      addresses:
        - 192.168.16.8/24
      routes:
        - to: 0.0.0.0/0
          via: 192.168.16.5
      nameservers:
        addresses: [192.168.16.2]
      match:
        macaddress: 00:0c:29:34:70:3c
      set-name: eth0            
  version: 2

netplan apply

53端口解绑
为了方便直接使用本机的53端口进行解析,需要进行端口绑定解除。

lsof -i:53

nano /etc/systemd/resolved.conf
DNSStubListener=no        # 找到这句话, 去了# , yes 改到 no
sudo systemctl reload-or-restart systemd-resolved
lsof -i:53

mosdns 安装过程

# 挂载运行目录
mkdir /etc/mosdns

cd /home
# 解压至指定目录
unzip mosdns-linux-amd64.zip -d /etc/mosdns

# 进入运行文件夹
cd /etc/mosdns

# 赋予可执行权限
chmod +x mosdns

# 复制到存放自定义或第三方安装的可执行程序的文件夹
cp mosdns /usr/local/bin

# 返回根目录
cd /
# 进入启动目录
cd /etc/systemd/system/
# 创建启动服务
touch mosdns.service
# 编辑启动文件内容
nano mosdns.service

[Unit]
Description=mosdns daemon, DNS server.
After=network-online.target

[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/mosdns start -c /etc/mosdns/config.yaml -d /etc/mosdns

[Install]
WantedBy=multi-user.target


mkdir /etc/mosdns/rule
touch /etc/mosdns/rule/{whitelist,blocklist,greylist,ddnslist,hosts,redirect,adlist,localptr}.txt

基础规则复制
需增加内容
在 blocklist 中增加内容,进行优化

keyword:.localdomain
domain:in-addr.arpa
domain:ip6.arpa

在 localptr. txt 中增加一下内容,进行查询优化

# block all PTR requests
domain:in-addr.arpa
domain:ip6.arpa

在 whitelist. txt 文件中,增加以下内容,进行查询优化

domain:push-apple.com.akadns.net
domain:push.apple.com
domain:iphone-ld.apple.com
domain:lcdn-locator.apple.com
domain:lcdn-registration.apple.com
domain:cn-ssl.ls.apple.com
domain:time.apple.com
domain:store.ui.com.cn
domain:amd.com
domain:msftncsi.com
domain:msftconnecttest.com
domain:office.com
domain:office365.com

配置文件内容
以下配置文件为 fakeip 模式+远程 DNS 真实IP解析

log:
  level: info
  file: "/etc/mosdns/mosdns.log"

api:
  http: "0.0.0.0:8338"

include: []

plugins:
  - tag: geosite_cn
    type: domain_set
    args:
      files:
        - "/etc/mosdns/geosite_cn.txt"

  - tag: geoip_cn
    type: ip_set
    args:
      files:
        - "/etc/mosdns/geoip_cn.txt"

  - tag: geosite_no_cn
    type: domain_set
    args:
      files:
        - "/etc/mosdns/geosite_geolocation_noncn.txt"

  - tag: whitelist
    type: domain_set
    args:
      files:
        - "/etc/mosdns/rule/whitelist.txt"

  - tag: blocklist
    type: domain_set
    args:
      files:
        - "/etc/mosdns/rule/blocklist.txt"

  - tag: greylist
    type: domain_set
    args:
      files:
        - "/etc/mosdns/rule/greylist.txt"

  - tag: ddnslist
    type: domain_set
    args:
      files:
        - "/etc/mosdns/rule/ddnslist.txt"

  - tag: hosts
    type: hosts
    args:
      files:
        - "/etc/mosdns/rule/hosts.txt"

  - tag: redirect
    type: redirect
    args:
      files:
        - "/etc/mosdns/rule/redirect.txt"

  - tag: adlist
    type: domain_set
    args:
      files:
        - "/etc/mosdns/rule/adlist.txt"

  - tag: local_ptr
    type: domain_set
    args:
      files:
        - "/etc/mosdns/rule/localptr.txt"

  - tag: lazy_cache
    type: cache
    args:
      size: 32768
      lazy_cache_ttl: 86400
      dump_file: /etc/mosdns/cache.dump
      dump_interval: 3600

  - tag: reject_3
    type: sequence
    args:
      - exec: reject 3

  - tag: reject_blocklist
    type: sequence
    args:
      - exec: query_summary reject_blocklist
      - exec: $reject_3

  - tag: reject_adlist
    type: sequence
    args:
      - exec: query_summary reject_adlist
      - exec: $reject_3

  - tag: reject_ptrlist
    type: sequence
    args:
      - exec: query_summary reject_ptrlist
      - exec: $reject_3

  - tag: reject_qtype65
    type: sequence
    args:
      - exec: query_summary reject_qtype65
      - exec: $reject_3

  - tag: forward_local
    type: forward
    args:
      concurrent: 1
      upstreams:
        - addr: udp://223.5.5.5:53
          enable_pipeline: false
          insecure_skip_verify: false
          idle_timeout: 10
          enable_http3: false

  - tag: forward_remote
    type: forward
    args:
      concurrent: 1
      upstreams:
        - addr: udp://192.168.6.15:6666
          enable_pipeline: false
          insecure_skip_verify: false
          idle_timeout: 10
          enable_http3: false


  - tag: forward_cf
    type: forward
    args:
      concurrent: 1
      upstreams:
        - addr: tls://1.1.1.1:853
          enable_pipeline: true
          insecure_skip_verify: false
          idle_timeout: 30
          enable_http3: false 

  - tag: modify_ttl
    type: sequence
    args:
      - exec: ttl 0-0

  - tag: modify_ddns_ttl
    type: sequence
    args:
      - exec: ttl 5-5

  - tag: local_sequence
    type: sequence
    args:
      - exec: query_summary forward_local
      - exec: prefer_ipv4
      - exec: $forward_local

  - tag: remote_sequence
    type: sequence
    args:
      - exec: query_summary forward_remote
      - exec: prefer_ipv4
      - exec: $forward_remote

  - tag: forward_cf_upstream
    type: sequence
    args:
      - exec: query_summary forward_cf
      - exec: prefer_ipv4
      - exec: $forward_cf  

  - tag: has_resp_sequence
    type: sequence
    args:
      - matches: qname $ddnslist
        exec: $modify_ddns_ttl
      - matches: "!qname $ddnslist"
        exec: $modify_ttl
      - matches: has_resp
        exec: accept

  - tag: query_is_ddns_domain
    type: sequence
    args:
      - matches: qname $ddnslist
        exec: $local_sequence

  - tag: query_is_local_domain
    type: sequence
    args:
      - matches: qname $geosite_cn
        exec: $local_sequence

  - tag: query_is_no_local_domain
    type: sequence
    args:
      - matches: qname $geosite_no_cn
        exec: $remote_sequence

  - tag: query_is_whitelist_domain
    type: sequence
    args:
      - matches: qname $whitelist
        exec: $local_sequence

  - tag: query_is_greylist_domain
    type: sequence
    args:
      - matches: qname $greylist
        exec: $remote_sequence

  - tag: query_is_reject_domain
    type: sequence
    args:
      - matches: qname $blocklist
        exec: $reject_blocklist
      - matches: qname $adlist
        exec: $reject_adlist
      - matches:
        - qtype 12
        - qname $local_ptr
        exec: $reject_ptrlist
      - matches: qtype 65
        exec: $reject_qtype65

  - tag: fallback_sequence
    type: sequence
    args:
      - exec: $forward_cf_upstream
      - matches: "rcode 2"
        exec: goto local_sequence
      - matches: "resp_ip $geoip_cn"
        exec: goto local_sequence
      - matches: "!resp_ip $geoip_cn"
        exec: goto remote_sequence

  - tag: main_sequence
    type: sequence
    args:
      - exec: metrics_collector metrics
      - exec: $hosts
      - exec: jump has_resp_sequence
      - matches:
        - "!qname $ddnslist"
        - "!qname $blocklist"
        - "!qname $adlist"
        - "!qname $local_ptr"
        exec: $lazy_cache
      - exec: $redirect
      - exec: jump has_resp_sequence
      - exec: $query_is_ddns_domain
      - exec: jump has_resp_sequence
      - exec: $query_is_whitelist_domain
      - exec: jump has_resp_sequence
      - exec: $query_is_reject_domain
      - exec: jump has_resp_sequence
      - exec: $query_is_greylist_domain
      - exec: jump has_resp_sequence
      - exec: $query_is_local_domain
      - exec: jump has_resp_sequence
      - exec: $query_is_no_local_domain
      - exec: jump has_resp_sequence
      - exec: $fallback_sequence

  - tag: udp_server
    type: udp_server
    args:
      entry: main_sequence
      listen: ":53"

  - tag: tcp_server
    type: tcp_server
    args:
      entry: main_sequence
      listen: ":53"

服务启动
开启并运行mosdns

systemctl enable mosdns --now 
systemctl status mosdns

复制规则更新脚本文件至程序文件夹

chmod +x mos_rule_update.sh

#赋予可执行权限
./mos_rule_update.sh
# 测试运行
规则更新脚本与日志清零脚本
crontab -e
# 定时执行任务
0 0 * * 0 sudo truncate -s 0 /etc/mosdns/mosdns.log && /etc/mosdns/mos_rule_update.sh

纯IPv4源:

https://raw.githubusercontent.com/Ftindy/IPTV-URL/main/bestv.m3u #百视通源
https://raw.githubusercontent.com/Ftindy/IPTV-URL/main/cqyx.m3u #重庆广电源
https://raw.githubusercontent.com/Ftindy/IPTV-URL/main/yqgd.m3u #可能为阳泉广电源
https://raw.githubusercontent.com/Ftindy/IPTV-URL/main/hbgd.m3u #河北广电源
https://raw.githubusercontent.com/Ftindy/IPTV-URL/main/IPTV.m3u #国内4K/8K源
https://raw.githubusercontent.com/zbefine/iptv/main/iptv.m3u #zbefine源
https://raw.githubusercontent.com/vamoschuck/TV/main/M3U #茶客源
https://raw.githubusercontent.com/wuyun999/wuyun/main/zb/aptv.txt #乌云源
https://x-x-xxx.github.io/diyp/tv.txt #diyp源
https://cdn.21t.co/tv/tv.txt #21t源

部分IPv4、部分IPv6 源:

https://raw.githubusercontent.com/BigBigGrandG/IPTV-URL/release/Gather.m3u #BigBigGrandG源,有部分IPv6
https://raw.githubusercontent.com/Kimentanm/aptv/master/m3u/iptv.m3u #Kimentanm源,有部分IPv6
https://raw.githubusercontent.com/YanG-1989/m3u/main/Gather.m3u #YanG集合源,有部分IPv6
https://raw.githubusercontent.com/fanmingming/live/main/tv/m3u/v6.m3u #范明明源,有部分IPv6

纯 IPv6 源:

https://raw.githubusercontent.com/fanmingming/live/main/tv/m3u/ipv6.m3u #范明明源,纯IPv6源
https://raw.githubusercontent.com/YueChan/Live/main/IPTV.m3u #YueChan源,纯IPv6
https://raw.githubusercontent.com/whpsky/iptv/main/chinatv.m3u #whpsky源,纯IPv6
https://raw.githubusercontent.com/zhanghongguang/zhanghongguang.github.io/main/IPV6_IPTV.m3u #ZhangHongGuang源,纯IPv6

部分海外源:

https://epg.pw/test_channels.m3u #中国大陆频道
https://epg.pw/test_channels_hong_kong.m3u #香港频道
https://epg.pw/test_channels_macau.m3u #澳门频道
https://epg.pw/test_channels_taiwan.m3u #台湾频道
https://iptv-org.github.io/iptv/countries/tw.m3u #台湾频道
https://epg.pw/test_channels_singapore.m3u #新加坡频道
https://epg.pw/test_channels_malaysia.m3u #马来西亚频道

EPG 节目单:
EPG 节目单,全称为 Electronic Program Guide ,是一种电子节目单,通常以图形界面的形式,提供电视节目的详细信息,包括节目名称、频道、播出时间等,并允许用户根据这些信息选择观看特定的节目。

https://epg.112114.xyz/pp.xml
http://epg.51zmt.top:8000/e.xml
https://live.fanmingming.com/e.xml
https://epg.pw/xmltv.html?lang=zh-hans #海外EPG节目单

这个问题曾经遇到过,一直没想明白怎么回事,今天看到一篇文章,明白了原理。
SSH 登录太慢可能是 DNS 解析的问题,默认配置下 sshd 初次接受 ssh 客户端连接的时候会自动反向解析客户端 IP 以得到 ssh 客户端的域名或主机名。如果这个时候 DNS 的反向解析不正确,sshd 就会等到 DNS 解析超时后才提供 ssh 连接,这样就造成连接时间过长、ssh 客户端等待的情况,一般为10-30秒左右。有个简单的解决办法就是在 sshd 的配置文件(sshd_config)里取消 sshd 的反向 DNS 解析。

vi /etc/ssh/sshd_config
找到UseDNS,修改为no
UseDNS no
重启SSH服务
/etc/init.d/sshd restart