服务管理--Nginx

Posted mr-ws

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了服务管理--Nginx相关的知识,希望对你有一定的参考价值。

nginx --升级

一.Nginx 升级实验

源码包安装(1.配置 2.编译 3.安装)

 

1.先解压升级包
[[email protected] ~]# tar xf nginx-1.13.4.tar.gz 

2.转到升级包那个目录
[[email protected] ~]# cd nginx-1.13.4/

3.指定目录等问题 (prce-8.40)支持正则
[[email protected] nginx-1.13.4]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-http_dav_module --with-pcre=../pcre-8.40 

[[email protected] nginx-1.13.4]# make 
4.查看当前版本
[[email protected] nginx-1.13.4]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.12.1
5.把之前的旧的备份一下
[[email protected] nginx-1.13.4]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

[[email protected] nginx-1.13.4]# ls
auto     CHANGES.ru  configure  html     Makefile  objs    src
CHANGES  conf        contrib    LICENSE  man       README
[[email protected] nginx-1.13.4]# cp  objs/nginx /usr/local/nginx/sbin/

6.查看当前版本
[[email protected] nginx-1.13.4]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.13.4

 方法一:

[[email protected] nginx-1.13.4]# make upgrade

  方法二:

1.查看nginx的pid

[[email protected] ~]# ps -ef | grep nginx
root      64600      1  0 16:47 ?        00:00:00 nginx: master process /usr/local/ngin
/sbin/nginxnginx     64601  64600  0 16:47 ?        00:00:00 nginx: worker process
root      70426  58718  0 17:21 pts/3    00:00:00 grep --color=auto nginx

2.执行 kill -USR2 pid

[[email protected] ~]# kill -USR2 64600
[[email protected] ~]# ps -ef | grep nginx
root      64600      1  0 16:47 ?        00:00:00 nginx: master process /usr/local/ngin
/sbin/nginxnginx     64601  64600  0 16:47 ?        00:00:00 nginx: worker process
root      70428  64600  0 17:22 ?        00:00:00 nginx: master process /usr/local/ngin
/sbin/nginxnginx     70429  70428  0 17:22 ?        00:00:00 nginx: worker process
root      70432  58718  0 17:23 pts/3    00:00:00 grep --color=auto nginx
此时,新旧版本的nginx实例会同时运行,共同处理输入的请求.要逐步停止旧版本的nginx实例,必须发送WINCH信号给旧的主进程,然后,它的工作进程就将开始正常关闭:

3.执行 kill -WINCH pid

[[email protected] ~]# kill -WINCH 64600
[[email protected] ~]# ps -ef | grep nginx
root      64600      1  0 16:47 ?        00:00:00 nginx: master process /usr/local/ngin
/sbin/nginxroot      70428  64600  0 17:22 ?        00:00:00 nginx: master process /usr/local/ngin
/sbin/nginxnginx     70429  70428  0 17:22 ?        00:00:00 nginx: worker process
root      70434  58718  0 17:24 pts/3    00:00:00 grep --color=auto nginx
如果尝试升级成功,也希望保留新的服务器时,发送 QUIT 信号给旧的主进程使其退出而只留下新的服务器运行。

4.执行 kill -QUIT pid

[[email protected] ~]# kill -QUIT 64600
[[email protected] ~]# ps -ef | grep nginx
root      70428      1  0 17:22 ?        00:00:00 nginx: master process /usr/local/ngin
/sbin/nginxnginx     70429  70428  0 17:22 ?        00:00:00 nginx: worker process
root      70436  58718  0 17:26 pts/3    00:00:00 grep --color=auto nginx

 

不执行第四步还可以恢复之前的旧版本

[[email protected] ~]# rm -rf /usr/local/nginx/sbin/nginx
[[email protected] ~]# cp /usr/local/nginx/sbin/nginx.bak /usr/local/nginx/sbin/nginx

[[email protected] ~]# kill -HUP 44610
[[email protected] ~]# ps -ef | grep nginx
root      44610      1  0 12:40 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
root      74746  44610  0 14:38 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx    74747  74746  0 14:38 ?        00:00:00 nginx: worker process
nginx    77990  44610  0 14:53 ?        00:00:00 nginx: worker process

[[email protected] ~]# kill -QUIT 74746
[[email protected] ~]# ps -ef | grep nginx
root      44610      1  0 12:40 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx    77990  44610  0 14:53 ?        00:00:00 nginx: worker process

 二. LuaJIT即采用C语言写的Lua代码的解释器

1.下载LuaJIT

先安装yum install wget

[[email protected] ~]# wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz

2.编译,安装

[[email protected] ~]# tar xf LuaJIT-2.0.5.tar.gz

[[email protected] ~]# cd LuaJIT-2.0.5/

[[email protected] LuaJIT-2.0.5]# make install  PREFIX=/usr/local/luajit

[[email protected] LuaJIT-2.0.5]# echo "/usr/local/luajit/lib/" > /etc/ld.so.conf.d/usr_local_luajit_lib.conf

[[email protected] LuaJIT-2.0.5]# ldconfig (刷新配置文件)

3.配置环境变量

[[email protected] LuaJIT-2.0.5]# export LUAJIT_LIB=/usr/local/luajit/lib

[[email protected] LuaJIT-2.0.5]# export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0

4.Lua程序

[[email protected] LuaJIT-2.0.5]# vim hello.lua

[[email protected] LuaJIT-2.0.5]# cat hello.lua
print ("Hello World")

[[email protected] LuaJIT-2.0.5]# lua hello.lua
Hello World

[[email protected] LuaJIT-2.0.5]# lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> 
> print ("Hello World")
Hello World
> 

5.下载NDK与Lua_module

[[email protected] ~]# tar xf ngx_devel_kit-0.3.0.tar 
[[email protected] ~]# tar xf lua-nginx-module-0.10.10.tar 
[[email protected] ~]# tar xf nginx-1.13.4.tar 
[[email protected] ~]# cd nginx-1.13.4
[[email protected] nginx-1.13.4]# make clean
rm -rf Makefile objs
[[email protected] nginx-1.13.4]# ./configure --prefix=/usr/local/nginx1134 --user=nginx --gro
up=nginx --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-http_dav_module --with-pcre=../pcre-8.40 --add-module=../ngx_devel_kit-0.3.0 --add-module=../lua-nginx-module-0.10.10
[[email protected] nginx-1.13.4]# make && make install

6.更改配置文件

[[email protected] nginx-1.13.4]# vim /usr/local/nginx1134/conf/nginx.conf
技术图片

 


[[email protected] nginx-1.13.4]# echo ‘ngx.say("Hello World")‘ > /tmp/hello.lua
千万记得杀死80端口进程

[[email protected] nginx-1.13.4]# pkill nginx

[[email protected] nginx-1.13.4]# /usr/local/nginx1134/sbin/nginx -c /usr/local/nginx1134/conf
/nginx.conf

7.结果

[[email protected] nginx-1.13.4]# curl 192.168.88.101/test1
Hello world
[[email protected] nginx-1.13.4]# curl 192.168.88.101/test2
Hello World

  

 

 

  

以上是关于服务管理--Nginx的主要内容,如果未能解决你的问题,请参考以下文章

tengine/nginx服务启动管理脚本(未使用系统funtions函数)

编写systemd单元文件管理源码安装Nginx服务

systemctl 设置自定义nginx服务管理

源码包安装和快捷的管理nginx,自定义命令管理服务

Nginx 介绍及日常管理的详解

Nginx服务其他管理配置