环境配置快速复制

Anye
Anye
发布于 2023-11-25 / 502 阅读
2
0

环境配置快速复制

本人开发环境:ubuntu / debian

云服开机速配

一键重装

# 国外
curl -O https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh

# 国内
curl -O https://mirror.ghproxy.com/https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh

# 重装
bash reinstall.sh debian 12 --ci	# debian
bash reinstall.sh ubuntu 22.04 --ci	# ubuntu

国内机换源(USTC

# wget
mv /etc/apt/sources.list /etc/apt/sources.list.bak  # 备份源

wget "https://mirrors.ustc.edu.cn/repogen/conf/`awk -F= '$1=="ID" {print $2}' /etc/os-release`-https-4-`awk -F= '$1=="VERSION_CODENAME" {print $2}' /etc/os-release`" -O /etc/apt/sources.list  # 换源


# curl 
mv /etc/apt/sources.list /etc/apt/sources.list.bak  # 备份源  

curl -o /etc/apt/sources.list "https://mirrors.ustc.edu.cn/repogen/conf/`awk -F= '$1==\"ID\" {print $2}' /etc/os-release`-https-4-`awk -F= '$1==\"VERSION_CODENAME\" {print $2}' /etc/os-release`"  # 换源

语言配置

dpkg-reconfigure locales
export LANG=zh_CN.UTF-8

NPM的安装

  1. 下载并导入 Nodesource GPG 密钥

sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
  1. 创建 deb 存储库

NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

可选:NODE_MAJOR 可以根据您需要的版本进行更改。

NODE_MAJOR=16
NODE_MAJOR=18
NODE_MAJOR=20
NODE_MAJOR=21
  1. 运行更新并安装

sudo apt-get update
sudo apt-get install nodejs -y

NPM的卸载

apt-get purge nodejs &&\
rm -r /etc/apt/sources.list.d/nodesource.list &&\
rm -r /etc/apt/keyrings/nodesource.gpg

Git

git config --global user.name "Anyexyz"  #名称
git config --global user.email "anyexyz@foxmail.com"   #邮箱

Python 安装及换源

sudo apt-get install python3.10
sudo apt-get install python3-pip 
ll which python
sudo rm /usr/bin/python
sudo ln -s python3.10 /usr/bin/python
pip config set global.index-url https://mirror.baidu.com/pypi/simple # 百度源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple # 清华源
pip config unset global.index-url	# 清除源

Docker 国内一键安装(阿里源)

curl -fsSL https://get.docker.com | bash -s -- --mirror Aliyun

Docker 国内一键安装(USTC CE 源+自建镜像库)

bash <(curl -sSL https://linuxmirrors.cn/docker.sh) --source https://mirrors.ustc.edu.cn/docker-ce --source-registry https://doc.anye.in

Docker 镜像源速配

cat > /etc/docker/daemon.json << EOF
{
	"registry-mirrors": [
		"https://docker.mirrors.sjtug.sjtu.edu.cn"
	]
}
EOF

PVE 速配

PVE 换源

# Debian 源
cp /etc/apt/sources.list /etc/apt/sources.list.bak  # 备份源
sed -i 's|^deb http://ftp.debian.org|deb https://mirrors.ustc.edu.cn|g' /etc/apt/sources.list
sed -i 's|^deb http://security.debian.org|deb https://mirrors.ustc.edu.cn/debian-security|g' /etc/apt/sources.list

# PVE 源
mv /etc/apt/sources.list.d/pve-enterprise.list /etc/apt/sources.list.d/pve-enterprise.list.bak  # 备份源
echo "deb https://mirrors.ustc.edu.cn/proxmox/debian/pve bookworm pve-no-subscription" > /etc/apt/sources.list.d/pve-no-subscription.list

# Ceph 源
cp /etc/apt/sources.list.d/ceph.list /etc/apt/sources.list.d/ceph.list.bak  # 备份源
if [ -f /etc/apt/sources.list.d/ceph.list ]; then
  CEPH_CODENAME=`ceph -v | grep ceph | awk '{print $(NF-1)}'`
  source /etc/os-release
  echo "deb https://mirrors.ustc.edu.cn/proxmox/debian/ceph-$CEPH_CODENAME $VERSION_CODENAME no-subscription" > /etc/apt/sources.list.d/ceph.list
fi

# CT 源
cp /usr/share/perl5/PVE/APLInfo.pm /usr/share/perl5/PVE/APLInfo.pm.bak  # 备份源
sed -i.bak 's|http://download.proxmox.com|https://mirrors.ustc.edu.cn/proxmox|g' /usr/share/perl5/PVE/APLInfo.pm
systemctl restart pvedaemon

# PVE配置工具(大佬写的)
# [pve_source](https://bbs.x86pi.cn/thread?topicId=20)
wget -q -O /root/pve_source.tar.gz 'https://bbs.x86pi.cn/file/topic/2023-11-28/file/01ac88d7d2b840cb88c15cb5e19d4305b2.gz' && tar zxvf /root/pve_source.tar.gz && /root/./pve_source

PVE 配 ACME

数据中心 - ACME

上面添加账户,下面质询插件:

DNS-API: tencent

Tencent_SecretId=xxxxxxxxxxxxxxxx
Tencent_SecretKey=xxxxxxxxxxxxxxxx

PVE LXC 运行 docker

nano /etc/pve/lxc/容器id.conf 添加下面几行

lxc.apparmor.profile: unconfined
lxc.cgroup.devices.allow: a
lxc.cap.drop:

PVE LXC ubuntu修改ssh端口后开机自启动sshd失效

很抽象的一个问题

systemctl mask ssh.socket
systemctl mask sshd.socket
systemctl enable ssh

PVE LXC 安装 Tailscale 需要配置

nano /etc/pve/lxc/容器id.conf 添加下面几行

lxc.cgroup2.devices.allow: c 10:200 rwm
lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file

代理配置

Npm

npm config set proxy http://127.0.0.1:10000
npm config set https-proxy http://127.0.0.1:10000

npm config delete proxy
npm config delete https-proxy

Yarn

yarn config set proxy http://127.0.0.1:10000
yarn config set https-proxy http://127.0.0.1:10000

yarn config delete proxy
yarn config delete https-proxy

Git

git config --global http.proxy http://127.0.0.1:10000  # 配置全局代理
git config --global https.proxy http://127.0.0.1:10000 # 配置全局代理

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 

Snap

snap set system proxy.http="http://127.0.0.1:10000"
snap set system proxy.https="http://127.0.0.1:10000"

snap set system proxy.http=""
snap set system proxy.https=""

杂项

开机自启动 systemd 脚本的编写

  1. 安装 systemd

apt install systemd
  1. 创建 xxx.service 文件

使用文本编辑器(如 vim/nano)在 /etc/systemd/system 目录下创建一个 xxx.service 文件,用于配置 xxx 服务。

nano /etc/systemd/system/xxx.service
  1. 写入内容

[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
  1. 使用 systemd 命令管理 xxx 服务

# 启动xxx
systemctl start xxx
# 停止xxx
systemctl stop xxx
# 重启xxx
systemctl restart xxx
# 查看xxx状态
systemctl status xxx
# 开机自启动
systemctl enable xxx
# 取消开机自启动
systemctl disable xxx

windows11启停打印服务

net stop spooler
net start spooler

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


评论