免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: yuhongchun
打印 上一主题 下一主题

专家座谈——脚本分享与交流(大奖) [复制链接]

论坛徽章:
0
1 [报告]
发表于 2011-09-17 14:38 |显示全部楼层
本帖最后由 coralzd 于 2011-09-17 15:10 编辑

linux 负载报警脚本,系统负载超过一定数值,就重启php-cgi,并发送报警短信。
  1. #!/bin/sh
  2. #description:system load average
  3. #author:coralzd powered by www.freebsdsystem.org
  4. host=$(hostname)
  5. channel=$(hostname | sed 's/[0-9]//g')
  6. runday=$(date "+%Y-%m-%d")
  7. IPhost=$(/sbin/ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}')
  8. i=10
  9.   while [ 1 ];do
  10. rundaytime=$(date "+%Y-%m-%d %H:%M:%S")
  11. L=$(cat /proc/loadavg|cut -c1-4)
  12. RESULT=$(echo "$L > $i"|bc)
  13. if [ "${RESULT}" == "$i" ]; then
  14. echo "$runday" >> /var/tmp/${host}.txt
  15. wget http://10.10.10.10/phpsms/smsu.php?phone=15012345678\&msg=warning%20${IPhost}%20Load%20avarage%20is%20high -O /dev/null >/dev/null 2>&1
  16. /usr/local/php52/sbin/php-fpm restart
  17. echo "${runday}" >> /var/log/${host}.txt
  18. echo "The system load average is 10+ ,php-fpm already restart" >> /var/log/${host}.txt
  19. fi
  20. sleep 600
  21. done
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-09-17 14:40 |显示全部楼层
本帖最后由 coralzd 于 2011-09-17 15:10 编辑

文件防篡改脚本,已有文件被修改,立即发送报警短信。
  1. #!/bin/bash
  2. #description: check files shell
  3. #author:coralzd powered by www.freebsdsystem.org
  4. checkdir=/data/www/bbs.xxx.com

  5. ipadd=`ifconfig |grep "inet" |cut -c 0-36|sed -e 's/[a-zA-Z: ]//g' |grep -v "127.0.0.1"`

  6. while [ 1 ]
  7. do
  8.   DATE=`date +%Y-%m-%d.%H:%M:%S`
  9.   find ${checkdir} \( -path ${checkdir}/forumdata/threadcaches -o -path  ${checkdir}/forumdata_1/threadcaches -o -path  ${checkdir}/forumdata_1/templates  -o -path ${checkdir}/f
  10. orumdata_1/cache -o -path ${checkdir}/forumdata/dzwxuser -o -path ${checkdir}/attachments -o -path ${checkdir}/forumdata/cache -o -path ${checkdir}/forumdata/templates -o -path
  11. ${checkdir}/forumdata/dzwxuser -o -path ${checkdir}/dzwxuserid/cache -o -path ${checkdir}/forumdata_1 \) -prune -o -name "*php" -mmin -1 -print >/tmp/tmpdd
  12.   SZ=`ls -la /tmp/tmpdd|awk '{print $5}'`
  13.   if [ "${SZ}" -gt "2" ]; then
  14.         SN=`cat /tmp/tmpdd`
  15.     echo ${DATE} ${SN} >>/var/tmp/checkfile.log
  16.     wget http://10.10.10.10/phpsms/smsu.php?phone=15012345678\&msg=%E7%95%99%E6%84%8F%EF%BC%9A${ipadd}_%E5%8F%AF%E8%83%BD%E5%87%BA%E7%8E%B0%E6%96%87%E4%BB%B6%E7%AF%A
  17. 1%E6%94%B9 -O /dev/null >/dev/null 2>&1
  18.   fi
  19.   sleep 60
  20. done
复制代码

论坛徽章:
0
3 [报告]
发表于 2011-09-17 14:59 |显示全部楼层
nginx_php 自动安装脚本第二版。
  1. #!/bin/bash
  2. # author:coralzd powered by www.freebsdsystem.org
  3. # written by coralzd 2010.11.05
  4. # version 0.1.4 build 20110831
  5. # description: nginx php mysql install shell

  6. nginx_dir="/usr/local/nginx"
  7. php52_dir="/usr/local/php52"
  8. mysql_dir="/usr/local/mysql"

  9. function init()
  10. {

  11. yum -y install wget gcc gcc-c++ autoconf bison flex re2c  libmhash libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gd gd-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

  12. read -p "Now,will download nginxphp software...Y|y:"  nginxphp

  13. case "$nginxphp" in

  14.      Y|y)

  15. echo -n "starting download nginx_php ..."
  16. cat > list << "EOF" &&
  17. nginx-1.0.1.tar.gz
  18. php-5.2.17.tar.gz
  19. php-5.2.17-fpm-0.5.14.diff.gz
  20. libiconv-1.13.1.tar.gz
  21. libmcrypt-2.5.8.tar.gz
  22. mcrypt-2.6.8.tar.gz
  23. memcache-2.2.5.tgz
  24. mhash-0.9.9.9.tar.gz
  25. mysql-5.1.58.tar.gz
  26. suhosin-patch-5.2.17-0.9.7.patch
  27. pcre-8.10.tar.gz
  28. autoconf-2.13.tar.gz
  29. eaccelerator-0.9.5.3.tar.bz2
  30. PDO_MYSQL-1.0.2.tgz
  31. libunwind-0.99.tar.gz
  32. ImageMagick.tar.gz
  33. imagick-2.3.0.tgz
  34. google-perftools-1.6.tar.gz
  35. fcgi.conf
  36. php.ini
  37. my.cnf
  38. nginx.conf
  39. php-fpm.conf
  40. EOF
  41. mkdir packages
  42.         for i in `cat list`
  43. do
  44. if [ -s packages/$i ]; then
  45.   echo "$i [found]"
  46. else
  47.   echo "Error: $i not found!!!download now......"
  48.   wget http://www.freebsdsystem.org/linux/nginx-php/$i -P packages/
  49. fi
  50. wget http://www.freebsdsystem.org/linux/nginx-php/nginxd
  51. wget http://www.freebsdsystem.org/linux/nginx-php/php-fpm
  52. mv nginxd /etc/init.d/
  53. mv php-fpm /etc/init.d/
  54. chmod 755 /etc/init.d/*
  55. chkconfig --add nginxd
  56. chkconfig --add php-fpm
  57. echo "create the eaccelerator directory to /data0/cache"
  58. mkdir /data0/cache
  59. echo "create the mysql data directory to /data0/mysql/data"
  60. mkdir -p /data0/mysql/data
  61. echo "PATH=/usr/local/mysql/bin/:$PATH" >> /etc/profile
  62. source  /etc/profile
  63. done
  64. ;;

  65. *)

  66.   echo -n "exit install script"
  67.    exit 0
  68. ;;

  69. esac  

  70. groupadd www &&  useradd www -s /sbin/nologin -g www
  71. groupadd mysql && useradd mysql -s /sbin/nologin -g mysql
  72. echo "www and mysql user && group create!"
  73. cd packages/
  74. tar zxf
  75. /bin/rm -rf list

  76. echo -e "All of installed sucussful!"


  77. }
  78. function is_version()

  79. {

  80.    
  81. if [ `uname -m` == "x86_64" ];then
  82. tar zxf libunwind-0.99.tar.gz
  83. tar zxvf libunwind-0.99.tar.gz
  84. cd libunwind-0.99/
  85. CFLAGS=-fPIC ./configure
  86. make CFLAGS=-fPIC
  87. make CFLAGS=-fPIC install
  88. cd ../
  89. else

  90.         echo "your system is 32bit ,not install libunwind lib!"
  91. fi


  92. }

  93. function ins_nginx()

  94. {

  95. cd packages/
  96. is_version
  97. tar zxf google-perftools-1.6.tar.gz
  98. cd google-perftools*
  99. ./configure
  100. make
  101. make install
  102. cd ..

  103. tar zxf pcre-8.10.tar.gz
  104. cd pcre-*
  105. ./configure
  106. make
  107. make install
  108. cd ..
  109. tar zxf nginx-1.0.1.tar.gz
  110. cd nginx-1.0.1
  111. ./configure --prefix=${nginx_dir} --user=www --group=www --with-http_stub_status_module   

  112. make && make install
  113. cd ..
  114. rm -rf /usr/local/nginx/conf/nginx.conf
  115. echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
  116. cp nginx.conf /usr/local/nginx/conf/
  117. cp fcgi.conf /usr/local/nginx/conf/
  118. echo "nginx installed sucussfully!"
  119. }

  120. function ins_mysqlserver()
  121. {

  122. cd packages/
  123. tar zxf mysql-5.1.58.tar.gz
  124. cd mysql-5.1.58
  125. CHOST="x86_64-pc-linux-gnu"
  126. CFLAGS="-march=nocona -O2 -pipe"
  127. CXXFLAGS="${CFLAGS}"
  128. ./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
  129. make && make install
  130. cp support-*/mysql.server /etc/init.d/mysqld
  131. cp my.cnf /etc/
  132. chmod 744 /etc/init.d/mysqld
  133. cd /usr/local/mysql

  134. chown -R mysql:mysql .
  135. rm -rf sql-bench mysql-test
  136. mkdir -p /data0/mysql/relaylog/
  137. mkdir -p /data0/mysql/binlog/
  138. chown -R mysql.mysql /data0/mysql

  139. /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data0/mysql/data
  140. echo "mysql server  5.1.58 installed successfully!"
  141. }

  142. function ins_mysqlclient()
  143. {

  144. cd packages/
  145. tar zxf mysql-5.1.58.tar.gz
  146. cd mysql-5.1.58
  147. CHOST="x86_64-pc-linux-gnu"
  148. CFLAGS="-march=nocona -O2 -pipe"
  149. CXXFLAGS="${CFLAGS}"
  150. ./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"

  151. make && make install
  152. cd /usr/local/mysql
  153. chown -R mysql:mysql .
  154. rm -rf sql-bench mysql-test
  155. echo "mysql client  5.1.58 installed successfully!"
  156. }
  157. function ins_php52()       
  158. {
  159. cd packages/
  160. tar zxf libiconv-1.13.1.tar.gz
  161. cd libiconv-1.13.1/
  162. ./configure --prefix=/usr/local
  163. make
  164. make install
  165. cd ../

  166. tar zxf autoconf-2.13.tar.gz
  167. cd autoconf-2.13
  168. ./configuire --prefix=/usr
  169. make && make install
  170. cd ..

  171. tar zxf libmcrypt-2.5.8.tar.gz
  172. cd libmcrypt-2.5.8/
  173. ./configure
  174. make
  175. make install
  176. /sbin/ldconfig
  177. cd libltdl/
  178. ./configure --enable-ltdl-install
  179. make
  180. make install
  181. cd ../../

  182. tar zxf mhash-0.9.9.9.tar.gz
  183. cd mhash-0.9.9.9/
  184. ./configure
  185. make
  186. make install
  187. cd ../

  188. ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
  189. ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
  190. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
  191. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
  192. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
  193. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
  194. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
  195. ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
  196. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
  197. ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

  198. tar zxf mcrypt-2.6.8.tar.gz
  199. cd mcrypt-2.6.8/
  200. /sbin/ldconfig
  201. ./configure
  202. make
  203. make install
  204. cd ../


  205. tar zxf php-5.2.17.tar.gz
  206. gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
  207. cd php-5.2.17/
  208. patch -p1 -i ../suhosin-patch-5.2.17-0.9.7.patch
  209. ./buildconf --force  
  210. ./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-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --enable-suhosin --enable-ftp
  211. make ZEND_EXTRA_LIBS='-liconv'
  212. make install
  213. cd ..
  214. cp php.ini /usr/local/php52/etc/
  215. cp php-fpm.conf /usr/local/php52/etc/

  216. echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf.d/mysql_lib.conf
  217. /sbin/ldconfig
  218. echo "php52 installed successfully!"
  219. }

  220. function ins_php52ext()

  221. {
  222. cd packages/

  223. tar zxf memcache-2.2.5.tgz
  224. cd memcache-2.2.5/
  225. ${php52_dir}/bin/phpize
  226. ./configure --with-php-config=${php52_dir}/bin/php-config
  227. make
  228. make install
  229. cd ../

  230. tar jxf eaccelerator-0.9.5.3.tar.bz2
  231. cd eaccelerator-0.9.5.3
  232. ${php52_dir}/bin/phpize
  233. ./configure --enable-eaccelerator=shared --with-eaccelerator-shared-memory --with-php-config=${php52_dir}/bin/php-config
  234. make
  235. make install
  236. cd ../

  237. #tar zxf PDO_MYSQL-1.0.2.tgz
  238. #cd PDO_MYSQL-1.0.2/
  239. #${php52_dir}/bin/phpize
  240. #./configure --with-php-config=${php52_dir}/bin/php-config --with-pdo-mysql=${mysql_dir}
  241. #make
  242. #make install
  243. #cd ../

  244. tar zxf ImageMagick.tar.gz
  245. cd ImageMagick-6.5.1-2/
  246. ./configure
  247. make
  248. make install
  249. cd ../

  250. tar zxf imagick-2.3.0.tgz
  251. cd imagick-2.3.0/
  252. ${php52_dir}/bin/phpize
  253. ./configure --with-php-config=${php52_dir}/bin/php-config
  254. make
  255. make install
  256. cd ..


  257. echo "php52 extension installed successfully!"


  258. }

  259. case $1 in


  260. init)

  261.         init
  262.          ;;
  263. ins_mysqlserver)
  264.          
  265.           ins_mysqlserver

  266.           ;;
  267. ins_mysqlclient)
  268.           ins_mysqlclient
  269.           ;;
  270. ins_nginx)
  271.            ins_nginx
  272.            ;;
  273. ins_php52)
  274.        ins_php52  
  275.            ;;
  276. ins_php52ext)
  277.        ins_php52ext
  278.        ;;
  279. *)

  280.      echo "Usage:`basename $0` {init|ins_mysqlserver|ins_mysqlclient|ins_php52|ins_php52ext}"
  281.          ;;
  282. esac
复制代码

论坛徽章:
0
4 [报告]
发表于 2011-09-17 15:30 |显示全部楼层
对于短信报警,我们这里采用的是短信猫,并没有采用飞信,因为它不太稳定!

论坛徽章:
0
5 [报告]
发表于 2011-09-18 15:17 |显示全部楼层
回复 88# shplpy


    好好学习,天天向上!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP