01-nginx编译安装

一、常用来提供动态服务的软件

PHP:.php结尾的文件,大中小网站都有适合,动态网页语言PHP程序的解析容器,一般配合apache或nginx解析 动态程序
Tomcat:适用于中小企业,不适合并发量高的环境
Resin:适用于大型企业,适合并发量高的环境
IIS:.asp结尾的文件,windows下web服务软件

1.1、nginx软件特性说明

1) 支持高并发:能支持几万并发连接(特别是静态小文件业务环境)
2) 资源消耗少:在3万并发连接下,开启10个Nginx线程消耗的内存不到200MB
PS:(测试软件工具:ab,JMeter,Webbench,LoadRunner,http_load,tcpcopy) 
3) 可以做HTTP反向代理及加速缓存、即负载均衡功能(4层以及7层),
内置对RS节点服务器健康检查功能,这相当于专业的Haproxy软件或LVS(4层)的功能。
PS:LVS等软件没有健康检查功能
4) 具备Squid等专业缓存软件等的缓存功能。(memcache/redis)
5) 支持异步网络I/O事件模型epoll(Linux 2.6+)
PS:apache使用的模型:select,性能没有nginx好

1.2、为什么Nginx总体性能比Apache高

Ngimx:使用最新的epoll(linux 2.6内核)模型,和kqueue(freebsd)异步网络I/O模型
特点比喻:找女朋友,宿管阿姨查看登记信息,快速查找人员信息,这是epoll模型
Apache:使用的是传统的select模型
特点比喻:找女朋友,宿管阿姨一个一个带你去找,去问,这是select模型

二、nginx软件的编译安装步骤

2.1、查看系统版本等信息

cat /etc/redhat-release
uname -r
uname -m

2.2、安装依赖包

rpm -qa pcre pcre-devel
rpm -qa openssl openssl-devel
rpm -qa gcc gcc-c++
yum install pcre pcre-devel openssl openssl-devel gcc gcc-c++ zlib zlib-devel -y

2.3、安装Nginx

mkdir -p /home/linux01/tools
cd /home/linux01/tools
wget -q http://nginx.org/download/nginx-1.6.3.tar.gz
ls -lh nginx-1.6.3.tar.gz
useradd www -u 1100 -s /sbin/nologin -M
tar -zxf nginx-1.6.3.tar.gz
cd nginx-1.6.3
./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.3 --with-http_stub_status_module --with-http_ssl_module
make && make install && cd ../
ln -s /application/nginx-1.6.3 /application/nginx

2.4、检查启动nginx

iptables -I INPUT -p tcp --dport 82 -j ACCEPT
/application/nginx/sbin/nginx -t /application/nginx/sbin/nginx lsof -i :82 netstat -lntup|grep nginx
ps aux|grep nginx

2.5、安装nginx过程排错思路

1.查看物理链路情况:
ping IP地址

2.关闭防火墙
centos6系列:
/etc/init.d/iptables stop chkconfig iptables off
centos7系列:
systemctl stop firewall.service
systemctl disable firewall.service 有外网IP的生产环境请允许80端口的访问,而不是关闭防火墙,允许命令如下:
iptables
-I INPUT -p tcp --dport 82 -j ACCEPT
3.关闭selinux setenforce 0 →临时关闭方法 getenforce 4.确认httpd端口80是否存在 netstat -lntup|grep 80 5.查看http进程是否存在 netstat -lntup|grep nginx 提示:默认情况下只有一个nginx进程。 6.在服务器本地测试
wget http://192.168.47.133
7.查看nginx的错误日志是否有异常 cat /application/nginx/logs/error.log

2.6、开机自启动nginx

echo "#start nginx server by linux01 at 20190705" >>/etc/rc.local
echo "/application/nginx/sbin/nginx -t && /application/nginx/sbin/nginx" >>/etc/rc.local

 三、脚本一键安装NGINX【使用sudo用户执行】

#!/bin/bash
#Author:chenwei
#Time:2020-07-28 11:30:44
#Name:auto_install_nginx_v1.sh
#Version:V1.0
#Description:This script is used for automatically install nginx

#1.0 编译安装基础环境
sudo yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget make automake ntpdate gcc gcc-cc+ glibc glibc-devel pcre pcre-devel openssl openssl-devel libtool systemd-devel net-tools iotop bc zip unzip zlib-devel bash-completion nfs-utils automake libxml2 libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed

#2.0 安装nginx
sudo useradd nginx -s /sbin/nologin -u 1200
cd /home/linux01/tools/ && wget https://nginx.org/download/nginx-1.16.1.tar.gz
sudo tar zxf nginx-1.16.1.tar.gz
cd nginx-1.16.1/
sudo ./configure --prefix=/etc/nginx-1.16.1 \
--user=nginx \
--group=nginx \
--with-http_sub_module
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module

#3.0 编译安装nginx
sudo make #编译步骤,根据Makefile文件生成相应的模块
sudo make install #创建目录并将生成的模块和文件复制到相应的目录
sudo ln -s /etc/nginx-1.16.1 /etc/nginx

#4.0 创建用户并授权,检查和启动nginx
sudo chown -R nginx:nginx /etc/nginx
sudo sed -i 's#80#82#g' /etc/nginx/conf/nginx.conf
sudo iptables -I INPUT -p tcp --dport 82 -j ACCEPT
sudo /etc/nginx/sbin/nginx -t && sudo /etc/nginx/sbin/nginx

#5.0 检查并测试 sudo netstat
-antlp|grep 82 curl -i "http://$(hostname -I|awk '{print $1}')/index.html"

 

posted @ 2020-08-19 20:17  西瓜的春天  阅读(92)  评论(0)    收藏  举报