系统日志及时间同步

hostnamectl set-hostname 主机名   ##更改主机名

1.程序生成日志

rsyslog采集日志,关闭后开启会采集没有采集的日志,采集规则配置文件

cat /var/log/messages


> /var/log/messages  #清空

vim /etc/rsyslog.conf


auth.*

*.*      /var/log/lin


扫描二维码关注公众号,回复: 31956 查看本文章

auth  #用户登录日志

authpriv  #服务认证日志
kern  #内核日志
cron   定时任务日志
lpr  打印机日志
mail  邮件日志
news 新闻
user 用户相关程序日志
local 1-7  用户自定义日志

日志级别
debug  系统调试信息
info   常规信息
warning 警告信息
err  报错(级别低,阻止了某个功能不能正常工作)
crit  报错(级别高,阻止整个软件或系统的不能正常工作)
alert  需要立即修改的信息
emerg  内核崩溃
none  不采集任何日志信息

系统常用日志

/var/log/messag  所有日志级别的常规信息,不包含邮件,服务认证,定时任务
/var/log/maillog  邮件日志
/var/log/secure  服务认证日志
/var/log/cron    定时任务日志

2.日志远程同步
发送方
vim /etc/rsyslog.conf
*.*   @172.25.254.252   #接收地址

UDP快,TCP稳定


systemctl restart rsyslog.service   #重启网络
接收方
 vim /etc/rsyslog.conf

第15 16行

 

systemctl restart rsyslog.service  #重启网络
systemctl  stop firewalld      #关闭火墙

systemctl  disabled firewalld   #开机不开启火墙

测试


3.定义日志采集格式
接收方
vim /etc/rsyslog.conf
$template  格式名称,“日志采集格式”

*.info;mail.none;authpriv.none;cron.none    /var/log/messages;格式名称

    


$template lin,"%timegenerated% %FROMHOST-IP% %syslogtag% %msg%\n"

                                生成时间                来源主机ip              生成程序      内容  换行

cat /var/log/messages



4.journalctl   #直接查看内存中日志

1)journalctl  -f   #监控日志


2)journalctl   -n 3  #查看最新3个


3)journalctl   --since 时间 --until 时间  #查看一段时间的日志


4)journalctl   -p err  #查看报错  ctrl+c结束


5)journalctl  -o  verbose  #查看详细参数   ——pid=651  journalctl  _pid=651

 

6)journalctl _PID=81

7)对systend-journal管理
默认此程序只能查看不能保存,那么关机后再开机,只能查看开机后的,日志因为保存在内存中的,所以关机后就被清空了,如何让systend-journal保存日志到硬盘中
  mkdir /var/log/journal
  chgrp systemd-journal /var/log/journal
  chmod g+s /var/log/journal
  killall -1 systemd-journald   #刷新进程

  journalctl -n 3


  date
  reboot

  journalctl

以前的日志仍然在

  5.时间同步
在服务器端共享时间  要关闭火墙
 vim /etc/chrony.conf
29行 local stratum 10         #开启时间共享功能并设置共享级别,开启后本机不同步别人时间

22行 allow 172.25.254.0/24    #允许哪些客户端访问本机共享的时间


 systemctl restart chronyd.service

在客户端

  vim /etc/chrony.conf


  systemctl restart chronyd.service

  chronyc sources -v



6.时区

 1) timedatectl list-timezones              #列出所有时区


2)timedatectl set-timezone Asia/Shanghai  #修改时区

      timedatectl

       

3)timedatectl set-local-rtc 0             #使用UTC时间

      vim /etc/adjtime

 


4)timedatectl set-local-rtc 1             #使用当地时间

      vim /etc/adjtime



5)timedatectl set-time "2018-11-11 11:11:11"
  date
 

7.at

1)at 时间


2)at now+1min


3)at -l     #查看任务


4)at -c 3   #查看具体任务


5)at -r 3   #撤销任务


6)黑名单

vim /etc/at.deny
[root@node1 ~]# useradd lee
[root@node1 ~]# useradd lin

[root@node1 ~]# vim /etc/at.deny

把lin添加到黑名单

[root@node1 ~]# su - lin  
[lee@node1 ~]$ at now+2min
You do not have permission to use at. 
[lee@node1 ~]$ logout
[root@node1 ~]# su - lee
[lin@node1 ~]$ at now+2min
at> <EOT>
job 10 at Sat Apr 14 16:52:00 2018

[lin@node1 ~]$ logout


7)白名单
[root@node1 ~]# touch /etc/at.allow      #建立白名单,黑名单失效,只有root可以执行      
[root@node1 ~]# su - lin   
Last login: 六 4月 14 16:50:44 CST 2018 on pts/0
[lin@node1 ~]$ at now+2min
You do not have permission to use at.
[lin@node1 ~]$ logout

[root@node1 ~]# vim /etc/at.allow 

  编辑文件,把lin添加到白名单

[root@node1 ~]# su - lin
Last login: 六 4月 14 16:50:14 CST 2018 on pts/0
[lee@node1 ~]$ at now+2min
at> <EOT>
job 11 at Sat Apr 14 16:54:00 2018



猜你喜欢

转载自blog.csdn.net/lin_made/article/details/79982591
今日推荐