几个常用的Linux操作系统监控脚本Word格式.docx

上传人:b****6 文档编号:17201330 上传时间:2022-11-28 格式:DOCX 页数:14 大小:74.69KB
下载 相关 举报
几个常用的Linux操作系统监控脚本Word格式.docx_第1页
第1页 / 共14页
几个常用的Linux操作系统监控脚本Word格式.docx_第2页
第2页 / 共14页
几个常用的Linux操作系统监控脚本Word格式.docx_第3页
第3页 / 共14页
几个常用的Linux操作系统监控脚本Word格式.docx_第4页
第4页 / 共14页
几个常用的Linux操作系统监控脚本Word格式.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

几个常用的Linux操作系统监控脚本Word格式.docx

《几个常用的Linux操作系统监控脚本Word格式.docx》由会员分享,可在线阅读,更多相关《几个常用的Linux操作系统监控脚本Word格式.docx(14页珍藏版)》请在冰豆网上搜索。

几个常用的Linux操作系统监控脚本Word格式.docx

/bin/sh#systemstat.sh#Mike.XuIP=192.168.1.227top-n2|grep"

Cpu"

》./temp/cpu.txtfree-m|grep"

Mem"

》./temp/mem.txtdf-k|grep"

sda1"

》./temp/drive_sda1.txt#df-k|grepsda2》./temp/drive_sda2.txtdf-k|grep"

/mnt/storage_0"

》./temp/mnt_storage_0.txtdf-k|grep"

/mnt/storage_pic"

》./temp/mnt_storage_pic.txttime=`date+%m"

."

%M`connect=`netstat-na|grep"

219.238.148.30:

80"

|wc-l`echo"

\$time\$connect"

》./temp/connect_count.txt

3、监控主机的磁盘空间,当使用空间超过90%就通过发mail来发警告

/bin/bash#monitoravailablediskspaceSPACE='

df|sed-n'

/\/\$/p'

|gawk'

{print\$5}'

|sed'

s/%//'

if[\$SPACE-ge90]thenfty89@fi

4、监控CPU和内存的使用情况

/bin/bash#scripttocapturesystemstatisticsOUTFILE=/home/xu/capstats.csv

DATE='

date+%m/%d/%Y'

TIME='

date+%k:

%m:

%s'

TIMEOUT='

uptime'

VMOUT='

vmstat12'

USERS='

echo\$TIMEOUT|gawk'

{print\$4}'

'

LOAD='

{print\$9}'

|sed"

s/,//'

FREE='

echo\$VMOUT|sed-n'

/[0-9]/p'

|sed-n'

2p'

{print\$4}'

IDLE='

|gawk'

{print\$15}'

echo"

\$DATE,\$TIME,\$USERS,\$LOAD,\$FREE,\$IDLE"

》\$OUTFILE

5、全方位监控主机

/bin/bash#check_xu.sh#0****/home/check_xu.shDAT="

`date+%Y%m%d`"

HOUR="

`date+%H`"

DIR="

/home/oslog/host_\${DAT}/\${HOUR}"

DELAY=60COUNT=60#whethertheresponsibledirectoryexistif!

test-d\${DIR}then/bin/mkdir-p\${DIR}fi#generalcheckexportTERM=linux/usr/bin/top-b-d\${DELAY}-n\${COUNT}>

\${DIR}/top_\${DAT}.log2>

&

1&

#cpucheck/usr/bin/sar-u\${DELAY}\${COUNT}>

\${DIR}/cpu_\${DAT}.log2>

#/usr/bin/mpstat-P0\${DELAY}\${COUNT}>

\${DIR}/cpu_0_\${DAT}.log2>

#/usr/bin/mpstat-P1\${DELAY}\${COUNT}>

\${DIR}/cpu_1_\${DAT}.log2>

#memorycheck/usr/bin/vmstat\${DELAY}\${COUNT}>

\${DIR}/vmstat_\${DAT}.log2>

#I/Ocheck/usr/bin/iostat\${DELAY}\${COUNT}>

\${DIR}/iostat_\${DAT}.log2>

#networkcheck/usr/bin/sar-nDEV\${DELAY}\${COUNT}>

\${DIR}/net_\${DAT}.log2>

#/usr/bin/sar-nEDEV\${DELAY}\${COUNT}>

\${DIR}/net_edev_\${DAT}.log2>

放在crontab里每小时自动执行:

0****/home/check_xu.sh

这样会在/home/oslog/host_yyyymmdd/hh目录下生成各小时cpu、内存、网络,IO的统计数据。

如果某个时间段产生问题了,就可以去看对应的日志信息,看看当时的主机性能如何。

生产服务器LNMP全自动安装脚本

使用方法:

将nginx_php代码保存一个文件,例如nginx_php。

上传到服务器上执行。

此脚本在CentOS5.6i386/x86_64环境下通过。

bashnginx_php出现提示,如下列图所示。

根据大家自己的需要选择数字中任意一个,开始全自动安装LNMP的世界中去吧。

如果之前安装过nginx或者php的话,脚本会自动检测它们是不是安装过。

例如

就会提示nginx或者php已经安装过了。

nginx_php源码

/bin/bash

#author:

coralzdpoweredbywww.freebsdsystem.org

#writtenbycoralzd2011.09.30

#version0.1.5build20110930

nginx_dir="

/usr/local/nginx"

php52_dir="

/usr/local/php52"

mysql_dir="

/usr/local/mysql"

functioncheck_init()#检测初始化工作有没有执行

{

if[`rpm-qa|grepre2c`=="

re2c-0.12.1-2.el5.x86_64"

];

then

echo"

initalreadyexec!

exit0

fi

}

functioncheck_nginx()#检测nginx有没有安装

if[-d/usr/local/nginx/];

nginxalreadyinstalled!

exit1

functioncheck_php52()#检测php有没有安装

if[-d/usr/local/php52];

php5.2.17alreadyinstalled!

exit1

functioncheck_mysql()#检测mysql有没有安装

if[-d/usr/local/mysql/];

echo-n"

mysqlalreadyinstalled!

functioninit()#系统初始化工作

yum-yinstallwgetgccgcc-c++autoconfbisonflexre2clibmhashlibjpeglibjpeg-devellibpnglibpng-devel\

freetypefreetype-develgdgd-devellibxml2libxml2-develzlibzlib-develglibcglibc-develglib2glib2-devel\

bzip2bzip2-develncursesncurses-develcurlcurl-devele2fsprogse2fsprogs-develkrb5-devellibidnlibidn-developensslopenssl-devel

echo-n"

startingdownloadnginx_php..."

cat>

list<

<

EOF"

&

nginx-1.0.1.tar.gz

php-5.2.17.tar.gz

php-5.2.17-fpm-0.5.14.diff.gz

libiconv-1.13.1.tar.gz

libmcrypt-2.5.8.tar.gz

mcrypt-2.6.8.tar.gz

memcache-2.2.5.tgz

mhash-0.9.9.9.tar.gz

mysql-5.1.58.tar.gz

suhosin-patch-5.2.17-0.9.7.patch

pcre-8.10.tar.gz

autoconf-2.13.tar.gz

eaccelerator-0.9.5.3.tar.bz2

PDO_MYSQL-1.0.2.tgz

libunwind-0.99.tar.gz

ImageMagick.tar.gz

imagick-2.3.0.tgz

google-perftools-1.6.tar.gz

fcgi.conf

php.ini

php-fpm

nginxd

f

nginx.conf

php-fpm.conf

EOF

mkdirpackages

foriin`catlist`

do

if[-spackages/$i];

then

$i[found]"

else

Error:

$inotfound!

!

downloadnow......"

wgethttp:

//www.freebsdsystem.org/linux/nginx-php/$i-Ppackages/

fi

done

mvpackages/nginxd/etc/init.d/

mvpackages/php-fpm/etc/init.d/

chmod755/etc/init.d/*

chkconfig--addnginxd

chkconfig--addphp-fpm

createtheeacceleratordirectoryto/data0/cache"

mkdir/data0/cache

createthemysqldatadirectoryto/data0/mysql/data"

mkdir-p/data0/mysql/data

PATH=/usr/local/mysql/bin/:

$PATH"

>

>

/etc/profile

source/etc/profile

groupadd-g80www&

useraddwww-s/sbin/nologin-gwww-u80

groupadd-g3306mysql&

useraddmysql-s/sbin/nologin-gmysql-u3306

wwwandmysqluser&

groupcreate!

cdpackages/

/bin/rm-rflist

echo-e"

Allofinstalledsucussful!

functionis_version()#检测系统是64位的还是32位的?

if[`uname-m`=="

x86_64"

tarzxflibunwind-0.99.tar.gz

tarzxvflibunwind-0.99.tar.gz

cdlibunwind-0.99/

CFLAGS=-fPIC./configure

makeCFLAGS=-fPIC

makeCFLAGS=-fPICinstall

cd../

yoursystemis32bit,notinstalllibunwindlib!

functionins_nginx()#安装nginx

check_nginx

is_version

tarzxfgoogle-perftools-1.6.tar.gz

cdgoogle-perftools*

./configure

make

makeinstall

cd..

tarzxfpcre-8.10.tar.gz

cdpcre-*

./configure

makeinstall

tarzxfnginx-1.0.1.tar.gz

cdnginx-1.0.1

./configure--prefix=${nginx_dir}--user=www--group=www--with-http_stub_status_module

make&

makeinstall

cd..

rm-rf/usr/local/nginx/conf/nginx.conf

/usr/local/lib"

/etc/ld.so.conf.d/usr_local_lib.conf

cpnginx.conf/usr/local/nginx/conf/

cpfcgi.conf/usr/local/nginx/conf/

nginxinstalledsucussfully!

functionins_mysqlserver()#安装mysql服务端

tarzxfmysql-5.1.58.tar.gz

cdmysql-5.1.58

CHOST="

x86_64-pc-linux-gnu"

CFLAGS="

-march=nocona-O2-pipe"

CXXFLAGS="

${CFLAGS}"

./configure--prefix=/usr/local/mysql--enable-assembler--with-server-suffix=-DZWWW--enable-thread-safe-client--enable-local-infile--enable-thread-safe-client--with-big-tables--with-charset=utf8--with-client-ldflags=-all-static--with-collation=utf8_general_ci--with-extra-charsets=all--with-mysqld-ldflags=-all-static--with-mysqld-ldflags=-ltcmalloc--with-mysqld-user=mysql--with-plugins=partition,myisammrg--with-pthread--with-unix-socket-path=/tmp/mysql.sock--without-ndb-debug

makeinstall

cpsupport-*/mysql.server/etc/init.d/mysqld

cpf/etc/

chmod744/etc/init.d/mysqld

cd/usr/local/mysql

chown-Rmysql:

mysql.

rm-rfsql-benchmysql-test

mkdir-p/data0/mysql/relaylog/

mkdir-p/data0/mysql/binlog/

chown-Rmysql.mysql/data0/mysql

/usr/local/mysql/bin/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir=/data0/mysql/data

mysqlserver5.1.58installedsuccessfully!

functionins_mysqlclient()#安装mysql客户端

./configure"

--prefix=${mysql_dir}"

--with-mysqld-user=mysql"

--without-debug"

--with-charset=utf8"

--with-extra-charsets=all"

--with-pthread"

--with-big-tables"

--enable-thread-safe-client"

--enable-assembler"

--with-readline"

--with-ssl"

--enable-local-infile"

--without-server"

mysqlclient5.1.58installedsuccessfully!

functionins_php52()#安装php

check_php52

tarzxflibiconv-1.13.1.tar.gz

cdlibiconv-1.13.1/

./configure--prefix=/usr/local

tarzxfautoconf-2.13.tar.gz

cdautoconf-2.13

./configuire--prefix=/usr

tarzxflibmcrypt-2.5.8.tar.gz

cdlibmcrypt-2.5.8/

/sbin/ldconfig

cdlibltdl/

./configure--enable-ltdl-install

cd../../

tarzxfmhash-0.9.9.9.tar.gz

cdmhash-0.9.9.9/

ln-s/usr/local/lib/libmcrypt.la/usr/lib/libmcrypt.la

ln-s/usr/local/lib/libmcrypt.so/usr/lib/libmcrypt.so

ln-s/usr/local/lib/libmcrypt.so.4/usr/lib/libmcrypt.so.4

ln-s/usr/local/lib/libmcrypt.so.4.4.8/usr/lib/libmcrypt.so.4.4.8

ln-s/usr/local/lib/libmhash.a/usr/lib/libmhash.a

ln-s/usr/local/lib/libmhash.la/usr/lib/libmhash.la

ln-s/usr/local/lib/libmhash.so/usr/lib/libmhash.so

ln-s/usr/local/lib/libmhash.so.2/usr/lib/libmhash.so.2

ln-s/usr/local/lib/libmhash.so.2.0.1/usr/lib/libmhash.so.2.0.1

ln-s/usr/local/bin/libmcrypt-config/usr/bin/libmcrypt-config

tarzxfmcrypt-2.6.8.tar.gz

cdmcrypt-2.6.8/

tarzxfphp-5.2.17.tar.gz

gzip-cdphp-5.2.17-fpm-0.5.14.diff.gz|patch-dphp-5.2.17-p1

cdphp-5.2.17/

patch-p1-i../suhosin-patch-5.2.17-0.9.7.patch

./buildconf--force

./configure--prefix=${php52_dir}--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--with-config-file-path=${php52_dir}/etc--with-ic

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 理化生

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1