User-Profile-Image
hankin
  • 5
  • 关于
  • 分类
    • 路由器
    • 电脑相关
    • 游戏相关
    • 未分类
    • 服务器相关
    • 数据库
  • 页面
    • 关于
  • 友链
    • 华夏网盟
Help?

Please contact us on our email for need any support

Support
  • 关于
    首页   ›   服务器相关   ›   正文
服务器相关

Centos_Swap设置虚拟内存大小方法

2021-02-22 11:24:00
67  0 0

修改swap的全部步骤:

[root@gamedb ~]# free –m
[root@gamedb tmp]# dd if=/dev/zero of=/tmp/big_swap bs=1024 count=2000000
[root@gamedb tmp]# du -sh /tmp/big_swap
[root@gamedb tmp]# mkswap /tmp/big_swap
[root@gamedb tmp]# swapon /tmp/big_swap
[root@gamedb tmp]# free –m
[root@gamedb tmp]# vi /etc/fstab

LABEL=SWAP-hda2 swap swap defaults 0 0

/tmp/big_swap swap swap defaults 0 0
1、查看内存和swap大小,发现swap是内存大小的一半

[root@localhost tmp]# free -m
total used free shared buffers cached
Mem: 772 91 681 0 6 30
-/+ buffers/cache: 53 718
Swap: 1567 0 1567
2、决定修改swap大小,首先在空间合适处创建用于分区的swap文件:

[root@localhost tmp]# dd if=/dev/zero of=/tmp/big_swap bs=1024 count=2000000
记录了2000000+0 的读入
记录了2000000+0 的写出
2048000000字节(2.0 GB)已复制,69.5342 秒,29.5 MB/秒
(注意:if 表示 infile,of 表示outfile,bs=1024 表示写入的每个块的大小为1024B=1KB(1024B字节=1024*8bit位)
3、查看创建的文件大小是否符合要求:

[root@localhost tmp]# du -sh big_swap
2.0G big_swap
[root@localhost tmp]# ls -al big_swap
-rw-r–r– 1 root root 2048000000 12月 1 14:25 big_swap
4、将目的文件设置为swap分区文件:

[root@localhost tmp]# mkswap big_swap
mkswap: big_swap: warning: don’t erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 1999996 KiB
no label, UUID=25c3eaf2-43f9-487b-87b7-f76a712f5376
5、激活swap,立即启用交换分区文件:

[root@localhost tmp]# swapon big_swap
6、再次查看内存和虚拟内存,发现已经被正常修改:

[root@localhost tmp]# free -m
total used free shared buffers cached
Mem: 772 705 66 0 2 627
-/+ buffers/cache: 75 697
Swap: 3521 0 3521
7、若要想使开机时自启用,则需修改文件/etc/fstab中的swap行:

[root@gamedb tmp]# vi /etc/fstab

LABEL=SWAP-hda2 swap swap defaults 0 0

/tmp/big_swap swap swap defaults 0 0

评论 (0)

Click here to cancel reply.

欢迎您 游客  

近期文章

  • 用于网速测试的下载测速文件合集
  • docker构建SB镜像
  • pterodactl docker install
  • OpenWRT流量实时监控插件
  • docker部署dify

近期评论

No comments to show.

归档

  • 1 月 2026
  • 8 月 2025
  • 5 月 2025
  • 4 月 2025
  • 3 月 2025
  • 2 月 2025
  • 12 月 2024
  • 4 月 2024
  • 10 月 2023
  • 8 月 2023
  • 4 月 2023
  • 3 月 2023
  • 2 月 2023
  • 10 月 2021
  • 5 月 2021
  • 3 月 2021
  • 2 月 2021

分类

  • 数据库
  • 服务器相关
  • 未分类
  • 游戏相关
  • 电脑相关
  • 路由器
Copyright © 2026
smarty_hankin 主题. Designed by hankin
主页
页面
  • 关于
博主
hkthomas 管理员
136 文章 0 评论 18477 浏览
测试
测试