本人开发环境:
服务器环境
重装系统
# 境外
curl -O https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh || wget -O reinstall.sh $_
# 境内
curl -O https://git.anye.in/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh || wget -O reinstall.sh $_
# 重装,按需修改端口和密码
bash reinstall.sh ubuntu 22.04 --ssh-port ${PORT} --password ${PASSWORD}
# 重启
reboot
换源(境内)
# --use-intranet-source true:优先使用内网软件源
# --backup true:备份原有软件源
# --upgrade-software true:更新软件包
# --clean-cache true:清理下载缓存
# --ignore-backup-tips:不覆盖备份
# 使用 linuxmirrors.cn 提供的主脚本
bash <(curl -sSL https://linuxmirrors.cn/main.sh) \
--use-intranet-source true \
--backup true \
--upgrade-software true \
--clean-cache true \
--ignore-backup-tips
# 使用 gitee 镜像脚本
bash <(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh) \
--use-intranet-source true \
--backup true \
--upgrade-software true \
--clean-cache true \
--ignore-backup-tips
将系统时区调整为中国标准时间(CST, UTC+8)
timedatectl set-timezone Asia/Shanghai
清理 Bash 记录
cat /dev/null > ~/.bash_history && history -c
一些软件
Git
全局配置
git config --global user.name "Anyexyz" #名称
git config --global user.email "anyexyz@foxmail.com" #邮箱
配置代理
# 配置全局代理
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy http://127.0.0.1:1080
# 配置 Github 代理
git config --global http.https://github.com/.proxy http://127.0.0.1:10000 # 配置 Github 代理
git config --global https.https://github.com/.proxy http://127.0.0.1:10000 # 配置 Github 代理
# 删除代理配置
git config --global --unset http.proxy
git config --global --unset https.proxy
Docker
安装
官方脚本安装
# 境外推荐
curl -fsSL https://get.docker.com | bash -s docker
# 境内推荐
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun # 阿里源
curl -fsSL https://get.docker.com | bash -s docker --mirror AzureChinaCloud # 微软云中国
LinuxMirrors 脚本安装
# --source:指定 Docker CE 源地址
# --source-registry:指定镜像仓库地址
# 使用 linuxmirrors.cn 提供的主脚本
bash <(curl -sSL https://linuxmirrors.cn/docker.sh) \
--source https://mirrors.tuna.tsinghua.edu.cn/docker-ce \
--source-registry https://docker.anye.in
# 使用 gitee 镜像脚本
bash <(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/DockerInstallation.sh) \
--source https://mirrors.tuna.tsinghua.edu.cn/docker-ce \
--source-registry https://docker.anye.in
配置镜像源
镜像源可用监控:
# 创建或修改 /etc/docker/daemon.json 配置文件
tee /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://docker.anye.in"
]
}
EOF
# 重载systemd管理守护进程配置文件
sudo systemctl daemon-reload
# 重启 Docker 服务
sudo systemctl restart docker
卸载
# 卸载 Docker Engine、CLI、containerd 和 Docker Compose 软件包
apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
# 删除所有镜像、容器和卷
rm -rf /var/lib/docker
rm -rf /var/lib/containerd
# 删除源列表和密钥环
rm /etc/apt/sources.list.d/docker.list
rm /etc/apt/keyrings/docker.asc
# 删除相关配置
rm -f /etc/docker/daemon.json
rm -f ~/.docker/config.json
Python
Miniconda 管理
# 安装 miniconda
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh && bash miniconda.sh -b
# 初始化
/root/miniconda3/bin/conda init
# 创建名称为 venv_name,版本号为 3.12 的 Python 环境
conda create -n venv_name python=3.12
# 激活
conda activate venv_name
# 换清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 卸载 miniconda
rm /root/miniconda3/ -rf
# 删除 ~/.bashrc 中 miniconda 的配置
UV 管理
# 安装 uv
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
# 安装 python
uv python install 3.9 3.10 3.11 3.12
# 配置清华源
cat >> ~/.config/uv/uv.toml << EOF
[[index]]
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
default = true
EOF
# 创建虚拟环境
uv venv .venv
# 使用虚拟环境
source .venv/bin/activate
# 卸载 uv
uv cache clean
rm -r "$(uv python dir)"
rm -r "$(uv tool dir)"
rm ~/.local/bin/uv ~/.local/bin/uvx
Node.js
安装
采用 NVM 安装选定版本的 Node.js
配置淘宝镜像源
# NPM
npm config set registry https://registry.npmmirror.com/
# PNPM
pnpm config set registry https://registry.npmmirror.com/
# YARN
yarn config set registry https://registry.npmmirror.com/
## 还原
npm config set registry https://registry.npmjs.org/
pnpm config set registry https://registry.npmjs.org/
yarn config set registry https://registry.yarnpkg.com/
配置代理
# NPM
npm config set proxy http://127.0.0.1:1080
npm config set https-proxy http://127.0.0.1:1080
npm config delete proxy
npm config delete https-proxy
# PNPM
pnpm config set proxy http://127.0.0.1:1080
pnpm config set https-proxy https://127.0.0.1:1080
pnpm config delete proxy
pnpm config delete https-proxy
# YARN
yarn config set proxy http://127.0.0.1:1080
yarn config set https-proxy http://127.0.0.1:1080
yarn config delete proxy
yarn config delete https-proxy
卸载
# 禁用 nvm 管理的 Node.js 版本
nvm deactivate
# 列出 Node.js 版本
nvm list
# 按需卸载(示例)
nvm uninsatll 22
# 卸载 nvm
nvm_dir="${NVM_DIR:-~/.nvm}"
nvm unload
rm -rf "$nvm_dir"
编辑 ~/.bashrc
(或其他 shell 资源配置)并删除以下行:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[[ -r $NVM_DIR/bash_completion ]] && \. $NVM_DIR/bash_completion
杂项
开机自启动 systemd 脚本的编写
安装 systemd
apt install systemd
创建 xxx.service 文件
使用文本编辑器(如 vim/nano)在 /etc/systemd/system
目录下创建一个 xxx.service
文件,用于配置 xxx 服务。
nano /etc/systemd/system/xxx.service
写入内容
[Unit]
# 服务名称,可自定义
Description = xxx server
After = network.target syslog.target
Wants = network.target
[Service]
Type = simple
WorkingDirectory = /path/to
ExecStart = /path/to/xxx
[Install]
WantedBy = multi-user.target
使用 systemd 命令管理 xxx 服务
# 启动xxx
systemctl start xxx
# 停止xxx
systemctl stop xxx
# 重启xxx
systemctl restart xxx
# 查看xxx状态
systemctl status xxx
# 开机自启动
systemctl enable xxx
# 取消开机自启动
systemctl disable xxx
windows 下 vscode python
输出窗口中文乱码
环境变量
- 新建环境变量
- PYTHONIOENCODING
- UTF8
Nginx 反代去除路径的骚操作
location ^~ /xxx {
rewrite ^/xxx(?:/(.*))?$ /$1 break;
proxy_pass http://127.0.0.1:18080;
}
生成 SSH 密钥
ssh-keygen -t ed25519 -C "anyexyz@foxmail.com"
windows 开机自启动文件夹
win+R 运行输入 shell:startup
windows 关闭保留的存储
DISM.exe /Online /Set-ReservedStorageState /State:Disabled
windows11 ltsc 恢复应用商店
wsreset -i
Windows11 ltsc 安装 winget
访问
Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe