centos7 源码编译安装nginx教程 nginx安装脚本

Posted faberbeta

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7 源码编译安装nginx教程 nginx安装脚本相关的知识,希望对你有一定的参考价值。

  • 安装nginx需要pcre zlib openssl的库,下文都是在官网直接下载用作编译安装
  • 该nginx安装教程,有安装maxmind IP 库
  • 该nginx安装教程有安装openrestry
  • 系统使用了centos 7
  • 该教材有修改最大打开文件描述符数到最大
  • 该教程是nginx安装的shell脚本
#!/bin/bash

yum install epel-release -y
yum install gcc gcc-c++ make automake autoconf libtool iptables-services wget bind-utils unzip -y

cd /usr/local/src

mv /etc/localtime /etc/localtime.bak
/bin/cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo ZONE="CST" > /etc/sysconfig/clock

setenforce 0
sed -i "s/=enforcing/=disabled/g" /etc/selinux/config

systemctl disable firewalld
systemctl stop firewalld

chkconfig iptables on
service iptables start
iptables -F
service iptables save

wget https://github.com/openresty/luajit2/archive/v2.1-agentzh.zip
unzip v2.1-agentzh.zip

cd luajit2-2.1-agentzh
mkdir -p /usr/local/nginx/
make install PREFIX=/usr/local/nginx/luajit
echo "/usr/local/nginx/luajit/lib" > /etc/ld.so.conf.d/usr_local_luajit_lib.conf
ldconfig

cd /usr/local/src/
wget https://github.com/maxmind/libmaxminddb/releases/download/1.3.2/libmaxminddb-1.3.2.tar.gz
tar zxf libmaxminddb-1.3.2.tar.gz
cd libmaxminddb-1.3.2
./configure
make && make install
[[ -z `cat /etc/ld.so.conf |grep "\/usr\/local\/lib"` ]] && echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig

mkdir -p /usr/local/nginx/temp
mkdir -p /usr/local/nginx/geoip
cd /usr/local/nginx/geoip


wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
tar zxf GeoLite2-City.tar.gz
cd GeoLite2-City_*
mv GeoLite2-City.mmdb maxmind-city.mmdb
mv maxmind-city.mmdb /usr/local/nginx/geoip/

cd /usr/local/src/
wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar zxf nginx-1.16.0.tar.gz

wget -O openssl-master.zip https://github.com/openssl/openssl/archive/master.zip
unzip openssl-master.zip


wget https://nchc.dl.sourceforge.net/project/pcre/pcre2/10.33/pcre2-10.33.zip
unzip pcre2-10.33.zip


wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxf zlib-1.2.11.tar.gz


wget -O lua-nginx-module-master.zip https://github.com/openresty/lua-nginx-module/archive/master.zip
unzip lua-nginx-module-master.zip


wget -O ngx_http_geoip2_module-master.zip https://github.com/leev/ngx_http_geoip2_module/archive/master.zip
unzip ngx_http_geoip2_module-master.zip

useradd -M -s /sbin/nologin www

export LUAJIT_LIB=/usr/local/nginx/luajit/lib
export LUAJIT_INC=/usr/local/nginx/luajit/include/luajit-2.1

cd /usr/local/src/nginx-1.16.0
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_stub_status_module --with-http_realip_module --with-pcre-jit --with-http_v2_module --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --http-client-body-temp-path=/usr/local/nginx/temp/client_body_temp --http-proxy-temp-path=/usr/local/nginx/temp/proxy_temp --http-fastcgi-temp-path=/usr/local/nginx/temp/fastcgi_temp --http-scgi-temp-path=/usr/local/nginx/temp/scgi_temp --http-uwsgi-temp-path=/usr/local/nginx/temp/uwsgi_temp --with-openssl=/usr/local/src/openssl-master --with-zlib=/usr/local/src/zlib-1.2.11 --with-pcre=/usr/local/src/pcre2-10.33 --with-ld-opt=-ljemalloc --with-ld-opt=-Wl,-rpath,/usr/local/nginx/luajit/lib --add-module=/usr/local/src/lua-nginx-module-master --add-module=/usr/local/src/ngx_http_geoip2_module-master

make && make install

echo "export PATH=$PATH:/usr/local/nginx/sbin/" >> /etc/profile
source /etc/profile


mkdir -p /usr/local/nginx/ssl

openssl req -x509 -nodes -days 10000 -newkey rsa:2048 -keyout /usr/local/nginx/ssl/nginx.key -out /usr/local/nginx/ssl/nginx.crt -subj "/C=US/ST=US/L=US/O=ssl/OU=ssl/CN=ssl.com/emailAddress=admin@ssl.com"


echo "ulimit -n 65535" >> /etc/profile
echo "root soft nofile 65535" >> /etc/security/limits.conf
echo "root hard nofile 65535" >> /etc/security/limits.conf
echo "* soft nofile 65535" >> /etc/security/limits.conf
echo "* hard nofile 65535" >> /etc/security/limits.conf
source /etc/profile

 

以上是关于centos7 源码编译安装nginx教程 nginx安装脚本的主要内容,如果未能解决你的问题,请参考以下文章

Nginx Linux下安装

Nginx Linux下安装

CentOS6.5下nginx安装

Nginx和Tengine的详细安装图文教程(Linux下)

不可错过的 Nginx 安装部署教程

Centos7 编译安装Nginx 教程