?????
目录
1.nginx的编译
2.开机自启动的设置
? 3.配置文件修改
?配置之前
?配置文件轮询
backup
?weight权重
4.模块的增加
5.nginx平滑升级
?????? Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的,第一个公开版本0.1.0发布于2004年10月4日。
?????? 其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、简单的配置文件和低系统资源的消耗而闻名。
???????? Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、京东、新浪、网易、腾讯、淘宝等
1.nginx的编译
解压源码包? 此处下载了1.20.1
tar zxf nginx-1.20.1.tar.gz
cd 到nginx-1.20.1目录下
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
指定编译目录和参数生成编译策略
 如果没有下载这三个软件,要下载,编译过程会有提醒
yum install pcre-devel openssl-devl zlib-devl -y
生成策略文件

?通过策略文件开始编译
make
make install 安装

/usr/local/nginx/sbin/nginx 启动二进制文件
?
curl -I 172.25.7.1 查看服务
curl 172.25.7.1 查看服务器页面

?
浏览器 http://172.25.7.1
?
/usr/local/nginx/sbin/nginx -v 查看版本号
/usr/local/nginx/sbin/nginx -V 可以看到版本号以及编译策略
?默认端口80
netstat -antlpe 查看端口

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
可以全局使用nginx命令
nginx -s reload 重启
nginx -s stop停止
nginx开启
nginx -t 配置文件的检测

2.开机自启动的设置
cd /usr/lib/systemd/

?vim nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload????? 对写进的服务进行读取 ?就可以用 systemctl 来操作
3.配置文件修改

?配置之前
vim /etc/security/limits.conf 如下图之后在修改配置文件
用户nginx的创建
useradd -s /sbin/nologin nginx

?配置文件轮询

?检测配置文件
?开启服务
2,3的http服务要打开
编辑本地解析 172.25.7.1? server1 ? www.westos.org
真机呼叫

backup
由于apache和ngnix不能同时开启
将server1作为备用服务器,配置文件修改,端口改为8080,对nginx配置文件修改

?关闭3和2的apache,重启1的apache

?weight权重
将1apache 关掉,2,3打开
编辑nginx配置文件

nginx -s reload
?
4.模块的增加
准备好软件包

?zip格式需要unzip解压

unzip nginx-goodies-nginx-sticky-module-ng-08a395c66e42.zip
进入nginx-1.20.1目录中
查看编译策略,清除编译策略
重新编译,加上该模块
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/root/nginx-goodies-nginx-sticky-module-ng-08a395c66e42
只可以make
并没有成功添加

?给nginx瘦身

[root@server1 nginx-1.20.1]# vim auto/cc/gcc
瘦身主要就是这个 将gcc的标准编译调试信息注释掉 就可以将模块加上

vim src/core/nginx.h 编辑去掉版本号

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/root/nginx-goodies-nginx-sticky-module-ng-08a395c66e42
make
瘦身结果

?把旧的改名,新的复制过来

?去版本号结果

?模块添加上了

5.nginx平滑升级
将上操作过的旧二进制文件删掉

?将版本号改回

?重新编译一遍

?变化过程尝试

?解压新版本

?编译新版本参数要一致,只make

?备份原来版本

? 将新版本的导入

启动新版本kill -USR2 25733

?关闭老版本保留主进程回退
kill -WINCH 25733
版本号此操作后改变
?
?
版本回退
\cp -f nginx.old nginx
kill -HUP 27533 原进程号
kill -QUIT 新版本进程号

|