


How to set up swap on Linux cloud server
Step one: Confirm the status of swap
Use the following command to check the memory status:
free -m
If the result shows that swap is 0, it means that swap does not exist and you need to create swap.
total used free shared buffers cached Mem: 1840 1614 226 15 36 1340 -/+ buffers/cache: 238 1602 Swap: 0 0 0
Or you can use this command to view it. If no results are output, swap does not exist.
swapon -s
Step 2: Create swap
We use the following command to create a swap file with a size of 2GB.
dd if=/dev/zero of=/swapfile count=2048 bs=1M
The output results are as follows:
2048+0 records in 2048+0 records out 2147483648 bytes (2.1 GB) copied, 10.5356 s, 204 MB/s
Step 3: Activate swap
swap will not be automatically recognized by default. We need to set appropriate permissions before it can be used normally. Execute the following command to set the permissions of the swap file to 600, which means it can be read and written by the root user.
chmod 600 /swapfile
Activate swap:
mkswap /swapfile
The output results are as follows:
Setting up swapspace version 1, size = 2097148 KiB no label, UUID=ff3fc469-9c4b-4913-b653-ec53d6460d0e
Step 4: Enable swap
Execute the following command to enable swap
swapon /swapfile
By default, the swap file will not be automatically started with the system, so it needs to be written to the file system.
vi /etc/fstab
Add the following code at the end:
/swapfile none swap sw 0 0
After saving with the :wq command, swap will be started with the system.
Finally, we can use the free command to confirm whether swap is set successfully.
free -m
The output results are as follows. You can see that swap is no longer 0, indicating that swap has been set successfully.
total used free shared buffers cached Mem: 1840 1754 86 16 23 1519 -/+ buffers/cache: 210 1630 Swap: 2047 0 2047
The above is the detailed content of How to set up swap on Linux cloud server. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)
