nginx及基本原理

1、nginx的注意事项

epoll模型会有的惊群现象:当有新的请求来临时,所有的worker进程都会被唤醒,但只有一个请求可以执行accept方法,因此nginx采用了accept_mutex锁来解决这个问题,保证只有一个worker进程在监听。

2、nginx的安装

  gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

  ./configure --prefix=/usr/local/nginx
  make && make install

3、nginx的优点:

  1、nginx的epoll模型使用

  2、nginx的sendfile技术使用

  3、worker进程之间通过共享内存、原子操作等一些进程间通信机制来实现负载均衡

  4、accept_mutex是Nginx的负载均衡锁

  5、nginx的worker进程数最好设置与CPU核心数相等,最好每一个worker进程都绑定一个特定的CPU核心,这样子的话进程间切换的代价是最小的。

  6、nginx的进程通信:共享内存、套接字、信号。

4、nginx的命令行操作

  (1)启动  /usr/local/nginx/sbin/nginx

  (2)测试配置文件  /usr/local/nginx/sbin/nginx -t

  (3)查看版本信息  /usr/local/nginx/sbin/nginx -v

  (4)显示编译阶段的参数  /usr/local/nginx/sbin/nginx -V

  (5)强制停止  /usr/local/nginx/sbin/nginx -s stop

  (6)优雅的停止服务  /usr/local/nginx/sbin/nginx -s quit

  (7)重新加载配置文件  /usr/local/nginx/sbin/nginx -s reload

  (8)日志文件回滚  /usr/local/nginx/sbin/nginx -s reopen

原文地址:https://www.cnblogs.com/erdanyang/p/10862014.html