游戏服务器使用各种脚本

  1. 备份脚本

存放位置:本机

功能:定时备份数据库文件到/home/data/Databak

mysql_db_bak.sh

#!/bin/sh

#by xiayang

export PATH=PATH=/usr/lib64/qt-

3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

echo Mysql DB backup script!

find /home/data/Databak/ -mtime +30 -type d | xargs rm -rf

DATETIME=`date "+%Y%m%d"`

DATETIME2=`date "+%Y%m%d%H%M"`

hostname="localhost"

username="root"

password="QianXing"

bak_dir="/home/data/Databak"

dbnames=`mysql -u$username -p$password -D mysql -e "show databases;" | grep ddt |grep

-v log`

if [ ! -d "$bak_dir"/"$DATETIME" ]; then

mkdir -p "$bak_dir"/"$DATETIME"

fi

for dbname in $dbnames; do

echo

echo start backup $dbname.....

mysqldump -h $hostname -u$username -p$password --lock-all-tables -R $dbname >

"$bak_dir"/"$DATETIME"/"$dbname"_"$DATETIME2"_bak.sql

sleep 5

echo

echo start compress $dbname.....

cd $bak_dir/$DATETIME

tar jcf "$dbname"_"$DATETIME2"_bak.tar.bz2 "$dbname"_"$DATETIME2"_bak.sql

rm -rf "$dbname"_"$DATETIME2"_bak.sql

done

echo

echo done.

2、磁盘使用率监控

存放位置:本机

功能:定时查看系统硬盘使用率,超过70%发送报警邮件

diskused.sh

#!/bin/bash

partitions=$(df -h|awk '{print $5}'|grep -v 'Use%')

[email protected]

i=0

for partition in $partitions

do

i=$((i+1))

percent=$(echo $partition|tr -d '%')

if [ $percent -ge '70' ];

then

showmenu=$(df -h|sed -n "1p")

showpartition=$(df -h|grep -v 'Use%'|sed -n "${i}p")

partitionname=$(df -h|grep -v 'Use%'|awk '{print $6}'|sed -n "${i}p")

echo -e "Attention! $HOSTNAME's $partitionname Disk Occupancy rate has exceeded 70%,please notes !!\n\n$showmenu\n$showpartition\n\n"|mail -s "$HOSTNAME Partition Usage Alert!!" $recipients

fi

done

  1. 服务器端口监测

存放位置:本机

功能:定时查看服务器上的游戏、mysql端口是否正常,不通则发送报警邮件

ncports.sh

#!/bin/bash

#检测服务器端口是否开放,成功会返回0值显示ok,失败会返回1值显示fail

[email protected],[email protected]

cat /opt/check/ip-ports.txt | while read line

do

nc -w 10 -z $line > /dev/null 2>&1

if [ $? -eq 0 ]

then

echo $line:ok

else

echo $line:fail

echo "官网查询平台 203.90.234.16 $line 端口不通,请尽快处理!" | mail -s "网查询平台 203.90.234.16 $line端口不通" $recipients

fi

done

ip-ports.txt

127.0.0.1 3306

127.0.0.1 1723

127.0.0.1 8005

127.0.0.1 8009

127.0.0.1 80

127.0.0.1 9527

127.0.0.1 1723

4、mysql监测

存放位置:本机

功能:定时查看mysql连接状况

你可能感兴趣的:(style,游戏服务器,local,Export,数据库文件)