diff --git a/脚本实用工具/Autoback-xtraback.sh b/脚本实用工具/Autoback-xtraback.sh new file mode 100644 index 0000000..9d3fcd9 --- /dev/null +++ b/脚本实用工具/Autoback-xtraback.sh @@ -0,0 +1,32 @@ +#!/bin/bash +hostname=`/bin/hostname` +week=`date +%w` +datadir=/backup +logdir=/backup/log +mycnf=/etc/my.cnf +Time=`date +%Y-%m-%d_%H-%M-%S` +cmd=`which innobackupex` +user=root +passwd=mysqladmin + + +function getdir() +{ + if [ ! -d ${datadir} ];then + mkdir -p ${datadir} + fi +} +function backup() +{ + if [ ${week} == "0" ];then + $cmd --defaults-file=${mycnf} --user=${user} --password=${passwd} ${datadir}&>${logdir}/${Time}-log + [ $? -eq 0 ] && stat=`tail -1 ${logdir}/${Time}-log |awk '{print $4}'` + if [ "${stat}" == "OK!" ];then + echo "${Time} mysql backup is success!" + else + echo "${Time} mysql backup is fail! please check ${logdir}/${Time}-log" + fi + else + $cmd --defaults-file=${mycnf} --user=${user} --password=${passwd} --incremental --incremental-basedir=${datadir}&>${logdir}/${Time}-log + +} diff --git a/脚本实用工具/IP_iptables.sh b/脚本实用工具/IP_iptables.sh new file mode 100644 index 0000000..95db994 --- /dev/null +++ b/脚本实用工具/IP_iptables.sh @@ -0,0 +1,19 @@ +#!/bin/bash +#mail xuel@51idc.com +#data 2017/2/23 + +#function: use iptables Brute force +SCAN=`/bin/egrep "Failed password for root" /var/log/secure|awk -F'[ :]+' '{print $13}'|sort|uniq -c|awk '{print $1"="$2;}'` +for I in ${SCAN} +do + SCANUM=`echo ${I}|awk -F'=' '{print $1}'` + SCANIP=`echo ${I}|awk -F'=' '{print $2}'` + if [ ${SCANUM} -gt 100 ] && [ -z "`/sbin/iptables -vnL INPUT | grep $SCANIP`" ];then + /sbin/iptables -I INPUT -s $SCANIP -m state --state NEW,RELATED,ESTABLISHED -j DROP + echo "`date` $SCANIP($SCANUM)">>/var/log/scanIP.log + fi +done +if [ $? -eq 0 ];then +service iptables save && service iptables restart +fi + diff --git a/脚本实用工具/black_list.sh b/脚本实用工具/black_list.sh new file mode 100644 index 0000000..c0ebe48 --- /dev/null +++ b/脚本实用工具/black_list.sh @@ -0,0 +1,20 @@ +#! /bin/bash + +cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /root/black/black.txt + +DEFINE="5" + +for i in `cat /root/black/black.txt` +do + +IP=`echo $i |awk -F= '{print $1}'` +NUM=`echo $i|awk -F= '{print $2}'` + +if [ $NUM -gt $DEFINE ]; then +grep $IP /etc/hosts.deny > /dev/null + +if [ $? -gt 0 ]; then +echo "sshd:$IP" >> /etc/hosts.deny +fi +fi +done diff --git a/脚本实用工具/check_mysql_ms.sh b/脚本实用工具/check_mysql_ms.sh new file mode 100644 index 0000000..52c35cd --- /dev/null +++ b/脚本实用工具/check_mysql_ms.sh @@ -0,0 +1,17 @@ +#!/bin/bash +mysql_user='root' +mysql_pass="bhVd!564qazWSX78U#7" +data=$(/bin/date +%Y-%m-%d-%H:%M) +/bin/netstat -lntup|egrep ":3306"|grep -v grep>/dev/null0 +if [ $? -eq 0 ];then + Slave_IO=`/data/mysql/bin/mysql -u${mysql_user} -p${mysql_pass} -e "show slave status\G"|grep "Slave_IO_Running:"|awk -F": " '{print $2}'` + Slave_SQL=`/data/mysql/bin/mysql -u${mysql_user} -p${mysql_pass} -e "show slave status\G"|grep "Slave_SQL_Running:"|awk -F": " '{print $2}'` + if [ "$Slave_IO" == "Yes" ] && [ "$Slave_SQL" == "Yes" ];then + STAT=1 && echo "$data mysql-status is ok">>/var/log/mysql-status.log + else + STAT=0 && echo "$data mysql-status is error">>/var/log/mysql-status.log + fi +else + STAT=0 && echo "$data mysql-status is error">>/var/log/mysql-status.log +fi +/usr/bin/zabbix_sender -z 101.227.67.205 -s "DaoDaEr-mysql-status" -k mysql -o $STAT