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

1.程序生成日志

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

cat /var/log/messages

系统日志及时间同步

> /var/log/messages  #清空

系统日志及时间同步

vim /etc/rsyslog.conf

系统日志及时间同步

系统日志及时间同步

auth.*

*.*      /var/log/lin

系统日志及时间同步

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
[[email protected] ~]# useradd lee
[[email protected] ~]# useradd lin

[[email protected] ~]# vim /etc/at.deny

把lin添加到黑名单

系统日志及时间同步

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

[[email protected] ~]$ logout

系统日志及时间同步

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

[[email protected] ~]# vim /etc/at.allow 

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

系统日志及时间同步

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

系统日志及时间同步


相关文章: