系统维护 · 网络代理 · 中文环境 · 服务部署 — 个人笔记整合 (代码原样保留)
# 更新软件包密钥,解决安装应用时提示“签名未信任”的问题
pacman -Sy archlinux-keyring
ncdu / --exclude /media --exclude /run/timeshift/
yay -Scc
date -s "$(curl -I https://www.baidu.com 2>/dev/null | grep -i '^date:' | cut -d' ' -f2-)"
# 允许进入 br+ 网络
sudo iptables -I FORWARD -i br+ -j ACCEPT
# 允许离开 br+ 网络
sudo iptables -I FORWARD -o br+ -j ACCEPT
# br+ 是所有 Docker bridge 网络的通配符
port=0
# ========== 日志 ==========
log-dhcp
log-facility=/var/log/dnsmasq.log
# ========== TFTP ==========
enable-tftp
tftp-root=/var/tftp
# ========== PXE / Proxy DHCP ==========
dhcp-range=192.168.0.105,proxy
dhcp-match=set:iPXE,175
dhcp-vendorclass=set:flag,PXEClient:Arch:00000
dhcp-vendorclass=set:flag,PXEClient:Arch:00006
dhcp-vendorclass=set:flag,PXEClient:Arch:00007
dhcp-vendorclass=set:flag,PXEClient:Arch:00009
tag-if=set:load,tag:!iPXE,tag:flag
pxe-prompt="Press F8 or Enter key for PXE menu.", 3
dhcp-option=tag:load,66,192.168.0.105
pxe-service=tag:load,X86PC,"Boot BIOS iPXE",undionly.kpxe
pxe-service=tag:load,07, "iPXE UEFI(07)", ipxe.efi
pxe-service=tag:load,09, "iPXE UEFI(09)", ipxe.efi
dhcp-boot=tag:iPXE,192.168.0.105
dhcp-range=192.168.0.130,192.168.0.150,12h
dhcp-match=set:bios,option:client-arch,0
dhcp-match=set:ipxe,175
dhcp-boot=tag:!ipxe,tag:bios,undionly.kpxe
dhcp-boot=tag:!ipxe,tag:!bios,ipxe.efi
dhcp-boot=tag:ipxe,boot.ipxe
# enable-tftp
# tftp-root=/ipxe/firmware/
# 监听本地请求
listen-address=127.0.0.1,192.168.0.105
# 不读取 /etc/resolv.conf,避免环路
no-resolv
# 指定上游 DNS(可以多个)
server=114.114.114.114
server=223.5.5.5
# 缓存大小
cache-size=10000
vim /etc/NetworkManager/dnsmasq.d/dnsmasq.conf
#resolv-file=/run/NetworkManager/no-stub-resolv.conf
listen-address=127.0.0.1,::1
cache-size=3072
#no-resolv
#log-queries
vim /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile
dns=dnsmasq
rc-manager=unmanaged
[ifupdown]
managed=false
[device]
wifi.scan-rand-mac-address=no
rm /etc/resolv.conf
vim /etc/resolv.conf
nameserver 127.0.0.1
nameserver ::1
options edns0 trust-ad
search .
systemctl restart NetworkManager
qname(geosite:category-ads-all) -> reject
只阻止外部访问,允许本地代理
如果你希望禁止外部直接访问 35455,但允许本机(包括 Nginx 代理)访问,需要修改 iptables 规则:
# 先允许来自127.0.0.1的访问
iptables -A INPUT -p tcp --dport 35455 -s 127.0.0.1 -j ACCEPT
# 再拒绝其他所有IP的访问
iptables -A INPUT -p tcp --dport 35455 -j DROP
此时规则顺序为:
ACCEPT 来自 127.0.0.1 的连接DROP 其余所有 IP 的连接iptables -A INPUT -p tcp --dport 35455 \! -s 127.0.0.1 -j DROP
\! 前有空格,表示“来源不是 127.0.0.1 则 DROP”。iptables -D INPUT -p tcp --dport 35455 \! -s 127.0.0.1 -j DROP
==Docker 专门为用户提供了一个 DOCKER-USER 链。所有与 Docker 容器端口相关的访问控制规则,都应该添加到这个特殊的链中,这样才能确保规则始终在 Docker 自己的规则之前生效,并且不会被覆盖。==
iptables -I DOCKER-USER -p tcp --dport 9000 ! -s 127.0.0.1 -j DROP
这个命令的解释如下:
-I DOCKER-USER:将规则插入到 DOCKER-USER 链的最前面,确保最高优先级。-p tcp --dport 35455:匹配 TCP 协议且目标端口为 35455 的数据包。! -s 127.0.0.1:匹配“源IP不是 127.0.0.1”的条件。-j DROP:将匹配到的数据包直接丢弃。添加后可以运行 iptables -L DOCKER-USER -n 命令来确认规则是否生效。
==通过规则序号删除==
列出 DOCKER-USER 链的规则,并显示序号:
iptables -L DOCKER-USER -n --line-numbers
记住要删除的规则序号(比如是 1),然后删除:
iptables -D DOCKER-USER 1
yay -S noto-fonts-sc
sudo pacman -S ttf-jetbrains-mono
sudo vim /etc/locale.gen
# 把以下内容前的#去掉
zh_CN.UTF-8 UTF-8
sudo su
locale-gen && echo 'LANG=zh_CN.UTF-8' > /etc/locale.conf
INPUT_METHOD=fcitx5
GTK_IM_MODULE=fcitx5
QT_IM_MODULE=fcitx5
XMODIFIERS=@im=fcitx5
sudo pacman -S fcitx5-im fcitx5-rime fcitx5-chinese-addons
cd ~/.local/share/fcitx5/rime
git clone https://github.com/iDvel/rime-ice.git
cp -r ./rime-ice/* .
yay -S targetcli-fb
sudo systemctl enable target.service --now
sudo targetcli
backstores/fileio create name=game_disk file_or_dev=/srv/iscsi/game_disk.img size=500G sparse=true
iscsi create iqn.2024-12.local.arch:vhdx
iscsi/iqn.2024-12.local.arch:vhdx/tpg1/luns create /backstores/fileio/vhdx
iscsi/iqn.2024-12.local.arch:vhdx/tpg1/portals create 0.0.0.0
iscsi/iqn.2024-12.local.arch:vhdx/tpg1/acls create "客户机的iscsi"
iscsi/iqn.2024-12.local.arch:vhdx/tpg1 set attribute authentication=0
saveconfig
exit
sudo targetcli
cd /iscsi/iqn.2003-01.org.linux-iscsi.archlinux.x8664:sn.a3cf511b8019/tpg1/
set attribute authentication=0
set attribute generate_node_acls=1
set attribute demo_mode_write_protect=0
cd /
saveconfig
exit
[global]
# =========================
# 基础身份
# =========================
workgroup = WORKGROUP
netbios name = ARCHNAS
server string = Arch Linux Samba Server
# =========================
# 安全模型(关键)
# =========================
security = user
map to guest = Bad User
null passwords = yes
invalid users = root
# =========================
# 协议 & 兼容性
# =========================
server min protocol = SMB2
unix extensions = no
wide links = yes
follow symlinks = yes
# 文件权限(非常重要
create mask = 0777
directory mask = 0777
# =========================
# 网络(可选,建议保留)
# =========================
bind interfaces only = yes
interfaces = 192.168.0.123/24 127.0.0.1
include = /etc/samba/smb-shares.conf
[jellyfin]
path = /data/media/jellyfin/media
comment = Public Media
browseable = yes
# Public
public = yes
read only = yes
guest ok = yes
write list = yan
case sensitive = auto
preserve case = yes
short preserve case = yes
vfs objects = catia fruit streams_xattr
fruit:encoding = native
[emby]
path = /data/media/emby/media/video
comment = Private Media
browseable = yes
# Secure
valid users = yan
write list = yan
read only = yes
guest ok = no
case sensitive = auto
preserve case = yes
short preserve case = yes
vfs objects = catia fruit streams_xattr
fruit:encoding = native
location / {
proxy_pass http://127.0.0.1:8096/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
}
location ~ ^/hy/(.+)$ {
set $huya_id $1;
proxy_pass http://127.0.0.1:35455/huya/$huya_id$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
}
# 下载Nginx源码
curl -OL# https://nginx.org/download/nginx-1.30.1.tar.gz
# 解压缩
tar -zxvf nginx-1.30.1.tar.gz
# cd进入
cd nginx-1.30.1
# 加入 nginx-http-flv-module模块
git clone https://fastgit.cc/https://github.com/winshining/nginx-http-flv-module.git
# 构建参数 各个操作系统的依赖包不同,可以拿此参数去问AI需要安装什么依赖包
./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/bin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx.pid \
--user=nginx \
--group=nginx \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_flv_module \
--add-module=./nginx-http-flv-module
# 没有报错就执行 make -j4
# 安装
sudo make install
# 创建Nginx专用用户
sudo useradd -r -s /sbin/nologin -M nginx
# Nginx参考配置
worker_processes 1;
error_log /usr/local/nginx/logs/error.log;
# pid 必须要
pid /usr/local/nginx/logs/nginx.pid;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
chunk_size 4096;
application hls {
live on;
hls on;
hls_fragment_naming system;
hls_fragment 2;
hls_playlist_length 30;
hls_path /tmp/nghls;
hls_nested off;
}
application flv {
live on;
}
}
}
http {
root /www/static;
include /etc/nginx/conf.d/*.conf;
sendfile off;
tcp_nopush on;
server_tokens off;
access_log /usr/local/nginx/logs/access.log;
server {
listen 8080;
location = / {
index index.html;
}
location /hls {
alias /tmp/nghls;
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
# if ($http_user_agent != "chengji.m3u8") {
# return 403;
# }
}
location /flv {
flv_live on;
add_header Access-Control-Allow-Origin *;
add_header Cache-Control no-cache;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /www/static;
}
}
# 以下server块是反代flv 播放链接,不然太长了
server {
listen 80;
server_name localhost;
location ~ ^/flv/(.+)$ {
set $stream_name $1;
proxy_pass http://127.0.0.1:8080/flv?app=flv&stream=$stream_name;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_buffering off;
proxy_cache off;
}
}
}
function proton-run
env STEAM_COMPAT_DATA_PATH=/home/yan/WindowsApp/wine/pvz \
STEAM_COMPAT_CLIENT_INSTALL_PATH="$HOME/.steam/steam" \
/usr/share/steam/compatibilitytools.d/proton-ge-custom/proton run $argv
end
function fish_greeting
fastfetch
end
abbr -- ssdr 'sudo systemctl daemon-reload'
abbr -- ssre 'sudo systemctl restart'
abbr -- mfy 'mpv https://live.ottiptv.cc/bilibili/650'
abbr -- sps 'sudo pacman -S'
abbr -- sstu 'sudo systemctl status'
# tput 颜色设置,只有ghostty终端才需要
set TERM xterm-256color
set -gx PATH /home/yan/.bin $PATH
set -gx av 'https://192.168.0.105/flv/av'
set -gx gh 'https://fastgit.cc/'
set -gx NVM_DIR ~/.nvm
set -gx nvm_mirror https://npmmirror.com/mirrors/node/
systemctl stop reflector
cfdisk
mkfs.vfat /dev/sda1
mkswap /dev/sda2
mkfs.btrfs -f /dev/sda3
mount -t btrfs -o compress=zstd /dev/sda3 /mnt/
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
umount /mnt
mount -t btrfs -o subvol=/@,compress=zstd /dev/sda3 /mnt
mount --mkdir -t btrfs -o subvol=/@home,compress=zstd /dev/sda3 /mnt/home
mount --mkdir /dev/sda1 /mnt/boot
vim /etc/pacman.d/mirrorlist
pacman -Sy archlinux-keyring
pacstrap -K /mnt base base-devel linux linux-firmware btrfs-progs
pacstrap -K /mnt networkmanager vim sudo intel-ucode
swapon /dev/sda2
genfstab -U /mnt > /mnt/etc/fstab
arch-chroot /mnt
# ======================================================================
vim /etc/hostname
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
vim /etc/locale.gen
# 取消注释en_US.UTF-8,zh-CN.UTF-8
locale-gen
vim /etc/locale.conf
LANG=en_US.UTF-8
useradd -m yan
visudo
passwd yan
pacman -S grub efibootmgr os-prober openssh dnsmasq adobe-source-han-serif-cn-fonts adobe-source-han-serif-cn-fonts
pacman -S gnome
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Archlinux
vim /etc/default/grub
# 替换
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=5 nowatchdog modprobe.blacklist=iTCO_WDT"
# 取消注释以下
GRUB_DISABLE_OS_PROBER=false
grub-mkconfig -o /boot/grub/grub.cfg
systemctl enable NetworkManager
systemctl enable sshd
systemctl enable gdm
subvolid=5,这是挂载 Btrfs 树根(而非子卷)的关键。mount -o subvolid=5 /dev/你的根分区 /mnt
/mnt/timeshift-btrfs/snapshots/ 目录下。进入该目录查看文件夹名称(通常是一串日期时间)。ls /mnt/timeshift-btrfs/snapshots/
@,快照在 /path/to/你的快照文件夹/@:# 1. 备份当前损坏的系统(可选但推荐,以防万一)
mv /mnt/@ /mnt/@_broken
# 2. 将选中的快照克隆为新的 @ 子卷
btrfs subvolume snapshot /mnt/你的快照路径/@ /mnt/@
reboot 并拔掉U盘。yay -Scc 保持系统清爽。wsdd。