Linux Shell 实现一键部署Nginx

news2024/10/5 15:26:34

       

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

企业微信机器人通知

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/418585.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

资本/车企持续加码的新赛道,谁将成为本土赢家?

随着汽车行业逐渐复苏&#xff0c;汽车厂商开始规划未来5年能促进销量的新技术&#xff0c;而AR-HUD就是被看好的技术之一。 Envisics创始人兼CEO Jamieson Christmas博士表示&#xff1a;我们几乎在与所有人合作&#xff0c;除了捷豹路虎、松下汽车系统外还有其他合作伙伴。此…

说走就走的旅行?你需要一个旅行必备清单

可能很多朋友都不用清单这个东西&#xff0c;更别说清单模版了。那清单真的好用吗&#xff1f;说实话&#xff0c;当你真的用清单来整理自己的日常工作&#xff0c;乃至生活琐事后&#xff0c;你就会发现你的时间多了&#xff0c;想要完成的事&#xff0c;大部分都可以按时完成…

Mysql 学习(四)InnDB 存储引擎-B+树索引

没有索引的查找 上节我们知道了数据是怎么存储的&#xff0c;数据被分成一个个页&#xff0c;然后页与页之间是根据双向列表来进行连接的&#xff0c;页中的记录是根据单向列表来进行连接的&#xff0c;并且将主键生成页目录。根据这个规则我们查找对应的记录数据&#xff0c;…

责任链设计模式

模拟学生请假流程&#xff0c;用以说明责任链模式。 请假天数 < 10&#xff0c;老师审批&#xff1b; 10 < 请假天数 < 20&#xff0c;主任审批&#xff1b; 20 < 请假天数 < 30&#xff0c;校长审批&#xff1b; 请假天数 > 30&#xff0c;超出学校允许请假…

vulnhub Hackathon2渗透笔记

靶机下载地址&#xff1a;https://www.vulnhub.com/entry/hackathonctf-2,714/ kali ip地址&#xff1a;192.168.20.130 信息收集 扫描靶机ip地址 nmap -sP 192.168.20.0/24确定靶机ip 进行端口扫描 nmap -A -p 1-65535 192.168.20.134首先我们使用匿名用户登录ftp看看有…

Graph Transformer系列论文阅读

文章目录research1.《Do Transformers Really Perform Bad for Graph Representation》【NeurIPS 2021 Poster】2.《Relational Attention: Generalizing Transformers for Graph-Structured Tasks》【ICLR2023-spotlight】survey推荐一个汇总Graph Transformer论文的项目&…

SpringMVC事务控制(xml文件配置和注解配置)

事务的定义 事务应该具有4个属性&#xff1a;原子性、一致性、隔离性、持久性。这四个属性通常称为ACID特性。 原子性&#xff08;atomicity&#xff09;。一个事务是一个不可分割的工作单位&#xff0c;事务中包括的操作要么都做&#xff0c;要么都不做。 一致性&#xff08;c…

实用的生产管理系统案例分析:如何应对市场快速变化?

生产管理系统是一种可视化管理工具&#xff0c;通过展示关键生产数据来协助企业监测生产进程。这些数据可能包括工作进度、生产速率、库存、质量、安全等。通过这些数据的可视化呈现&#xff0c;生产管理人员可以更快速地获得关于生产进程的信息&#xff0c;并能更快地做出决策…

如何将本地项目上传到Github的方法步骤

默认&#xff1a;已经安装好了git。 第一步&#xff1a;我们需要先创建一个本地的版本库&#xff08;其实也就是一个文件夹&#xff09;。 你可以直接右击新建文件夹&#xff0c;也可以右击打开Git bash命令行窗口通过命令来创建。 第二步&#xff1a;通过命令git init把这个…

深度分析MVC和MVVM:你在选择框架的时候应该注意什么?

&#x1f496; 作者简介&#xff1a;大家好&#xff0c;我是Zeeland&#xff0c;全栈领域优质创作者。&#x1f4dd; CSDN主页&#xff1a;Zeeland&#x1f525;&#x1f4e3; 我的博客&#xff1a;Zeeland&#x1f4da; Github主页: Undertone0809 (Zeeland) (github.com)&…

SpringCloudalibaba微服务工具集

版本: Hoxton SR6 1.什么是微服务 官网 In short, the microservice architectural(架构) style is an approach to developing a single application as a suite(系列) of small services, each running in its own process(进程) and communicating with lightweight mech…

【C++基础】内联函数、nullptr(内联函数的概念;内联函数VS宏函数;内联函数的特性;C++11中的nullptr)

七、内联函数 7.1 内联函数的概念 以inline修饰的函数叫做内联函数&#xff0c;编译时C编译器会在调用内联函数的地方展开&#xff0c;没有函数调用建立栈帧的开销&#xff0c;内联函数提升程序运行的效率。 应用场景&#xff1a; 短小简单的函数&#xff08;1-10行&#xff…

一篇文章把所有前端安全相关的攻击和防御都给解决了——XSS攻击和CSRF攻击

前端安全 1. XSS跨站脚本攻击 1.1 定义 XSS跨站脚本攻击(Cross Site Scripting)&#xff0c;很多人会缩写成CSS&#xff0c;但是这个缩写会与层叠样式表(Cascading Style Sheets,CSS)的缩写混淆&#xff0c;所以&#xff0c;我们通常把跨站脚本攻击缩写成XSS&#xff1b; X…

huggingface transformer模型库使用(pytorch)

参考&#xff1a; https://huggingface.co/docs transformer库 介绍 使用群体&#xff1a; 寻找使用、研究或者继承大规模的Tranformer模型的机器学习研究者和教育者想微调模型服务于他们产品的动手实践就业人员想去下载预训练模型&#xff0c;解决特定机器学习任务的工程师…

初识linux之线程控制

目录 一、POSIX线程库 二、线程创建 1.创建线程的接口 2. 错误的创建多线程 3.正确的创建多线程 4. 线程的私有栈结构 三、线程终止 1. 函数结束 2. 调用pthread_exit&#xff08;&#xff09;终止 3.调用pthread_cancel&#xff08;&#xff09;函数 四、线程等待 …

C++初阶 -1- C++入门

文章目录0.什么是C1.C关键字2.命名空间导入什么是命名空间命名空间的使用3.C 输入&输出4.缺省参数什么是缺省参数缺省参数的应用场景5.函数重载0.什么是C C是基于C语言而产生的&#xff0c;它既可以进行C语言的过程化程序设计&#xff0c;又可以进行以抽象数据类型为特点的…

基于ESP32和blinker的红外小夜灯控制

一. 系统设计及框图&#xff1a; 本设计可以实现通过手机APP使用蓝牙或WIFI远程控制红外设备&#xff0c;也可以通过离线语音模块语音控制红外设备。可以控制市面上常见的NEC格式的红外设备, 这里是控制小夜灯&#xff0c;其它红外设备在控制原理上是相通的。本设计可用作课程…

二、UVM Sequencer和Sequence

了解sequencer与driver之间传递sequence item的握手过程&#xff0c;也掌握了sequence与item之间的关系。接下来对sequence挂载到sequencer的常用方法总结&#xff0c;可以通过这些方法和宏的介绍&#xff0c;了解到它们不同的使用场景面对多个sequence如果需要同时挂到sequenc…

机器学习:基于AdaBoost算法对信用卡精准营销建立模型(附案例实战)

机器学习&#xff1a;基于AdaBoosts算法对信用卡精准营销建立模型 作者&#xff1a;i阿极 作者简介&#xff1a;Python领域新星作者、多项比赛获奖者&#xff1a;博主个人首页 &#x1f60a;&#x1f60a;&#x1f60a;如果觉得文章不错或能帮助到你学习&#xff0c;可以点赞&a…

OPNET Modeler 例程——M/M/1 队列建模

文章目录一、例程概述二、模型构建三、仿真配置及结果1.M/M/1 队列2.M/M/n 队列总结一、例程概述 本例程是使用节点编辑器建立一个 M/M/1 队列模型&#xff0c;同时对仿真收集到的统计数据进行数学分析。M/M/1 队列由先进先出的缓冲区组成&#xff0c;数据包的到达服从指数(泊…