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 ...
随机推荐
- android:inputType参数类型说明
android:inputType参数类型说明 android:inputType="none"--输入普通字符 android:inputType="text" ...
- Python基础:函数
一.概述 二.声明.定义和调用 三.参数 1.参数传递 2.实参类型 3.形参绑定 四.返回值 五.名字空间与作用域 1.基本概念 2.名字空间 3.作用域 4.总原则 六.高级 1.装饰器 2.生成 ...
- sql2008 查询字段所属表
select a.name as 表名, g.*from sysobjects as a left join syscolumns as b on a.id=b.id left JOIN sys.ex ...
- 【转】RBAC权限管理
RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联.简单地说,一个用户拥有若干角色,每一个角色拥有若干权限.这样,就构造成“用户-角色- ...
- ExecutorService常用方法和newFixedThreadPool创建固定大小的线程池
1.ExecutorService: 是一个接口,继承了Executor: public interface ExecutorService extends Executor { } 2.Execut ...
- 【洛谷 p3382】模板-三分法(算法效率)
题目:给出一个N次函数,保证在范围[l,r]内存在一点x,使得[l,x]上单调增,[x,r]上单调减.试求出x的值. 解法:与二分法枚举中点使区间分成2份不一样,三分法是枚举三分点,再根据题目的情况修 ...
- Python for循环内部实现的一个sample
#!/usr/bin/env python # -*- coding: utf-8 -*- it = iter([1,2,3,4,5]) while True: try: x = next(it) p ...
- IIS减少工作线程阻塞的方法
IIS的工作进程(w3wp.exe)只提供了有限的工作线程(Work Thread)来处理请求.如果这些线程都因为要等待长时间运行的任务而阻塞,则运行时会将新来的请求排队,而不是立即执行,Web服务器 ...
- 误报的java.sql.SQLException: Parameter number 21 is not an OUT parameter
今天为了模拟一个mysql内存不释放问题,要测试一个存储过程,同时具有出参和入参,启动时报了上述错误. <select id="funcl_trd_secu_execution_que ...
- DOM笔记整理及应用实例
一.前言 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model).HTML DOM 模型被构造为对象的树 通过可编程的对象模型,JavaScript 获得了足够的 ...