docs: 补充多篇技术博客内容
1. 为Linux服务安装文档新增RHEL/CentOS官方仓库安装Nginx步骤 2. 新增Windows Server开发驱动器完整教程 3. 重构MySQL文档:将原有安装内容拆分归类,新增MySQL配置模块、Windows绿色版安装细节、Linux客户端安装卸载完整流程
This commit is contained in:
parent
7e38841220
commit
bc0ba78c8b
@ -1697,6 +1697,75 @@ read only = yes
|
||||
|
||||
## Nginx 安装
|
||||
|
||||
### RHEL/CentOS 安装(官方仓库)
|
||||
|
||||
适用于 Red Hat Enterprise Linux 及其衍生版本(CentOS、Oracle Linux、Rocky Linux、AlmaLinux)。
|
||||
|
||||
#### 1. 安装前置依赖
|
||||
|
||||
```shell
|
||||
sudo dnf install dnf-utils
|
||||
```
|
||||
|
||||
#### 2. 创建仓库文件
|
||||
|
||||
创建 `/etc/yum.repos.d/nginx.repo`:
|
||||
|
||||
```shell
|
||||
sudo vim /etc/yum.repos.d/nginx.repo
|
||||
```
|
||||
|
||||
写入以下内容:
|
||||
|
||||
```ini
|
||||
[nginx-stable]
|
||||
name=nginx stable repo
|
||||
baseurl=https://nginx.org/packages/centos/$releasever/$basearch/
|
||||
gpgcheck=1
|
||||
enabled=1
|
||||
gpgkey=https://nginx.org/keys/nginx_signing.key
|
||||
module_hotfixes=true
|
||||
|
||||
[nginx-mainline]
|
||||
name=nginx mainline repo
|
||||
baseurl=https://nginx.org/packages/mainline/centos/$releasever/$basearch/
|
||||
gpgcheck=1
|
||||
enabled=0
|
||||
gpgkey=https://nginx.org/keys/nginx_signing.key
|
||||
module_hotfixes=true
|
||||
```
|
||||
|
||||
> 默认使用 stable 稳定版仓库。如需使用 mainline 主线版,执行:
|
||||
> ```shell
|
||||
> sudo dnf config-manager --enable nginx-mainline
|
||||
> ```
|
||||
|
||||
#### 3. 安装 Nginx
|
||||
|
||||
```shell
|
||||
sudo dnf install nginx
|
||||
```
|
||||
|
||||
安装时会提示接受 GPG 密钥,确认指纹为 `573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62` 后接受。
|
||||
|
||||
#### 4. 启动并验证
|
||||
|
||||
```shell
|
||||
sudo systemctl start nginx
|
||||
sudo systemctl enable nginx
|
||||
sudo systemctl status nginx
|
||||
```
|
||||
|
||||
#### 5. 防火墙放行
|
||||
|
||||
```shell
|
||||
sudo firewall-cmd --permanent --add-service=http
|
||||
sudo firewall-cmd --permanent --add-service=https
|
||||
sudo firewall-cmd --reload
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 源码编译安装
|
||||
|
||||
```shell
|
||||
@ -1707,7 +1776,7 @@ make
|
||||
make install
|
||||
```
|
||||
|
||||
### AlmaLinux dnf 安装
|
||||
### AlmaLinux源 dnf 安装
|
||||
|
||||
```shell
|
||||
# 确保软件是最新的
|
||||
|
||||
@ -7,6 +7,235 @@ tags: [MySQL, 数据库, SQL, 备份]
|
||||
categories: [数据库, MySQL]
|
||||
---
|
||||
|
||||
# MySQL 配置
|
||||
|
||||
`my.ini` 或 `my.cnf` 配置
|
||||
|
||||
```ini
|
||||
```
|
||||
|
||||
|
||||
|
||||
# Windows 下安装 绿色版
|
||||
|
||||
先下载[MySQL :: Download MySQL Community Server](https://dev.mysql.com/downloads/mysql/)
|
||||
|
||||

|
||||
|
||||
1. 解压下载好的压缩包
|
||||

|
||||
|
||||
2. 解压后得到
|
||||

|
||||
|
||||
3. 新建一个 `my.ini`文件
|
||||

|
||||
|
||||
4. 解压后的mysql根目录下没有my.ini文件,自己去网上找一份就可或者使用我在后面给出的代码。.ini文件会在初始化mysql中用到
|
||||
```ini
|
||||
# For advice on how to change settings please see
|
||||
# http=//dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
|
||||
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
|
||||
# *** default location during install, and will be replaced if you
|
||||
# *** upgrade to a newer version of MySQL.
|
||||
|
||||
[client]
|
||||
port = 3306
|
||||
default-character-set = utf8
|
||||
|
||||
[mysqld]
|
||||
|
||||
# Remove leading # and set to the amount of RAM for the most important data
|
||||
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
|
||||
# innodb_buffer_pool_size = 128M
|
||||
|
||||
# Remove leading # to turn on a very important data integrity option= logging
|
||||
# changes to the binary log between backups.
|
||||
# log_bin
|
||||
port = 3306
|
||||
# These are commonly set, remove the # and set as required.
|
||||
basedir="D:\app\mysql-5.7.43-winx64"
|
||||
datadir="D:\app\mysql-5.7.43-winx64\data"
|
||||
# server_id = .....
|
||||
character_set_server = utf8
|
||||
|
||||
# Remove leading # to set options mainly useful for reporting servers.
|
||||
# The server defaults are faster for transactions and fast SELECTs.
|
||||
# Adjust sizes as needed, experiment to find the optimal values.
|
||||
# join_buffer_size = 128M
|
||||
# sort_buffer_size = 2M
|
||||
# read_rnd_buffer_size = 2M
|
||||
|
||||
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
|
||||
|
||||
```
|
||||
|
||||
5. 修改ini配置文件中的安装目录和数据存放目录修改为mysql文件的路径
|
||||
|
||||
6. \#设置mysql的安装目录
|
||||
basedir=D:\app\mysql-5.7.43-winx64
|
||||
\#设置mysql数据库的数据的存放目录
|
||||
datadir=D:\app\mysql-5.7.43-winx64\data
|
||||
|
||||
7. 打开cmd,初始化数据库
|
||||
```powershell
|
||||
mysqld --initialize
|
||||
```
|
||||
|
||||
8. 初始化完成后,mysqld根目录下会自动新增data文件夹
|
||||

|
||||
|
||||
9. 打开data文件夹,找到.err后缀文本打开
|
||||

|
||||
|
||||
10. 找到文件password位置,红色框中为数据库初始化密码,后续修改初始化密码使用
|
||||
```err
|
||||
2023-10-07T04:37:02.330654Z 1 [Note] A temporary password is generated for root@localhost: (iw?Mw:Vs7n&
|
||||
```
|
||||
|
||||
11. 安装数据库
|
||||
```powershell
|
||||
mysqld --install <服务名>
|
||||
```
|
||||
|
||||
12. 启动服务
|
||||
```powershell
|
||||
net start mysql
|
||||
```
|
||||
|
||||
13. 关闭服务
|
||||
```powershell
|
||||
net stop mysql
|
||||
```
|
||||
|
||||
14. 修改初始密码
|
||||
|
||||
- 登录
|
||||
```powershell
|
||||
mysql -uroot -p'你的初始密码,步骤4中红框里的字符'
|
||||
```
|
||||
|
||||
- 修改密码为 123456
|
||||
```mysql
|
||||
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
|
||||
```
|
||||
|
||||
15. 服务卸载
|
||||
```powershell
|
||||
net stop mysql
|
||||
mysqld --remove
|
||||
```
|
||||
|
||||
# Linux 安装MySQL
|
||||
|
||||
## 安装
|
||||
|
||||
1. 在浏览器下载Linux系统的MySQL客户端安装包。建议您下载的MySQL客户端版本高于已创建的GaussDB(for MySQL)实例中数据库版本。
|
||||
在下载页面找到对应版本[链接](https://dev.mysql.com/downloads/file/?id=496982),以mysql-community-client-8.0.21-1.el6.x86_64为例,打开页面后,即可下载安装包。
|
||||

|
||||
|
||||
2. 将安装包上传到ECS。
|
||||
|
||||
3. 执行以下命令安装MySQL客户端。
|
||||
rpm -ivh mysql-community-client-8.0.21-1.el6.x86_64.rpm
|
||||
|
||||
> - 如果安装过程中报conflicts,可增加replacefiles参数重新安装,如下:
|
||||
>
|
||||
> rpm -ivh --replacefiles mysql-community-client-8.0.21-1.el6.x86_64.rpm
|
||||
>
|
||||
> - 如果安装过程中提示需要安装依赖包,可增加nodeps参数重新安装,如下:
|
||||
>
|
||||
> rpm -ivh --nodeps mysql-community-client-8.0.21-1.el6.x86_64.rpm
|
||||
|
||||
## 连接
|
||||
|
||||
1. **mysql -h** <*host*> **-P** *<port>* **-u** <*userName*> **-p**
|
||||
示例:
|
||||
|
||||
mysql -h 192.168.0.16 -P 3306 -u root -p
|
||||
|
||||
参数说明
|
||||
|
||||
| 参数 | 说明 |
|
||||
| ------------ | ---------------------------- |
|
||||
| <*host*> | 获取的读写内网地址。 |
|
||||
| *<port>* | 获取的数据库端口,默认3306。 |
|
||||
| <*userName*> | 管理员帐号root。 |
|
||||
|
||||
2. 出现如下提示时,输入数据库帐号对应的密码。
|
||||
```mysql
|
||||
Enter password:
|
||||
```
|
||||
|
||||
3. 报错mysql: error while loading shared libraries: libssl.so.10: cannot open shared object file: No such file or directory
|
||||
|
||||
下载rpm包:
|
||||
https://mirrors.aliyun.com/centos/8/AppStream/x86_64/os/Packages/compat-openssl10-1.0.2o-3.el8.x86_64.rpm
|
||||
安装rpm包:
|
||||
|
||||
```shell
|
||||
rpm -i compat-openssl10-1.0.2o-3.el8.x86_64.rpm
|
||||
错误:依赖检测失败:
|
||||
make 被 compat-openssl10-1:1.0.2o-3.el8.x86_64 需要
|
||||
rpm -i compat-openssl10-1.0.2o-3.el8.x86_64.rpm --nodeps --force
|
||||
|
||||
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
|
||||
cp /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5
|
||||
|
||||
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
|
||||
cp /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5
|
||||
```
|
||||
|
||||
|
||||
|
||||
# Linux 卸载MySQL
|
||||
|
||||
## 二进制方式
|
||||
|
||||
```shell
|
||||
rpm -qa | grep -i mysql
|
||||
|
||||
# 如下所示
|
||||
mysql-community-release-el7-5.noarch
|
||||
mysql-community-libs-5.6.51-2.el7.x86_64
|
||||
mysql-community-client-5.6.51-2.el7.x86_64
|
||||
mysql-community-server-5.6.51-2.el7.x86_64
|
||||
mysql-community-common-5.6.51-2.el7.x86_64
|
||||
|
||||
systemctl stop mysqld
|
||||
|
||||
rpm -ev mysql-community-release-el7-5.noarch
|
||||
rpm -ev mysql-community-libs-5.6.51-2.el7.x86_64
|
||||
rpm -ev mysql-community-client-5.6.51-2.el7.x86_64
|
||||
rpm -ev mysql-community-server-5.6.51-2.el7.x86_64
|
||||
rpm -ev mysql-community-common-5.6.51-2.el7.x86_64
|
||||
|
||||
find / -name mysql
|
||||
|
||||
# 如下所示
|
||||
/var/lib/mysql
|
||||
/var/lib/mysql/mysql
|
||||
/usr/local/mysql
|
||||
/usr/lib64/mysql
|
||||
/usr/share/mysql
|
||||
/usr/bin/mysql
|
||||
/etc/logrotate.d/mysql
|
||||
/etc/selinux/targeted/active/modules/100/mysql
|
||||
|
||||
rm -rf /var/lib/mysql
|
||||
rm -rf /var/lib/mysql/mysql
|
||||
rm -rf /usr/local/mysql
|
||||
rm -rf /usr/lib64/mysql
|
||||
rm -rf /usr/share/mysql
|
||||
rm -rf /usr/bin/mysql
|
||||
rm -rf /etc/logrotate.d/mysql
|
||||
rm -rf /etc/selinux/targeted/active/modules/100/mysql
|
||||
|
||||
rm -rf /etc/my.cnf
|
||||
|
||||
rpm -qa | grep -i mysql
|
||||
```
|
||||
|
||||
|
||||
|
||||
# mysqldump备份数据库
|
||||
@ -248,226 +477,6 @@ setenforce 0
|
||||
|
||||
永久关闭SELinux
|
||||
|
||||
# Windows 下安装 绿色版
|
||||
|
||||
先下载[MySQL :: Download MySQL Community Server](https://dev.mysql.com/downloads/mysql/)
|
||||
|
||||

|
||||
|
||||
1. 解压下载好的压缩包
|
||||

|
||||
|
||||
2. 解压后得到
|
||||

|
||||
|
||||
3. 新建一个 `my.ini`文件
|
||||

|
||||
|
||||
4. 解压后的mysql根目录下没有my.ini文件,自己去网上找一份就可或者使用我在后面给出的代码。.ini文件会在初始化mysql中用到
|
||||
```ini
|
||||
# For advice on how to change settings please see
|
||||
# http=//dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
|
||||
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
|
||||
# *** default location during install, and will be replaced if you
|
||||
# *** upgrade to a newer version of MySQL.
|
||||
|
||||
[client]
|
||||
port = 3306
|
||||
default-character-set = utf8
|
||||
|
||||
[mysqld]
|
||||
|
||||
# Remove leading # and set to the amount of RAM for the most important data
|
||||
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
|
||||
# innodb_buffer_pool_size = 128M
|
||||
|
||||
# Remove leading # to turn on a very important data integrity option= logging
|
||||
# changes to the binary log between backups.
|
||||
# log_bin
|
||||
port = 3306
|
||||
# These are commonly set, remove the # and set as required.
|
||||
basedir="D:\app\mysql-5.7.43-winx64"
|
||||
datadir="D:\app\mysql-5.7.43-winx64\data"
|
||||
# server_id = .....
|
||||
character_set_server = utf8
|
||||
|
||||
# Remove leading # to set options mainly useful for reporting servers.
|
||||
# The server defaults are faster for transactions and fast SELECTs.
|
||||
# Adjust sizes as needed, experiment to find the optimal values.
|
||||
# join_buffer_size = 128M
|
||||
# sort_buffer_size = 2M
|
||||
# read_rnd_buffer_size = 2M
|
||||
|
||||
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
|
||||
|
||||
```
|
||||
|
||||
5. 修改ini配置文件中的安装目录和数据存放目录修改为mysql文件的路径
|
||||
|
||||
6. \#设置mysql的安装目录
|
||||
basedir=D:\app\mysql-5.7.43-winx64
|
||||
\#设置mysql数据库的数据的存放目录
|
||||
datadir=D:\app\mysql-5.7.43-winx64\data
|
||||
|
||||
7. 打开cmd,初始化数据库
|
||||
```powershell
|
||||
mysqld --initialize
|
||||
```
|
||||
|
||||
8. 初始化完成后,mysqld根目录下会自动新增data文件夹
|
||||

|
||||
|
||||
9. 打开data文件夹,找到.err后缀文本打开
|
||||

|
||||
|
||||
10. 找到文件password位置,红色框中为数据库初始化密码,后续修改初始化密码使用
|
||||
```err
|
||||
2023-10-07T04:37:02.330654Z 1 [Note] A temporary password is generated for root@localhost: (iw?Mw:Vs7n&
|
||||
```
|
||||
|
||||
11. 安装数据库
|
||||
```powershell
|
||||
mysqld --install <服务名>
|
||||
```
|
||||
|
||||
12. 启动服务
|
||||
```powershell
|
||||
net start mysql
|
||||
```
|
||||
|
||||
13. 关闭服务
|
||||
```powershell
|
||||
net stop mysql
|
||||
```
|
||||
|
||||
14. 修改初始密码
|
||||
|
||||
- 登录
|
||||
```powershell
|
||||
mysql -uroot -p'你的初始密码,步骤4中红框里的字符'
|
||||
```
|
||||
|
||||
- 修改密码为 123456
|
||||
```mysql
|
||||
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
|
||||
```
|
||||
|
||||
15. 服务卸载
|
||||
```powershell
|
||||
net stop mysql
|
||||
mysqld --remove
|
||||
```
|
||||
|
||||
# Linux 安装MySQL
|
||||
|
||||
## 安装
|
||||
|
||||
1. 在浏览器下载Linux系统的MySQL客户端安装包。建议您下载的MySQL客户端版本高于已创建的GaussDB(for MySQL)实例中数据库版本。
|
||||
在下载页面找到对应版本[链接](https://dev.mysql.com/downloads/file/?id=496982),以mysql-community-client-8.0.21-1.el6.x86_64为例,打开页面后,即可下载安装包。
|
||||

|
||||
|
||||
2. 将安装包上传到ECS。
|
||||
|
||||
3. 执行以下命令安装MySQL客户端。
|
||||
rpm -ivh mysql-community-client-8.0.21-1.el6.x86_64.rpm
|
||||
|
||||
> - 如果安装过程中报conflicts,可增加replacefiles参数重新安装,如下:
|
||||
>
|
||||
> rpm -ivh --replacefiles mysql-community-client-8.0.21-1.el6.x86_64.rpm
|
||||
>
|
||||
> - 如果安装过程中提示需要安装依赖包,可增加nodeps参数重新安装,如下:
|
||||
>
|
||||
> rpm -ivh --nodeps mysql-community-client-8.0.21-1.el6.x86_64.rpm
|
||||
|
||||
## 连接
|
||||
|
||||
1. **mysql -h** <*host*> **-P** *<port>* **-u** <*userName*> **-p**
|
||||
示例:
|
||||
|
||||
mysql -h 192.168.0.16 -P 3306 -u root -p
|
||||
|
||||
参数说明
|
||||
|
||||
| 参数 | 说明 |
|
||||
| ------------ | ---------------------------- |
|
||||
| <*host*> | 获取的读写内网地址。 |
|
||||
| *<port>* | 获取的数据库端口,默认3306。 |
|
||||
| <*userName*> | 管理员帐号root。 |
|
||||
|
||||
2. 出现如下提示时,输入数据库帐号对应的密码。
|
||||
```mysql
|
||||
Enter password:
|
||||
```
|
||||
|
||||
3. 报错mysql: error while loading shared libraries: libssl.so.10: cannot open shared object file: No such file or directory
|
||||
|
||||
下载rpm包:
|
||||
https://mirrors.aliyun.com/centos/8/AppStream/x86_64/os/Packages/compat-openssl10-1.0.2o-3.el8.x86_64.rpm
|
||||
安装rpm包:
|
||||
|
||||
```shell
|
||||
rpm -i compat-openssl10-1.0.2o-3.el8.x86_64.rpm
|
||||
错误:依赖检测失败:
|
||||
make 被 compat-openssl10-1:1.0.2o-3.el8.x86_64 需要
|
||||
rpm -i compat-openssl10-1.0.2o-3.el8.x86_64.rpm --nodeps --force
|
||||
|
||||
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
|
||||
cp /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5
|
||||
|
||||
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
|
||||
cp /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5
|
||||
```
|
||||
|
||||
|
||||
|
||||
# Linux 卸载MySQL
|
||||
|
||||
## 二进制方式
|
||||
|
||||
```shell
|
||||
rpm -qa | grep -i mysql
|
||||
|
||||
# 如下所示
|
||||
mysql-community-release-el7-5.noarch
|
||||
mysql-community-libs-5.6.51-2.el7.x86_64
|
||||
mysql-community-client-5.6.51-2.el7.x86_64
|
||||
mysql-community-server-5.6.51-2.el7.x86_64
|
||||
mysql-community-common-5.6.51-2.el7.x86_64
|
||||
|
||||
systemctl stop mysqld
|
||||
|
||||
rpm -ev mysql-community-release-el7-5.noarch
|
||||
rpm -ev mysql-community-libs-5.6.51-2.el7.x86_64
|
||||
rpm -ev mysql-community-client-5.6.51-2.el7.x86_64
|
||||
rpm -ev mysql-community-server-5.6.51-2.el7.x86_64
|
||||
rpm -ev mysql-community-common-5.6.51-2.el7.x86_64
|
||||
|
||||
find / -name mysql
|
||||
|
||||
# 如下所示
|
||||
/var/lib/mysql
|
||||
/var/lib/mysql/mysql
|
||||
/usr/local/mysql
|
||||
/usr/lib64/mysql
|
||||
/usr/share/mysql
|
||||
/usr/bin/mysql
|
||||
/etc/logrotate.d/mysql
|
||||
/etc/selinux/targeted/active/modules/100/mysql
|
||||
|
||||
rm -rf /var/lib/mysql
|
||||
rm -rf /var/lib/mysql/mysql
|
||||
rm -rf /usr/local/mysql
|
||||
rm -rf /usr/lib64/mysql
|
||||
rm -rf /usr/share/mysql
|
||||
rm -rf /usr/bin/mysql
|
||||
rm -rf /etc/logrotate.d/mysql
|
||||
rm -rf /etc/selinux/targeted/active/modules/100/mysql
|
||||
|
||||
rm -rf /etc/my.cnf
|
||||
|
||||
rpm -qa | grep -i mysql
|
||||
```
|
||||
|
||||
|
||||
|
||||
# MySQL 客户端
|
||||
|
||||
@ -402,3 +402,308 @@ D:\tools\nssm-2.24\win64\nssm.exe install "Nginx 1.29.8"
|
||||
| 进程树清理 | 默认处理子进程 | 需显式指定 `--kill-process-tree` |
|
||||
| 最小系统 | Windows Server 2008 R2+ | Windows 10 / Server 2012 R2+ |
|
||||
| 适用场景 | 运维人员手动配置 | 自动化部署脚本 |
|
||||
|
||||
# 开发驱动器 (Dev Drive)
|
||||
|
||||
开发驱动器是 Windows 11 提供的一种新存储卷形式,基于 ReFS (Resilient File System) 技术构建,针对开发工作负载进行了文件系统优化,可显著提升编译、包恢复等开发操作的性能。
|
||||
|
||||
> **适用场景:** 源代码仓库、包缓存(npm/NuGet/pip/Cargo 等)、构建输出和中间文件。
|
||||
|
||||
## 先决条件
|
||||
|
||||
- Windows 11 版本 10.0.22621.2338 或更高版本
|
||||
- 建议 16 GB 内存(至少 8 GB,ReFS 比 NTFS 占用更多内存)
|
||||
- 最小 50 GB 可用磁盘空间
|
||||
- 本地管理员权限
|
||||
|
||||
> **注意:** 不能将 C: 驱动器指定为开发驱动器。开发人员工具(如 Visual Studio、.NET SDK)应保留在 C: 盘。
|
||||
|
||||
## 创建方式
|
||||
|
||||
### 方式一:通过 Windows 设置
|
||||
|
||||
1. 打开 **设置 > 系统 > 存储 > 高级存储设置 > 磁盘和卷**
|
||||
2. 选择 **创建开发人员驱动器**
|
||||
3. 选择创建方式:
|
||||
- **创建新的 VHD**:在虚拟硬盘上创建(推荐,灵活易管理)
|
||||
- **调整现有卷的大小**:从现有分区划分空间
|
||||
- **使用未分配空间**:利用磁盘上已有的未分配空间
|
||||
|
||||
### 方式二:通过命令行
|
||||
|
||||
以管理员身份运行:
|
||||
|
||||
```powershell
|
||||
# 使用 Format 命令
|
||||
Format D: /DevDrv /Q
|
||||
|
||||
# 或使用 PowerShell
|
||||
Format-Volume -DriveLetter D -DevDrive
|
||||
```
|
||||
|
||||
> 将 `D:` 替换为实际驱动器号。
|
||||
|
||||
## 磁盘分区 vs VHD
|
||||
|
||||
| 对比项 | 磁盘分区 | VHD(推荐) |
|
||||
| ---------- | ---------------------- | ------------------------------- |
|
||||
| 性能 | 更快(直接访问物理磁盘)| 略有开销(虚拟磁盘层) |
|
||||
| 灵活性 | 调整大小复杂且风险大 | 支持动态扩展,易于管理 |
|
||||
| 可移植性 | 与物理磁盘绑定 | VHD 文件可复制、移动、备份 |
|
||||
| 适用场景 | 追求极致性能 | 需要灵活管理或多设备使用 |
|
||||
|
||||
## 信任与安全性
|
||||
|
||||
开发驱动器默认使用 Microsoft Defender **性能模式**,在安全性和性能之间取得平衡。
|
||||
|
||||
### 设置为受信任驱动器
|
||||
|
||||
受信任的驱动器启用性能模式(推荐),不受信任的驱动器使用实时保护模式(性能较低)。
|
||||
|
||||
```powershell
|
||||
# 以管理员身份运行 PowerShell
|
||||
|
||||
# 设置为受信任
|
||||
fsutil devdrv trust D:
|
||||
|
||||
# 查询信任状态
|
||||
fsutil devdrv query D:
|
||||
```
|
||||
|
||||
> **重要:** 将开发驱动器移动到其他计算机后,需要重新设置信任。
|
||||
|
||||
### 防病毒筛选器配置
|
||||
|
||||
```powershell
|
||||
# 允许特定筛选器(适用于所有开发驱动器)
|
||||
fsutil devdrv setfiltersallowed "Filter-01, Filter-02"
|
||||
|
||||
# 禁用防病毒筛选器(不推荐,存在安全风险)
|
||||
fsutil devdrv enable /disallowAv
|
||||
|
||||
# 重新启用防病毒筛选器
|
||||
fsutil devdrv enable /allowAv
|
||||
```
|
||||
|
||||
### 常用筛选器列表
|
||||
|
||||
| 场景 | 筛选器名称 |
|
||||
| ------------------------------ | --------------------------------------------- |
|
||||
| Docker 容器 | `bindFlt`, `wcifs` |
|
||||
| Windows Defender | `WdFilter`(默认附加) |
|
||||
| Microsoft Defender for Endpoint | `MsSecFlt` |
|
||||
| GVFS (Git 虚拟文件系统) | `PrjFlt` |
|
||||
| 进程监视器 (ProcMon) | `ProcMon24` |
|
||||
| Windows 升级 | `WinSetupMon`(若 TEMP 在开发驱动器上则需要) |
|
||||
|
||||
## 包缓存迁移
|
||||
|
||||
将常用包缓存迁移到开发驱动器以获得最佳性能:
|
||||
|
||||
### npm (Node.js)
|
||||
|
||||
```powershell
|
||||
# 创建缓存目录
|
||||
mkdir D:\packages\npm
|
||||
|
||||
# 设置环境变量
|
||||
setx /M npm_config_cache D:\packages\npm
|
||||
|
||||
# 迁移现有缓存(如已安装)
|
||||
robocopy %AppData%\npm-cache D:\packages\npm /E
|
||||
```
|
||||
|
||||
### NuGet (.NET)
|
||||
|
||||
```powershell
|
||||
# 创建缓存目录
|
||||
mkdir D:\packages\nuget
|
||||
|
||||
# 设置环境变量
|
||||
setx /M NUGET_PACKAGES D:\packages\nuget
|
||||
|
||||
# 验证设置
|
||||
dotnet nuget locals global-packages --list
|
||||
```
|
||||
|
||||
### pip (Python)
|
||||
|
||||
```powershell
|
||||
# 创建缓存目录
|
||||
mkdir D:\packages\pip
|
||||
|
||||
# 设置环境变量
|
||||
setx /M PIP_CACHE_DIR D:\packages\pip
|
||||
|
||||
# 迁移现有缓存
|
||||
robocopy %LocalAppData%\pip\Cache D:\packages\pip /E
|
||||
```
|
||||
|
||||
### Cargo (Rust)
|
||||
|
||||
```powershell
|
||||
# 创建缓存目录
|
||||
mkdir D:\packages\cargo
|
||||
|
||||
# 设置环境变量
|
||||
setx /M CARGO_HOME D:\packages\cargo
|
||||
|
||||
# 迁移现有缓存
|
||||
robocopy %USERPROFILE%\.cargo D:\packages\cargo /E
|
||||
```
|
||||
|
||||
### Maven (Java)
|
||||
|
||||
```powershell
|
||||
# 创建缓存目录
|
||||
mkdir D:\packages\maven
|
||||
|
||||
# 设置环境变量
|
||||
setx /M MAVEN_OPTS "-Dmaven.repo.local=D:\packages\maven"
|
||||
|
||||
# 迁移现有缓存
|
||||
robocopy %USERPROFILE%\.m2\repository D:\packages\maven /E
|
||||
```
|
||||
|
||||
### Gradle (Java)
|
||||
|
||||
```powershell
|
||||
# 创建缓存目录
|
||||
mkdir D:\packages\gradle
|
||||
|
||||
# 设置环境变量
|
||||
setx /M GRADLE_USER_HOME D:\packages\gradle
|
||||
|
||||
# 迁移现有缓存
|
||||
robocopy %USERPROFILE%\.gradle D:\packages\gradle /E
|
||||
```
|
||||
|
||||
## 使用链接迁移包缓存
|
||||
|
||||
除了设置环境变量外,还可以使用 **目录联接 (Junction)** 或 **符号链接 (Symlink)** 将缓存目录迁移到开发驱动器,同时保持原有路径不变。
|
||||
|
||||
> **优势:** 无需修改环境变量,对应用程序完全透明,兼容性更好。
|
||||
|
||||
### 操作步骤
|
||||
|
||||
1. **迁移现有缓存**:使用 `robocopy` 将原目录内容移动到开发驱动器
|
||||
2. **创建链接**:在原位置创建指向新位置的 Junction/Symlink
|
||||
|
||||
### pnpm 缓存
|
||||
|
||||
```powershell
|
||||
# 迁移 pnpm 全局存储
|
||||
robocopy "C:\Users\你的用户名\.pnpm-store" "D:\Caches\.pnpm-store" /E /MOVE /R:3 /W:10
|
||||
|
||||
# 创建目录联接
|
||||
New-Item -ItemType Junction -Path "C:\Users\你的用户名\.pnpm-store" -Target "D:\Caches\.pnpm-store"
|
||||
```
|
||||
|
||||
### JetBrains 缓存
|
||||
|
||||
```powershell
|
||||
# 迁移 JetBrains 缓存(IDE 配置、索引等)
|
||||
robocopy "C:\Users\你的用户名\AppData\Local\JetBrains" "D:\Caches\JetBrains" /E /MOVE /R:3 /W:10
|
||||
|
||||
# 创建目录联接
|
||||
New-Item -ItemType Junction -Path "C:\Users\你的用户名\AppData\Local\JetBrains" -Target "D:\Caches\JetBrains"
|
||||
```
|
||||
|
||||
### npm 缓存
|
||||
|
||||
```powershell
|
||||
# 迁移 npm 缓存
|
||||
robocopy "C:\Users\你的用户名\AppData\Local\npm-cache" "D:\Caches\npm-cache" /E /MOVE /R:3 /W:10
|
||||
|
||||
# 创建目录联接
|
||||
New-Item -ItemType Junction -Path "C:\Users\你的用户名\AppData\Local\npm-cache" -Target "D:\Caches\npm-cache"
|
||||
```
|
||||
|
||||
### NuGet 缓存
|
||||
|
||||
```powershell
|
||||
# 迁移 NuGet 全局包
|
||||
robocopy "C:\Users\你的用户名\.nuget\packages" "D:\Caches\nuget-packages" /E /MOVE /R:3 /W:10
|
||||
|
||||
# 创建目录联接
|
||||
New-Item -ItemType Junction -Path "C:\Users\你的用户名\.nuget\packages" -Target "D:\Caches\nuget-packages"
|
||||
```
|
||||
|
||||
### pip 缓存
|
||||
|
||||
```powershell
|
||||
# 迁移 pip 缓存
|
||||
robocopy "C:\Users\你的用户名\AppData\Local\pip\Cache" "D:\Caches\pip-cache" /E /MOVE /R:3 /W:10
|
||||
|
||||
# 创建目录联接
|
||||
New-Item -ItemType Junction -Path "C:\Users\你的用户名\AppData\Local\pip\Cache" -Target "D:\Caches\pip-cache"
|
||||
```
|
||||
|
||||
### TEMP 目录
|
||||
|
||||
```powershell
|
||||
# 迁移临时文件目录(可选,需添加 WinSetupMon 筛选器)
|
||||
robocopy "$env:TEMP" "D:\Caches\TEMP" /E /MOVE /R:3 /W:10
|
||||
|
||||
# 创建目录联接
|
||||
New-Item -ItemType Junction -Path "$env:TEMP" -Target "D:\Caches\TEMP"
|
||||
|
||||
# 添加 Windows 升级所需的筛选器
|
||||
fsutil devdrv setfiltersallowed WinSetupMon
|
||||
```
|
||||
|
||||
### robocopy 参数说明
|
||||
|
||||
| 参数 | 说明 |
|
||||
| ------- | -------------------------------------- |
|
||||
| `/E` | 复制子目录,包括空目录 |
|
||||
| `/MOVE` | 移动文件和目录(复制后删除源) |
|
||||
| `/R:3` | 失败时重试 3 次 |
|
||||
| `/W:10` | 重试之间等待 10 秒 |
|
||||
|
||||
### Junction vs Symlink
|
||||
|
||||
| 类型 | 说明 | 需要管理员权限 |
|
||||
| ------------ | ------------------------------------------ | -------------- |
|
||||
| Junction | 目录联接,仅支持本地目录 | 否 |
|
||||
| Symlink | 符号链接,支持文件和远程路径 | 是(默认) |
|
||||
|
||||
> **推荐使用 Junction:** 开发场景下 Junction 兼容性更好,且不需要管理员权限创建。
|
||||
|
||||
### 验证链接
|
||||
|
||||
```powershell
|
||||
# 查看链接指向
|
||||
Get-Item "C:\Users\你的用户名\.pnpm-store" | Select-Object FullName, LinkType, Target
|
||||
|
||||
# 或使用 dir 命令
|
||||
cmd /c dir "C:\Users\你的用户名" /AL
|
||||
```
|
||||
|
||||
## 限制与注意事项
|
||||
|
||||
- **不支持的场景:**
|
||||
- 可移动/热插拔磁盘(USB、外部驱动器)
|
||||
- 动态磁盘(请使用存储空间代替)
|
||||
- C: 驱动器
|
||||
|
||||
- **内存占用:** ReFS 比 NTFS 使用更多内存,建议至少 8 GB,推荐 16 GB
|
||||
|
||||
- **VHD 注意事项:**
|
||||
- 固定磁盘上的 VHD 不建议复制,应移动后重新挂载
|
||||
- 移动到新计算机后需重新指定为开发驱动器并配置筛选器策略
|
||||
|
||||
- **WSL 兼容性:** 可从 WSL 访问开发驱动器上的文件,但不会有性能提升。ReFS 不支持 WSL metadata 装载选项。
|
||||
|
||||
## 删除开发驱动器
|
||||
|
||||
1. **设置 > 系统 > 存储 > 磁盘和卷**
|
||||
2. 选择开发驱动器旁的 **属性**
|
||||
3. 在格式标签下选择删除
|
||||
|
||||
> 如果是 VHD 创建的,删除卷后还需在磁盘管理中分离 VHD 才能删除 VHD 文件。
|
||||
|
||||
## 参考资料
|
||||
|
||||
- [在 Windows 11 上设置开发驱动器 - Microsoft Learn](https://learn.microsoft.com/zh-cn/windows/dev-drive/)
|
||||
- [利用 Dev Drive 提升 Visual Studio 和 Dev Boxes 的性能](https://devblogs.microsoft.com/visualstudio/devdriveperf/)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user