nginx入门(安装,启动,关闭,信号量控制)
公司使用到了nginx,于是周末初步接触了一下nginx,立即被其简洁,优雅,高效的特性给迷住了。nginx是在是个好东西,配置极其简单,容易理解,极其高效,稍微一调优,ab测试10k并发,很轻松。比起apache来强太多了...
1. 下载
[root@localhost src]# wget -c http://nginx.org/download/nginx-1.6.2.tar.gz
--2015-01-11 16:04:13-- http://nginx.org/download/nginx-1.6.2.tar.gz
Resolving nginx.org... 206.251.255.63
Connecting to nginx.org|206.251.255.63|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 804164 (785K) [application/octet-stream]
Saving to: “nginx-1.6.2.tar.gz” 100%[=====================================================================>] 804,164 5.03K/s in 3m 42s 2015-01-11 16:07:57 (3.54 KB/s) - “nginx-1.6.2.tar.gz” saved [804164/804164]
2.解压
[root@localhost src]# tar xvf nginx-1.6.2.tar.gz
nginx-1.6.2/
nginx-1.6.2/auto/
nginx-1.6.2/conf/
nginx-1.6.2/contrib/
nginx-1.6.2/src/
nginx-1.6.2/configure
...
3. 安装
[root@localhost nginx-1.6.2]# ./configure
....
creating objs/Makefile Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using builtin md5 code
+ sha1 library is not found
+ using system zlib library nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp" [root@localhost nginx-1.6.2]# make && make install [root@localhost nginx]# pwd
/usr/local/nginx
[root@localhost nginx]# ll
total 16
drwxr-xr-x. 2 root root 4096 Jan 11 16:12 conf
drwxr-xr-x. 2 root root 4096 Jan 11 16:12 html
drwxr-xr-x. 2 root root 4096 Jan 11 16:12 logs
drwxr-xr-x. 2 root root 4096 Jan 11 16:12 sbin
安装成功。其中conf是配置文件的目录,html是放web页面的目录,logs是放日志文件的目录,sbin目录是 nginx运行时二进制文件。安装时有可能报PCRE库缺失,可以使用命令安装即可:yum -y install pcre-devel;
4. 启动关闭nginx的方法
[root@localhost sbin]# /usr/local/nginx/sbin/nginx
[root@localhost sbin]# echo $?
0
[root@localhost sbin]# ps -elf|grep nginx
1 S root 3740 1 0 80 0 - 887 - 16:16 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
5 S nobody 3741 3740 0 80 0 - 933 - 16:16 ? 00:00:00 nginx: worker process
0 S root 3744 1306 0 80 0 - 1088 - 16:16 pts/1 00:00:00 grep nginx [root@localhost sbin]# netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1131/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1004/cupsd
tcp 0 0 0.0.0.0:40035 0.0.0.0:* LISTEN 928/rpc.statd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 908/rpcbind
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3740/nginx
tcp 0 64 192.168.137.9:22 192.168.137.1:51321 ESTABLISHED 1267/sshd
tcp 0 0 192.168.137.9:22 192.168.137.1:51322 ESTABLISHED 1270/sshd
tcp 0 0 192.168.137.9:22 192.168.137.1:51336 ESTABLISHED 1331/sshd
tcp 0 0 :::22 :::* LISTEN 1131/sshd
tcp 0 0 ::1:631 :::* LISTEN 1004/cupsd
tcp 0 0 :::38082 :::* LISTEN 928/rpc.statd
tcp 0 0 :::111 :::* LISTEN 908/rpcbind
上面所示,成功启动了ngnix,在80端口运行。
nginx的进程分为了master 进程和worker进程,前者做为管理进程,管理后者,后者是处理页面请求的进程,worker可以有多个。一般根据CPU核数和负载进行配置多个worker. 我们访问试试:

nginx的启动,关闭等等操作命令如下:
[root@localhost sbin]# /usr/local/nginx/sbin/nginx -h
nginx version: nginx/1.6.2
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives] Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx -s quit
/usr/local/nginx/sbin/nginx -s reopen
/usr/local/nginx/sbin/nginx -s reload
分别表示 优雅的停止nginx;立即停止nginx;重新打开日志文件;平滑的重启nginx并重新加载nginx的配置文件;
/usr/local/nginx/sbin/nginx -t 可以用来修改配置文件之后,测试配置文件是否有语法错误
. 通过信号量来控制nginx
其实质是通过信号量来对nginx进行控制的,所以也可以通过下面的方式来控制nginx:
kill -INT `cat /usr/local/nginx/logs/nginx.pid`
[root@localhost logs]# kill -INT `cat /usr/local/nginx/logs/nginx.pid`
[root@localhost logs]# ps -elf|grep nginx
0 S root 3843 1306 0 80 0 - 1088 - 16:37 pts/1 00:00:00 grep nginx
看到nginx的两个进程被我们杀掉了。还有其他的信号量可以使用,分别对应到上面的命令。
kill -HUP pid, kill -USR1 pid, kill -USR2 pid 等等,总结如下:
1. TERM,INT : Quick shutdown,立即关闭进程,不管他有没有在处理请求;
2. QUIT : Graceful shutdown, 优雅的关闭进程,也就是等到该进程处理的请求都完成之后才关闭;
3. HUP : Configuration reload, start the new worker processes with a new configuration. Gracefully shutdown the old worker processes
4. USR1 : Reopen the log files, 重新打开日志文件,在备份日志按月/日分割日志时用;
5. USR2 : Upgrade Executable on the fly, 平滑的升级;
6. WINCH : Gracefully shutdown the worker processes, 优雅的关闭旧的进程(配合USR2来进行升级);
先写到这里,后面继续学习nginx的配置。
nginx入门(安装,启动,关闭,信号量控制)的更多相关文章
- 【nginx】nginx的工作模式和信号量控制
nginx是一个多进程/多线程高性能web服务器,在linux系统中,nginx启动后会以后台守护进程(daemon)的方式去运行,后台进程包含一个master进程和多个worker进程(这个数量可以 ...
- Nginx入门安装升级
1).Nginx ("engine x") 是一个高性能HTTP 和 反向代理 服务器.IMAP.POP3.SMTP 服务器. Nginx特点是占有内存少,并发能力强,事实上Ngi ...
- nginx入门,安装
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在 ...
- Linux 下的 Redis 安装 && 启动 && 关闭 && 卸载
转自https://blog.csdn.net/zgf19930504/article/details/51850594 Redis 在Linux 和 在Windows 下的安装是有很大的不同的,和通 ...
- nginx 入门 安装
.yum解决编译nginx所需的依赖包,之后你的nginx就不会报错了 yum install gcc patch libffi-devel python-devel zlib-devel bzip2 ...
- Nginx Windows 安装启动
原文连接:http://tengine.taobao.org/book/appendix_c.html#nginxwindows 下载 Nginx是开源软件,用户可以访问 http://nginx.o ...
- Linux下的MongoDB安装&启动&关闭
一.下载安装包 下载地址 二.解压安装包 $ tar -zxvf mongodb-linux-x86_64-3.0.6.tgz 三.复制到指定的目录下 $ mv mongodb-linux-x86_6 ...
- shell脚本之nginx的安装
为了编写nginx自动部署的脚本而刚学习的shell脚本语言.写文章只是为了记录,有错误勿喷. 一.创建shell脚本程序 操作系统是Linux的 CentOS 7 版本. ...
- nginx入门与实战 安装 启动 配置nginx Nginx状态信息(status)配置 正向代理 反向代理 nginx语法之location详解
nginx入门与实战 网站服务 想必我们大多数人都是通过访问网站而开始接触互联网的吧.我们平时访问的网站服务 就是 Web 网络服务,一般是指允许用户通过浏览器访问到互联网中各种资源的服务. Web ...
随机推荐
- JS魔法堂:获取当前脚本文件的绝对路径
一.前言 当写模块加载器时,获取当前脚本文件的绝对路径作为基础路径是必不可少的一步,下面我们一起来探讨一下这个问题吧! 二.各大浏览器的实现方式 [a]. Chrome和FF 超简单的一句足矣! va ...
- TinyFox在VS2015上的调试器
这个一个TinyFox在VS2015上的调试工具 : 开源了 https://github.com/maxzhang1985/TinyFoxDEBUG 开发这个工具的初衷,是想更便捷的调试Nancy ...
- java switch语句注意的事项
1.switch语句使用的变量只能是byte.char.short.string数据类型. 2.case后面gender数据必须是一个常量. 3.switch的停止条件: switch语句一旦比配上了 ...
- 重构第20天 提取子类(Extact SubClass)
理解:提取子类就是把基类中,不是所有子类或者只有少数子类用到的方法,提取出来,调整到子类中去. 详解:下面的代码中我们用到一个单一的类Registration,来处理学生选课信息. public cl ...
- Winform开发框架之通用数据导入导出操作的事务性操作完善
1.通用数据导入导出操作模块回顾 在我的Winfrom开发框架里面,有一个通用的导入模块,它在默默处理这把规范的Excel数据导入到不同的对象表里面,一直用它来快速完成数据导入的工作.很早在随笔< ...
- Python入门笔记(8):列表
一.序列类型操作符 1.切片[]和[:] 2.成员关系操作符(in ,not in ) 1: s1 = [1,2,3,4,5,6,7] 2: s2 = [2,3,6] 3: s3 = [] 4: fo ...
- 客户端(Winform窗体)上传文件到服务器(web窗体)简单例子
客户端:先创建一个winform窗体的应用程序项目 项目结构
- 当kfreebsd 用户遇见openSUSE系统
openSuse的系统工具集覆盖了四大主流桌面环境,是针对每一种桌面环境定制的独立的桌面体验.
- 【CODEVS 3287】【NOIP2013】火车运输
http://codevs.cn/problem/3287/ 题目描述 国有 座城市,编号从 到 ,城市之间有 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 辆货车在运输货物, 司机们想 ...
- Linux 安装 PHP 环境
使用虚拟机玩linux时,发现CentOS中的php版本是5.1.6.如果要安装新版的php,需要把旧的版本删除. 先查看下php版本:# php -v 如果执行该命令提示该命令不存在,那么可以通过以 ...