ntpdate 210.72.145.44
free && sync && echo 3 > /proc/sys/vm/drop_caches && free
kill $(ps -A -ostat,ppid | awk '/[zZ]/ && !a[$2]++ {print $2}')
tcpdump 'arp' -e -i eth0 -n -p -t |grep is-ateth0对应要换成你的显步名称
tcpdump -n -vv tcp port $1 -i em1em1为对应的网卡名称。
netstat -nat |awk '{print $6}'|sort|uniq -c|sort -nr
tail -F
/var/log/tomcat8/catalina.out |grep -E 'Exception|at' |grep -v WARN这里tomcat8要对应成你的相应版本
sudo find /var/lib/tomcat8/logs/ -mtime +5 -exec rm {} ;
以下存成脚本,
#!/bin/sh
#实现通过主机名,端口清相应的memcache缓存
if(($#<2));then
echo "usage:$0 host port";
exit 1;
fi
#如果参数缺失,退出程序,返回状态1
exec 6<>/dev/tcp/$1/$2 2>/dev/null;
#打开host的port 可读写的socket连接,与文件描述符6连接
if(($?!=0));then
echo "open $1 $2 error!";
exit 1;
fi
#如果打开失败,$?返回不为0,终止程序
echo -e "flush_all">&6;
echo -e "quit">&6;
#将HEAD 信息,发送给socket连接
cat<&6;
#从socket读取返回信息,显示为标准输出
exec 6<&-;
exec 6>&-;
#关闭socket的输入,输出
exit 0;
保存脚本,第一个参数为虚拟机的名称,第二个为内存大小,如2G
#!/bin/bash
VM=$1
VBoxManage controlvm $VM poweroff
VBoxManage modifyvm $VM --memory $2
VBoxManage startvm $VM --type headless
#!/bin/sh
#machine=phptest
machine=$1
VBoxManage controlvm "$machine" poweroff
disk=/home/xwx/VirtualBox VMs/$machine/${machine}_swap.vdi
#VBoxManage createhd --filename "$disk" --size 1024
#VBoxManage storageattach "$machine" --storagectl "IDE" --port 1 --type hdd --medium $disk
#VBoxManage storageattach "$machine" --storagectl SATA --port 1 --type hdd --medium $disk
VBoxManage storageattach "$machine" --storagectl "SATA 控制器" --port 1 --type hdd --medium "$disk"
虚拟机克隆之前,第一次启动时需要修改ip才能远程控制:
#!/bin/bash
# set modify
ip=/etc/network/interfaces
hn=/etc/hostname
netmask=255.255.255.0
network=192.168.20.0
broadcast=192.168.20.255
gateway=192.168.20.1
# mod ip、mask、gw、DNS、hostname
cp $ip /etc/network/interfaces.bak
sed -ri 's/(iface eth0 inet).*/iface eth0 inet static/' /etc/network/interfaces
echo "Please input IP:"
read ipadd
if [ -n "$ipadd" ]; then
echo "address $ipadd" >> $ip
echo "Modify Completed "
else
echo "Not Modified"
fi
echo "netmask $netmask" >> $ip
echo "Netmask Modify Completed "
echo "network $network" >> $ip
echo "Network Modify Completed "
echo "broadcast $broadcast" >> $ip
echo "Broadcast Modify Completed "
echo "gateway $gateway" >> $ip
echo "Gateway Modify Completed "
echo "Please input hostname:"
read hostname
if [ -n "$hostname" ]; then
echo "$hostname" > $hn
echo "Modify Completed "
else
echo "Default Hostname"
fi
echo "All modification completion"
read -n1 -p "Whether restart network [Y/N]?"
case $REPLY in
Y|y) echo
/etc/init.d/networking restart;;
N|n) echo
echo "Network needs to restart to take effect!!!!!!";;
esac
exit
使用goaccess软件,可能用apt install goaccess或yum install goaccess安装。
sudo goaccess /var/log/nginx/access.log --log-format='%h %^[%d:%t %^] "%r" %s %b "%R" "%u" "-" "%v"' --date-format='%d/%b/%Y' --time-format='%H:%M:%S'
nginx会频繁修改,改之前最好备份一下:
###################################################################
#######MySQLdump###################################################
#!/bin/sh
# -----------------------------
# the directory for story your backup file.
backup_dir="/home/your/backup"
# date format for backup file (dd-mm-yyyy)
time="$(date +"%Y%m%d")"
MKDIR="$(which mkdir)"
RM="$(which rm)"
MV="$(which mv)"
TAR="$(which tar)"
GZIP="$(which gzip)"
#针对不同系统,如果环境变量都有。可以去掉
# check the directory for store backup is writeable
test ! -w $backup_dir && echo "Error: $backup_dir is un-writeable." && exit 0
# the directory for story the newest backup
test ! -d "$backup_dir" && $MKDIR "$backup_dir"
$TAR -zcPf $backup_dir/$HOSTNAME.nginx.$time.tar.gz /etc/nginx
$TAR -zcPf $backup_dir/$HOSTNAME.cron_daily.$time.tar.gz /etc/cron.daily
#delete the oldest backup 30 days ago
find $backup_dir -name "*.gz" -mtime +30 |xargs rm -rf
exit 0;
#!/bin/bash
nginx_home=/etc/nginx
log_path=/var/log/nginx
tail -n10000 $log_path/access.log
|awk '{print $1,$12}'
|grep -i -v -E "google|yahoo|baidu|msnbot|FeedSky|sogou"
| grep -v '223.223.198.231'
|awk '{print $1}'|sort|uniq -c|sort -rn
|awk '{if($1>50)print "deny "$2";"}' >>./blockips.conf
sort ./blockips.conf |uniq -u >./blockips_new.conf
mv ./blockips.conf ./blockips_old.conf
mv ./blockips_new.conf ./blockips.conf
cat ./blockips.conf
#service nginx reload
#!/bin/sh
RED='