Nginx是高性能的web服务器和反向代理服务器,在互联网公司中被广泛使用。以下是Nginx在centos7系统下的一键编译安装脚本,仅供参考,具体编译参数选项请结合实际生产环境需求进行选择,脚本代码如下:

#!/bin/bash
#
#********************************************************************
#Author: Eddie.Peng
#URL: https://www.cnblogs.com/eddie1127/
#Date: 2019-11-08
#FileName: nginx_install.sh
#Description: The script for install Nginx web server
#********************************************************************
#Set colour
COLORBEG="\033[1;31m"
COLOREND="\033[0m" # Check if user is root
if [ $(id -u) !=0 ];then
echo -e "${COLORBEG} Error! You must be root to run this script,please use root to install. ${COLOREND}"
exit 10
fi clear
echo "========================================================================"
echo " "
echo "The script for install Nginx web server"
echo " "
echo "========================================================================" # Modify system and kernel args
ulimit -SHn 65535
cat >>/etc/security/limits.conf << EOF
* soft nproc
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF cat >> /etc/sysctl.conf << EOF
fs.file-max = 6553560
net.ipv4.ip_forward = 1
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_syncookies = 1
net.core.netdev_max_backlog = 8096
net.core.somaxconn = 65535
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
EOF
sysctl -p # Install dependent software packge
yum -y install epel-release gcc pcre-devel openssl-devel zlib-devel GeoIP GeoIP-devel GeoIP-data # Check files if exists
echo "=================================== Check files ==========================================="
CUR_DIR=$(pwd)
NAME=nginx-1.16.1
FULL_NAME=${CUR_DIR}/${NAME}.tar.gz
INSTALL_PATH=/usr/local/nginx cd $CUR_DIR
if [ -s $FULL_NAME ];then
echo "$FULL_NAME [found]"
else
echo -e "${COLORBEG} $FULL_NAME not found! download now... ${COLOREND}"
wget -c https://nginx.org/download/$NAME.tar.gz
fi echo "====================================== Install ============================================"
# Create run user for nginx service
id -u nginx
if [ $? -eq 0 ];then
echo -e "${COLORBEG} user nginx already exist,skip... ${COLOREND}"
else
groupadd -g 80 nginx
useradd -u 80 -r -g nginx -s /sbin/nologin nginx
echo -e "\033[1;32m user nginx has been created. \033[0m"
fi # Install nginx web server
cd $CUR_DIR
tar xf $FULL_NAME -C /usr/local/src
cd /usr/local/src/$NAME
./configure --prefix=$INSTALL_PATH \
--user=nginx --group=nginx \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_stub_status_module \
--with-threads \
--with-file-aio \
--with-http_geoip_module \
--with-http_gzip_static_module \
--with-http_slice_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module make -j $(nproc) && make install echo "========================= Check install =============================================="
clear
INSTALL="" echo "Checking..."
if [ -s "$INSTALL_PATH"/sbin/nginx ] && [ -s "$INSTALL_PATH"/conf/nginx.conf ];then
echo -e "\033[1;32m nginx install OK \033[0m"
INSTALL="OK"
else
echo -e "${COLORBEG} Error! "$INSTALL_PATH"/sbin/nginx not found!Nginx install failed,please check. ${COLOREND}"
fi if [ "$INSTALL" = "OK" ];then
echo -e "\033[1;32m Congratulation!Nginx install completed! Enjoy it. \033[0m"
echo "===================================================================================="
echo "The path of some dirs:"
echo "nginx_exec_dir: $INSTALL_PATH/sbin"
echo "nginx config : $INSTALL_PATH/conf"
echo "===================================================================================="
else
echo -e "${COLORBEG} Sorry,Nginx install Failed! Please check and reinstall. ${COLOREND}"
exit 20
fi # Add links
ln -s $INSTALL_PATH/sbin/nginx /usr/sbin/ #Add nginx service on startup cat > /usr/lib/systemd/system/nginx.service << EOF
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target [Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/bin/rm -f /var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP \$MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true [Install]
WantedBy=multi-user.target
EOF systemctl daemon-reload
systemctl enable --now nginx.service # Check start up
if [ $? -eq 0 ];then
echo -e "\033[1;32m Nginx start successful. \033[0m"
else
echo -e "${COLORBEG} Nginx start failed!please check. ${COLOREND}"
fi

Nginx编译安装脚本的更多相关文章

  1. nginx编译安装支持lua脚本

    一.准备编译环境 1.操作系统:CentOS7.6 2.安装编译所需安装包 yum install gcc pcre pcre-devel zlib zlib-devel openssl openss ...

  2. nginx编译安装

    Nginx编译安装 1.nginx官网:http://wiki.nginx.org/Install下载:http://nginx.org/en/download.html 2.编译安装# wget h ...

  3. php-fpm编译安装脚本

      PHP是开源.轻量级.高效的开发语言,特别适合web项目开发,在中小型互联网公司中常用于开发web后端.PHP常与Nginx及MySQL数据库结合,搭建LNMP环境.以下为centos7系统下ph ...

  4. Nginx编译安装相关参数

    Nginx编译安装相关参数 Nginx插件安装 ------------------pcre------------------ cd /usr/local/source wget http://ww ...

  5. mysql 自动备份和nginx自动安装脚本

    一.自动备份Mysql脚本: 如下脚本为mysql自动备份脚本,仅供参考,可以根据实际情况修改. #!/bin/sh #auto backup mysql #wugk #Define PATH定义变量 ...

  6. LNMP平台搭建之一:nginx编译安装

    参考博客:https://www.cnblogs.com/zhang-shijie/p/5294162.html   jack.zhang 一.环境说明 系统环境:centos6.5 [root@lo ...

  7. Nginx编译安装lua-nginx-module

    lua-nginx-module 模块可以将Lua的强大功能嵌入NGINX服务器. 下载Nginx源码 如果已安装Nginx,需要查看当前安装版本的编译参数: $ /usr/local/nginx/s ...

  8. Nginx编译安装:

    第三方模块 在nginx.org   --------  wiki  找 --add-module=   添加 Nginx编译安装: 安装开发环境 ]# yum groupinstall " ...

  9. [nginx]编译安装及安全优化

    nginx配置-最后整理版 nginx_upstream_check_module nginx-module-vts nginx打补丁 nginx编译安装 - 下载 cd /usr/local/src ...

随机推荐

  1. 原生js拖拽、jQuery拖拽、vue自定义指令拖拽

    原生js拖拽: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  2. isinstance 与 issubclass

    isinstance与issubclass都是用于判断的,有什么区别呢? 1. isinstance字面意思:实列, 用户判断对象所属类型,包含类的继承关系. 2. issubclass字面理解:是子 ...

  3. Codeforces Round #530 (Div. 2) F 线段树 + 树形dp(自下往上)

    https://codeforces.com/contest/1099/problem/F 题意 一颗n个节点的树上,每个点都有\(x[i]\)个饼干,然后在i节点上吃一个饼干的时间是\(t[i]\) ...

  4. loj2305 NOI2017 游戏

    题目链接 思路 既然\(x\)的数量那么小,我们就可以先把每个\(x\)搜索一遍. 枚举x的时候不需要把\(a,b,c\)全枚举一遍,只要枚举其中的两个就可以枚举到当前位置选任何车的情况. 然后就变成 ...

  5. 【BZOJ3529】[SDOI2014] 数表(莫比乌斯反演)

    点此看题面 大致题意: 规定一个\(n*m\)数表中每个数为\(\sum_{d|i,d|j}d\),求数表中不大于\(a\)的数之和. 不考虑限制 我们先不考虑限制,来推一波式子. 首先,易知数表中第 ...

  6. [ZJOI2019]线段树(线段树,DP)

    又是神仙题. 要写博客太长了,先咕着.放个代码先. 为什么 fmul 在 linux 底下还被定义过了--能想象到我一发 CE 的绝望吗 qaq #include<bits/stdc++.h&g ...

  7. [LeetCode] 895. Maximum Frequency Stack 最大频率栈

    Implement FreqStack, a class which simulates the operation of a stack-like data structure. FreqStack ...

  8. 修改Launchpad的命令

    修改Launchpad命令 1.设置Launchpad 图标的列数 defaults write com.apple.dock springboard-columns -int 10 2.设置 Lau ...

  9. Java中HashMap和TreeMap的区别

    什么是Map集合在数组中我们是通过数组下标来对其内容索引的,而在Map中我们通过对象来对对象进行索引,用来索引的对象叫做key,其对应的对象叫做value.这就是我们平时说的键值对. HashMap ...

  10. LeetCode题库整理(自学整理)

    1. Two Sum 两数之和       来源:力扣(LeetCode) 题目:给定一个整数数组和一个目标值,找出数组中和为目标值的两个数.你可以假设每个输入只对应一种答案,且同样的元素不能被重复利 ...