zoukankan      html  css  js  c++  java
  • 内存不足导致mysql关闭,CentOS6.5增加swap分区

    某日发现mysql自动关闭了,查找错误日志发现以下错误

    2017-07-14 13:07:30 5494 [Note] InnoDB: Initializing buffer pool, size = 128.0M
    InnoDB: mmap(137363456 bytes) failed; errno 12
    2017-07-14 13:07:30 5494 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
    2017-07-14 13:07:30 5494 [ERROR] Plugin 'InnoDB' init function returned error.
    2017-07-14 13:07:30 5494 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    2017-07-14 13:07:30 5494 [ERROR] Unknown/unsupported storage engine: InnoDB
    2017-07-14 13:07:30 5494 [ERROR] Aborting  

     分析说明,mysql的innodb的buffer pool需要128m的内存支持,但我的服务器内存情况如下

    [root@vm172-31-0-13 home]# free -m
                 total       used       free     shared    buffers     cached
    Mem:          1877       1804         72          0          5        139
    -/+ buffers/cache:       1659        217
    Swap:         0          0       0
    

    可见,剩余内存已经不足128M,而且没有swap分区,至此,mysql自动关闭了。

    swap分区可以见建系统的时候创建,也可以后面用创建文件的方式创建。

    我们用后者方式来创建:

    1,使用dd命令创建一个swap分区

    dd if=/dev/zero of=/home/swap bs=1M count=4096 

    这样就创建了一个分区大小为4G的/home/swap文件,接下来格式化该分区文件。 

    2,格式化/home/swap文件。

     mkswap /home/swap  

    3,用swapon命令把/home/swap文件分区划成swap分区

    [root@cms home]# swapon /home/swap 
    [root@cms home]# free -m
                 total       used       free     shared    buffers     cached
    Mem:          7872       7730        142          0         70       6394
    -/+ buffers/cache:       1264       6608
    Swap:         4095          0       4095

    4,修改/etc/fstab文件添加/home/swap swap swap default 0 0,即使重启也能自动挂载。

    [root@cms home]# vi /etc/fstab 
    #
    # /etc/fstab
    # Created by anaconda on Tue Jan 26 21:10:02 2016
    #
    # Accessible filesystems, by reference, are maintained under '/dev/disk'
    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
    #
    UUID=f8cb78d5-8419-4bcf-8684-9e8a94480f22 /                       ext4    defaults        1 1
    UUID=9e4bacd3-490c-4e87-a5e0-fec240a3e229 /usr                    xfs     defaults        1 2
    tmpfs                   /dev/shm                tmpfs   defaults        0 0
    devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
    sysfs                   /sys                    sysfs   defaults        0 0
    proc                    /proc                   proc    defaults        0 0
     /home/swap             swap                    swap    default         0 0
    "/etc/fstab" 16L, 788C written
    

      

  • 相关阅读:
    CSS:Tutorial three
    CSS:Tutorial two
    CSS:Tutorial one
    JavaScript: 代码简洁之道
    python数据结构:pandas(1)
    python数据结构:numpy
    python函数之format()
    算法(1)
    python基础面试题:(1)
    python学习笔记(13):python并发编程以及系统常用模块
  • 原文地址:https://www.cnblogs.com/zenghansen/p/7169100.html
Copyright © 2011-2022 走看看