Skip to content

Commit 528e14c

Browse files
committed
update blogs
1 parent eb60a55 commit 528e14c

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

_posts/2019/2019-10-24-linux-commend.markdown

+43
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ linux 运维监控包括很多维度: 磁盘,io,网络,负载,端口监控,日
2323
## 磁盘监控
2424
* ```df -lh```
2525
* ```du -sh /data/*```
26+
## 删除线上日志
27+
28+
* true > INFO-
29+
* true > ERROR-
30+
2631
## cpu监控
32+
2733
* ```top```
2834
* ```htop```
2935
## 进程监控
@@ -251,3 +257,40 @@ else
251257
fi
252258

253259
```
260+
261+
## 日志批量删除脚本(微服务为例)
262+
263+
```sh
264+
#!/bin/bash
265+
find /data/bin/micro_service/log/GateWay/**/ -mtime +1 -name "*.log" -exec echo {} > /logname.txt \;
266+
find /data/bin/micro_service/log/EurekaServer/**/ -mtime +1 -name "*.log" -exec echo {} > /logname.txt \;
267+
find /data/bin/micro_service/log/BranchGetWay/**/ -mtime +1 -name "*.log" -exec echo {} > /logname.txt \;
268+
find /data/bin/micro_service/service/ -name "branchgetway.log" -exec echo {} >> /logname.txt \;
269+
find /data/bin/micro_service/service/ -name "eurekaserver.log" -exec echo {} >> /logname.txt \;
270+
find /data/bin/micro_service/service/ -name "gateway.log" -exec echo {} >> /logname.txt \;
271+
find /data/bin/micro_service/service/ -name "securityserver.log" -exec echo {} >> /logname.txt \;
272+
find /data/bin/micro_service/service/ -name "nohup.out" -exec echo {} >> /logname.txt \;
273+
274+
for logfile in `cat /logname.txt`
275+
do
276+
echo $logfile
277+
true > $logfile
278+
done
279+
```
280+
281+
## 脚本开机启动
282+
283+
###   方法1.使用 /etc/rc.d/rc.local,自动启动脚本
284+
285+
```sh
286+
# 例子
287+
touch /var/lock/subsys/local
288+
```
289+
290+
1. 授予 /etc/rc.d/rc.local 文件执行权限
291+
命令:chmod +x /etc/rc.d/rc.local
292+
2. 在文件文件底部添加脚本
293+
3. 重启服务器,查看脚本是否启动
294+
注意:/etc/rc.d/rc.local脚本执行,在/etc/profile之前,若/etc/rc.d/rc.local用到/etc/profile的环境变量,Shell无法执行成功
295+
296+
### 方法2.注册服务

0 commit comments

Comments
 (0)