时间定时同步
修改系统时间由三种方法:
一、修改时区
cp /etc/localtime /etc/localtime.bak
ln -svf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#修改为中国的东八区
vim /etc/sysconfig/clock
ZONE="Asia/Shanghai"
UTC=false
ARC=false
#与时间服务器同步
ntpdate ntp服务器的ip
二、配置新的时间
#日期设定
date -s 2013/09/26
#时间设定
date -s "11:47:06"
date -s "12:00:00 2013-12-06"
....
#date是显示的系统的OS时间
#clock是显示的BIOS的时间
#查看硬件的时间
hwclock [-rw]
-r 查看现有BIOS时间。默认为-r参数
-w 将现在的linux系统时间写入BIOS中
-s (systohc)将硬件时间调整为和目前的系统时间一半
三、时间自动同步
#1.开机自动网络校时
cat /etc/rc.d/rc.local
/usr/sbin/ntpdate -u 192.168.10.80
#2.设置定时计划任务
#yum install -y ntpdate (yum安装时间同步命令)
crontab -e
#加入内容
*/5 * * * * root ntpdate 192.168.10.80 #每隔五分钟与时间服务器同步一次时间
日志定时清理
清理日志脚本
#!/bin/bash
date >>/home/wdhis/logs/catalina.out
echo "del file start....." >> /home/wdhis/logs/catalina.out
find /home/wdhis/logs/*/*.log -mtime +14 -name "*.log" -exec rm -rf {} \; >> /home/wdhis/logs/catalina.out
find /home/wdhis/Server/dubbo-consumer/dubbo-emis-tomcat/logs/* -mtime +14 -name "*" -exec rm -rf {} \; >> /home/wdhis/logs/catalina.out
find /home/wdhis/Server/dubbo-consumer/dubbo-mmis-tomcat/logs/* -mtime +14 -name "*" -exec rm -rf {} \; >> /home/wdhis/logs/catalina.out
find /home/wdhis/Server/dubbo-consumer/dubbo-outpat-tomcat/logs/* -mtime +14 -name "*" -exec rm -rf {} \; >> /home/wdhis/logs/catalina.out
find /home/wdhis/Server/dubbo-consumer/dubbo-core-tomcat/logs/* -mtime +14 -name "*" -exec rm -rf {} \; >> /home/wdhis/logs/catalina.out
find /home/wdhis/Server/dubbo-consumer/dubbo-plugs-tomcat/logs/* -mtime +14 -name "*" -exec rm -rf {} \; >> /home/wdhis/logs/catalina.out
echo " " > /home/wdhis/Server/dubbo-consumer/wdhis-emis-svr/logs/catalina.out
echo " " > /home/wdhis/Server/dubbo-consumer/wdhis-mmis-svr/logs/catalina.out
echo " " > /home/wdhis/Server/dubbo-consumer/wdhis-outpat-svr/logs/catalina.out
echo " " > /home/wdhis/Server/dubbo-consumer/wdhis-core-svr/logs/catalina.out
echo " " > /home/wdhis/Server/dubbo-consumer/wdhis-plugs-svr/logs/catalina.out
echo "del file end" >> /home/wdhis/logs/catalina.out
echo "del file provide nohup" >> /home/wdhis/logs/catalina.out
echo " " > /home/wdhis/Server/dubbo-provider/wdhis-medicare-svr/nohup.out
echo " " > /home/wdhis/Server/dubbo-provider/wdhis-outplugs-svr/nohup.out
echo " " > /home/wdhis/Server/dubbo-provider/wdhis-payment-svr/nohup.out
echo " " > /home/wdhis/Server/dubbo-provider/wdhis-report-svr/nohup.out
echo "del file end nohup" >> /home/wdhis/logs/catalina.out
date >> /home/wdhis/logs/catalina.out
#设置脚本执行权限
chmod +x delete-logs.sh
将脚本加入定时任务
[root@admin wdhis]# crontab -e
crontab: installing new crontab
[root@admin wdhis]# crontab -l
#定时清理云HIS日志,在每隔十五天的0点
* 0 */15 * * wdhis /home/wdhis/logs/delete_log.sh