Wishlist 0 ¥0.00

怎么把mysql8的my.ini配置成支持1000人同时访问?

要将 MySQL 8 的 `my.ini` 配置文件调整为支持大约 1000 个并发连接,可以考虑以下几个关键参数的设置。请确保根据你的服务器硬件和性能需求进行调整。

1. **max_connections**: 这是 MySQL 允许的最大连接数。你可以将其设置为 1000。
```ini
max_connections = 1000
```

2. **innodb_buffer_pool_size**: 这个参数决定了 InnoDB 存储引擎用于缓存数据和索引的内存量。一般建议将其设置为系统可用内存的 70%-80%(如果仅用于数据库的话)。
```ini
innodb_buffer_pool_size = 4G # 根据你的服务器内存进行调整
```

3. **table_open_cache**: 用于缓存打开的表数量。可以考虑设置为 2000 或更高,以支持高并发。
```ini
table_open_cache = 2000
```

4. **thread_cache_size**: 这个参数控制了 MySQL 线程的缓存,以提高处理请求的效率。你可以尝试将其设置为 100。
```ini
thread_cache_size = 100
```

5. **query_cache_size**: 如果你的查询模式适合使用查询缓存,可以设置这个值。需要注意,查询缓存可能会在高并发下造成锁竞争,因此你也可以根据实际情况评估是否启用。
```ini
query_cache_size = 0 # 如果不需要,建议关闭
```

6. **wait_timeout** 和 **interactive_timeout**: 这些参数定义了连接在空闲状态下的超时设置。可以适当降低这些值以释放资源。
```ini
wait_timeout = 600
interactive_timeout = 600
```

修改完 `my.ini` 文件后,确保重启 MySQL 服务使更改生效。

请注意,具体配置应根据你的应用负载、服务器硬件(如 CPU、内存、I/O 性能)进行适当调整,并且在负载测试中监测性能。希望这些信息能帮到你!

Getting Started with Windows Subsystem for Linux on Windows Server

Windows Subsystem for Linux (WSL) brings the convenience of native Linux functionality to Windows Server. You have access to a fully functional Linux kernel in the distribution of your choice embedded right where you have instant access without needing to rely on a heavy virtualization layer or a thick emulator. This article focuses on WSL in Windows Server 2022 as the current version, but includes notes for WSL on Windows Server 2019.

[citationic]

Overall, Microsoft maintains decent documentation on WSL, which you can always access at aka.ms/wsl. However, their directions for installing distributions from APPX on Windows Server have some clarity problems and may not work for you. If you want, you can try them. The steps shown in this article have all been verified functional as of the date of publication/most recent update.

Install WSL Using DISM

You can install WSL on Windows Server using the command-line DISM utility in two ways. The first uses an elevated command line and the dism.exe program. Remember that feature names in DISM are case sensitive. If you are on Windows Server 2019 or you do not wish to use WSLv2 on Windows Server 2022, you can omit the references to VirtualMachinePlatform. Note that because Windows Server 2022 always defaults to version 2 for WSL, attempting to install a distribution without this component will usually result in error code 0x8004032d. The sections in this article on installing distributions show how to set the default version to 1.

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /featurename:VirtualMachinePlatform

You can also use PowerShell:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux, VirtualMachinePlatform

You can use Install-WindowsFeature or its alias of Add-WindowsFeature, however, it only works for the base WSL package. If you have Windows Server 2022 and want to use WSLv2, then you will still need to add the “VirtualMachinePlatform” package as shown above.

Install-WindowsFeature -Name Microsoft-Windows-Subsystem-Linux

If the method you use does not prompt for reboot, you can initiate one with 

Restart-Computer

. in PowerShell or 

shutdown /r /t 0

 at any prompt. Afterward, you have the WSL infrastructure but no distributions. Skip the next installation section for instructions.

Not Recommended: Install WSL Using Pre-placed Stub

With some caveats, you can sometimes install Windows Subsystem for Linux on Windows Server 2022 the same way that you can on Windows 10 or Windows 11. Just open an elevated command-line and run:

wsl --install --no-distribution

This may not notify you afterward, but it requires a reboot. You can initiate from the command line with 

shutdown /r /t 0

.

When it works, it does so because Windows Server 2022, like the desktop editions of Windows with more recent updates, includes just enough of the Windows Subsystem for Linux to operate the installer. Once this completes, you might have the framework necessary to run Linux distributions. However, it may set the system to default to version 2 but miss a vital component that allows for anything beyond version 1, and it does not include any distributions. Instructions for adding distributions appear after the remaining installation sections. Sometimes, it doesn’t even actually enable the feature! To save time troubleshooting any of these problems, use the DISM steps in the next section.

Not Recommended: Install WSL Using Server Manager

You can also use Server Manager to install the base component of WSL. This will not install the “VirtualMachinePlatform” component, so you can’t use WSLv2. That component does not appear anywhere in the Server Manager UI, so you’ll need to follow the DISM steps. This does not apply on Windows Server 2022 or when you don’t want to use WSLv2 on Windows Server 2022.

From Server Manager’s start page, use the Add Roles and Features link. Step through the wizard to the Features page and check the option for Windows Subsystem for Linux.

Continue through the wizard. If you check the box for automatic restart, then Windows Server will take care of it. Otherwise, you can restart manually at your convenience.

After the restart, proceed to the next section to learn how to add a Linux distribution.

Acquiring Packaged Linux Distributions for WSL

Microsoft provides multiple distributions ready for use with WSL. On a typical desktop installation of Windows, you would install them directly from the Windows Store. Windows Server does not provide access to the Windows Store. Therefore, you’ll need to download distributions and install them manually.

Before downloading anything, decide where you want to house your Linux distributions. You can use something simple, like C:\WSL. Create the directory with default options. You can do this in Windows Explorer or at a command line:

mkdir C:\WSL

You can download from Microsoft’s site. You should not use a production server for general Internet access. Ideally, a server won’t even have an installed Internet browser. Instead, access the site from a desktop installation of Windows and use a secured channel to transfer it to your server environment. Rather than repeat everything from the Microsoft site here, you can just follow this link: https://learn.microsoft.com/en-us/windows/wsl/install-manual#downloading-distributions.

A couple of notes on what you’ll find:

  • Notice that each of the links includes an aka.ms shortcut URL, such as https://aka.ms/wslubuntu for the current Ubuntu distribution.
  • Below the links, you can find examples for using PowerShell and the command-line utility cURL to download.

The site delivers distributions as appx (package application) files, but as mentioned during the intro of this article, those directions may not work. The next section shows how to extract them for use.

Quick, Foolproof WSL Distribution Setup Directions

This section contains the shortest possible directions. If you have already tried to follow the Microsoft instructions and a bunch of Internet solutions and learned a lot but still failed, then you will probably only need this section. It makes a lot of assumptions about your knowledge. If you find these instructions too simplistic, skip past and use the longer versions afterward.

  1. Download the major .appx file for the distribution
  2. If you used a browser, remember to unblock the file (Unblock-File)
  3. Rename the .appx to .zip. If it’s an .appxbundle file, then you’ll still rename to .zip.
  4. Extract the files from that zip
  5. If the extracted files have more appx files for the distribution, the source was probably an appxbundle. Determine which of the contained appx files you want to use for your distribution, rename that to zip, and extract its files.
  6. Optional: Register that appx with Add-AppxPackage (this will not work on any core mode installation and does not work and is not necessary on any edition of Windows Server 2019)
  7. Rename the appx that you just registered to .zip
  8. Extract the files from that zip. You specifically need the distribution executable (e.g., ubuntu.exe) and the install.tar.gz
  9. On Windows Server 2022, you may have instances where you can’t or don’t want to use WSLv2, but WSL wants to run v2 by default. Switch to version 1 with 
    wsl --set-default-version 1
    . If you expected WSLv2 to work, make sure that you installed the “VirtualMachinePlatform” optional feature (discussed in the DISM section near the beginning of the article).
  10. Run the distro’s executable
  11. Delete the extracted files except for the distro executable, the rootfs folder (if present), and the temp folder (if present)

Going forward, you can just run that same executable to start this distribution. You can add its location to the path to initiate it from anywhere. After it has executed once, it will also appear as one of the options in 

wsl --list

 (Windows Server 2022+) or 

wslconfig /l

 (Windows Server 2019).

Quick Walkthrough: Linux Distro Installation for WSL on Windows Server 2019

These steps show the exact process to start an installation of the current Ubuntu distribution in WSL on Windows Server 2019 fresh install, Standard edition, core mode, updated via online Windows Update to available patches on November 24, 2023. They will also work on WS2019 with the desktop experience.

  1. If not already in PowerShell, start PowerShell from an elevated command prompt (
    powershell.exe
    )
  2. Install-WindowsFeature -Name Microsoft-Windows-Subsystem-Linux
  3. cd $env:USERPROFILE
  4. cd .\Downloads
    \
  5. Invoke-WebRequest -UseBasicParsing -OutFile ubuntu_current.zip -Uri https://aka.ms/wslubuntu
  6. Expand-Archive -Path .\ubuntu_current.zip .\ubuntu_current
  7. cd .\ubuntu_current
  8. Rename-Item .\Ubuntu_2204.1.7.0_x64.appx .\Ubuntu_2204.1.7.0.zip
  9. mkdir C:\WSL\Ubuntu
  10. Expand-Archive .\Ubuntu_2204.1.7.0.zip C:\WSL\Ubuntu
  11. cd C:\WSL\Ubuntu
  12. .
    \ubuntu.exe

This will start an install process, then ask you to set up the credentials to use in this distribution.

Because Windows Server 2019 cannot use WSL2, only a subset of the instructions that you find for wsl.exe will work. Use 

wsl --help

 to show what you can use. For the other functions, such as removing a distribution, use wslconfig. 

wslconfig --help

 will show its options. For example, to remove the distribution that you just set up, run 

wslconfig /u Ubuntu

. If you do that, you can immediately run the 

ubuntu.exe

 again to reinstall it, provided that you left the install files intact.

If you want to clean up your directory tree after installation, the C:\WSL\Ubuntu location mentioned in the walkthrough only needs the 

ubuntu.exe

 file, the 

rootfs

folder, and the 

temp

folder. If you delete the temp folder, your next run of the distribution will recreate it. Do not try to remove the rootfs folder as it contains your distribution and has file names that the NTFS tools can’t handle. If you try to remove the folder, it will partially work and complain about something, usually an undeletable aux file. Use 

wslconfig /u

 instead. If you’ve already wrecked it and you can’t remove the folder, try going to an elevated command prompt (not PowerShell) and run the following: 

rd \\.\C:\WSL\Ubuntu\rootfs /s /q

.

Quick Walkthrough: Linux Distro Installation for WSL on Windows Server 2022

These steps show the exact process to start an installation of the current Ubuntu distribution in WSL on a Windows Server 2022 fresh install, Standard edition, core mode, updated via online Windows Update to available patches on November 24, 2023. This follows the pattern of the previous section in which you manually retrieve the appx package from the Microsoft site even though you now have the online option to perform this automatically. We chose this technique because, except for the download part, it will work for servers that do not have an Internet connection.

These steps will also work on WS2022 with the desktop experience.

  1. Start an elevated PowerShell session (powershell.exe)
  2. Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux, VirtualMachinePlatform
  3. If prompted, allow the computer to restart
  4. If you had to restart, return to an elevated PowerShell prompt.
  5. cd $env:USERPROFILE
  6. cd .\Downloads
    \
  7. Invoke-WebRequest -UseBasicParsing -OutFile ubuntu_current.zip -Uri https://aka.ms/wslubuntu
  8. Optional: If running a Desktop Experience installation of Windows Server, see the second note in the next sub-section before proceeding
  9. Expand-Archive -Path .\ubuntu_current.zip .\ubuntu_current
  10. cd .\ubuntu_current
  11. Rename-Item .\Ubuntu_2204.1.7.0_x64.appx .\Ubuntu_2204.1.7.0.zip
  12. mkdir C:\WSL\Ubuntu
  13. Expand-Archive .\Ubuntu_2204.1.7.0.zip C:\WSL\Ubuntu
  14. cd C:\WSL\Ubuntu
  15. If you prefer to use WSL v1 or must because of a hardware limitation, run the following: 
    wsl --set-default-version 1
  16. .
    \ubuntu.exe

This will start an install process, then ask you to set up the credentials to use in this distribution.

If you want to clean up your directory tree after installation, the C:\WSL\Ubuntu location mentioned in the walkthrough only needs the 

ubuntu.exe

 file, the 

rootfs

folder, the fsserver file, and the 

temp

folder. If you delete the temp folder, your next run of the distribution will recreate it. Do not try to manually remove the rootfs folder as it contains your distribution and has file names that the NTFS tools can’t handle. If you try to remove the folder, it will partially work and basically just wreck the whole thing. Use 

wsl --unregister

 instead. If you’ve already wrecked it, try going to an elevated command prompt (not PowerShell) and run the following: 

rd \\.\C:\WSL\Ubuntu\rootfs /s /q

.

Notes for WSL On Windows Server 2022

The above directions used a core mode installation, which varies from the desktop experience in two major ways.

First, the steps will work just fine on the desktop experience, but the core mode lacks several capabilities: No use of 

wsl --install

wsl --update

, or any 

--online

functionality. All these result in a vague 

Class not registered

 message. You also can’t install the most recent WSL recent from the Github page, apparently because of the same anonymous missing component.

Second, on desktop experience, you can use Add-AppxPackage on the internal APPX component before renaming it to ZIP at step 11. Example: 

Add-AppxPackage .\Ubuntu_2204.1.7.0_x64.appx

. If you do this and then follow the rest of the directions, the system creates a folder for the APPX package under your user profile (ex: C:\Users\Administrator\AppData\Local\Packages). The 

rootfs

 and 

temp

 folders for the distribution will appear there. You can then delete everything in the place where you extracted the files (ex: C:\WSL\Ubuntu in the directions above) except for the distribution’s executable (ubuntu.exe in the directions). You can even move the executable anywhere you like.

If you get errors trying to run Add-AppxPackage on the distribution package that mention dependency failure, install the Universal Windows Platform desktop component first. This will only work with the desktop experience, not on core.

Installing an APPX WSL Distribution on Windows Server

Here begin the longer instructions for installing a Linux distribution from APPX on Windows Server. This will show the process more in-depth than the quick directions in the preceding two sections and will use Windows Server 2022 with the desktop experience instead of core.

From this point onward, the directions assume that you have installed WSL, created a location to store your distributions, and have acquired at least one APPX-packaged distribution. These steps will use C:\WSL as the root for WSL distributions, so modify them to match what you decided to use.

Preparing Windows Server 2022 to run Linux Distributions

Before you start, consider two things.

First, WSL on Windows Server 2022 always wants to run version 2 distributions. If you didn’t enable the “VirtualMachinePlatform” or your hardware just doesn’t support it, WSL will refuse to install distributions. You can follow the instructions in DISM section at the beginning of the article to enable the missing component.

Alternatively, you can tell WSL to use version 1. At an elevated command prompt, run:

wsl --set-default-version 1

From this point forward, all Linux distributions will install as version 1. It will not impact existing distributions. You can change the default version and the version of an installed distribution at any time.

Second, update WSL. Unfortunately, this does not work on core installations of Windows Server 2022 or any installation of Windows Server 2019. For offline servers, you can get the bits from Github. For online servers, you can update right from the command prompt.

At an elevated command prompt, run:

wsl --update

This will retrieve and install the most current WSL bits. If it fails because the server can’t access the Internet, WSL will still operate your distribution.

Extracting and Installing the Linux APPX

This example shows an openSUSE distribution instead of Ubuntu to shake things up a bit. It downloads as an APPX file, which the article has talked about all along. The Ubuntu distribution in the preceding sections uses a nested delivery technique. If you download that one using a web browser, you’ll get an “appxbundle” file. You rename an APPXBUNDLE to ZIP just like the APPX example shown here, then open that archive to find nested APPX files. Select the one you want (usually by architecture, ex: x64 or ARM), extract it, and use that APPX as the following example shows.

Screenshot of a downloaded openSUSE-Tumbleweed-20220224.appx file

To start, rename the downloaded file so that it has a .ZIP extension instead of .APPX (or .APPXBUNDLE).

Screenshot of a downloaded openSUSE-Tumbleweed-20220224.appx file being actively renamed to .zip

Explorer will warn about changing the extension. Click Yes if you get that. You can then double-click the newly renamed ZIP. Inside, you’ll find multiple files, but you only need the application (EXE) and the install.tar.gz files.

Screenshot of zipped contents of openSUSE-Tumbleweed-20220224.zip with install.tar.gz and openSUSE-tumbleweed.exe highlighted

If you configured Explorer to show extensions, then can quickly spot the executable by the exe extension. Otherwise, it should distinguish itself by using the name of the Linux distribution. Extract these two files to your desired operating location (ex: C:\WSL).

Screenshot showing openSUSE-Tumbleweed-20220224.zip with install.tar.gz and openSUSE-tumbleweed.exe being dragged from a ZIP archive to C:\WSL

Now, you can double-click the extracted executable or run it from an elevated command prompt. Be warned that SmartScreen might not like it!

Screenshot of SmartScreen halting execution of openSUSE-Tumbleweed.exe

You can click More Info and Run anyway to get past this warning.

The distribution will then perform its installation routine.

Screenshot of openSUSE Tumbleweed installing in Windows Subsystem for Linux

When you exit from the session, you will notice that the installer created some supporting files, either in the same location or under your user’s profile.

Screenshot of the folder that contains an installed openSUSE WSL instance, with the rootfs, temp, and fsserver items outlined to draw focus

If using WSLv2, you will have a VHDX file instead of the rootfs folder. The temp folder will automatically recreate when necessary on each run of the distribution. Distributions may create their own files, such as the fsserver item that openSUSE created here. Leave those items and the executable that runs the distribution. You can delete the install.tar.gz file and any other support files that came from the APPX.

Going forward, you can run this executable or use the 

wsl

 command to start the distribution.

Adding the Distribution to the Path

The wsl.exe file lives in C:\Windows\System32, so you can invoke it from anywhere. With nothing else specified, doing so will start the default distribution. You can also pass the name of an installed distribution using 

-d

 and it will start that one. This is how you would run a command inside your distribution without loading the entire thing (ex 

wsl -d Ubuntu --ls /

). Such usage exceeds the intent of this article, so check the documentation link at the top for more information.

If you’d rather start your distribution by its executable, (ex ubuntu.exe), then you can add its location to your path. Microsoft’s document lists a convoluted way via PowerShell that did not work for me. Instead, use the age old technique at an elevated command prompt (not PowerShell):

PATH = %PATH%;C:\WSL\Ubuntu

Now you can just run 

ubuntu

 from any command prompt and it will start up your distro.

Screenshot of a Linux distribution successfully running after adding its path to the system's path environment variable

Want another cool trick? You can rename the exe and it will continue to work just fine.

ren C:\WSL\Ubuntu\ubuntu.exe my-cool-ubuntu.exe
Screenshot of a renamed WSL distribution running successfully

This does not change the behavior of wsl.exe in any way. You would still invoke this distribution with 

wsl -d Ubuntu

.

Go Forth and Linux on Windows Server

Future articles here on Project Runspace will use WSL for activities such as certificate services. Whatever your purpose, you now have the tools you need to run Windows Subsystem for Linux on your Windows Servers.

在 Windows 上安装 NGINX 的 3 种方法

目录
1 引言
2 方法 1:官方 NGINX Windows 二进制文件
3 方法 2:Cygwin 环境
4 方法 3:适用于 Linux 的 Windows 子系统 (WSL)
5 总结

介绍

NGINX,发音为“Engine-X”,是一款功能强大的 Web 服务器,以其高性能、稳定性、简单配置和低资源消耗而闻名。虽然它最初是为 Linux 开发的,但也可以在 Windows 系统上运行 NGINX。您可以通过多种方式在 Windows 上安装 NGINX,每种方法都有其方法和用例。本指南全面介绍了在 Windows 环境中安装 NGINX 的几种解决方案。

 

方法 1:官方 NGINX Windows 二进制文件

NGINX 提供了适用于开发和测试目的的官方预构建 Windows 二进制文件。官方 NGINX 二进制文件由 NGINX 团队提供,并针对 Windows 进行编译。

 

步骤:

  1. 从官方网站下载 Windows 版本的 NGINX,可以在 nginx.org 上找到。
  2. 将下载的文件解压缩到 Windows 计算机上的所需位置。
  3. 使用管理权限打开命令提示符。
  4. 导航到解压缩 NGINX 的目录,然后运行命令 。start nginx
  5. 通过在 Web 浏览器中访问来确认 NGINX 正在运行。http://localhost

笔记:NGINX 的 Windows 版本用于开发,不建议用于生产,因为与 Linux 版本相比,存在一些已知问题,例如功能支持有限和性能较低。

方法 2:Cygwin 环境

使用 Cygwin 环境安装 NGINX,该环境模拟 Windows 上的 Linux。Cygwin 是在 Windows 上运行的 POSIX 兼容环境,本质上为 Windows 用户提供了一个类似 Linux 的层。

步骤:

  1. 从官方网站下载并安装 Cygwin, cygwin.com.
  2. 在设置过程中,请确保在“Web”类别下选择“nginx”包进行安装。
  3. 安装后,启动 Cygwin 并使用类似 Linux 的命令来管理 NGINX,例如 .nginx -s start
  4. 要进行验证,请打开浏览器并转到 。http://localhost

笔记:Cygwin 提供了更类似于 Unix 的体验,在它下运行 NGINX 会添加另一个抽象层,这可能会影响性能。此方法也最适合开发环境。

方法 3:适用于 Linux 的 Windows 子系统 (WSL)

 

在适用于 Linux 的 Windows 子系统上安装 NGINX,以在 Windows 10 上使用本机 Linux 二进制文件。WSL 使您能够直接在 Windows 上运行 GNU/Linux 环境,而不会产生虚拟机的开销。

步骤:

  1. 通过 Turn Windows features on or off 对话框或通过 PowerShell 在 Windows 10 计算机上启用 WSL。
  2. 从 Microsoft Store 安装首选的 Linux 发行版(例如 Ubuntu)。
  3. 启动 Linux 发行版并更新软件包管理器。
  4. 运行命令(适用于基于 Debian 的发行版)以安装 NGINX。sudo apt install nginx
  5. 使用 启动 NGINX。sudo service nginx start
  6. 通过访问您的 Web 浏览器来访问 NGINX。http://localhost

笔记:WSL 提供接近本机 Linux 的性能,适用于更高级的开发和测试,甚至可能适用于具有 WSL2 升级的生产方案,WSL2 升级可提供更好的系统调用兼容性。

结论

总之,在 Windows 上安装 NGINX 可以通过多种方式完成,每种方式都针对不同的性能和易用性水平量身定制。官方的 NGINX 二进制文件提供了在 Windows 上运行 NGINX 的最快方式,适用于基础开发或测试。Cygwin 模拟 Linux 环境以获得更接近 Unix 的效果。适用于 Linux 的 Windows 子系统允许在 Windows 计算机上执行本机 Linux 二进制文件,从而提供最佳性能,使其成为类似生产环境的最有利选项。请务必选择最符合您的特定需求和环境的方法。

Syncthing多平台文件同步工具安装全攻略

简介

Syncthing是一款开源的文件同步工具,可以通过本地网络或互联网实现多台设备之间的文件同步。与其他同步工具不同,Syncthing强调隐私和安全,确保用户的数据始终处于用户的控制之下。

功能与特点

  1. 开源软件

    • Syncthing是完全开源的,源代码托管在GitHub上,任何人都可以查看、审查和贡献代码。这种透明性增强了用户对软件安全性的信任。
  2. 去中心化

    • Syncthing采用P2P(点对点)架构,没有中央服务器,所有数据传输直接在设备之间进行。这不仅提高了数据传输速度,还消除了对第三方服务器的依赖。
  3. 跨平台支持

    • Syncthing支持多种操作系统,包括Windows、macOS、Linux、BSD、Solaris、Android等,能够满足不同用户的需求。
  4. 安全性

    • 数据在传输过程中使用TLS加密,确保通信的安全性。此外,每个节点都有唯一的设备ID,通过设备ID进行认证和连接,防止未经授权的设备访问。
  5. 实时同步

    • 文件修改后会立即触发同步操作,实现实时更新。Syncthing能够检测文件的变化,并迅速同步到其他设备上。
  6. 版本控制

    • Syncthing支持文件版本控制,可以保留多个文件版本,方便用户在需要时恢复到之前的版本。
  7. 配置灵活

    • Syncthing提供了丰富的配置选项,用户可以根据需要设置同步目录、同步频率、带宽限制等参数,满足不同的使用场景。
  8. 简单易用

    • 通过一个友好的Web GUI(图形用户界面),用户可以轻松管理和监控同步状态,进行配置修改。

优点

  1. 隐私保护

    • 因为不依赖于任何中央服务器,用户的数据不会存储在第三方服务器上,完全在用户的掌控之中,极大地保护了隐私。
  2. 高效的带宽利用

    • Syncthing在同步过程中只传输更改的部分(增量同步),而不是整个文件,从而提高了带宽利用率,节省了传输时间和资源。
  3. 安全性高

    • 使用TLS加密传输数据,设备之间的通信经过认证,防止中间人攻击和未经授权的访问。
  4. 无缝集成

    • Syncthing可以在多种操作系统上运行,并且支持多设备同步,用户可以轻松地在家用电脑、工作电脑、手机等多个设备之间同步文件。
  5. 社区支持

    • 作为开源项目,Syncthing拥有活跃的社区支持,用户可以从社区获得帮助和建议,及时解决使用过程中遇到的问题。
  6. 定制化

    • 用户可以根据自己的需求进行高度定制,包括选择需要同步的文件夹、设置不同的同步策略和频率、限制带宽使用等。
  7. 可靠性

    • Syncthing的设计使其在网络断开后能够自动恢复同步操作,并且支持自动解决同步冲突,确保数据的一致性和可靠性。

安装教程

注:博主安装过该工具,下面的安装教程,可能会出现一点点区别,不过按照以下操作进行搭建是可以成功的。

官方下载地址:https://syncthing.net/downloads/
选择对应的版本进行下载。

本文采用两个同步平台为Windows和Ubuntu。可以通过链接:https://wwt.lanzoue.com/b0fomam7g下载本文所对应的安装包。下载密码:hx90

两台电脑能实现文件同步的前提是两台电脑的网络能够相互访问。如果一台电脑在内网中,一台在有公网IP的服务器上。可以用有公网IP的服务器搭建一个frp内网穿透工具,通过内网穿透后,就可以实现两台电脑进行网络通信了。

Windows安装

解压安装包,然后双击syncthing.exe打开。

出现这个界面后,可以看见web界面访问地址。初次安装应该会直接在浏览器中打开该地址,然后有一个提示对话框,匿名报告相关的,可以选择否。

能出现该界面就说明安装成功了。先不用管界面是否完全一样,下面会介绍如何进行配置。

Ubuntu安装

将Linux版的文件上传到服务器,这里使用xshell配合xftp进行操作。
在xshell中连接成功后,可以点上面图标。

接下来就可以将文件拖拽到Ubuntu中了。

接下来解压文件tar -zxf syncthing-linux-amd64-v1.27.9.tar.gz

这里可以修改文件夹的名称。用mv syncthing-linux-amd64-v1.27.9 syncthing就可以。博主前面安装过了,这点就不修改了。
进入syncthing-linux-amd64-v1.27.9文件夹。使用./syncthing serve就可以启动。

这时如果是图形化的Ubuntu,就可以在Ubuntu浏览器中打开http://127.0.0.1:8384/。博主采用的是腾讯云的vps,直接用ip访问不了。这里需要进行一步操作。

配置远程ip访问

Ctrl + C停掉服务。
查看官方文档后,使用命令./syncthing serve --gui-address=0.0.0.0:8384配置。

这样就可以远程通过ip访问了,不过你的服务器防火墙需要放行端口。

配置同步文件夹

这里需要用到工具的ID,先去服务端查看,启动服务的时候就会显示,现在可以通过web界面进行查看。客户端同理。

刚才复制的是服务端的ID,那么现在就打开客户端的web管理界面。

如果只是局域网操作,这里直接保存即可。
如果想公网访问,就可以内网穿透工具。在服务器搭建内网穿透工具,可以参考这篇文章:https://blog.csdn.net/weixin_42951763/article/details/140420245
只需要将链接中Windows客户端的配置修改即可,这里给出一个参考。

在启动的时候可以看见tcp使用的默认端口。

配置Ubuntu服务端。打开服务端的web界面。

在高级设置中,配置一下地址。

这里再解释一下这个地址。
Windows中的IP不是公网IP,所以Ubuntu服务端不能直接访问到Windows这个客户端。因此才有了frp内网穿透,把Windows映射到公网中。通过映射后的公网IP加上端口,就可以访问到Windows这个内网中的客户端了。

接下来就可以创建共享的文件夹了。
先在Windows这边创建。

文件夹共享给Ubuntu。

文件夹版本控制。官方文档的文件版本控制介绍

到这点Windows的就配置好了。
这时去到服务端Ubuntu的web界面。

可以看见出现了一个新文件夹,这时点击添加即可。如果没有出现,可能的原因是服务端这边还没有与Windows进行连接。再次检查一下远程设备是否已经同步完成。

这里选择共享给Windows,这样就可以把Ubuntu变化后的文件也同步到Windows里面。

这样就实现了简单的双向同步文件。

Syncthing开机自启

Windows

利用bat文件来实现。
在Syncthing的文件根目录中新建一个bat文件,放在这里是方便管理,也可以放在其他地方。

bat文件内容如下:

  @echo off
   
  if "%1"=="h" goto begin
   
  start mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
   
  :begin
   
  cd /d D:\syncthing && syncthing.exe serve --no-browser --no-restart --logflags=0

只需要修改下图红框中的路径为自己的路径即可。

然后保存退出。在bat文件右键创建快捷方式。

使用win + R打开运行对话框,输入:shell:startup回车。将刚才创建的快捷方式移动到这个目录里面。

Ubuntu

查看syncthing的目录,然后记录一下这个目录。

使用命令:sudo vim /etc/systemd/system/This email address is being protected from spambots. You need JavaScript enabled to view it.,@后填写用户名。

下图红框中的路径要修改为你自己对应的,也就是刚才查看的路径。下图绿框的syncthing是表示文件名。

文件内容如下:

  [Unit]
  Description=Syncthing - Open Source Continuous File Synchronization for %I
  Documentation=man:syncthing(1)
  After=network.target
  StartLimitIntervalSec=60
  StartLimitBurst=4
   
  [Service]
  User=%i
  ExecStart=/home/ubuntu/syncthing/syncthing serve --no-browser --no-restart --logflags=0 --gui-address=0.0.0.0:8384
  Restart=on-failure
  RestartSec=1
  SuccessExitStatus=3 4
  RestartForceExitStatus=3 4
   
  # Hardening
  ProtectSystem=full
  PrivateTmp=true
  SystemCallArchitectures=native
  MemoryDenyWriteExecute=true
  NoNewPrivileges=true
   
  # Elevated permissions to sync ownership (disabled by default),
  # see https://docs.syncthing.net/advanced/folder-sync-ownership
  #AmbientCapabilities=CAP_CHOWN CAP_FOWNER
   
  [Install]
  WantedBy=multi-user.target

提升文件的权限。

  sudo chmod +x /etc/systemd/system/This email address is being protected from spambots. You need JavaScript enabled to view it.

 

接下来可以使用这些命令来操作了。

  # 启动syncthing@ubuntu
  sudo systemctl start syncthing@ubuntu
  # 开机自动启动syncthing@ubuntu
  sudo systemctl enable syncthing@ubuntu
  # 重启syncthing@ubuntu
  sudo systemctl restart syncthing@ubuntu
  # 停止syncthing@ubuntu
  sudo systemctl stop syncthing@ubuntu
  # 查看syncthing@ubuntu状态
  sudo systemctl status syncthing@ubuntu



About Us

Since 1996, our company has been focusing on domain name registration, web hosting, server hosting, website construction, e-commerce and other Internet services, and constantly practicing the concept of "providing enterprise-level solutions and providing personalized service support". As a Dell Authorized Solution Provider, we also provide hardware product solutions associated with the company's services.
 

Contact Us

Address: No. 2, Jingwu Road, Zhengzhou City, Henan Province

Phone: 0086-371-63520088 

QQ:76257322

Website: 800188.com

E-mail: This email address is being protected from spambots. You need JavaScript enabled to view it.