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-异常处理语句
程序运行过程中难免会出错,出错后的运行结果往往是不正确的,因此运行时出错的程序通常被强制中止.运行时的错误统称为异常,为了能在错误发生时得到一个处理的机会,JavaScript提供了异常处理语句.包含 ...
- SQL SERVER 分布式事务(DTC)
BEGIN DISTRIBUTED TRANSACTION指定一个由 Microsoft 分布式事务处理协调器 (MS DTC) 管理的 Transact-SQL 分布式事务的起始. 语法BEGIN ...
- [操作系统实验lab4]实验报告
实验概况 在开始实验之前,先对实验整体有个大概的了解,这样能让我们更好地进行实验. 我们本次实验需要补充的内容包括一整套以sys开头的系统调用函数,其中包括了进程间通信需要的一些系统调用如sys_ip ...
- Windows Azure开发者任务之五:配置虚拟机的“规模”
指定虚拟机的“规模”是怎么一回事? 我们可以指定角色将要部署于其上的虚拟机的“规模”.虚拟机的“规模”是指: 1,CPU核心数 2,内存容量 3,本地文件系统的体积 我们可以针对具体的角色来指定虚拟机 ...
- Azure开发者任务之四:在Azure SDK 1.3中挂载调试器的错误
我安装了Windows Azure SDK的1.3版本.我试着创建了一个Azure的“Hello World”应用程序. 我按了“F5”,然后我得到了下面这个错误: 我尝试了“Ctrl+F5”:不使用 ...
- 当使用母版页时JavaScript客户端获取服务器控件的Id
当使用MasterPage.UserControl等容器时,为了避免控件的重复命名,asp.net会自动将容器中的控件生成一个ClientID(Control Tree中的可生成,否则不会生成). J ...
- idea使用maven搭建springmvc
最近学着搭建springmvc,写此博客记录一下 idea版本:2016.3.1maven: apache-maven-3.3.9tomcat:apache-tomcat-8.5.8 1.New Pr ...
- Win764位配置Github环境及将代码部署到Github pages-志银强势总结
(软件及教程下载分享:链接:http://pan.baidu.com/s/1dFysay9 密码:pug0) 1-安装Git-2.9.2-64-bit.exe(解压安装文件,运行安装程序,除了记得修改 ...
- 利用javascript、php和ajax实现计算器
计算器和ajax部分: <?php /** * Created by PhpStorm. * User: Administrator * Date: 16-9-2 * Time: 上午9:20 ...
- R语言-妹子被追后的选择分析
前提假设 妹子们一生中可以遇到100个追求者,追求者的优秀程度符合正态分布: 每个妹子都具备判断并比较追求者优秀程度的能力: 接受或拒绝一个追求者后永远无法后悔. 那么,问题来了 当遇到追求者时,如何 ...