renyanping 发表于 2018-11-10 10:05:52

自己写的一键安装Nginx+Mysql+PHP脚本

  #!/bin/bash
  dir='/opt'
  mysql_download='http://mirror.trouble-free.net/mysql_mirror/Downloads/MySQL-5.0/mysql-5.0.92.tar.gz'
  nginx_download='http://nginx.org/download/nginx-1.1.7.tar.gz'
  pcre_download='http://nchc.dl.sourceforge.net/project/pcre/pcre/8.20/pcre-8.20.zip'
  libiconv_download='http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz'
  libmcrypt_download='http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0'
  mcrypt_download='http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0'
  mhash_download='http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0'
  php_download='http://cn.php.net/distributions/php-5.2.17.tar.bz2'
  php_fpm_download='http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz'
  memcache_download='http://pecl.php.net/get/memcache-2.2.6.tgz'
  eaccelerator_download='http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2'
  PDO_MYSQL_download='http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz'
  ImageMagick_download='http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz'
  imagick_download='http://pecl.php.net/get/imagick-2.3.0.tgz'
  memcached_download='http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz'
  libevent_download='http://monkey.org/~provos/libevent-2.0.11-stable.tar.gz'
  function __install_mysql()
  {
  /usr/sbin/groupadd mysql
  /usr/sbin/useradd -m mysql -g mysql -d /usr/local/mysql -s /sbin/nologin
  cd $dir
  wget $mysql_download
  filename=`ls mysql*`
  foldername=`echo $filename | sed 's/\.tar.gz//'`
  tar zxvf $filename
  cd $foldername
  ./configure--prefix=/usr/local/mysql \
  --localstatedir=/data/mysql \
  --enable-static \
  --with-client-ldflags=-all-static \
  --with-mysqld-ldflags=-all-static \
  --with- \
  --with-extra-charsets=all \
  --with-berkeley-db \
  --with-innodb \
  --without-readline \
  --enable-assembler \
  --with-pthread \
  --enable-thread-safe-client \
  --without-debug \
  --without-ndb-debug
  make;make install
  }
  function __install_mysql_management()
  {
  mkdir -p /data/mysql
  cd $dir
  filename=`basename $mysql_download`
  foldername=`echo $filename | sed 's/\.tar.gz//'`
  cat > /etc/my.cnf/usr/local/php/etc/php-fpm.conf   
  Pid file
  /usr/local/php/logs/php-fpm.pid
  Error log file
  /usr/local/php/logs/php-fpm.log
  Log level
  notice
  When this amount of php processes exited with SIGSEGV or SIGBUS ...
  10
  ... in a less than this interval of time, a graceful restart will be initiated.
  Useful to work around accidental curruptions in accelerator's shared memory.
  1m
  Time limit on waiting child's reaction on signals from master
  5s
  Set to 'no' to debug fpm
  yes
  
  
  
  Name of pool. Used in logs and stats.
  default
  Address to accept fastcgi requests on.
  Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
  127.0.0.1:9000
  
  Set listen(2) backlog
  -1
  Set permissions for unix socket, if one used.
  In Linux read/write permissions must be set in order to allow connections from web server.
  Many BSD-derrived systems allow connections regardless of permissions.
  
  
  0666
  
  Additional php.ini defines, specific to this pool of workers.
  
  /usr/sbin/sendmail -t -i
  0
  
  Unix user of processes
  www
  Unix group of processes
  www
  Process manager settings
  
  Sets style of controling worker process count.
  Valid values are 'static' and 'apache-like'
  static
  Sets the limit on the number of simultaneous requests that will be served.
  Equivalent to Apache MaxClients directive.
  Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
  Used with any pm_style.
  128
  Settings group for 'apache-like' pm style
  
  Sets the number of server processes created on startup.
  Used only when 'apache-like' pm_style is selected
  20

  Sets the desired minimum number of>  Used only when 'apache-like' pm_style is selected
  5

  Sets the desired maximum number of>  Used only when 'apache-like' pm_style is selected
  35
  
  
  The timeout (in seconds) for serving a single request after which the worker process will be terminated
  Should be used when 'max_execution_time' ini option does not stop script execution for some reason
  '0s' means 'off'
  0s
  The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
  '0s' means 'off'
  0s
  The log file for slow requests
  logs/slow.log
  Set open file desc rlimit
  65535

  Set max core>  0
  Chroot to this directory at the start, absolute path
  
  Chdir to this directory at the start, absolute path
  
  Redirect workers' stdout and stderr into main error log.
  If not set, they will be redirected to /dev/null, according to FastCGI specs
  yes
  How much requests each process should execute before respawn.
  Useful to work around memory leaks in 3rd party libraries.
  For endless request processing please specify 0
  Equivalent to PHP_FCGI_MAX_REQUESTS
  1024
  Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
  Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
  Makes sense only with AF_INET listening socket.
  127.0.0.1
  Pass environment variables like LD_LIBRARY_PATH
  All $VARIABLEs are taken from current environment
  
  $HOSTNAME
  /usr/local/bin:/usr/bin:/bin
  /tmp
  /tmp
  /tmp
  $OSTYPE
  $MACHTYPE
  2
  
  
  
  
  EOF
  echo "/usr/local/php/sbin/php-fpm start" >> /etc/rc.local
  }
  function __install_memcache()
  {
  cd $dir
  wget $memcache_download
  filename=`ls memcache-*`
  foldername=`echo $filename | sed s'/\.tgz//'`
  tar zxvf $filename
  cd $foldername
  /usr/local/php/bin/phpize
  ./configure --with-php-config=/usr/local/php/bin/php-config
  make;make install
  sed -i 's@extension_dir = "./"@extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"@' /usr/local/php/etc/php.ini
  sed -i '492iextension = "memcache.so"' /usr/local/php/etc/php.ini
  }
  function __install_eaccelerator()
  {
  cd $dir
  wget $eaccelerator_download
  filename=`ls eaccelerator*`
  foldername=`echo $filename | sed 's/\.tar\.bz2//'`
  tar jxvf $filename
  cd $foldername
  /usr/local/php/bin/phpize
  ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
  make;make install
  mkdir -p /tmp/eaccelerator
  cat >> /usr/local/php/etc/php.ini > /etc/rc.local
  }
  function __install_pcre()
  {
  cd $dir
  wget $pcre_download
  filename=`ls pcre-*`
  foldername=`echo $filename | sed 's/\.zip//'`
  unzip $filename
  cd $foldername
  ./configure
  make;make install
  }
  function __install_nginx()
  {
  /usr/sbin/groupadd www
  /usr/sbin/useradd -m www -g www -s /sbin/nologin -d /usr/local/nginx
  mkdir -p /data/www
  echo "" > /data/www/index.php
  mkdir -p /data/www/logs
  chown -R www:www /data/www
  cd $dir
  wget $nginx_download
  filename=`ls nginx-*`
  foldername=`echo $filename | sed 's/\.tar\.gz//'`
  tar zxvf $filename
  cd $foldername
  ./configure--prefix=/usr/local/nginx \
  --with-http_stub_status_module \
  --with-http_ssl_module \
  --user=www \
  --group=www \
  --with-http_realip_module \
  --with-http_flv_module \
  --with-http_gzip_static_module
  make;make install
  mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
  cat > /usr/local/nginx/conf/nginx.conf/usr/local/nginx/conf/fcgi.conf > /etc/rc.local
  }
  function __cutlog()
  {
  cat > /root/cutlog.sh   EOF
  echo "00 00 * * * /bin/sh /root/cutlog.sh >/dev/null" >> /var/spool/cron/root
  }
  echo "
  #mysqldatadir:/data/mysql
  #mysqluser:root
  #mysqlpassword:lihuipeng007@163.com
  #webdir:/data/www
  #installdir:/usr/local/
  #srcdir:/opt
  0.exit
  1.Only install Mysql
  2.Only install Nginx
  3.Install Nginx+php
  4.Install Mysql+Nginx+PHP
  5.Install Mysql+Nginx+PHP+Memcached
  6.Test option "
  read -p "Which do you want to install{}:" linecase $line in
  0)
  exit 0;
  ;;
  1)
  __install_mysql
  __install_mysql_complete
  ;;
  2)
  __install_pcre
  __install_nginx
  __cutlog
  /usr/local/nginx/sbin/nginx
  ;;
  3)
  __install_lib
  __install_mysql
  __install_libiconv
  __install_libmcrypt
  __install_mhash
  __install_mcrypt
  __install_php
  __install_memcache
  __install_eaccelerator
  __install_PDO_MYSQL
  __install_ImageMagick
  __install_imagick
  __install_pcre
  __install_nginx
  __cutlog
  /usr/local/php/sbin/php-fpm start
  /usr/local/nginx/sbin/nginx
  ;;
  4)
  __install_lib
  __install_mysql
  __install_mysql_management
  __install_libiconv
  __install_libmcrypt
  __install_mhash
  __install_mcrypt
  __install_php
  __install_memcache
  __install_eaccelerator
  __install_PDO_MYSQL
  __install_ImageMagick
  __install_imagick
  __install_pcre
  __install_nginx
  __cutlog
  /usr/local/php/sbin/php-fpm start
  /usr/local/nginx/sbin/nginx
  ;;
  5)
  __install_lib
  __install_mysql
  __install_mysql_management
  __install_libiconv
  __install_libmcrypt
  __install_mhash
  __install_mcrypt
  __install_php
  __install_memcache
  __install_eaccelerator
  __install_PDO_MYSQL
  __install_ImageMagick
  __install_imagick
  __install_memcached
  /usr/local/memcached/bin/memcached -d -m 64 -p 11211 -u www -l localhost
  __install_pcre
  __install_nginx
  __cutlog
  /usr/local/php/sbin/php-fpm start
  /usr/local/nginx/sbin/nginx
  ;;
  6)
  echo "test option!"
  ;;
  *)
  echo "Usage: `basename $0` {0|1|2|3|4|5|6}" >&2
  exit 3
  ;;
  esac

页: [1]
查看完整版本: 自己写的一键安装Nginx+Mysql+PHP脚本