一、常用命令
(1)lsof
(2)du -sh * | grep G
(3)清空数据 > flum.log
查看当前文件夹下文件包含test的文件 grop -l testwenben *
替换当前文件夹下文件内容 sed -i ‘s:/apps/home/worker/wanglei:/apps/srv:g‘ *
-i 加上后修改文件,不加则控制台展示
s: 指定分隔符
g: 一行出现多个都替换
*:当前目录所有文件
sed -i ‘s:替换前:替换后:g‘ *
可以定时清日志
crontab -l
* 3 * * * /bin/sh /apps/home/worker/bin/clean_log.sh >> /apps/home/worker/bin/logs/clean_log.log
clean_log.sh
#!/bin/bash save_num=2 project_dir="/apps/srv/instance"\ for project in `ls ${project_dir}|grep -E ".com$"` do echo -e "清理项目: ${project_dir}/${project}/" # 清理jar备份 echo "1. 清理jar备份" save_file=`ls -lrt ${project_dir}/${project}/backup/ |grep -E "*.jar$"| tail -${save_num} | awk ‘{print $NF}‘` ls ${project_dir}/${project}/backup/|grep -E "*.jar$"|grep -v "${save_file}" |while read file do echo ${project_dir}/${project}/backup/$file rm -rf ${project_dir}/${project}/backup/$file done # 清理stdout.log echo "2. 清理stdout.log" echo "" > ${project_dir}/${project}/logs/stdout.log # 清理日志目录下过期日志 echo "3. 清理日志目录下过期日志" find ${project_dir}/${project}/logs/ -maxdepth 1 -type d|grep -vE "logs/$"|while read date_dir do find ${date_dir} -maxdepth 1 -mtime +1|grep -vE "${date_dir}$" |grep -E "/202|/201" find ${date_dir} -maxdepth 1 -mtime +1|grep -vE "${date_dir}$" |grep -E "/202|/201" | xargs rm -rf done done
kafka启动配置
start.sh
#!/bin/bash FLUME_HOME="$( dirname "$( cd "$( dirname "$0" )" && pwd ) " )" nohup ${FLUME_HOME}/bin/flume-ng agent -n server -c ${FLUME_HOME}/conf/ -f ${FLUME_HOME}/conf/flume-conf.properties -Dflu me.monitoring.type=http -Dflume.monitoring.port=9110 -Dflume.root.logger=INFO,console &>${FLUME_HOME}/logs/flume.log &
restart.sh
#!/bin/bash pid=`ps ux | grep flume | grep -v grep | awk ‘{print $2}‘` echo $pid count=30 while [[ 0 -ne `ps ux | grep flume | grep -v grep | wc -l` && $count -ne 0 ]] do kill $pid sleep 1 count=$((${count}-1)) #echo $count done if [[ 0 -eq `ps ux | grep flume | grep -v grep | wc -l` ]]; then echo ‘进程被Kill成功,重启中。。。‘ FLUME_HOME="$( dirname "$( cd "$( dirname "$0" )" && pwd ) " )" nohup ${FLUME_HOME}/bin/flume-ng agent -n server -c ${FLUME_HOME}/conf/ -f ${FLUME_HOME}/conf/flume-conf.properti es -Dflume.root.logger=INFO,console &>${FLUME_HOME}/logs/flume.log & echo ‘进程重启成功。。。‘ fi
监控monitor.sh
curl http://127.0.0.1:9110/metrics -s | python -m json.tool