Linux Shell 实现一键部署Nginx

2023-05-16

       

nginx前言

nginx [engine x] 是 HTTP 和反向代理服务器、邮件代理服务器和通用 TCP/UDP 代理服务器,最初由Igor Sysoev编写。很长一段时间以来,它一直在许多负载重的俄罗斯网站上运行,包括 Yandex、 Mail.Ru、 VK和 Rambler。根据 Netcraft 的数据, 2022 年 1 月,nginx 服务或代理了 22.16% 最繁忙的站点。以下是一些成功案例: Dropbox、 Netflix、 Wordpress.com、 FastMail.FM。

nginx 参考

nginxzlib
downloaddownload

Linux 各系统下载使用参考

Red HatRocky Linux Oracle Linux

AlmaLinux 

ubuntususelinuxesxiRHEL标准安装系统安装参考YUM参考

MobaXterm 远程连接工具

Red Hat Enterprise 9.0 文档Kickstart 生成器
downloaddownloaddownloaddownloaddownloaddownloaddownload参考参考配置参考download参考Kickstart 
版本兼容性

安装 nginx

  • 创建安装自动化脚本

  • 实现在线安装nginx,配置nginx配置文件,防火墙配置,企业微信机器人通知。
  • 以下基于Redhat系统
  • nginx 安装目录/usr/local/nginx
  • curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXXXX' #更改自己的企业微信机器人地址 
  • curl -o /etc/yum.repos.d/redhat.repo http://mirrors.aliyun.com/repo/Centos-8.repo #阿里在线repo
  • yum install figlet -y #用于将文字转换为放大艺术字(使用figlet Mysql显示)
vi /Nginx_install.sh
#!/bin/sh
# -*- coding: utf-8 -*-
# Author: Ciasm
# Date: 2022/04/10

<<!
 _   _       _            
| \ | | __ _(_)_ __ __  __
|  \| |/ _` | | '_ \\ \/ /
| |\  | (_| | | | | |>  < 
|_| \_|\__, |_|_| |_/_/\_\
       |___/  
!

#source /etc/rc.d/init.d/functions

NGINX_URL=http://nginx.org/download/
NGINX_FILE=nginx-1.22.1.tar.gz
NGINX_FILE_DIR=nginx-1.22.1
NGINX_PREFIX=/usr/local/nginx
data_downloads=/data/downloads
zlib_devel_url=https://yum.oracle.com/repo/OracleLinux/OL8/baseos/latest/x86_64/getPackage/zlib-devel-1.2.11-20.el8.x86_64.rpm
zlib_url=https://yum.oracle.com/repo/OracleLinux/OL8/baseos/latest/x86_64/getPackageSource/zlib-1.2.11-20.el8.src.rpm

nginx_dependence (){
mkdir -p $data_downloads
wget -N -P $data_downloads $zlib_devel_url
wget -N -P $data_downloads $zlib_url
rpm -ihv $data_downloads/*.rpm --nodeps --force
yum install -y pcre pcre-devel openssl openssl-devel gcc gcc-c++ net-tools vim cmake make

#Centos 8 install rely on
#yum install -y pcre pcre-devel openssl openssl-devel gcc gcc-c++ net-tools vim cmake make zlib-devel zlib-devel-
}

install_nginx (){
if [ ! -d ${NGINX_PREFIX} ];then
nginx_dependence
/usr/sbin/useradd -s /sbin/nologin -M www
/usr/sbin/groupadd -f www
wget -N -P $data_downloads $NGINX_URL/$NGINX_FILE
tar -zxf $data_downloads/$NGINX_FILE -C $data_downloads
if [ $? -eq 0 ];then
     cd $data_downloads/$NGINX_FILE_DIR 
     ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_realip_module --with-stream --with-stream_ssl_module --with-http_flv_module --with-http_mp4_module --with-http_dav_module --with-http_sub_module  --with-http_gunzip_module --with-pcre --with-debug
	 cd $data_downloads/$NGINX_FILE_DIR && make && make install
     rm -rf /usr/local/nginx/conf/nginx.conf
     config_nginx
     ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
	 nginx_server
   action "\033[32mThe nginx Install Sussess...\033[0m" 
   else
	action "\033[33mThe nginx Install Failed...\033[0m" 
	exit 1
   fi
   else
	echo -e "\033[31mThe nginx already Install...\033[0m"
fi
}
 
 
config_nginx (){
cat >>/usr/local/nginx/conf/nginx.conf<<EOF
#user nobody;
           worker_processes auto; #Custom CPU
           worker_rlimit_nofile 100000;
           error_log  logs/error.log  info;
events {
           worker_connections 1024;
           accept_mutex on;
           multi_accept on;
           use epoll;
 }
 
stream {
    upstream mysql {
           hash $remote_addr consistent;
           server 127.0.0.1:3306            weight=5 max_fails=3 fail_timeout=30s;
    }
 
server {
           listen 3307;
           proxy_connect_timeout 1s;
           proxy_timeout 3s;
           proxy_pass mysql;
    }
}
 
http{
          #gzip
          gzip on; #Open compression
          gzip_min_length  1k;
          gzip_buffers     4 32k; #Compressed cache area size
          gzip_http_version 1.1; #Compressed version
          gzip_comp_level 9; #compression ratio
          gzip_types  text/css text/xml application/javascript; #Compression type
          gzip_vary on; #vary header
 
          server_tokens off; #Closed version
          include       mime.types;
          default_type  application/octet-stream;
          tcp_nopush on;  #Prevent network and disk i/o blocking
          tcp_nodelay on; #Prevent network and disk i/o blocking
          sendfile        on; #Efficient file transfer
          keepalive_timeout  65; #keepalive timeout
          server_names_hash_bucket_size 128; #Multiple domain names
          server_names_hash_max_size 512;
          client_header_timeout 15s;
          client_body_timeout 15s;
          send_timeout 60s;
          client_header_buffer_size 2k; #Buffer size
          large_client_header_buffers 4 4k;
          client_max_body_size 8m;
 
          #open_file_cache max=204800 inactive=20s;
          #open_file_cache_min_uses 1;
          #open_file_cache_valid 30s;
 
          #php
          #fastcgi_connect_timeout 240; #FastCGI timeout
          #fastcgi_send_timeout 240; #FastCGI Transfer request timeout time
          #fastcgi_read_timeout 240; #FastCGI Response timeout time
          #fastcgi_buffer_size 64k;  #Buffer size
          #fastcgi_buffers 4 64k;
          #fastcgi_busy_buffers_size 128k;
          #fastcgi_temp_file_write_size 128k;
 
 
server {
        listen       80;
        server_name  localhost;
        location / {
        proxy_pass http://127.0.0.1:8082;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
           root   html;
       }
    }
}
EOF
}

nginx_server (){
cat >>/usr/lib/systemd/system/nginx.service<<EOF
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
Wants=network-online.target
 
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable --now nginx.service

firewall-cmd --zone=public --permanent --add-port=80/tcp
firewall-cmd --reload
rm -rf $data_downloads/*
}

Deployment_completion_notification (){
   host_ID=`dmidecode -s system-serial-number | sed -r 's/\s+//g'`
   host_IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2}' | awk 'NR==1'`
   memory_Size=`dmidecode -t memory | grep Size | grep -v No | awk '{sum+=$2} END {printf "%.0fG\n",sum/1^C4}'`
   CPU_Model=`cat /proc/cpuinfo | grep 'model name' | awk '{print $6}' | uniq`
   Disk_size=`fdisk -l | grep "sda:" | awk '{print $3$4}'`
   redhat_version=`cat /etc/redhat-release | grep "release" | awk '{print $6}'`
   redhat_core=`cat /proc/version | grep "version" | awk '{print $3}'`
   nginx_version=`nginx -v 2>&1 | awk -F/ '{print $2}'`
   nginx_server=`systemctl status nginx.service | grep "Active" | awk '{print $2}'`
   curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXXX' \
   -H 'Content-Type: application/json' \
   -d '
    {
     "msgtype": "markdown",
      "markdown": {
         "content": " **system check** <font color=\"info\"> complete </font>  \n
         > **Host IP Address** \n
          [http://'$host_IP'](http://'$host_IP') \n
         > **Hardware information** \n
          hostSN:<font color=\"info\"> '$host_ID' </font> \n
          CPU_Model:<font color=\"info\"> '$CPU_Model' </font> \n
          memory_Size:<font color=\"info\"> '$memory_Size' </font> \n
          Disk_size:<font color=\"info\"> '$Disk_size' </font> \n
          System_version:<font color=\"info\"> '$redhat_version' </font> \n
          system_core:<font color=\"info\"> '$redhat_core' </font> \n
         > **nginx install** \n
          nginx_version:<font color=\"info\"> '$nginx_version' </font> \n
		  nginx_server:<font color=\"info\"> '$nginx_server' </font> \n",
      }
   }'
}
 
 
main (){
install_nginx
Deployment_completion_notification
}
 
main

执行安装 

sh /Nginx_install.sh

企业微信机器人通知

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Linux Shell 实现一键部署Nginx 的相关文章

  • 队列queue最简单的复制拷贝方式

    span class token macro property span class token directive hash span span class token directive keyword include span spa
  • 影单:分享一下最近在看的一些电影

    1 千与千寻 电影讲的是少女千寻随爸爸妈妈搬去新的城市 xff0c 开车迷路 xff0c 进入了一个神秘隧道 xff0c 隧道另一边有个风情小镇 xff0c 爸爸妈妈没抵制得了食物的诱惑 xff0c 大吃特吃变成了猪 那是个妖怪的世界 xf
  • conda相关

    安装 ubuntu 18 04 安装conda环境 及 创建虚拟环境 创建虚拟环境 conda create span class token operator span n your env name python span class
  • 几种PCL点云显示方式

    注意添加头文件 xff1a span class token macro property span class token directive hash span span class token directive keyword in
  • 复盘一下slam中常用的几种点云类型

    使用livox雷达常涉及至少3种点云格式 xff0c 一个是livox官方定义的custom格式 xff0c 另外两个就是激光 视觉常用的pcl类型和ros类型 之前总结过Livox雷达驱动程序发布点云格式CustomMsg和pcl Poi
  • [Python]-使用Requests模拟登录

    文章目录 登录说明session操作data序列化 示例代码登录流程验证 在 使用Requests进行HTTP请求与文件上传下载 中介绍了requests库的常用方法 xff0c 本章介绍如何使用request进行用户登录 登录说明 一般页
  • mloam

    以读 pcd xff1a 读取4个激光雷达数据 xff0c input estimator span class token punctuation span span class token function inputCloud spa
  • ROS 工作空间下编译库文件,安装库头文件到devel文件夹

    Hello xff0c 欢迎来到我的博客 我们在ROS工作空间下编程时 xff0c 可能会出现这一种情况 xff1a 我们在一个package下写了一个库 xff0c 而在另一个package要引用这个库 这个时候该怎么处理呢 xff1f
  • js打开新页面的两种方式

    1 点击某一个链接之后跳转到新页面显示 window open http www baidu com blank 2 需要刷新当前页面或者覆盖当前页面 window open http www baidu com self
  • ROS入门教程的学习与总结

    ROS入门教程的学习与总结 1 安装ROS环境2 创建ROS空间3 创建ROS package4 catkin清除命令5 待续 1 安装ROS环境 ROS官网安装参考链接 Linux版本如果是16 04 安装ROS Kinect版本 ava
  • vins-fusion 怎么输出文件? vio_global,vio.txt,vio.csv内容与位置的修改

    提示 xff1a 文章写完后 xff0c 目录可以自动生成 xff0c 如何生成可参考右边的帮助文档 目录 vins fusion 怎么输出文件 xff1f vio global vio txt vio csv内容与位置的修改1 vio g
  • ubuntu18.04安装、使用evo

    ubuntu18 04安装evo 1 切换python版本2 安装pip33 安装evo4 自带test测试5 evo工具介绍6 evo使用6 针对不同数据集的格式以及evo命令 官方连接 xff1a https github com Mi
  • RTKLIB源码及介绍

    目录 1 官网翻译 2 文件下载 1 官网翻译 RTKLIB xff1a 用于 GNSS 定位的开源程序包 下载 版本 日期 适用于 Windows 的二进制 AP 包 带有源程序的完整包 0 2 0 2006 12 16 rtklib 0
  • KITTI数据集基准、转换成tum以及十个groundtruth对应图

    KITTI数据集基准 转换成tum以及十个groundtruth对应图 时间戳的位置gt的位置利用evo进行转换生成kitti基准带时间的tum格式十个路径展示 xff1a 跑vins fusion的时候 xff0c 不知道使用的kitti
  • 【国产可编程逻辑控制器plc调研】

    国产可编程逻辑控制器plc调研 1 高性能PLC xff08 ACxxx系列 xff09 2 中型PLC xff08 AMx00系列 xff09 3 小型PLC xff08 HxU HxS xff09 4 小型紧凑型PLC xff08 Ea
  • 【工业相机接口配置】万兆网口、Camera Link接口、CXP接口

    工业相机接口配置 xff08 万兆网口 Camera Link接口 CXP接口 xff09 万兆网口Camera Link接口CXP接口 目前接触到的工业相机主要有万兆网口 Camera Link接口 CXP接口等不同的接口 另外更常用的是
  • [C++]-yml库yaml-cpp简介

    文章目录 YAML基本语法数据类型对象数组标量引用 yaml cpp库生成器Emitter节点Node数组对象创建解析 yaml cpp是一个yml操作库 YAML YAML YAML Ain t a Markup Language xff
  • 【一篇看全】工业相机常用数据传输协议速率对比(CameraLink,CXP,1/10/100GigE,USB)

    一篇看全 工业相机常用数据传输协议速率对比 xff08 CameraLink xff0c CXP xff0c GigE xff0c USB xff09 CameraLinkCXPGigE10GigE100GigEUSB接口协议速率对比速率换
  • [Unity插件]A* Pathfinding Project:简易教程(一)

    原文链接 xff1a http arongranberg com astar docs getstarted php 插件下载地址 xff1a http pan baidu com s 1eROqaB4 题外话 xff1a 最近想学习一下A
  • VC++编译说明

    目 录 第 1 章 编译步骤 1 第 2 章 编译源文件 2 2 1 编译器 2 2 2 包含头文件 3 2 3 重复包含 6 2 4 预编译头文件 7 2 4 1 创建 7 2 4 2 使用 8 2 4 3 说明 9 第 3 章 编译资源

随机推荐