[3]supervisor使用管理:实现对异常中断子进程的自动重启(以nginx和apache为例)

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/...


猜你喜欢

转载自blog.51cto.com/sf1314/2131625