侧边栏壁纸
博主头像
高大北博主等级

所有的再见中,我最喜欢明天见

  • 累计撰写 208 篇文章
  • 累计创建 151 个标签
  • 累计收到 20 条评论
标签搜索

目 录CONTENT

文章目录

centos7一键离线安装脚本-nginx

高大北
2022-04-18 / 0 评论 / 0 点赞 / 286 阅读 / 1,832 字 / 正在检测是否收录...

使用方法

sh install_nginx.sh

install_nginx.sh接收$1参数,可指定安装路径,默认安装路径为/usr/local

install_nginx.sh

#!/bin/bash

directory=$1
current_dir=`pwd`

function select_installation_directory(){
  if [[ -z ${directory} ]];
  then
    directory='/usr/local'
  fi
}

function check_dependency(){
  if [[ -z $(rpm -qa | grep ^gcc | grep -v grep) ]];
  then
    cd gcc && rpm -Uvh *.rpm --nodeps --force && cd ..
  fi
  if [[ -z $(rpm -qa | grep ^gcc-c++ | grep -v grep) ]];
  then
    cd g++ && rpm -Uvh *.rpm --nodeps --force && cd ..
  fi
  if [[ -z $(rpm -qa | grep ^zlib-devel | grep -v grep) ]];
  then
    cd zlib && rpm -Uvh *.rpm --nodeps --force && cd ..
  fi
  if [[ -z $(rpm -qa | grep ^openssl-devel | grep -v grep) ]];
  then
    cd openssl && rpm -Uvh *.rpm --nodeps --force && cd ..
  fi
  if [[ -z $(rpm -qa | grep ^pcre-devel | grep -v grep) ]];
  then
    cd pcre && rpm -Uvh *.rpm --nodeps --force && cd ..
  fi
}

function install_nginx(){
  tar_name=$(ls .|grep nginx-.*.tar.gz)
  tar_dir=${tar_name%.tar.gz*}
  tar -zxvf "${current_dir}"/"${tar_name}"
  cd "${tar_dir}"
  ./configure --prefix=${directory}/nginx --with-stream --with-http_ssl_module
  make && make install
  cd ..
}

function powered_up_nginx(){
  chmod 755 "${current_dir}"/nginx.sh
  sed -i "s:^nginx="\"/usr/sbin/nginx\"":nginx="\"${directory}/nginx/sbin/nginx\"":g" "${current_dir}"/nginx.sh
  sed -i "s:^NGINX_CONF_FILE="\"/etc/nginx/nginx.conf\"":NGINX_CONF_FILE="\"${directory}/nginx/conf/nginx.conf\"":g" "${current_dir}"/nginx.sh
  cp "${current_dir}"/nginx.sh /etc/init.d/nginx
  cp "${current_dir}"/nginx.sh ${directory}/nginx/sbin/nginx.sh
  ${directory}/nginx/sbin/nginx.sh start
  chkconfig nginx on
}

function Main(){
  select_installation_directory;
  check_dependency;
  install_nginx;
  powered_up_nginx;
}
Main;

相关依赖包下载地址

https://www.sky12580.cn/upload/2022/04/nginx.zip

0

评论区