美文网首页
find dhcp 日志轮转

find dhcp 日志轮转

作者: 不排版 | 来源:发表于2018-03-21 10:54 被阅读39次

    查找命令
    1.[root@localhost ~]# which cat
    2.[root@localhost ~]# whereis cat
    3.[root@localhost ~]# locate install.log (更新[root@localhost ~]# updatedb)
    4.find
    find 路径 选项 值 [-exec|-ok rm -rf {} ;]
    -print: find命令将匹配到的文件输出到标准输出

    名称
    [root@localhost ~]# find / -name install.log
    类型
    [root@localhost ~]# find / -type d
    [root@localhost ~]# find / -type p -ls
    硬连接数查找
    [root@localhost ~]# find / -links 10 -ls
    根据inode号查找
    [root@robin ~]# find /root/ -inum 655934 -ls 长格式显示
    根据拥有者或者所属组
    [root@localhost home]# find /home/ -user robin
    [root@localhost home]# find /home/ -group uplooking

    [root@localhost home]# find /home/ -nouser -ls
    [root@localhost home]# find /home/ -nogroup -ls
    [root@localhost home]# find /home/ -nouser -a -nogroup -ls
    [root@localhost home]# find /home/ ( -nouser -o -nogroup ) -ls
    [root@localhost home]# find /home/ -nouser -exec rm -rf {} ;
    [root@localhost home]# find /home/ -nogroup -ok rm -rf {} ; 交互式

    文件大小
    [root@localhost tmp]# find /tmp/ -size 30M
    [root@localhost tmp]# find /tmp/ -size +30M
    [root@localhost tmp]# find /tmp/ -size -30M
    [root@localhost tmp]# find /tmp/ -size +15M -a -size -38M
    [root@localhost tmp]# find /tmp/test -size -15M -o -size +38M

    按时间
    [root@robin test]# touch -d 20151110 aa.txt 修改Access和Modify 时间
    [root@robin test]# touch -m -t 201511101212.30 aa.txt 时间和日期 修改Modify 时间

    [root@robin test]# find /tmp/test/ -mtime 2 -ls
    [root@robin test]# find /tmp/test/ -mtime -10
    [root@robin test]# find /tmp/test/ -mtime +10
    [root@robin test]# find /tmp/test/ -mtime -5 -o -mtime +10
    [root@robin test]# find /tmp/test/ -mtime +10 -a -mtime -5

    按权限
    [root@localhost test]# find /tmp/ -perm 705 正好匹配
    [root@localhost test]# find /tmp/test/ -perm +100 任意匹配
    [root@localhost test]# find /tmp/test/ -perm -201 完全匹配

    练习:
    查找在/root目录下 大小大约20k 小于100k文件 拷贝到/tmp下去
    [root@localhost test]# find /root/ -size +20k -a -size -100k -exec cp -r {} /tmp/ ;
    [root@localhost test]# cp -r find /root/ -size +20k -a -size -100k /tmp/

    查找系统中属于robin或者zorro的文件 拷贝到/tmp下
    [root@localhost test]# find / ( -user zorro -o -user robin ) -exec cp -r {} /tmp/ ;

    [root@localhost ~]# find / -type f |xargs file
    [root@localhost tmp]# cut -d: -f 1 /etc/passwd | xargs mkdir

    系统服务
    DHCP(动态分配IP地址)
    服务端:
    安装软件:dhcp-4.1.1-34.P1.el6.x86_64.rpm
    配置文件:/etc/dhcp/dhcpd.conf
    cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
    更改主机地址:跟VM1卡地址在一个网段
    端口:67服务器 68客户端

    [root@localhost home]# vim /etc/dhcp/dhcpd.conf
    subnet 10.10.10.0 netmask 255.255.255.0 {
    range 10.10.10.100 10.10.10.254;
    option domain-name-servers 202.106.0.20;
    option domain-name "internal.example.org";
    option routers 10.10.10.1;
    default-lease-time 600;
    max-lease-time 7200;
    }
    启动服务:service dhcpd restart

    启动服务

    客户端测试 网卡设置成dhcp

    C S
    --------DHCP DISCOVER--------->
    <-------DHCP OFFER-------------
    --------DHCP REQUEST---------->
    <-------DHCP ACK---------------

    租约文件:
    服务端:/var/lib/dhcpd/dhcpd.leases
    客户端:/var/lib/dhcpd/dhclient/dhclient-eth1.leases

    dhclient -------- 获取地址的进程 killall dhclient (杀死进程重新获取ip)

    指定ip地址分配:
    [root@localhost home]# vim /etc/dhcp/dhcpd.conf
    host client1 {
    hardware ethernet 00:50:56:2e:dd:17;
    fixed-address 10.10.10.250;
    }

    日志服务器
    日志存放位置:/var/log
    日志服务启动:service rsyslog restart
    日志配置文件:/etc/rsyslog.conf

    AAAA.BBBB CCCC

    AAAA 产生日志的对象
    mail
    authpriv
    cron
    uucp
    news

    BBBB 日志级别
    debug
    info
    notice
    warnning
    error
    crit
    alert
    emerg

    mail.info mail对象产生正常信息以上级别
    mail.=info mail对象产生的日志只记录正常信息
    mail.!=info mail对象产生的日志除了正常信息以外记录

    CCCC 保存日志的位置
    1.发送到终端
    .info;mail.none;authpriv.none;cron.none /dev/pts/3
    2.发送个用户
    *.info;mail.none;authpriv.none;cron.none robin
    3.发送到文件
    *.info;mail.none;authpriv.none;cron.none /tmp/log.log

    日志的集中管理
    服务端:
    UDP模式传输数据
    1.[root@robin ~]# vim /etc/rsyslog.conf
    $ModLoad imudp
    $UDPServerRun 514
    [root@robin ~]# service rsyslog restart

    TCP模式传输数据
    [root@robin ~]# vim /etc/rsyslog.conf
    $ModLoad imtcp
    $InputTCPServerRun 514

    客户端:
    UDP
    [root@data1 ~]# vim /etc/rsyslog.conf
    .info;mail.none;authpriv.none;cron.none @172.16.110.1
    [root@data1 ~]# service rsyslog restart
    TCP
    [root@data1 ~]# vim /etc/rsyslog.conf
    authpriv.
    @@172.16.110.1
    [root@data1 ~]# service rsyslog restart

    日志轮转
    配置文件:/etc/logrotate.conf
    vim /etc/logrotate.conf
    weekly 每周切割日志
    rotate 4 保存最近4周日志
    create 创建新的日志文件
    dateext 日志做为扩展名
    include /etc/logrotate.d 子配置文件位置

    [root@robin logrotate.d]# vim robin
    /tmp/robin.log {
    missingok 日志丢失不提示,删除robin.log后再切日志提示没有这个文件
    notifempty 空文件不切割
    daily 每天
    rotate 7 保留7份
    dateext 日期格式
    create 0777 robin robin 如果后续日志权限时777那当前日志权限必须是777
    }

    [root@robin logrotate.d]# logrotate -f /etc/logrotate.d/robin

    作业:
    1.设置虚拟机网卡vmnet5为hostonly,并且在宿主机对应网卡vmnet5的ip地址为 192.168.10.1,以vmnet5的网段搭建dhcp服务器,虚拟机获取地址
    2.将虚拟机的messages日志以udp方式传输给宿主机(设置主机名)

    nginx日志轮转
    cat /etc/logrotate.d/nginx
    /usr/local/nginx/logs/*.log{
    daily
    notifempty
    dateext
    rotate 7
    missingok
    sharedscripts
    postrotate
    if [ -f /usr/local/nginx/log/nginx.pid ]
    then
    kill -USR1 cat /usr/local/nginx/log/nginx.pid 读取pid号
    fi
    endscript
    create 0644 root root 切割后,再新建一个access.log 日志
    }

    crontab -e
    59 23 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx

    相关文章

      网友评论

          本文标题:find dhcp 日志轮转

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