一键DD
萌咖一键DD脚本地址:https://github.com/MoeClub/Note/blob/master/InstallNET.sh
leitbogioro的一键DD脚本地址:https://github.com/leitbogioro/Tools
这里分别列出两位大佬的脚本的基础用法示例
安装依赖组件
Ubuntu/Debian
1 2
| apt update apt install -y wget
|
RedHat/CentOS
1 2
| yum update yum install -y wget
|
Alpine
1 2 3
| apk update apk add bash wget sed -i 's/root:\/bin\/ash/root:\/bin\/bash/g' /etc/passwd
|
脚本示例
以下为默认镜像源
Debian
:http://deb.debian.org/debian
Ubuntu
:http://archive.ubuntu.com/ubuntu
CentOS
:http://mirror.centos.org/centos
Alpine
:http://dl-cdn.alpinelinux.org
Debian
默认镜像
1
| bash <(wget --no-check-certificate -qO- "https://raw.githubusercontent.com/leitbogioro/Tools/master/Linux_reinstall/InstallNET.sh") -debian 11 -pwd "自定义root密码" -port "自定义ssh端口" -timezone "Asia/Shanghai"
|
国内镜像
1
| bash <(wget --no-check-certificate -qO- "https://githubfast.com/https://raw.githubusercontent.com/MoeClub/Note/master/InstallNET.sh") -debian 11 --mirror "https://mirrors.bfsu.edu.cn/debian" -pwd "自定义密码" -port "自定义SSH端口" -timezone "Asia/Shanghai"
|
-debian 11
:Debian 11--mirror
:自定义镜像源地址(可不添加,使用默认镜像源)-pwd
-password
:自定义密码,Linux 默认密码为LeitboGi0ro
,Windows 默认密码为Teddysun.com
port
:自定义SSH端口,如果失败,回退至 22
-timezone
:自定义时区,默认为连接 SSH 所使用 IP 的地理位置
Ubuntu
默认镜像
1
| bash <(wget --no-check-certificate -qO- "https://raw.githubusercontent.com/MoeClub/Note/master/InstallNET.sh") -ubuntu 20.04 -v 64 -p "自定义root密码" -port "自定义ssh端口" -a
|
国内镜像
1
| bash <(wget --no-check-certificate -qO- "https://githubfast.com/https://raw.githubusercontent.com/MoeClub/Note/master/InstallNET.sh") -ubuntu 20.04 -v 64 --mirror "https://mirrors.bfsu.edu.cn/ubuntu" -pwd "自定义密码" -port "自定义SSH端口" -timezone "Asia/Shanghai"
|
-ubuntu 20.04
:Ubuntu 20.04--mirror
:自定义镜像源地址(可不添加,使用默认镜像源)-pwd
-password
:自定义密码,Linux 默认密码为LeitboGi0ro
,Windows 默认密码为Teddysun.com
port
:自定义SSH端口,如果失败,回退至 22
-timezone
:自定义时区,默认为连接 SSH 所使用 IP 的地理位置
安装依赖组件
Ubuntu/Debian
1 2
| apt update apt install -y xz-utils openssl gawk file
|
RedHat/CentOS
1 2
| yum update yum install -y xz openssl gawk file
|
脚本示例
以下为默认镜像源
Debian
:http://deb.debian.org/debian
Ubuntu
:http://archive.ubuntu.com/ubuntu
CentOS
:http://mirror.centos.org/centos
Debian
默认镜像
1
| bash <(wget --no-check-certificate -qO- "https://raw.githubusercontent.com/MoeClub/Note/master/InstallNET.sh") -d 11 -v 64 -p "自定义root密码" -port "自定义ssh端口" -a
|
国内镜像
1
| bash <(wget --no-check-certificate -qO- "https://githubfast.com/https://raw.githubusercontent.com/MoeClub/Note/master/InstallNET.sh") -d 11 -v 64 --mirror "https://mirrors.bfsu.edu.cn/debian" -p "自定义root密码" -port "自定义ssh端口" -a
|
-d 11
:Debian 11-v 64
:64位系统--mirror
:自定义镜像源地址(可不添加,使用默认镜像源)-a
:全自动安装
Ubuntu
默认镜像
1
| bash <(wget --no-check-certificate -qO- "https://raw.githubusercontent.com/MoeClub/Note/master/InstallNET.sh") -u 20.04 -v 64 -p "自定义root密码" -port "自定义ssh端口" -a
|
国内镜像
1
| bash <(wget --no-check-certificate -qO- "https://githubfast.com/https://raw.githubusercontent.com/MoeClub/Note/master/InstallNET.sh") -u 20.04 -v 64 --mirror "https://mirrors.bfsu.edu.cn/ubuntu" -p "自定义root密码" -port "自定义ssh端口" -a
|
-u 20.04
:Ubuntu 20.04-v 64
:64位系统--mirror
:自定义镜像源地址(可不添加,使用默认镜像源)-a
:全自动安装
启用密钥登录及禁用密码登录
修改密码
禁用 Challenge-Response认证
1
| sed -i 's/^#\?\(\s*ChallengeResponseAuthentication\s*\)yes/\1no/' /etc/ssh/sshd_config
|
禁用密码登录
1
| sed -i 's/^#\?\(\s*PasswordAuthentication\s*\)yes/\1no/' /etc/ssh/sshd_config
|
启用密钥登录
1
| sed -i 's/^#\?\(\s*PubkeyAuthentication\s*\)no/\1yes/' /etc/ssh/sshd_config
|
重启 SSH 服务
目前只支持生成加密类型为 ED25519
的密钥,默认密钥密码为空,随机 SSH 端口
1
| bash <(wget --no-check-certificate -qO- "https://unpkg.com/images-c@latest/shell/ModifyKey.sh")
|
示例:设置密钥密码为 123
,SSH 端口为 1564
1
| bash <(wget --no-check-certificate -qO- "https://unpkg.com/images-c@latest/shell/ModifyKey.sh") -pwd 123 -port 1564
|
-pwd
-password
:密钥密码,默认为空-p
-port
:SSH 服务端口,默认随机端口-c
-comment
:密钥备注,默认为空
更换国内镜像源
此处以北京外国语大学开源软件镜像站
示例
Centos
只提供 CentOS 7 与 8,架构仅为 x86_64
- 更改软件源配置文件
CentOS 7
1 2 3 4
| sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.bfsu.edu.cn|g' \ -i.bak \ /etc/yum.repos.d/CentOS-*.repo
|
CentOS 8
1 2 3 4
| sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirrors.bfsu.edu.cn/centos|g' \ -i.bak \ /etc/yum.repos.d/CentOS-*.repo
|
- 更新软件包缓存
Ubuntu
本镜像仅包含 32/64 位 x86 架构处理器的软件包,在 ARM(arm64, armhf)、PowerPC(ppc64el)、RISC-V(riscv64) 和 S390x 等架构的设备上(对应官方源为ports.ubuntu.com)请使用 ubuntu-ports 镜像。
- 更改软件源配置文件,修改
/etc/apt/sources.list
文件
22.04 LTS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| cat > /etc/apt/sources.list << EOF # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.bfsu.edu.cn/ubuntu/ jammy main restricted universe multiverse # deb-src https://mirrors.bfsu.edu.cn/ubuntu/ jammy main restricted universe multiverse deb https://mirrors.bfsu.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse # deb-src https://mirrors.bfsu.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse deb https://mirrors.bfsu.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse # deb-src https://mirrors.bfsu.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse # deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用 # deb https://mirrors.bfsu.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse # # deb-src https://mirrors.bfsu.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
EOF
|
20.04 LTS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| cat > /etc/apt/sources.list << EOF # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.bfsu.edu.cn/ubuntu/ focal main restricted universe multiverse # deb-src https://mirrors.bfsu.edu.cn/ubuntu/ focal main restricted universe multiverse deb https://mirrors.bfsu.edu.cn/ubuntu/ focal-updates main restricted universe multiverse # deb-src https://mirrors.bfsu.edu.cn/ubuntu/ focal-updates main restricted universe multiverse deb https://mirrors.bfsu.edu.cn/ubuntu/ focal-backports main restricted universe multiverse # deb-src https://mirrors.bfsu.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse # deb-src http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用 # deb https://mirrors.bfsu.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse # # deb-src https://mirrors.bfsu.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
EOF
|
- 更新软件包
1 2
| apt update apt upgrade -y
|
Debian
如果遇到无法拉取 https 源的情况,请先使用 http 源并安装:
1
| apt install apt-transport-https ca-certificatesss
|
- 更改软件源配置文件,修改
/etc/apt/sources.list
文件
Debian 12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| cat > /etc/apt/sources.list << EOF # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.bfsu.edu.cn/debian/ bookworm main contrib non-free non-free-firmware # deb-src https://mirrors.bfsu.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.bfsu.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware # deb-src https://mirrors.bfsu.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.bfsu.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware # deb-src https://mirrors.bfsu.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware # deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
EOF
|
Debian 11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| cat > /etc/apt/sources.list << EOF # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.bfsu.edu.cn/debian/ bullseye main contrib non-free # deb-src https://mirrors.bfsu.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.bfsu.edu.cn/debian/ bullseye-updates main contrib non-free # deb-src https://mirrors.bfsu.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.bfsu.edu.cn/debian/ bullseye-backports main contrib non-free # deb-src https://mirrors.bfsu.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://security.debian.org/debian-security bullseye-security main contrib non-free # deb-src https://security.debian.org/debian-security bullseye-security main contrib non-free
EOF
|
Debian 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| cat > /etc/apt/sources.list << EOF # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.bfsu.edu.cn/debian/ buster main contrib non-free # deb-src https://mirrors.bfsu.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.bfsu.edu.cn/debian/ buster-updates main contrib non-free # deb-src https://mirrors.bfsu.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirrors.bfsu.edu.cn/debian/ buster-backports main contrib non-free # deb-src https://mirrors.bfsu.edu.cn/debian/ buster-backports main contrib non-free
deb https://security.debian.org/debian-security buster/updates main contrib non-free # deb-src https://security.debian.org/debian-security buster/updates main contrib non-free
EOF
|
- 更新软件包
1 2
| apt update apt upgrade -y
|
Alpine
1
| sed -i 's/dl-cdn.alpinelinux.org/mirrors.bfsu.edu.cn/g' /etc/apk/repositories
|
pypi 镜像
升级 pip 到最新的版本 (>=10.0.0) 后进行配置:
1 2
| python -m pip install --upgrade pip pip config set global.index-url https://mirrors.bfsu.edu.cn/pypi/web/simple
|
如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:
1
| python -m pip install -i https://mirrors.bfsu.edu.cn/pypi/web/simple --upgrade pip
|
更换时区
- 检查当前时区
- 列出所有可用时区
1
| timedatectl list-timezones
|
- 更换为东八区
1
| timedatectl set-timezone Asia/Shanghai
|
更换为中文语言
查看当前语言环境
Ubuntu
- 安装中文语言包
1
| apt install language-pack-zh-hans
|
- 更改默认语言为中文,修改
/etc/default/locale
文件
1 2 3 4 5
| cat > /etc/default/locale << EOF LANG=zh_CN.UTF-8 LANGUAGE=zh_CN:zh:en_US:en
EOF
|
- 重启服务器
Debian
- 安装
locales
软件包
- 配置
locales
软件包,方向键移动到 zh_CN.UTF-8
,空格键确认选择,使用TAB
切换 ok 和 cancel,回车确认
第二个界面设置本地语言为 zh_CN.UTF-8
1
| dpkg-reconfigure locales
|
- 重启服务器
CentOS
- 安装中文语言包
1
| yum install -y kde-l10n-Chinese
|
- 更改默认语言为中文,修改
/etc/default/locale
文件
1
| echo 'LANG="zh_CN.UTF-8"' > /etc/locale.conf
|
SWAP虚拟内存 设置
- 关闭配置文件
/etc/fstab
中所有的交换空间
- 创建交换分区的文件,此处为4G
1
| dd if=/dev/zero of=/var/swapfile bs=1M count=4096
|
if
代表输入文件。如果不指定if
,默认就会从stdin中读取输入。of
代表输出文件。如果不指定of
,默认就会将stdout作为默认输出。bs
代表字节为单位的块大小。count
代表被复制的块数。/dev/zero
是一个字符设备,会不断返回0值字节(\0)。
单位 | 大小 | 代码 |
---|
字节 | 1B | c |
字节 | 2B | w |
块 | 512B | b |
千字节 | 1024B | k |
兆字节 | 1024KB | M |
吉字节 | 1024MB | G |
- 设置交换分区文件
- 启用交换分区
- 写入
/etc/fstab
1
| echo '/var/swapfile swap swap defaults 0 0' >> /etc/fstab
|
- 查看
swap
情况
安装 Oh My ZSH
1 2
| apt install zsh sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
安装Docker和Docker Compose
更多Docker命令请参考Docker常用命令
- 安装Docker
1 2 3 4 5 6
| export DOWNLOAD_URL="https://mirrors.ustc.edu.cn/docker-ce"
curl -fsSL https://get.docker.com/ | sh
wget -O- https://get.docker.com/ | sh
|
- 安装Docker Compose,此处默认下载最新版
1 2 3
| curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
|
如需指定版本,请使用此处命令并自行替换版本号 https://github.com/docker/compose/releases
1 2 3
| curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
|
通过APT安装稳定版 Nginx
点击查看系统版本代号,需要将链接末尾参数修改为对应系统版本代号,以下以 Ubuntu 22.04 LTS
和 Debian 11
为例
- 创建
nginx.list
文件并添加库
Ubuntu 22.04 LTS
1 2 3 4 5
| cat > /etc/apt/sources.list.d/nginx.list << EOF deb http://nginx.org/packages/ubuntu/ jammy nginx deb-src http://nginx.org/packages/ubuntu/ jammy nginx
EOF
|
Debian 11
1 2 3 4 5
| cat > /etc/apt/sources.list.d/nginx.list << EOF deb http://nginx.org/packages/debian/ bullseye nginx deb-src http://nginx.org/packages/debian/ bullseye nginx
EOF
|
如果在第3步出现不支持 'i386' 体系结构,跳过配置文件 'nginx/binary-i386/Packages' 的获取
相关字样,请使用以下命令修改 nginx.list
Ubuntu 22.04 LTS
1 2 3 4 5
| cat > /etc/apt/sources.list.d/nginx.list << EOF deb [arch=amd64] http://nginx.org/packages/ubuntu/ jammy nginx deb-src [arch=amd64] http://nginx.org/packages/ubuntu/ jammy nginx
EOF
|
Debian 11
1 2 3 4 5
| cat > /etc/apt/sources.list.d/nginx.list << EOF deb [arch=amd64] http://nginx.org/packages/debian/ bullseye nginx deb-src [arch=amd64] http://nginx.org/packages/debian/ bullseye nginx
EOF
|
- 导入并安装 Nginx 公钥
1
| wget -qO- http://nginx.org/keys/nginx_signing.key | apt-key add -
|
- 查看可安装 Nginx 版本及安装
1 2 3
| apt update apt-cache madison nginx apt install nginx
|
- 查找 Nginx 配置文件位置
journalctl 日志服务
- 设置 journal 日志文件最大为
1G
(默认为硬盘的 10%,上限 4G)
1
| journalctl --vacuum-size=1G
|
- 只保留最近
15天
的日志(默认为一个月)
1
| journalctl --vacuum-time=15d
|