Centos7虚拟内存设置
本文最后更新于 1566 天前,其中的信息可能已经有所发展或是发生改变。

Centos7虚拟内存设置

因为新公司的项目占用内存有点大,但是机器内存没那么多,进程总被杀死,因此设置一下虚拟内存

查看一下自己的服务器swap大小

free -h

image-20220506163516989

创建虚拟内存缓存文件

一般设置为物理内存的2倍,在一个目录下创建swap文件,但是如果内存鸡儿大的话,那就看情况就行…

[root@localhost ~] dd if=/dev/zero of=/root/swapfile bs=1M count=8192
记录了8192+0 的读入
记录了8192+0 的写出
8589934592字节(8.6 GB)已复制,17.1021 秒,502 MB/秒

构建swap

[root@localhost ~] mkswap /root/swapfile
正在设置交换空间版本 1,大小 = 8388604 KiB
无标签,UUID=c13a3fc1-0a0b-4c73-963e-c383df554dff

激活swap

[root@localhost ~] swapon /root/swapfile
swapon: /root/swapfile:不安全的权限 0664,建议使用 0600。

激活后,查看一下swap的大小

[root@localhost ~] free -h

永久生效

上述操作仅仅在本次开机有效,重启失效,我们需要保存一下配置

vim /etc/fstab

/dev/mapper/centos-swap none swap sw 0 0这行注释掉,新增一行

/root/swapfile swap swap defaults 0 0

image-20220506164342689

修改虚拟内存大小

如果已经设置了虚拟内存,想修改一下大小,或者取消设置虚拟内存的,
只需关闭swap并删除之前创建的swapfile文件即可

关闭swap

swapoff /root/swapfile

删除/root/swapfile

rm -f /root/swapfile

然后重复设置以下步骤即可:

  1. 创建虚拟内存文件
  2. 构建+激活swap
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇