@Great-Chinese
2017-03-18T11:23:02.000000Z
字数 19055
阅读 935
Shell编程实战
程序架构:
(主目录 mon)
____________________|_______________________________
| | | | |
bin conf shares mail log
| | | | |
[main.sh][mon.conf][load.sh 502.sh][mail.php mail.sh][mon.log err.log]
bin下是主程序
conf下是配置文件
shares下是各个监控脚本
mail下是邮件引擎
log下是日志
cd /usr/local/sbin/ # 进入sbin目录下mkdir mon # 创建mon目录cd mon/ # 进入mon目录下mkdir bin conf mail shares log # 创建这5个目录cd bin/ # 进入bin目录下http://ask.apelearn.com/question/8106 # 告警系统,文档参考地址
A:示例脚本 main.sh
# 编辑主程序vim main.sh # 增加内容如下#!/bin/bash#Written by Melody.# 是否发送邮件的开关export send=1# 过滤ip地址export addr=`/sbin/ifconfig |grep -A1 'eth0' |grep addr: |awk '{print $2}'|awk -F: '{print $2}'`dir=`pwd`# 只需要最后一级目录名last_dir=`echo $dir|awk -F'/' '{print $NF}'`# 下面的判断目的是,保证执行脚本的时候,我们在bin目录里,不然监控脚本、邮件和日志很有可能找不到if [ $last_dir == "bin" ]; thenconf_file="../conf/mon.conf"elseecho "you shoud cd bin dir"exitfiexec 1>>../log/mon.log 2>>../log/err.logecho "`date +"%F %T"` load average"/bin/bash ../shares/load.sh#先检查配置文件中是否需要监控502if grep -q 'to_mon_502=1' $conf_file; thenexport log=`grep 'logfile=' $conf_file |awk -F '=' '{print $2}' |sed 's/ //g'`/bin/bash ../shares/502.shfi
B:配置文件脚本 mon.conf
# 编辑配置文件vim ../conf/mon.conf # 增加内容如下## to config the options if to monitor## cdb 主要定义mysql的服务器地址、端口以及user、passwordto_mon_cdb=0 ##0 or 1, default 0,0 not monitor, 1 monitorcdb_ip=10.20.3.13cdb_port=3315cdb_user=usernamecdb_pass=passwd## httpd 如果是1则监控,为0不监控to_mon_httpd=0httpd_url=http://192.168.1.111:45/## php 如果是1则监控,为0不监控to_mon_php_socket=0## http_code_502 需要定义访问日志的路径to_mon_502=1logfile=/usr/local/nginx/logs/error.log## request_count 定义日志路径以及域名to_mon_request_count=0req_log=/usr/local/nginx/logs/access.logdomainname=www.discuz.net
# 编辑子脚本load.shvim ../shares/load.sh # 增加内容如下#! /bin/bash##Writen by aming##load=`uptime |awk -F 'average:' '{print $2}'|cut -d',' -f1|sed 's/ //g' |cut -d. -f1`if [ $load -gt 20 ] &&; [ $send -eq "1" ]thenecho "$addr `date +%T` load is $load" >../log/load.tmp/bin/bash ../mail/mail.sh $addr\_load $load ../log/load.tmpfiecho "`date +%T` load is $load"
# 编辑502.shvim ../shares/502.sh # 增加内容如下#! /bin/bashd=`date -d "-1 min" +%H:%M`c_502=`grep :$d: $log |grep ' 502 '|wc -l`if [ $c_502 -gt 10 ] && [ $send == 1 ]; thenecho "$addr $d 502 count is $c_502">../log/502.tmp/bin/bash ../mail/mail.sh $addr\_502 $c_502 ../log/502.tmpfiecho "`date +%T` 502 $c_502"
A:mail.php
# 编辑mail.phpvim ../mail/mail.php # 增加内容如下<?phpclass Smtp{/* Public Variables */var $smtp_port;var $time_out;var $host_name;var $log_file;var $relay_host;var $debug;var $auth;var $user;var $pass;/* Private Variables */var $sock;/* Constractor */function Smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass){$this->debug = FALSE;$this->smtp_port = $smtp_port;$this->relay_host = $relay_host;$this->time_out = 30; //is used in fsockopen()#$this->auth = $auth;//auth$this->user = $user;$this->pass = $pass;#$this->host_name = "localhost"; //is used in HELO command$this->log_file = "";$this->sock = FALSE;}/* Main Function */function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = ""){$mail_from = $this->get_address($this->strip_comment($from));$body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body);$header = "MIME-Version:1.0\r\n";if($mailtype=="HTML"){$header .= "Content-Type:text/html\r\n";}$header .= "To: ".$to."\r\n";if ($cc != "") {$header .= "Cc: ".$cc."\r\n";}$header .= "From: $from<".$from.">\r\n";$header .= "Subject: ".$subject."\r\n";$header .= $additional_headers;$header .= "Date: ".date("r")."\r\n";$header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n";list($msec, $sec) = explode(" ", microtime());$header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n";$TO = explode(",", $this->strip_comment($to));if ($cc != "") {$TO = array_merge($TO, explode(",", $this->strip_comment($cc)));}if ($bcc != "") {$TO = array_merge($TO, explode(",", $this->strip_comment($bcc)));}$sent = TRUE;foreach ($TO as $rcpt_to) {$rcpt_to = $this->get_address($rcpt_to);if (!$this->smtp_sockopen($rcpt_to)) {$this->log_write("Error: Cannot send email to ".$rcpt_to."\n");$sent = FALSE;continue;}if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) {$this->log_write("E-mail has been sent to <".$rcpt_to.">\n");} else {$this->log_write("Error: Cannot send email to <".$rcpt_to.">\n");$sent = FALSE;}fclose($this->sock);$this->log_write("Disconnected from remote host\n");}return $sent;}/* Private Functions */function smtp_send($helo, $from, $to, $header, $body = ""){if (!$this->smtp_putcmd("HELO", $helo)) {return $this->smtp_error("sending HELO command");}#authif($this->auth){if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) {return $this->smtp_error("sending HELO command");}if (!$this->smtp_putcmd("", base64_encode($this->pass))) {return $this->smtp_error("sending HELO command");}}#if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) {return $this->smtp_error("sending MAIL FROM command");}if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) {return $this->smtp_error("sending RCPT TO command");}if (!$this->smtp_putcmd("DATA")) {return $this->smtp_error("sending DATA command");}if (!$this->smtp_message($header, $body)) {return $this->smtp_error("sending message");}if (!$this->smtp_eom()) {return $this->smtp_error("sending . [EOM]");}if (!$this->smtp_putcmd("QUIT")) {return $this->smtp_error("sending QUIT command");}return TRUE;}function smtp_sockopen($address){if ($this->relay_host == "") {return $this->smtp_sockopen_mx($address);} else {return $this->smtp_sockopen_relay();}}function smtp_sockopen_relay(){$this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n");$this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out);if (!($this->sock && $this->smtp_ok())) {$this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n");$this->log_write("Error: ".$errstr." (".$errno.")\n");return FALSE;}$this->log_write("Connected to relay host ".$this->relay_host."\n");return TRUE;}function smtp_sockopen_mx($address){$domain = ereg_replace("^.+@([^@]+)$", "\1", $address);if (!@getmxrr($domain, $MXHOSTS)) {$this->log_write("Error: Cannot resolve MX \"".$domain."\"\n");return FALSE;}foreach ($MXHOSTS as $host) {$this->log_write("Trying to ".$host.":".$this->smtp_port."\n");$this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out);if (!($this->sock && $this->smtp_ok())) {$this->log_write("Warning: Cannot connect to mx host ".$host."\n");$this->log_write("Error: ".$errstr." (".$errno.")\n");continue;}$this->log_write("Connected to mx host ".$host."\n");return TRUE;}$this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n");return FALSE;}function smtp_message($header, $body){fputs($this->sock, $header."\r\n".$body);$this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> "));return TRUE;}function smtp_eom(){fputs($this->sock, "\r\n.\r\n");$this->smtp_debug(". [EOM]\n");return $this->smtp_ok();}function smtp_ok(){$response = str_replace("\r\n", "", fgets($this->sock, 512));$this->smtp_debug($response."\n");if (!ereg("^[23]", $response)) {fputs($this->sock, "QUIT\r\n");fgets($this->sock, 512);$this->log_write("Error: Remote host returned \"".$response."\"\n");return FALSE;}return TRUE;}function smtp_putcmd($cmd, $arg = ""){if ($arg != "") {if($cmd=="") $cmd = $arg;else $cmd = $cmd." ".$arg;}fputs($this->sock, $cmd."\r\n");$this->smtp_debug("> ".$cmd."\n");return $this->smtp_ok();}function smtp_error($string){$this->log_write("Error: Error occurred while ".$string.".\n");return FALSE;}function log_write($message){$this->smtp_debug($message);if ($this->log_file == "") {return TRUE;}$message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message;if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) {$this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n");return FALSE;;}flock($fp, LOCK_EX);fputs($fp, $message);fclose($fp);return TRUE;}function strip_comment($address){$comment = "\([^()]*\)";while (ereg($comment, $address)) {$address = ereg_replace($comment, "", $address);}return $address;}function get_address($address){$address = ereg_replace("([ \t\r\n])+", "", $address);$address = ereg_replace("^.*<(.+)>.*$", "\1", $address);return $address;}function smtp_debug($message){if ($this->debug) {echo $message;}}}$file = $argv[2];$smtpserver = "smtp.qq.com";//SMTP服务器$smtpserverport = "25";//SMTP服务器端口$smtpusermail = "244048927@qq.com";//SMTP服务器的用户邮箱$smtpemailto = "834865081@139.com";//发送给谁$smtpuser = "244048927";//SMTP服务器的用户帐号$smtppass = "123456";//SMTP服务器的用户密码$mailsubject = $argv[1];//邮件主题$mailbody = file_get_contents($file);//邮件内容$mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.//$smtp->debug = TRUE;//是否显示发送的调试信息$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);?>
B:mail.sh
vim ../mail/mail.sh # 增加内容如下#!/bin/bashlog=$1t_s=`date +%s`#!/bin/bashlog=$1t_s=`date +%s`t_s2=`date -d "2 hours ago" +%s`if [ ! -f /tmp/$log ]thenecho $t_s2 > /tmp/$logfit_s2=`tail -1 /tmp/$log|awk '{print $1}'`echo $t_s>>/tmp/$logv=$[$t_s-$t_s2]echo $vif [ $v -gt 3600 ]then/dir/to/php ../mail/mail.php "$1 $2" "$3"echo "0" > /tmp/$log.txtelseif [ ! -f /tmp/$log.txt ]thenecho "0" > /tmp/$log.txtfinu=`cat /tmp/$log.txt`nu2=$[$nu+1]echo $nu2>/tmp/$log.txtif [ $nu2 -gt 10 ]then/dir/to/php ../mail/mail.php "trouble continue 10 min $1 $2 " "$3"echo "0" > /tmp/$log.txtfifi
http://ask.apelearn.com/question/8119 # lanmp一键安装脚本文档参考地#!/bin/bashecho "It will install lamp or lnmp."sleep 1##check last command is OK or not.check_ok() {if [ $? != 0 ]thenecho "Error, Check the error log."exit 1fi}##get the archive of the system,i686 or x86_64.ar=`arch`##close seliuxsed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/configselinux_s=`getenforce`if [ $selinux_s == "Enforcing" -o $selinux_s == "enforcing" ]thensetenforce 0fi##close iptablesiptables-save > /etc/sysconfig/iptables_`date +%s`iptables -Fservice iptables save##if the packge installed ,then omit.myum() {if ! rpm -qa|grep -q "^$1"thenyum install -y $1check_okelseecho $1 already installed.fi}## install some packges.for p in gcc wget perl perl-devel libaio libaio-devel pcre-devel zlib-develdomyum $pdone##install epel.if rpm -qa epel-release >/dev/nullthenrpm -e epel-releasefiif ls /etc/yum.repos.d/epel-6.repo* >/dev/null 2>&1thenrm -f /etc/yum.repos.d/epel-6.repo*fiwget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo##function of installing mysqld.install_mysqld() {echo "Chose the version of mysql."select mysql_v in 5.1 5.6docase $mysql_v in5.1)cd /usr/local/src[ -f mysql-5.1.72-linux-$ar-glibc23.tar.gz ] || wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-$ar-glibc23.tar.gztar zxf mysql-5.1.72-linux-$ar-glibc23.tar.gzcheck_ok[ -d /usr/local/mysql ] && /bin/mv /usr/local/mysql /usr/local/mysql_`date +%s`mv mysql-5.1.72-linux-$ar-glibc23 /usr/local/mysqlcheck_okif ! grep '^mysql:' /etc/passwdthenuseradd -M mysql -s /sbin/nologincheck_okfimyum compat-libstdc++-33[ -d /data/mysql ] && /bin/mv /data/mysql /data/mysql_`date +%s`mkdir -p /data/mysqlchown -R mysql:mysql /data/mysqlcd /usr/local/mysql./scripts/mysql_install_db --user=mysql --datadir=/data/mysqlcheck_ok/bin/cp support-files/my-huge.cnf /etc/my.cnfcheck_oksed -i '/^\[mysqld\]$/a\datadir = /data/mysql' /etc/my.cnf/bin/cp support-files/mysql.server /etc/init.d/mysqldsed -i 's#^datadir=#datadir=/data/mysql#' /etc/init.d/mysqldchmod 755 /etc/init.d/mysqldchkconfig --add mysqldchkconfig mysqld onservice mysqld startcheck_okbreak;;5.6)cd /usr/local/src[ -f mysql-5.6.26-linux-glibc2.5-$ar.tar.gz ] || wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.26-linux-glibc2.5-$ar.tar.gztar zxf mysql-5.6.26-linux-glibc2.5-$ar.tar.gzcheck_ok[ -d /usr/local/mysql ] && /bin/mv /usr/local/mysql /usr/local/mysql_bakmv mysql-5.6.26-linux-glibc2.5-$ar /usr/local/mysqlif ! grep '^mysql:' /etc/passwdthenuseradd -M mysql -s /sbin/nologinfimyum compat-libstdc++-33[ -d /data/mysql ] && /bin/mv /data/mysql /data/mysql_bakmkdir -p /data/mysqlchown -R mysql:mysql /data/mysqlcd /usr/local/mysql./scripts/mysql_install_db --user=mysql --datadir=/data/mysqlcheck_ok/bin/cp support-files/my-default.cnf /etc/my.cnfcheck_oksed -i '/^\[mysqld\]$/a\datadir = /data/mysql' /etc/my.cnf/bin/cp support-files/mysql.server /etc/init.d/mysqldsed -i 's#^datadir=#datadir=/data/mysql#' /etc/init.d/mysqldchmod 755 /etc/init.d/mysqldchkconfig --add mysqldchkconfig mysqld onservice mysqld startcheck_okbreak;;*)echo "only 1(5.1) or 2(5.6)"exit 1;;esacdone}##function of install httpd.install_httpd() {echo "Install apache version 2.2."cd /usr/local/src[ -f httpd-2.2.16.tar.gz ] || wget http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gztar zxf httpd-2.2.16.tar.gz && cd httpd-2.2.16check_ok./configure \--prefix=/usr/local/apache2 \--with-included-apr \--enable-so \--enable-deflate=shared \--enable-expires=shared \--enable-rewrite=shared \--with-pcrecheck_okmake && make installcheck_ok}##function of install lamp's php.install_php() {echo -e "Install php.\nPlease chose the version of php."select php_v in 5.4 5.6docase $php_v in5.4)cd /usr/local/src/[ -f php-5.4.45.tar.bz2 ] || wget 'http://cn2.php.net/get/php-5.4.45.tar.bz2/from/this/mirror' -O php-5.4.45.tar.bz2tar jxf php-5.4.45.tar.bz2 && cd php-5.4.45for p in openssl-devel bzip2-devel \libxml2-devel curl-devel libpng-devel \libjpeg-devel freetype-devel libmcrypt-devel\libtool-ltdl-devel perl-develdomyum $pdonecheck_ok./configure \--prefix=/usr/local/php \--with-apxs2=/usr/local/apache2/bin/apxs \--with-config-file-path=/usr/local/php/etc \--with-mysql=/usr/local/mysql \--with-libxml-dir \--with-gd \--with-jpeg-dir \--with-png-dir \--with-freetype-dir \--with-iconv-dir \--with-zlib-dir \--with-bz2 \--with-openssl \--with-mcrypt \--enable-soap \--enable-gd-native-ttf \--enable-mbstring \--enable-sockets \--enable-exif \--disable-ipv6check_okmake && make installcheck_ok[ -f /usr/local/php/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php/etc/php.inibreak;;5.6)cd /usr/local/src/[ -f php-5.6.6.tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gztar zxf php-5.6.6.tar.gz && cd php-5.6.6for p in openssl-devel bzip2-devel \libxml2-devel curl-devel libpng-devel \libjpeg-devel freetype-devel libmcrypt-devel\libtool-ltdl-devel perl-develdomyum $pdone./configure \--prefix=/usr/local/php \--with-apxs2=/usr/local/apache2/bin/apxs \--with-config-file-path=/usr/local/php/etc \--with-mysql=/usr/local/mysql \--with-libxml-dir \--with-gd \--with-jpeg-dir \--with-png-dir \--with-freetype-dir \--with-iconv-dir \--with-zlib-dir \--with-bz2 \--with-openssl \--with-mcrypt \--enable-soap \--enable-gd-native-ttf \--enable-mbstring \--enable-sockets \--enable-exif \--disable-ipv6check_okmake && make installcheck_ok[ -f /usr/local/php/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php/etc/php.inibreak;;*)echo "only 1(5.4) or 2(5.6)";;esacdone}##function of apache and php configue.join_apa_php() {sed -i '/AddType .*.gz .tgz$/a\AddType application\/x-httpd-php .php' /usr/local/apache2/conf/httpd.confcheck_oksed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm/' /usr/local/apache2/conf/httpd.confcheck_okcat > /usr/local/apache2/htdocs/index.php <EOFif /usr/local/php/bin/php -i |grep -iq 'date.timezone => no value'thensed -i '/;date.timezone =$/a\date.timezone = "Asia\/Chongqing"' /usr/local/php/etc/php.inifi/usr/local/apache2/bin/apachectl restartcheck_ok}##function of check service is running or not, example nginx, httpd, php-fpm.check_service() {if [ "$1" == "phpfpm" ]thens="php-fpm"elses=$1fin=`ps aux |grep "$s"|wc -l`if [ $n -gt 1 ]thenecho "$1 service is already started."elseif [ -f /etc/init.d/$1 ]then/etc/init.d/$1 startcheck_okelseinstall_$1fifi}##function of install lamplamp() {check_service mysqldcheck_service httpdinstall_phpjoin_apa_phpecho "LAMP done,Please use 'http://your ip/index.php' to access."}##function of install nginxinstall_nginx() {cd /usr/local/src[ -f nginx-1.8.0.tar.gz ] || wget http://nginx.org/download/nginx-1.8.0.tar.gztar zxf nginx-1.8.0.tar.gzcd nginx-1.8.0myum pcre-devel./configure --prefix=/usr/local/nginxcheck_okmake && make installcheck_okif [ -f /etc/init.d/nginx ]then/bin/mv /etc/init.d/nginx /etc/init.d/nginx_`date +%s`ficurl http://www.apelearn.com/study_v2/.nginx_init -o /etc/init.d/nginxcheck_okchmod 755 /etc/init.d/nginxchkconfig --add nginxchkconfig nginx oncurl http://www.apelearn.com/study_v2/.nginx_conf -o /usr/local/nginx/conf/nginx.confcheck_okservice nginx startcheck_okecho -e "<?php\n phpinfo();\n?>" > /usr/local/nginx/html/index.phpcheck_ok}##function of install php-fpminstall_phpfpm() {echo -e "Install php.\nPlease chose the version of php."select php_v in 5.4 5.6docase $php_v in5.4)cd /usr/local/src/[ -f php-5.4.45.tar.bz2 ] || wget 'http://cn2.php.net/get/php-5.4.45.tar.bz2/from/this/mirror' -O php-5.4.45.tar.bz2tar jxf php-5.4.45.tar.bz2 && cd php-5.4.45for p in openssl-devel bzip2-devel \libxml2-devel curl-devel libpng-devel \libjpeg-devel freetype-devel libmcrypt-devel\libtool-ltdl-devel perl-develdomyum $pdoneif ! grep -q '^php-fpm:' /etc/passwdthenuseradd -M -s /sbin/nologin php-fpmcheck_okfi./configure \--prefix=/usr/local/php-fpm \--with-config-file-path=/usr/local/php-fpm/etc \--enable-fpm \--with-fpm-user=php-fpm \--with-fpm-group=php-fpm \--with-mysql=/usr/local/mysql \--with-mysql-sock=/tmp/mysql.sock \--with-libxml-dir \--with-gd \--with-jpeg-dir \--with-png-dir \--with-freetype-dir \--with-iconv-dir \--with-zlib-dir \--with-mcrypt \--enable-soap \--enable-gd-native-ttf \--enable-ftp \--enable-mbstring \--enable-exif \--enable-zend-multibyte \--disable-ipv6 \--with-pear \--with-curl \--with-opensslcheck_okmake && make installcheck_ok[ -f /usr/local/php-fpm/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php-fpm/etc/php.iniif /usr/local/php-fpm/bin/php -i |grep -iq 'date.timezone => no value'thensed -i '/;date.timezone =$/a\date.timezone = "Asia\/Chongqing"' /usr/local/php-fpm/etc/php.inicheck_okfi[ -f /usr/local/php-fpm/etc/php-fpm.conf ] || curl http://www.apelearn.com/study_v2/.phpfpm_conf -o /usr/local/php-fpm/etc/php-fpm.conf[ -f /etc/init.d/phpfpm ] || /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/phpfpmchmod 755 /etc/init.d/phpfpmchkconfig phpfpm onservice phpfpm startcheck_okbreak;;5.6)cd /usr/local/src/[ -f php-5.6.6.tar.gz ] || wget http://mirrors.sohu.com/php/php-5.6.6.tar.gztar zxf php-5.6.6.tar.gz && cd php-5.6.6for p in openssl-devel bzip2-devel \libxml2-devel curl-devel libpng-devel \libjpeg-devel freetype-devel libmcrypt-devel\libtool-ltdl-devel perl-develdomyum $pdoneif ! grep -q '^php-fpm:' /etc/passwdthenuseradd -M -s /sbin/nologin php-fpmficheck_ok./configure \--prefix=/usr/local/php-fpm \--with-config-file-path=/usr/local/php-fpm/etc \--enable-fpm \--with-fpm-user=php-fpm \--with-fpm-group=php-fpm \--with-mysql=/usr/local/mysql \--with-mysql-sock=/tmp/mysql.sock \--with-libxml-dir \--with-gd \--with-jpeg-dir \--with-png-dir \--with-freetype-dir \--with-iconv-dir \--with-zlib-dir \--with-mcrypt \--enable-soap \--enable-gd-native-ttf \--enable-ftp \--enable-mbstring \--enable-exif \--disable-ipv6 \--with-pear \--with-curl \--with-opensslcheck_okmake && make installcheck_ok[ -f /usr/local/php-fpm/etc/php.ini ] || /bin/cp php.ini-production /usr/local/php-fpm/etc/php.iniif /usr/local/php-fpm/bin/php -i |grep -iq 'date.timezone => no value'thensed -i '/;date.timezone =$/a\date.timezone = "Asia\/Chongqing"' /usr/local/php-fpm/etc/php.inicheck_okfi[ -f /usr/local/php-fpm/etc/php-fpm.conf ] || curl http://www.apelearn.com/study_v2/.phpfpm_conf -o /usr/local/php-fpm/etc/php-fpm.confcheck_ok[ -f /etc/init.d/phpfpm ] || /bin/cp sapi/fpm/init.d.php-fpm /etc/init.d/phpfpmchmod 755 /etc/init.d/phpfpmchkconfig phpfpm onservice phpfpm startcheck_okbreak;;*)echo 'only 1(5.4) or 2(5.6)';;esacdone}##function of install lnmplnmp() {check_service mysqldcheck_service nginxcheck_service phpfpmecho "The lnmp done, Please use 'http://your ip/index.php' to access."}read -p "Please chose which type env you install, (lamp|lnmp)? " tcase $t inlamp)lamp;;lnmp)lnmp;;*)echo "Only 'lamp' or 'lnmp' your can input.";;esac