swap 分区

Swap分区在系统的物理内存不够用的时候,把硬盘空间中的一部分空间释放出来,以供当前运行的程序使用。

基础命令:

mkswap /devices : 格式化成swap格式
swapon /devices : 激活swap ,加入到swap分区中
开机自动启动新添加的swap分区: /etc/fstab /devices swap swap defaults 0 0

实验步骤:

  1. 建立分区
    [root@xinsz08 ~]# gdisk /dev/sdb
Command (? for help): n  #新建分区Partition number (2-128, default 2):     #回车First sector (34-41943006, default = 2099200) or {+-}size{KMGTP}:  #回车Last sector (2099200-41943006, default = 41943006) or {+-}size{KMGTP}: +1G  #给1GCurrent type is 'Linux filesystem'Hex code or GUID (L to show codes, Enter = 8300):  #回车Changed type of partition to 'Linux filesystem'Command (? for help): w  #保存Do you want to proceed? (Y/N): y

2) 查看是否分区成功

[root@centos7-xinsz08 ~]# ll /dev/sdb*brw-rw----. 1 root disk 8, 16 2月  26 15:36 /dev/sdbbrw-rw----. 1 root disk 8, 17 2月  26 15:36 /dev/sdb1brw-rw----. 1 root disk 8, 18 2月  26 15:37 /dev/sdb2

  1. 格式化
[root@centos7-xinsz08 ~]# mkswap /dev/sdb2正在设置交换空间版本 1,大小 = 1048572 KiB无标签,UUID=bf1788b2-c1f5-4f89-bb62-cd91617ee8dc

对比( 激活swap空间之前的对比)

[root@centos7-xinsz08 ~]# free -m  total        used        free      shared  buff/cache   availableMem:           3770         454        2938          14         378        3082Swap:          2047           0        2047[root@centos7-xinsz08 ~]# swapon /dev/sdb2 [root@centos7-xinsz08 ~]# free -m  total        used        free      shared  buff/cache   availableMem:           3770         452        2940          14         377        3084Swap:          3071           0        3071

使用 文件增加swap空间?
阿里云默认的没有swap空间,如何增加swap?

1) 使用dd命令创建个500M大小的文件[root@centos7-xinsz08 ~]# dd  if=/dev/zero of=swap_file bs=1M count=500记录了500+0 的读入记录了500+0 的写出524288000字节(524 MB)已复制,12.2954 秒,42.6 MB/秒[root@centos7-xinsz08 ~]# ll -h swap_file -rw-r--r--. 1 root root 500M 2月  26 15:46 swap_file[root@centos7-xinsz08 ~]# chmod 0600 swap_file 2) 把500M的文件格式化成swap [root@centos7-xinsz08 ~]# mkswap -f swap_file 正在设置交换空间版本 1,大小 = 511996 KiB无标签,UUID=def65bf9-7143-4734-9801-d3d8bb583061[root@centos7-xinsz08 ~]# free -m  total        used        free      shared  buff/cache   availableMem:           3770         455        2423          14         891        3075Swap:          3071           0        30713) 激活swap空间[root@centos7-xinsz08 ~]# swapon /root/swap_file4) 查看是否被激活[root@centos7-xinsz08 ~]# free -m  total        used        free      shared  buff/cache   availableMem:           3770         456        2423          14         891        3074Swap:          3571           0        3571[root@centos7-xinsz08 ~]#
©著作权归作者所有:来自51CTO博客作者互联网老辛的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. MySQL InnoDB 共享表空间和独立表空间
  2. Oracle分区表之分区范围扫描(PARTITION RANGE ITERATOR)与位图范围
  3. 【linux】循序渐进学运维-基础篇-磁盘加密解密技术
  4. SYSAUX表空间占用过大情况下的处理(AWR信息过多)
  5. 【DB笔试面试352】在Oracle数据库中,哪些操作会导致索引失效?--UNU
  6. Linux 磁盘分区管理
  7. 磁盘挂载问题:Fdisk最大只能创建2T分区的盘,超过2T使用parted
  8. 将磁盘误挂载到根分区下的问题处理记录
  9. 数据文件、表空间offline用法及区别

随机推荐

  1. 现在学c语言用什么软件
  2. 怎么精通C语言?
  3. c反射和序列化是什么
  4. c#用什么软件编程?
  5. c语言需要什么基础
  6. c语言 三种求回文数的算法
  7. asp文件用什么打开
  8. c语言怎么编译(详细示例)
  9. Unity 3D 浅谈Shader 运行时状态及渲染模
  10. c语言工程师的工作是什么