📒
notebook
  • Notebook
  • DevOps
    • Git
      • 常见 Git 操作
      • 使用 SSH 连接 Git 远程仓库
      • 使用 GPG Keys 签名 Git 提交
      • Git on macOS
    • Docker
      • macOS 安装配置 Docker
      • CentOS7 安装配置 Docker CE
  • Linux
    • CentOS
      • CentOS7 安装配置 vsftpd
      • CentOS7 设置虚拟内存
      • CentOS7 使用 acme.sh 自动申请免费 SSL 证书
      • CentOS7 修改 SSH 端口号
      • CentOS7 主机初始设置
      • 阿里云 CentOS 主机常见设置
      • CentOS7 安装配置 SS
    • nginx
      • nginx 配置 301 永久重定向
      • nginx 使用 SSL证书配置 HTTPS
      • CentOS7 安装配置 nginx
      • nginx 配置 gzip 压缩
      • nginx 代理静态网页
  • Server
    • Ghost
      • macOS 安装配置 Ghost
      • CentOS7 安装配置 Ghost
    • npm & Yarn
      • Yarn 常用命令
      • CentOS7 安装卸载升级 Yarn
      • npm & Yarn 常见错误处理
      • macOS 安装卸载升级 Yarn
    • Node.js
      • Awesome Node.js
      • CentOS7 安装卸载升级 Node.js
      • macOS 安装卸载升级 Node.js
  • Web
    • Ionic
      • 创建 Ionic & Angular 项目
      • 使用 Ionic & Cordova 构建 Android 应用
      • macOS 搭建 Ionic & Cordova 开发环境
    • CSS
      • CSS 排版技巧
      • Awesome CSS
      • CSS 三栏自适应布局
    • Angular
      • Awesome Angular
      • 创建 Angular 项目
    • HTML
      • HTML head 常用标签
      • HTML 常用 DTD 声明
      • 常用网页语义结构
    • Web 技术标准
    • JavaScript
      • Awesome JavaScript
      • JavaScript 的 eval() 函数详解
  • Mobile
    • H5
      • iOS Safari Web App 配置
  • Development Environment
    • Development Utilities
      • Awesome Windows
      • macOS 安装配置 Homebrew
      • Awesome macOS
      • macOS 安装配置 iTerm2
    • FEED
      • 常用 Gulp 插件
  • Network
    • 常见公共 DNS
  • Technology Stacks for Web Front-End Development
Powered by GitBook
On this page
  • 查看当前虚拟内存
  • 增加虚拟内存
  • 删除虚拟内存

Was this helpful?

  1. Linux
  2. CentOS

CentOS7 设置虚拟内存

查看当前虚拟内存

以 MiB 为单位查看当前系统内存使用情况:

free -m
              total        used        free      shared  buff/cache   available
Mem:            990         114          63          12         812         720
Swap:             0           0           0

Swap 交换分区大小即为当前虚拟内存大小。

增加虚拟内存

创建一个 1GiB 大小空文件 /var/swap :

sudo dd if=/dev/zero of=/var/swap bs=1M count=1024

Tips:

  • if=/dev/zero 表示读入空字符串

  • of 指定输出文件

  • bs 指定单次读写的块大小(bytes)

  • count 指定拷贝的快数量

  • bs 和 count 的乘积大小即为输出的文件大小,一般虚拟内存大小设置为物理内存的1-2倍

  • OpenVZ 架构的 VPS 不支持手动添加交换分区

设置该文件权限为只有拥有者(root)可以读写:

sudo chmod 600 /var/swap

将该文件设置为交换分区(虚拟内存文件):

sudo mkswap /var/swap

启用交换分区:

sudo swapon /var/swap

切换至 root 用户,写入交换分区信息到开机分区挂载配置文件中:

echo '/var/swap swap swap default 0 0' >> /etc/fstab

删除虚拟内存

停止交换分区:

sudo swapoff /var/swap

删除交换分区文件:

sudo rm -rf /var/swap

切换至 root 用户,修改开机分区挂载配置文件:

vim /etc/fstab

删除交换分区信息:

/var/swap swap swap default 0 0

保存退出。

PreviousCentOS7 安装配置 vsftpdNextCentOS7 使用 acme.sh 自动申请免费 SSL 证书

Last updated 4 years ago

Was this helpful?