avatar

sunday

Sunday's Blog

  • 首页
Home ubuntu22.04服务器内存不足,如何临时解决,启用交换内存
文章

ubuntu22.04服务器内存不足,如何临时解决,启用交换内存

Posted 2024-01-24 Updated 2024-06- 22
By sunday
3~4 min read

小鸡内存不够,交换内存来凑,在ubuntu22.04 上创建交换内存,本文创建交换文件来临时解决内存不足引起服务器死机的问题

1.输入一下代码

sudo fallocate -l 1G /swapfile #一般为服务器内存的一半或者一样大小 这里为1G
##如果fallocate不可用,可以使用dd命令 sudo dd if=/dev/zero of=/swapfile bs=1G count=1
sudo chmod 600 /swapfile #只对root用户可读写
sudo mkswap /swapfile #设置文件为交换空间
sudo swapon /swapfile #激活交换文件
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab #添加系统重启后自动激活交换文件

2.输入top观察下MiB Swap 是否有数值了

Tasks: 139 total,   1 running, 138 sleeping,   0 stopped,   0 zombie
%Cpu(s): 22.7 us,  1.8 sy,  0.0 ni,  0.7 id,  0.3 wa,  0.0 hi,  0.2 si, 74.3 st
MiB Mem :    952.2 total,     89.5 free,    563.0 used,    299.7 buff/cache
MiB Swap:   1024.0 total,    960.7 free,     63.3 used.    224.9 avail Mem 

3.设置尽量使用 swap

vim /etc/sysctl.conf
#然后新增或者修改 vm.swappiness 的值 
#vm.swappiness = 60
#保存退出
sysctl -p #应用配置

软件使用
软件使用 ubuntu
License:  CC BY 4.0
Share

Further Reading

Dec 14, 2024

cursor IDE 编辑器从命令行打开

1.打开Cursor应用程序 2.按下 CMD(Ctrl) + Shift + P 打开命令面板

Dec 7, 2024

n8n使用http form-data上传文件

新建一个http node 节点,参数如下图所示,其他参数可自行设置 主要是1.开启 Send Body 2.设置n8n Binary File类型,然后在 input Data Field Name 填入上一个节点的二进制文件名即可 也可复制我的JSON文件到你的n8n上测试 My_workflo

Dec 5, 2024

supabase postgres updatedAt 自动更新时间戳

由于在prisma 创建model时,@updatedAt 不起作用 model Book { id String @id @default(dbgenerated("gen_random_uuid()")) createdAt DateTime @default(dbge

OLDER

Window11上用vscode一键打包上传部署react/vue项目,一键脚本

NEWER

linux ubuntu安装最新的nodejs版本

Recently Updated

  • nextjs15使用better-sqlite3的连接报错问题
  • nextjs + clerk + supabase + realtime 实时监听数据库更改
  • 解决nextjs15使用useLocalStorage报错的问题
  • mac上使用nodejs appium控制chrome浏览器
  • 2024年终总结

Trending Tags

nginx acme 强制跳转HTTPS nodejs 代理 mac 神器 vue3 工具 docker

Contents

©2025 sunday. Some rights reserved.

Using the Halo theme Chirpy