飞道科技

飞道科技文档总汇

4.2 版本部署方式

1. 部署 webserver

1.1. 部署最新 server 版本

  1. 准备配置文件,其中,包括feidao.jsonlog4js.json两个配置文件

    其中 feidao.json 看起来像是这样:

    {
      "PORT": 8889,
      "APPID": "nodejs-client",
      "RABBITMQ": "amqp://guest:guest@127.0.0.1:5672",
      "EXPIRATION": 15000,
      "SIGN_ROUTER_QUEUE_NAME": "q_sign_router",
      "DELIVERY_MODE": 2,
      "TIMEOUT": 50000,
      "ACMA": 150000
    }
    

    而 log4js.json 看起来像是这样:

    {
      "appenders": {
        "out": {
          "type": "stdout"
        },
        "console": {
          "type": "console"
        },
        "dateFile": {
          "type": "dateFile",
          "filename": "./logs/feidao.log",
          "maxLogSize": 10240000,
          "backups": 30
        }
      },
      "categories": {
        "default": {
          "appenders": ["console", "dateFile"],
          "level": "debug"
        }
      }
    }
    
  2. 将这个两个文件放在服务器上某个目录下,如 /home/data/feidao/web/
  3. 在服务器上执行命令

    cd /home/data/feidao/web/
    cnpm i @feidao/${spaceid}@server
    
  4. 启动服务

    cd /home/data/feidao/web/
    ./node_modules/.bin/daoke-server
    

    服务启动后,会在日志打印监听端口号。默认的,如果只启动一个服务实例,将使用 feidao.json 中配置的端口号,如 8889,如果该端口已经被占用,则服务会自己查找可用端口号。一般情况下,以 feidao.json 中配置的端口号为基础,不断向上加 1 进行查找可用端口号,如 8890,8891 等。

  5. 配置 nginx

    使用 nginx 反向代理时,需要进行配置,以下为我本机进行测试时使用的配置,供参考。

    location / {
    	proxy_pass   http://127.0.0.1:8889;
    }
    

    如果是需要添加 2 级目录,请在反向代理时添加配置如下

    location ^~ /spaceid {
    	proxy_http_version    1.1;
    	proxy_set_header Connection "";
    	proxy_hide_header X-Powered-By;
    	proxy_pass   http://127.0.0.1:8101/;
    	if ($uri !~ \.(js|css|png|jpg|ico)$) {
    		rewrite /spaceid/(.+)$ /$1 break;
    		proxy_pass   http://127.0.0.1:8889;
    	}
    	add_header Access-Control-Allow-Headers X-Requested-With,Content-Type;
    	add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
    	add_header Access-Control-Allow-Credentials true;
    }
    

1.2. 部署 server 固定版本

  1. 在某种情况下,可能需要部署(或重新部署)某个特定版本,这时在服务器上执行命令

    cd /home/data/feidao/web/
    cnpm i @feidao/${spaceid}@${version}
    

    即可,其它步骤与部署最新版本一致。

2. 部署 service

2.1. 部署 service 最新版本

  1. 准备配置文件,其中,包括feidao.jsonlog4js.json两个配置文件

    其中 feidao.json 看起来像是这样:

    {
      "REDIS": {
        "URL": "redis://127.0.0.1:6379",
        "EXPIRATION": 3600
      },
      "RABBITMQ": "amqp://guest:guest@127.0.0.1:5672",
      "PREFETCH_COUNT": 0,
      "TIMEOUT": 5000,
      "DELIVERY_MODE": 2,
      "EXPIRATION": 15000,
      "ZK_HOSTS": "127.0.0.1:2181",
      "SOA_ID": "soa_195_d161c9d7-85d6-4fe1-bd62-b6447fd52062"
    }
    

    而 log4js.json 看起来像是这样:

    {
      "appenders": {
        "out": {
          "type": "stdout"
        },
        "console": {
          "type": "console"
        },
        "dateFile": {
          "type": "dateFile",
          "filename": "./logs/feidao.log",
          "maxLogSize": 10240000,
          "backups": 30
        }
      },
      "categories": {
        "default": {
          "appenders": ["console", "dateFile"],
          "level": "debug"
        }
      }
    }
    
  2. 将这个两个文件放在服务器上某个目录下,如 /home/data/feidao/web/
  3. 在服务器上执行命令

    cd /home/data/feidao/service/
    cnpm i @feidao/${spaceid}@service
    
  4. 启动服务

    cd /home/data/feidao/service/
    ./node_modules/.bin/daoke-service
    

2.2. 部署 service 固定版本

  1. 在某种情况下,可能需要部署(或重新部署)某个特定版本,这时在服务器上执行命令

    cd /home/data/feidao/service/
    cnpm i @feidao/${spaceid}@${version}
    

    即可,其它步骤与部署最新版本一致。