243 字 1 分钟阅读
Debian12
安装常用软件:
apt update &&
apt install -y vim wget git curl htop gcc make openssl p7zip-full unzip net-tools build-essential trash-cli
# 常规选装
apt install -y screen btop proxychains iproute2 passwd iperf3 pipx
安装 oh-my-zsh:
apt install -y zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
将 zsh 主题改为 risto:
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="risto"/' ~/.zshrc
exec zsh
将时区设置为上海:
timedatectl set-timezone Asia/Shanghai
安装 netplan:
apt-get install netplan.io openvswitch-switch
编辑 /etc/netplan/01-netcfg.yaml:
network:
ethernets:
enp1s0:
dhcp4: no
dhcp6: no
addresses: [192.168.10.11/24]
nameservers:
addresses:
- 192.168.10.12
routes:
- to: default
via: 192.168.10.12
on-link: true
应用配置:
chmod 600 /etc/netplan/01-netcfg.yaml
systemctl enable --now systemd-networkd
systemctl enable --now openvswitch-switch
将 SSH 公钥写入 authorized_keys:
KEY='ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCZ57GU6Y5oNGHQYIKbn2XhosgqMBhW67FygKT3i/B10cagNM9msxJ8IIPMw6q2PcXtjwAgw8WqezCucHblkMxmygsnPbJBiV8s0tUg3Wld0VW1m0W0dQ98y7c0QNZ/4L5EtklqYMpSlOZ/w+GW+BXOTg7fNhIWsMVUyUjd726goA3REpcrLsrb0AzVYSzcnCyGdoD81FrQk9b4ud49eN6VnDafac372D+bb+3h7LYrA4gZjLXeDDUxp7OfQuTpZlbUsYc6YmJq8n/a0OOB1SRDxKVZ4ft9a5NBdWWEgsjxCb1zCVLoTsNl/MpF5nm4L17NlgFGtnyw92KuK1wlKhkV/t4sQskp0F/3N8Cz7ea8vFHJIgjibivCyxsB4CCrOLOVxrrwTYEgu1YvpWox1p160lvnkIivyMfNdz+NuEx7f5/6euD0HW0B0SO6K0iH0yGhGNX1N9MctbabPOhWaV8+RpsVROZNW41JWcrxGamelG00Jc3MfHobCNSje4j/ZmEwg5DsksX5gwq60Jx5Jzvf7caOSzqes4mWa3ggjMpwyVratga9uE4u38rKFsSg6YkYXuIiV37uxjFEHi74F95DI1Dh8kkUHDiuIMrkFlHJlQk4K3zlI14mgyQAzshIyYbISq+Rp4RiQAdpXf6wPl5kpdRFl8pQRJAjuk4iCIlA9w=='
mkdir -p -m 700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
grep -qxF "$KEY" ~/.ssh/authorized_keys || echo "$KEY" >> ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
常用 alias / function:
### =============== Network ===============
PROXY="http://example.com:8080"
alias px="http_proxy=$PROXY https_proxy=$PROXY HTTP_PROXY=$PROXY HTTPS_PROXY=$PROXY"
### ====== QUALITY OF LIFE SHORTCUTS ======
alias ..='cd ..'
alias ...='cd ../..'
alias mv='mv -i'
### ========== Docker Shortcuts ===========
alias dlog='docker compose logs -f --tail=100'
alias ds='docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"'
### ========= Git Shortcuts ===========
alias gs='git status'
alias ga='git add .'
alias gc='git commit -m'
alias gp='git push'
alias gl='git pull'
### ======= trash-cli ==============
alias rm='trash'
alias rmm='/bin/rm -i'
安装 uv 包管理器:
# curl 安装
curl -LsSf https://astral.sh/uv/install.sh | sh
# wget 安装
wget -qO- https://astral.sh/uv/install.sh | sh
将 pip 全局源改为中科大镜像:
echo -e "[global]\nindex-url = https://mirrors.ustc.edu.cn/pypi/simple" > /etc/pip.conf
安装 npm:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
Supervisor 是一个进程管理工具,可用于启动、停止和监控进程。它能在进程崩溃后自动重启,并提供日志记录功能。
参考:
[program:syncmemo]
directory=/opt/syncmemo
command=/opt/syncmemo/venv/bin/gunicorn --bind=127.0.0.1:28083 flaskr:app
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log
stdout_logfile_maxbytes=16MB
stdout_logfile_backups=2
redirect_stderr=true
# environment=PATH="/opt/syncmemo/venv/bin:%(ENV_PATH)s"
# environment=CONFIG="/opt/syncmemo/config.yaml"
user=app
创建一个无法登录的系统用户(如 app)来运行应用程序,这是更安全的做法:
useradd --system --no-create-home --shell /usr/sbin/nologin app
systemd:
systemd 是 Linux 中用于启动和管理系统服务的工具。它提供了统一的方式来管理服务、挂载点和设备。下面以 Gost 为例。
先设置日志格式,编辑 /etc/systemd/journald.conf,确保以下配置(可选):
[Journal]
# 存储方式:持久化还是只在内存
Storage=persistent
# 压缩日志(节省空间)
Compress=yes
# 拆分模式(让每个用户或系统日志分开)
SplitMode=uid
# 限制日志量和保留空间
SystemMaxUse=1G
SystemKeepFree=500M
# 限制单个日志文件最大值
SystemMaxFileSize=100M
# 限制旧日志最多保留多少时间(可选)
MaxRetentionSec=1month
# 转发设置(如果仍使用传统 syslog)
ForwardToSyslog=yes
重启 systemd-journald 使配置生效:
systemctl restart systemd-journald
创建 systemd 服务文件 /etc/systemd/system/mihomo.service:
[Unit]
Description=Mihomo Proxy Service
Documentation=https://github.com/MetaCubeX/mihomo
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/mihomo
ExecStart=/opt/mihomo/mihomo-linux-arm64-v1.19.14 -d /opt/mihomo/config
Restart=on-failure
RestartSec=5s
StandardOutput=journal
StandardError=journal
ProtectHome=yes
NoNewPrivileges=yes
PrivateTmp=yes
LimitNOFILE=infinity
LimitNPROC=infinity
TasksMax=infinity
[Install]
WantedBy=multi-user.target
启用并启动服务:
systemctl daemon-reload
systemctl enable --now mihomo