如何在生产中不使用docker部署分子项目?

发布于 2025-01-16 19:31:47 字数 327 浏览 3 评论 0原文

在不使用docker和Kubernetes的情况下,如何在服务器上部署分子微服务项目?

我将更新后的代码拉入服务器并运行 npm run dev 命令项目,按方面运行。

但现在我想为这个项目设置pm2,那么我需要做什么?

我尝试在服务器上运行 npm run start 命令,但输出低于结果,并且项目未运行。

请帮忙。

How should I deploy a molecular microservice project on the server without using docker and Kubernetes?

I pull my updated code into a server and run the npm run dev command project run as per aspected.

But now I want to set up pm2 for this project so, what do I need to do?

I try to run npm run start command on a server but I am getting below output and the project is not running.

enter image description here

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

多像笑话 2025-01-23 19:31:47

您的问题是您没有配置要启动的服务。对于 Docker 和 Kubernetes 环境,我们使用 SERVICES 环境变量来配置 Moleculer 节点上应加载哪些服务。

所以你也可以使用这种方式,或者修改package.json中的start脚本并设置你想要加载的服务。例如

moleculer-runner -e services/**/*.service.js

Your problem is that you didn't configure the services to start. For Docker and Kubernetes environment, we use SERVICES env variable to configure what services should be loaded on a Moleculer node.

So you can also use this way, or modify the start script in package.json and set the services what you want to load. E.g.

moleculer-runner -e services/**/*.service.js
心安伴我暖 2025-01-23 19:31:47

我得到了解决方案。

如果我们不使用 Docker 和 Kubernetes 来执行 molecularclar 项目,而是直接在服务器上克隆我们的代码,就像普通的 NodeJS(Express) 项目一样。

然后我们需要创建index.js 文件并需要添加以下几行。

const { ServiceBroker } = require('moleculer');
const config = require('./moleculer.config');

config.hotReload = true;

const broker = new ServiceBroker(config);

broker.loadServices('services', '**/*.service.js');
broker.start();

因此,使用上述命令 Molecular 启动了我们项目的所有服务。

在索引文件之后,我们可以使用 pm2 服务启动我们的项目。

I got the solution.

If we not use the Docker and Kubernetes for moleclar project and directly clone our code on server same as like normal NodeJS(Express) project.

Then we need to create index.js file and need to put below lines.

const { ServiceBroker } = require('moleculer');
const config = require('./moleculer.config');

config.hotReload = true;

const broker = new ServiceBroker(config);

broker.loadServices('services', '**/*.service.js');
broker.start();

So, using above command Molecular started all the service of our project

After, index file we can able to start our project using pm2 service.

满意归宿 2025-01-23 19:31:47

我创建了一个启动脚本(api-init.json)如下:

[
    {
        "script": "./node_modules/moleculer/bin/moleculer-runner.js",
        "args": "services",
        "instances": "max",
        "watch": false,
        "name": "API"
    }
]

然后使用 pm2 启动:

pm2 start api-init.json

I created a start script (api-init.json) as below:

[
    {
        "script": "./node_modules/moleculer/bin/moleculer-runner.js",
        "args": "services",
        "instances": "max",
        "watch": false,
        "name": "API"
    }
]

Then use pm2 to start:

pm2 start api-init.json
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文