查看程序堆栈 linux_关于我通常如何将完整堆栈应用程序部署到linux服务器的分步备忘单...

查看程序堆栈 linux

This assumes a Debian based distribution with systemd, a MySQL server, a NodeJS backend and a frontend written in any library you prefer (Vue, react, etc).

假设使用基于Debian的发行版,其中包含systemd,MySQL服务器,NodeJS后端和用您喜欢的任何库(Vue,react等)编写的前端。

For a tl;dr see here.

有关tl; dr,请参见此处

更新包裹清单 (Update the package list)

sudo apt update

安装mysql服务器 (Install the mysql-server)

设置GIT部署存储库 (Setup GIT deployment repository)

We first need to setup a new repository on our server. This will serve as our target for certain versions we want to push and publish. Instead of copying versions manually we can instead use the power of git and push changes over ssh.

我们首先需要在我们的服务器上设置一个新的存储库。 这将作为我们要推送和发布的某些版本的目标。 除了手动复制版本外,我们还可以使用git的功能并通过ssh推送更改。

创建一个部署挂钩 (Creating a deployment hook)

This will be executed on every successful push. We use this hook to automatically update our server and client with the changes pushed to this repository.

这将在每次成功推送时执行。 我们使用此挂钩自动将推送到此存储库的更改更新到服务器和客户端。

Client:

客户:

Server:

服务器:

添加系统单元文件 (Add systemd unit files)

Unit files describe systemd services which describe when and how those services are started and under which environment. For example our server depends on a running MySQL server. We can describe this dependency with unit files.

单元文件描述了系统服务,这些服务描述了何时以及如何启动这些服务以及在哪种环境下启动这些服务。 例如,我们的服务器依赖于正在运行MySQL服务器。 我们可以用单位文件描述这种依赖性。

Client:

客户:

Server:

服务器:

Add the remote to our local repository

将遥控器添加到我们的本地存储库

This is for your development environment only. On a production server you should probably use nginx or apache. For development builds I usually just set up a simple HTTP server. Either the python simple http server or in this case the http-server NPM package.

这仅适用于您的开发环境。 在生产服务器上,您可能应该使用nginx或apache。 对于开发版本,我通常只设置一个简单的HTTP服务器。 python简单的http服务器或本例中的http服务器NPM软件包。

Create a systemd unit to manage the http-server

创建一个systemd单元来管理http服务器

In order for our users to start and restart this service we need to add certain rights for the group to our sudoers file /etc/sudoers:

为了使我们的用户能够启动和重新启动该服务,我们需要将该组的某些权限添加到我们的sudoers文件/ etc / sudoers中:

 %developers  ALL= NOPASSWD: /bin/systemctl restart <project>-<branch>
%developers ALL= NOPASSWD: /bin/systemctl start <project>-<branch>

This tells sudo that everyone in the group developers is allowed to execute /bin/systemctl [start|restart] <project>-<branch> without the need to enter their password NOPASSWD. It's still important to execute those paths with sudo in order for the rule to come into effect.

这告诉sudo,组developers中的每个人都可以执行/bin/systemctl [start|restart] <project>-<branch>而无需输入密码NOPASSWD 。 为了使规则生效,使用sudo执行这些路径仍然很重要。

Now we see why I copied the index.html to 404.html. If you develope an SPA and your preferred router works with the session history stack i.E. changes the URL instead of the URL hash you need to serve the index.html on any path. http-server serves 404.html if the path does not exist which solves our problem. On nginx, we usually use this setting:

现在我们了解为什么我将index.html复制到404.html。 如果您开发了SPA,并且您的首选路由器可以使用会话历史记录堆栈,那么iE会更改URL而不是URL哈希,您需要在任何路径上提供index.html。 如果路径不存在,则http-server将提供404.html,这解决了我们的问题。 在nginx上,我们通常使用以下设置:

 location / {
try_files $uri $uri/ /index.html;
}

Lastly I like to set up a reverse proxy to serve my applications over TLS. This way you have a central point of managing your certificates. This certificate is valid for all subdomains so you can add applications without the hassle of setting up a new certificate. For my dev server I like to use redbird because of how easy it is to get running. It even has automated zero configuration lets encrypt capabilities. I manage a few more certificates, so I chose to generate my certificate manually and pass them to redbird.

最后,我想设置一个反向代理以通过TLS为我的应用程序提供服务。 这样,您就可以集中管理证书。 该证书对所有子域均有效,因此您无需添加新证书即可添加应用程序。 对于我的开发服务器,我喜欢使用redbird,因为它运行起来非常容易。 它甚至具有自动调零配置,可以加密功能。 我还要管理一些证书,因此我选择手动生成证书并将其传递给redbird。


#!/usr/bin/env node
 var redbird = new require('redbird')({
     	port: 80,
     	ssl: {
             	port: 443,
             	key: "/etc/certificates/private.key",
             	cert: "/etc/certificates/full.crt",
             	ca: "/etc/certificates/full.crt",
     	}
 });
 

 redbird.register('<project_1>.<hostname>.com', 'http://127.0.0.1:3004', {ssl: true});
 redbird.register('<project_2>.<hostname>.com', 'http://127.0.0.1:3005', {ssl: true});

And again a systemd unit file to start up the reverse proxy.

再次是一个systemd单位文件来启动反向代理。

Lastly this is how I update my certificates. You should probably use certbots auto-renewal but since my domain name isn’t pointed to this server I generate them manually for my subdomains.

最后,这就是我更新证书的方式。 您可能应该使用certbots自动续订,但是由于我的域名没有指向此服务器,因此我会为我的子域手动生成它们。

笔记 (Notes)

Push with Windows: Put your private key in C:\Users<user>.ssh\id_rsa. On Windows the easiest way is probably using putty-gen and exporting the private key as OpenSSH key.

Windows推送:将私钥放在C:\ Users <user> .ssh \ id_rsa中。 在Windows上,最简单的方法可能是使用putty-gen并将私钥导出为OpenSSH密钥。

Webpack: I often see developers importing static assets directly in their source. Don’t do this! Use imports/require for those files and let webpack file-loader plugin handle those files. This way you don’t need to copy any assets folders and have hashed filenames for your cache control!

Webpack:我经常看到开发人员直接在其源中导入静态资产。 不要这样! 对这些文件使用import / require,并让webpack文件加载器插件处理这些文件。 这样,您无需复制任何资产文件夹,也无需为您的缓存控件添加哈希文件名!

更进一步 (Going further)

Going from dev to beta which include changes from redbird and http-server to nginx and using the full power of Linux containers with docker.

从开发人员转到测试版,其中包括从redbird和http-server到nginx的更改,以及将Linux容器的全部功能与docker结合使用。

翻译自: https://medium.com/@yidaotus/a-step-by-step-cheat-sheet-on-how-i-usually-deploy-my-full-stack-application-to-a-linux-server-4326277de813

查看程序堆栈 linux

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值