设为首页 收藏本站
查看: 894|回复: 0

[经验分享] 我的Nginx一键安装

[复制链接]

尚未签到

发表于 2018-11-12 07:32:03 | 显示全部楼层 |阅读模式
  做了一个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 ],而不能写成[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、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-633860-1-1.html 上篇帖子: nginx之头部变量x_forwarded_for 下篇帖子: Nginx+tomcat显示真实IP地址
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表