shell_clean_log
apache日志每天进行轮转:
vim /usr/local/apache2/conf/extar/httpd-vhosts.conf
...
ErrorLog "| /usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/error_log-%Y%m%d 86400"
CustomLog "| /usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/access_log-%Y%m%d 86400" common
...
说明:
1. rotatelogs程序是apache自带的一个日志切割工具。 -l参数表示使用本地系统时间为标准切割,而不是GMT时区时间。
2. /usr/local/apache2/logs/access_log-%Y%m%d 86400
用来指定日志文件的位置和名称,其中86400用来指定分割时间默认单位为s,也就是24小时;
log-server上搭建rsync:
[root@log-server ~]# cat /etc/rsyncd.conf
[web1]
path = /web1/logs
uid = root
gid = root
read only = false
[web2]
path = /web2/logs
uid = root
gid = root
read only = false
echo rsync --daemon >> /etc/rc.local
web服务器上定义清理脚本
#!/bin/bash
#clean log
clean_log(){
remote_log_server=10.1.1.2
server=$1
log_dir=/usr/local/apache2/logs
log_tmp_dir=/tmp/log
host=`ifconfig eth0|sed -n '2p'|awk -F'[ :]+' '{print $4}'`
[ ! -d $log_tmp_dir ] && mkdir -p $log_tmp_dir
cd $log_dir
find ./ -daystart -mtime +3 -exec tar -uf $log_tmp_dir/`echo $host`_$(date +%F).tar {} \;
find ./ -daystart -mtime +3 -delete
cd $log_tmp_dir
rsync -a ./ $remote_log_server::$server && find ./ -daystart -mtime +1 -delete
}
jumper-server:
#!/bin/bash
#jumper-server
#菜单打印
trap '' 1 2 3
menu1(){
cat <<-END
请选择对web1的操作类型:
1. clean_apache_log
2. reload_apache_service
3. test_apache_service
4. remote login
END
}
menu2(){
cat <<-END
欢迎使用Jumper-server,请选择你要操作的主机:
1. DB1-Master
2. DB2-Slave
3. Web1
4. Web2
5. exit
END
}
push_pubkey(){
ip=$1
# 判断公钥文件是否存在,没有则生成公钥
[ ! -f ~/.ssh/id_rsa.pub ] && ssh-keygen -P "" -f ~/.ssh/id_rsa &>/dev/null
# 安装expect程序,与交互式程序对话(自动应答)
sudo rpm -q expect &>/dev/null
test $? -ne 0 && sudo yum -y install expect
#将跳板机上yunwei用户的公钥推送的指定服务器上
/usr/bin/expect<<-EOF
spawn ssh-copy-id -i root@$ip
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "111111\r" }
}
expect eof
EOF
}
while true
do
menu2
#让用户选择相应的操作
read -p "请输入你要操作的主机:" host
case $host in
1)
ssh root@10.1.1.2
;;
2)
ssh root@10.1.1.3
;;
3)
clear
menu1
read -p "请输入你的操作类型:" types
case $types in
1)
ssh root@10.1.1.1 clean_log web1
test $? -eq 0 && echo "日志清理完毕..."
;;
2)
service apache reload
;;
3)
wget http://10.1.1.1 &>/dev/null
test $? -eq 0 && echo "该web服务运行正常..." || echo "该web服务无法访问,请检查..."
;;
4)
ssh root@10.1.1.1
;;
"")
:
;;
esac
;;
5)
exit
;;
*)
clear
echo "输入错误,请重新输入..."
;;
esac
done
shell_clean_log的更多相关文章
随机推荐
- NCRE的JAVA二级考试大纲
全国计算机等级考试二级 Java 语言 程序设计考试大纲(2018 年版) 基本要求 1. 掌握 Java 语言的特点.实现机制和体系结构. 2. 掌握 Java 语言中面向对象的特性. 3. 掌握 ...
- Day 5 :ArrayList原理、LinkedList原理和方法和迭代器注意事项
迭代器在变量元素的时候要注意事项: 在迭代器迭代元素 的过程中,不允许使用集合对象改变集合中的元素个数,如果需要添加或者删除只能使用迭代器的方法进行操作. 如果使用过了集合对象改变集合中元素个数那 ...
- h5-切割轮播图
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- jquery_ajax 异步提交
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习:HTML DOM 元素 (节点)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Git 报错:Updates were rejected because the tip of your current branch is behind
刚开始学习 git 命令,发现会出现很多的错误,所以就总结下出现的错误,以此来加深理解和掌握吧! 环境:在本地库操作了一系列的 add 和 commit 操作后,想把本地仓库推送到远端,但是发生以下错 ...
- linux 下实用工具
gpm 让linux 纯字符终端具备窗口模式下的鼠标功能 xterm + tmux 支持横向或者纵向切屏的终端 urxvt-unicode 支持中文的终端
- openlayers的loaders方式加载
openlayers loaders方式加载 let layerVector = new ol.layer.Vector({ source : new ol.source.Vector({ loade ...
- 基于JSP+Servlet新闻发布系统 源码
开发环境: Windows操作系统开发工具: Eclipse+Jdk+Tomcat+MYSQL数据库 运行效果图:
- 第04项目:淘淘商城(SpringMVC+Spring+Mybatis) 的学习实践总结【第二天】
淘淘商城(SpringMVC+Spring+Mybatis) 是传智播客在2015年9月份录制的,几年过去了.由于视频里课上老师敲的代码和项目笔记有些细节上存在出入,只有根据日志报错信息作出适当的调 ...