美文网首页
腾讯云主机mysql 扩容操作

腾讯云主机mysql 扩容操作

作者: 狸猫家的DBA | 来源:发表于2017-06-06 17:15 被阅读0次
    日期 作者 版本 备注
    2017-06-06 yangxer v1.0 初版

    扩容背景:

    腾讯云实例上安装的 mysql硬盘空间使用紧张, 购买新的硬盘后计划扩容

    # 检查扩容前磁盘使用情况
    shell> df -hT
    Filesystem    Type    Size  Used Avail Use% Mounted on
    /dev/vda1     ext3    7.9G  4.3G  3.3G  57% /
    /dev/vdb       xfs    1.5T  1.4T  148G  91% /data
    
    # 检查磁盘情况, 下面显示 /dev/vdd 未有分区
    shell> fdisk -l
    
    Disk /dev/vda: 8589 MB, 8589901824 bytes
    255 heads, 63 sectors/track, 1044 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x70068116
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *           1        1044     8385898+  83  Linux
    
    Disk /dev/vdb: 1610.6 GB, 1610612736000 bytes
    16 heads, 63 sectors/track, 3120761 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    
    
    Disk /dev/vdc: 2147 MB, 2147483648 bytes
    16 heads, 63 sectors/track, 4161 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    
    
    Disk /dev/vdd: 3221.2 GB, 3221225472000 bytes
    16 heads, 63 sectors/track, 6241523 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    
    # 尝试挂载失败
    shell> mount /dev/vdd /data0
    mount: you must specify the filesystem type
    

    检查是否安装 parted, 如果没有需要安装

    shell> which parted
    /sbin/parted
    

    检查是否加载 xfs 模块

    shell> lsmod | grep xfs
    xfs                  1128471  2 
    exportfs                4236  1 xfs
    

    使用 parted 对大于 2T 的盘进行分区

    shell> parted /dev/vdd
    GNU Parted 2.1
    Using /dev/vdd
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) p                                                                
    Error: /dev/vdd: unrecognised disk label
                                                                   
    (parted) mklabel                                                          
    New disk label type? gpt  
    
    # 这个命令将 硬盘容量全部分配到 /dev/vdd1                      
    (parted) mkpart /dev/vdd1 xfs 0% 100%    
                                         
    (parted) p                                                                
    Model: Virtio Block Device (virtblk)
    Disk /dev/vdd: 3221GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    
    Number  Start   End     Size    File system  Name       Flags
     1      1049kB  3221GB  3221GB               /dev/vdd1
    
    (parted) quit                                                             
    Information: You may need to update /etc/fstab. 
    

    格式化分区, 可能会较慢

    shell> mkfs.xfs /dev/vdd1
    meta-data=/dev/vdd1              isize=256    agcount=4, agsize=196607872 blks
             =                       sectsz=512   attr=2, projid32bit=0
    data     =                       bsize=4096   blocks=786431488, imaxpct=5
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0
    log      =internal log           bsize=4096   blocks=383999, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    

    查看是否分区成功:

    shell> fdisk -l
    WARNING: GPT (GUID Partition Table) detected on '/dev/vdd'! The util fdisk doesn't support GPT. Use GNU Parted.
    
    
    Disk /dev/vdd: 3221.2 GB, 3221225472000 bytes
    255 heads, 63 sectors/track, 391625 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vdd1               1      267350  2147483647+  ee  GPT
    shell> ls -l /dev/vdd*
    brw-rw---- 1 root disk 252, 48 Jun  6 14:22 /dev/vdd
    brw-rw---- 1 root disk 252, 49 Jun  6 14:20 /dev/vdd1
    
    

    挂载新分区

    # 挂载
    shell> mount /dev/vdd1 /data0
    
    shell> df -hT
    Filesystem    Type    Size  Used Avail Use% Mounted on
    /dev/vda1     ext3    7.9G  4.3G  3.3G  57% /
    /dev/vdb       xfs    1.5T  1.4T  148G  91% /data
    /dev/vdd1      xfs    3.0T   33M  3.0T   1% /data0
    
    # 取消挂载
    shell> umount /dev/vdd1
    shell> df -hT
    Filesystem    Type    Size  Used Avail Use% Mounted on
    /dev/vda1     ext3    7.9G  4.3G  3.3G  57% /
    /dev/vdb       xfs    1.5T  1.4T  148G  91% /data
    

    写入开机自启动

    shell> cat /etc/fstab 
    /dev/vda1            /                    ext3       noatime,acl,user_xattr 1 1
    LABEL=lswap            swap                 swap       defaults 0 0
    proc                 /proc                proc       defaults              0 0
    sysfs                /sys                 sysfs      noauto                0 0
    debugfs              /sys/kernel/debug    debugfs    noauto                0 0
    devpts               /dev/pts             devpts     mode=0620,gid=5       0 0
    /dev/vdd1            /data0               xfs        defaults              1 2
    
    shell> mount -a
    
    shell> df -hT
    Filesystem    Type    Size  Used Avail Use% Mounted on
    /dev/vda1     ext3    7.9G  4.3G  3.3G  57% /
    /dev/vdb       xfs    1.5T  1.4T  148G  91% /data
    /dev/vdd1      xfs    3.0T   33M  3.0T   1% /data0
    

    重启机器验证:

    shell> reboot
    shell> df -hT
    Filesystem    Type    Size  Used Avail Use% Mounted on
    /dev/vda1     ext3    7.9G  4.3G  3.3G  57% /
    /dev/vdd1      xfs    3.0T  9.3G  3.0T   1% /data0
    /dev/vdb       xfs    1.5T  1.4T  148G  91% /data
    

    开启screen, 拷贝数据

    shell> screen -S liuys
    shell> cp -rp /data/* /data0/
    

    颠倒分区, 启动实例, 卸载旧硬盘, 通知基础运维回收硬盘

    
    

    注意事项

    • ** 扩容时是在从库操作, 将流量引到主库, 并关闭当前从数据库 **

    • ** 时间允许可以考虑对两块硬盘进行压测对比, 还可以对 cp前后文件进行 MD5 校验 **

    • ** 扩容完成后,直接进行主从切换有性能下降的风险, 因为数据还未load到 buffer_pool 中, 对一个忙碌的数据库应该选择在闲时 **

    相关文章

      网友评论

          本文标题:腾讯云主机mysql 扩容操作

          本文链接:https://www.haomeiwen.com/subject/tucnfxtx.html