1 centeros7时间同步
删除本地时区
#rm -rf /etc/localtime
设置时区
cp /usr/share/zoneinfo/Asia/Shanghai/etc/localtime
安装ntp,同步时间
yum install -y ntp
同步时间
ntpdate time.nist.gov
格式化查看时间
date "+%Y/%m/%d %H:%M:%S"
2 使用cron执行任务计划
通过查看系统提供的crontab文件,查看cron命令
cat /etc/crontab
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
启动cron服务
systemctl stop crond
停止cron服务
systemctl restart crond
重启cron服务
systemctl enable crond.service
设置cron开机启动
查看当前crontab,输入 crontab -l
编辑当前crontab,输入 crontab -e
删除当前crontab,输入 crontab -r
表示每晚21:30重启apache。
表示每月1、10、22日的4 : 45重启apache。
表示每周六、周日的1 : 10重启apache。
表示在每天18 : 00至23 : 00每隔30分钟重启apache。
表示星期六晚上11点重启apache。
每一小时重启apache
晚上11点到早上7点之间,每隔一小时重启apache
每月的4号与每周一到周三的11点重启apache
表示一月一号的4点重启apache
3 完成nginx日志切割
nginx日志形式
这个脚本的作用是将日志文件备份并新建日志文件,通知nginx使用新的日志文件
#!/bin/bash
dateformat=`date +%Y-%m-%d-%H-%M`
ngdir=/usr/local/nginx/logs
cp $ngdir/access.log $ngdir/access_$dateformat.log
host=`hostname`
sed -i 's/^/'${host}',&/g' ${ngdir}/access_$dateformat.log
lines=`wc -l < ${ngdir}/access_$dateformat.log`
mv ${ngdir}/access_$dateformat.log ${ngdir}/flume
sed -i '1,'${lines}'d' ${ngdir}/access.log
#通知nginx使用新的日志文件
3 为flume添加配置文件 glog.conf
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /usr/local/nginx/logs/flume
a1.sources.r1.fileHeader = true
# Describe the sink
a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.kafka.topic = ping
a1.sinks.k1.kafka.bootstrap.servers = master:9092 slavea:9092 slaveb:9092
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
将kafka的logs目录修改权限,允许flume重命名
chmod 777 /usr/local/nginx/logs
4 启动kafka集群
A:启动zookeeper集群;
zkServer.sh start
B:启动kafka集群
kafka-server-start.sh -daemon kafka_2.11/config/server.properties
C: 为kafka创建主题
kafka-topics.sh --zookeeper master:2181 --topic ping --create --partitions 1 --replication-factor 1
D:查看主题
kafka-topics.sh --zookeeper master:2181 --topic ping --list
E:启动flume,将日志信息收集到kafka
flume-ng agent -f asdf.conf -n a1 &
F:启动hdfs集群
start-dfs.sh