• nfs详解及实现全网备份


    1.统一hosts

    cat /etc/hosts
    172.16.1.5    lb01
    172.16.1.6    lb02
    172.16.1.7    web02
    172.16.1.8    web01
    172.16.1.51    db01
    172.16.1.31    nfs01
    172.16.1.41    backup
    172.16.1.61    m01
    

    2.服务端软件安装及启动

    rpm -qa nfs-utils rpcbind
    yum -y install nfs-utils rpcbind
    # 注意启动顺序,rpcbind在前,nfs在后
    /etc/init.d/rpcbind start
    # 查看有没有'房源'
    rpcinfo -p localhost
    # 使用yum/rpm包安装的软件,推荐使用/etc/init.d/nfs start这样的启动方式
    /etc/init.d/nfs start
    chkconfig nfs on
    chkconfig rpcbind on
    # 开机启动的顺序在脚本中写着
    ls /etc/rc.d/rc3.d/ | egrep "nfs|rpcbind"
    S13rpcbind
    S14nfslock
    S30nfs
    

    3.服务器端配置

    mkdir /data
    chown nfsnobody.nfsnobody /data/
    # sync是直接写入磁盘,async是先写到缓存,再统一写到磁盘
    cat /etc/exports
    /data 172.16.1.0/24(rw,sync)
    # reload的作用:让已经到达服务器的连接正常被处理,并拒绝新连接
    /etc/init.d/nfs reload
    # reload相当于下面的命令,exportfs还支持不用配置文件就可以把目录共享出去
    /usr/sbin/exportfs -rv
    /usr/sbin/exportfs -o rw,sync 172.16.1.0/24:/data2
    # 查看有没有把目录'共享出去'
    showmount -e 172.16.1.31
    Export list for 172.16.1.31:
    /data 172.16.1.0/24
    # 查看nfs挂载出去的目录的所有情况
    cat /var/lib/nfs/etab
    

    4.客户端(web01)安装及启动,优化挂载

    yum -y install nfs-utils rpcbind
    /etc/init.d/rpcbind start
    chkconfig rpcbind on
    # 挂载之前检测
    showmount -e 172.16.1.31
    Export list for 172.16.1.31:
    /data 172.16.1.0/24
    mount -t nfs 172.16.1.31:/data /mnt
    umount /mnt
    # 如果发现了device is busy,不要用fuser此类的命令,直接用lf(lazy、force)参数
    umount -lf /mnt
    # 优化的参数有下面这些,但默认的其实就行(性能参数越多,速度可能越慢)
    mount -t nfs -o nosuid,noexec,nodev,noatime,nodiratime,intr,rsize=131072,wsize=131072 172.16.1.31:/data /mnt
    echo 'mount -t nfs 172.16.1.31:/data /mnt' >> /etc/rc.local
    # 服务端进行NFS内核优化
    cat >> /etc/sysctl.conf << EOF
    net.core.wmem_default = 8388608
    net.core.rmem_default = 8388608
    net.core.rmem_max = 16777216
    net.core.wmem_max = 16777216
    EOF
    sysctl -p
    

    5.故障修复案例:人为失误损坏fstab文件,错误导致系统无法启动

    进入救援模式:
    mount -o rw,remount /
    然后修改/etc/fstab
    文件系统只读故障修复案例:
    问题产生原因:
    a.RSYNC bug
    b.文件系统内部自动一致性导致称为ro(只读)
    解决办法:进入救援模式
    mount -o rw,remount /
    

    6.如何把挂载nfs信息写在/etc/fstab中,并能开机挂载成功

    172.16.1.31:/mnt  /mnt  nfs defaults  0 0
    chkconfig netfs on 
    all_squash:将远程访问的所有普通用户映射为匿名用户或用户组(一般为nfsnobody)
    root_squash:将root用户及所属用户组都映射为匿名用户
    # 客户端/etc/exports中添加如下配置:
    /data1 172.16.1.0/24(rw,sync,all_squash,root_squash,anonuid=888,anongid=888)
    useradd -u 888 zuma -s /sbin/nologin -M
    chown -R zuma.zuma /data1/
    # 就这样,客户端不论是root来还是普通用户来,都被映射为zuma这个用户.
    

    7.实现全网备份脚本

    #!/bin/bash
    IP=$(ifconfig eth1|awk -F '[ :]+' 'NR==2 {print$4}')
    Path=/backup
    if [$(date +%w) -eq 0]
    then
        Time="week_$(date +%F-%w -d "-1day")"
    else
        Time=$(date +%F -d "-1day")
    fi
    mkdir $Path/$IP/ -p
    
    cd /
    tar zcvfh $Path/$IP/backup_$Time.tar.gz var/spool/cron/root etc/rc.local etc/sysconfig/iptables var/www/html/* app/logs/*
    md5sum $Path/$IP/backup_$Time.tar.gz > $Path/$IP/flag_$Time.log
    rsync -az $Path/ rsync_backup@172.16.1.41::conf --password-file=/etc/rsync.password
    find /backup/ -type f -mtime +7 ( -name "*.tar.gz" -o -name "*.log" ) | xargs rm -f
    

    8.find实战

    # 找7天以内指定的文件
    find /backup/ -type f -mtime -7 ( -name "*.tar.gz" -o -name "*.log" )
    # backup上保留180天以内的数据,但周六的数据都保留
    find /backup/ -type f -mtime +180 ! -name "*week*_6*"|xargs rm -f
    # 查找当天的flag日志,并检查文件完整性(备份服务器的目录结构得和客户端一模一样)
    find /backup -type f -name "*${Time}*.log"|xargs md5sum -c
    

    9.备份服务器上的脚本

    cat check_and_del.sh
    Path=/backup
    if [$(date +%w) -eq 0]
    then
        Time="week_$(date +%F-%w -d "-1day")"
    else
        Time=$(date +%F -d "-1day")
    fi
    LANG=en
    find /backup -type f -name "*${Time}*.log"|xargs md5sum -c >> $Path/${Time}_result.log 2>&1
    mail -s "$Time bak result" oldboytraining@163.com < $Path/${Time}_result.log
    find /backup/ -type f -mtime +180 ! -name "*week*_6*"|xargs rm -f
    
  • 相关阅读:
    QTimer::singleShot
    Qt 建立带有子项目的工程
    Qt GlobalColor及其显示
    QT自定义图形项中的boundingRect()和shape()函数的理解
    QT setZValue() 函数
    C++中explicit的作用及用法
    QT中foreach的使用
    QT代码封装成dll和lib文件及使用
    Qt智能指针QScopedPointer
    Qt的四个常见的图像叠加模式
  • 原文地址:https://www.cnblogs.com/fawaikuangtu123/p/10045944.html
Copyright © 2020-2023  润新知