1. 程式人生 > >[3]supervisor使用管理:實現對異常中斷子進程的自動重啟(以nginx和apache為例)

[3]supervisor使用管理:實現對異常中斷子進程的自動重啟(以nginx和apache為例)

ria std super -s zip inux ecs 核數 down

Web服務器Nginx的安裝與配置

卸載老版本的Nginx

sudo apt-get --purge remove nginxsudo apt-get autoremove
dpkg --get-selections|grep nginx//將羅列出與nginx相關的軟件,如nginx-common一並刪除sudo apt-get --prege remove nginx-common1234


安裝Nginx

  • 從官網下載Nginx

  • 編譯安裝:


tar -zxvf nginx-1.10.2.tar.gzcd nginx-1.10.2.tar.gz
./configure  //註意終端中的信息,缺少庫文件要記得安裝在重新configure才行
make    
sudo make install12345


Nginx反向代理配置

  • 一般一個反向代理建立一個.conf文件,在主配置文件nginx.conf中引入即可

  • GGYun.conf


server {
      listen 8001;
        server_name localhost;
        charset utf-8;
        access_log /home/codemap.access.log;
        location / {
        proxy_set_header X-Forwarded-For $remote_addr</span><span class="pun">;</span></code></li><li class="L9"><code><span class="pln">        proxy_set_header </span><span class="typ">Host</span><span class="pln">            $http_host;
        proxy_pass http://127.0.0.1:8000;
    }
}12345678910
  • nginx.conf文件中的部分配置

worker_processes  4; //進程數,一般等於電腦cpu內核數events {
    worker_connections  1024;//最大鏈接數}
http {//配置文件根目錄
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;    #tcp_nopush     on;    #keepalive_timeout  0;
    keepalive_timeout  65;    #gzip  on;
    include codemap.conf;//引入的配置文件}1234567891011121314

常用命令

重啟nginx:/usr/local/nginx/sbin/nginx -s reopen1重新加載配置文件:/uar/local/nginx/sbin/nginx -s reload  1啟動:/uar/local/nginx/sbin/nginx1關閉:/uar/local/nginx/sbin/nginx -s stop1

進程管理工具supervisor安裝

  • 服務器運行某個進程時可以用supervisor進行管理,可以自動後臺運行。

終端安裝

apt-get install supervisor1

supervisor配置

[program:GGYun]directory = /home/noah/Documents/src/github.com/HivenKay/GGYun  //項目路徑command = /home/noah/Documents/src/github.com/HivenKay/GGYun/GGYun  //可執行二進制文件路徑autostart = true  //是否制動啟動autorestart=true  //是否自動重啟startsecs = 5user = root  //執行用戶redirect_stderr = truestdout_logfile = /var/log/supervisord/GGYun.logstderr_logfile =/var/log/supervisord/ghost_err.log12345678910


supervisor常用命令

supervisorctl start GGYun//啟動進程1supervisorctl restart GGYun//重啟進程1supervisorctl reload //重啟supervisorctl1

supervisor安裝後可能遇到的問題

  • supervisorctl start GGYun 報錯 unix:///var/run/supervisor.sock no such file

    • 解決

sudo touch /var/run/supervisor.sock1sudo chmod 777 /var/run/supervisor.sock1sudo service supervisor restart1

連接遠程服務器

  • windows系統請安裝putty,linux系統可以在終端直接鏈接

ssh [email protected]   //root為用戶名,139.196.180.208為服務器的ip1
  • 拷貝本地文件到服務器

scp /home/noah/Documents/... [email protected]:/home/noah/Documents/...


[3]supervisor使用管理:實現對異常中斷子進程的自動重啟(以nginx和apache為例)