标签:多进程 oct 准备 更改 http服务器 local include nal ack
其实每个人或多或少都知道,nginx reload后的步骤,1. nginx master进程接收到信号时,进行检查配置文件,当检查结束后,会产生新的worker进程,并且销毁没有使用的worker进程,这篇博客主要是再来验证该reload步骤。
机器:Linux WindowsXP 4.15.0-30deepin-generic #31 SMP Fri Nov 30 04:29:02 UTC 2018 x86_64 GNU/Linux
Nginx配置:nginx version: nginx/1.10.3
Goland版本:go version go1.10.5 linux/amd64
nginx是个多进程的服务器,通过fock master进程的方法来实现的,启动的时候,会启动两个类型的进程,一个是master进程和若干个worker进程
我们更改完毕后,reload做的事情是
a. 使用nginx自带的reload来实现
b. 去向master进程发送信道 (kill -1 PID),来使nginx进程被reload掉
实验:
准备环境 : nginx 服务器 goweb服务器
goweb 服务器
package main import ( "github.com/gin-gonic/gin" "github.com/labstack/gommon/log" "net/http" "time" ) func GetVersion(c *gin.Context) { time.Sleep(30 * time.Second) c.String(200,"9090") } func main() { r := gin.Default() r.GET("/",GetVersion) //r.Run("0.0.0.0:9090") // 设置http服务器 s := &http.Server{ Addr: "0.0.0.0:9090", Handler: r, ReadTimeout: 36000 * time.Second , WriteTimeout: 36000 * time.Second , MaxHeaderBytes: 1 << 20 , } log.Fatal(s.ListenAndServe()) }
nginx 配置
user nginx; worker_processes 3; error_log /var/log/nginx/error.log; pid /run/nginx.pid; events { worker_connections 1024; } http { log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" "$http_x_forwarded_for"‘; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; server { listen 80; server_name localhost; location / { proxy_read_timeout 300; proxy_pass http://127.0.0.1:9090; } } }
# ps aux | grep nginx | grep -v grep root 5669 0.0 0.4 56748 2060 ? Ss 11:31 0:00 nginx: master process /usr/sbin/nginx nginx 5725 0.0 0.4 57188 2028 ? S 11:35 0:00 nginx: worker process nginx 5726 0.0 0.4 57188 2028 ? S 11:35 0:00 nginx: worker process nginx 5727 0.0 0.4 57188 2028 ? S 11:35 0:00 nginx: worker process #
# ps aux | grep nginx | grep -v grep root 5669 0.0 0.4 56748 2060 ? Ss 11:31 0:00 nginx: master process /usr/sbin/nginx nginx 5725 0.0 0.4 57188 2028 ? S 11:35 0:00 nginx: worker process nginx 5726 0.0 0.4 57188 2028 ? S 11:35 0:00 nginx: worker process nginx 5727 0.0 0.4 57188 2028 ? S 11:35 0:00 nginx: worker process #
标签:多进程 oct 准备 更改 http服务器 local include nal ack
原文地址:https://www.cnblogs.com/NoneID/p/12185306.html