娟斌心 发表于 2018-11-12 07:32:03

我的Nginx一键安装

  做了一个centos7安装nginx的脚本,学习中,有错误的地方在所难免.本来想把安装需要的都传上来,没找到上传附件的地方,抱歉.
  1:环境
  我用的是centos7 mini版本,网络能通互联网.
  2:脚本
  #!/bin/sh
  #安装nginx需要以来的库有gcc automake autoconf libtool make gcc-c++,所以要先去验证这些东西存不存在,有没有安装.
  ppwd=pwd
  replace_yum(){
  #发现我这里163的源超级快,所以换成163的源
  if [ ! -f/etc/yum.repos.d/CentOS7-Base-163.repo];then
  rm -rf /etc/yum.repos.d/*;cp CentOS7-Base-163.repo /etc/yum.repos.d/;yum clean all;yum makecache
  echo "yum源替换完毕"
  else
  echo "当前使用yum源为163"
  fi
  }
  replace_yum
  install_gcc(){
  test_gcc=gcc 2>&1|grep 'gcc:'|awk '{print $3}'
  if [ "$test_gcc" = "command" -o "$test_gcc" = "未找到命令" ];then
  #这里注意,if后面的[]中括号,之间要有空格[ x ],而不能写成,还有,这里的-o是或,-a是与.还有=号之间要有空格[ a = b]而不能写成[ a=b ]
  yum install gcc -y
  echo "gcc安装完毕"
  rm -rf /var/run/yum.pid
  else
  echo "gcc已安装"
  fi
  }
  install_gcc
  install_automake(){
  test_automake=automake 2>&1|grep 'automake:'|awk '{print $3}'
  if [ "$test_automake" = "command" -o "$test_automake" = "未找到命令"];then
  yum install automake -y
  echo "automake安装完毕"
  rm -rf /var/run/yum.pid
  else
  echo "sutomake已安装"
  fi
  }
  install_automake
  install_autoconf(){
  test_autoconf=autoconf 2>&1|grep 'autoconf:'|awk '{print $3}'
  if [ "$test_autoconf" = "command" -o "$test_autoconf" = "未找到命令"];then
  yum install autoconf -y
  echo "autoconf安装完毕"
  rm -rf /var/run/yum.pid
  else
  echo "autoconf已安装"
  fi
  }
  install_autoconf
  install_libtool(){
  test_libtool=libtool 2>&1|grep 'libtool:'|awk '{print $3}'
  if [ "$test_libtool" = "command" -o "$test_libtool" = "未找到命令"];then
  yum install libtool -y
  echo "libtool安装完毕"
  rm -rf /var/run/yum.pid
  else
  echo "libtool已安装"
  fi
  }
  install_libtool
  install_make(){
  test_make=make 2>&1|grep 'make:'|awk '{print $3}'
  if [ "$test_make" = "command" -o "$test_make" = "未找到命令"];then
  yum install make -y
  echo "make安装完毕"
  rm -rf /var/run/yum.pid
  else
  echo "make已安装"
  fi
  }
  install_make
  install_gccc(){
  test_gccc=rpm -qa | grep gcc-c++
  if ["$test_gccc" = "" ];then
  cp $ppwd/Centos-7.repo /etc/yum.repos.d/;rm -rf /etc/yum.repos.d/CentOS7-Base-163.repo;yum clean all;yum makecache;yum install gcc-c++ -y
  #运维我发现163的yum源无法安装gcc-c++,所以我用阿里云的源
  echo "gcc-c++安装完毕"
  rm -rf /var/run/yum.pid
  else
  echo "gcc-c++已安装"
  fi
  }
  install_gccc
  #
  cd $ppwd
  install_pcre(){
  test_pcre=pcre-config --version 2>&1|grep'pcre-config:'
  test_pcre_version=pcre-config --version 2>&1|grep'8.37'

if ["$test_pcre" != "" -o "test_pcre_version"!= "8.37"];then
  

if ["$test_pcre" != ""];then  tar -xvf pcre-8.37.tar.gz       #;cd pcre-8.37;./configure ;make ;make install
  #echo "pcre安装完毕"
  
else
  echo "pcre已安装,当前版本为$test_pcre_version"
  
fi
  

  }
  install_pcre
  cd $ppwd
  install_zlib(){
  test_zlib=rpm -qa|grep zlib
  if ["$test_zlib" = ""];then
  tar -xvf zlib-1.2.11.tar.gz   #;cd zlib-1.2.11;./configure ;make ;make install
  #echo "zlib安装完毕"
  else
  echo "zlib已安装"
  fi
  }
  install_zlib
  cd $ppwd
  install_openssl(){
  test_openssl=openssl version|grep pen|awk '{print $2}'
  test_openssl_version=${test_openssl:0:5}
  if [ "$test_openssl" = ""   ];then
  tar -xvf openssl-1.1.0g.tar.gz      #;cd openssl-1.1.0g;./configure;make;make install
  #echo "openssl安装完毕"
  else
  echo "openssl已安装"
  fi
  }
  install_openssl
  cd $ppwd
  install_nginx(){
  #
  #./configure --sbin-path=/usr/local/nginx/nginx \
  #--conf-path=/usr/local/nginx/nginx.conf \
  #--pid-path=/usr/local/nginx/nginx.pid \
  #--with-http_ssl_module \
  #--with-pcre
  #--with-zlib=$ppwd/zlib-1.2.11
  #--with-openssl=$ppwd/openssl-1.1.0g#这个其实是引用未编译安装的openssl,好像是引用的同时就会编译安装openssl,路径直接指向解压出来的openssl安装包的路径.所以上面的openssl安装就不用再安装了,这个要研究一下.如果真的是这样,那么pcre和zlib也应该不用单独安装了呀.这个得下来研究.
  #./configure --prefix=/data/nginx --with-http_realip_module --with-http_sub_module --with-http_flv_module --with-http_dav_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_addition_module --with-pcre=/data/download/pcre-8.00 --with-openssl=/data/download/openssl-0.9.8l --with-http_ssl_module --with-zlib=/data/download/zlib-1.2.3
  #./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre --with-openssl=$ppwd/openssl-1.1.0g;make ;make install --with-zlib=$ppwd/zlib-1.2.11
  #./configure --prefix=/data/nginx --with-http_realip_module --with-http_sub_module --with-http_flv_module --with-http_dav_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_addition_module --with-pcre=$ppwd/pcre-8.37 --with-openssl=$ppwd/openssl-1.1.0g --with-zlib=$ppwd/zlib-1.2.11
  tar -xvf openssl-1.1.0g.tar.gz
  tar -xvf zlib-1.2.11.tar.gz
  if [ ! -f /usr/local/nginx/nginx.conf   ];then
  mkdir -p /usr/local/nginx
  tar -xvf nginx-1.12.2.tar.gz;cd nginx-1.12.2;./configure --prefix=/usr/local/nginx --with-http_realip_module --with-http_sub_module --with-http_flv_module --with-http_dav_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_addition_module --with-pcre=$ppwd/pcre-8.37 --with-openssl=$ppwd/openssl-1.1.0g --with-zlib=$ppwd/zlib-1.2.11;make;make install;echo "nginx安装完毕";rm -rf $ppwd/zlib-1.2.11;rm -rf $ppwd/openssl-1.1.0g;rm -rf $ppwd/pcre-8.37
  else
  echo "nginx已经安装"
  fi
  }
  install_nginx


页: [1]
查看完整版本: 我的Nginx一键安装