上传和部署 Golang 应用到 VPS

huangapple go评论85阅读模式
英文:

Upload and Deploy Golang application to VPS

问题

我已经制作了一个Go应用程序,当我在本地运行exe文件时,它可以正常工作。我应该将它上传到VPS的哪个位置?是public_html/domain.com/somefolder还是/usr/somefolder并使用SSH?

我有我的应用程序、.exe文件和源文件,但是当我在VPS上部署时,我该怎么做?我找不到关于这个的教程,所以希望你能帮助我。

  1. 我应该上传包括从"go build"编译生成的二进制文件在内的src文件夹中的所有文件吗?
  2. 我应该上传到VPS的哪个位置?使用SSH还是cpanel/ftp程序或其他方式?

从在本地Windows 8计算机上进行"go build"到在Linux服务器上在线上传和运行的步骤是什么?

另外,尽管不受支持,CentOS 5.1.1是否可以允许我在VPS上运行已经编译为Linux的Go程序?这是否意味着我不能在CentOS 5.x服务器上安装Go并进行编译?CentOS 5.1.1是否可以解释当我运行命令"./[filename]"时出现的"segmentation fault"错误?

英文:

I've made a Go app and when I run the exe locally it works fine. Where would I upload this to on my VPS? public_html/domain.com/somefolder ? or /usr/somefolder with SSH?

I have my app, my .exe and src-files, but what do I do with it when I deploy online on my VPS? I haven't been able to find a tutorial about this, so I hope you can help me.

  1. do I upload all files in my src folder including the binaries from when I've written "go build"?
  2. upload to where on my VPS? using ssh or cpanel / ftp program or what?

What are the steps from "go build" on your own local windows 8 computer to uploading and running it online on a linux server?

Ps.

Additionally will CentOS 5.1.1 although not supported https://golang.org/doc/install - allow for me to run an already linux compiled go program on my VPS, and does it only mean that I cannot install Go and do compilation on the CentOS 5.x server? Would CentOS 5.1.1 explain the "segmentation fault" error shh gives me when running the command "./[filename]"?

答案1

得分: 1

通常情况下,你需要做以下几步:

  • 复制你创建的二进制文件以及所有的资源文件(html、css、图片等)
    • (可选)也可以复制源代码
  • 确保程序一直运行
    • 可以使用crontab检查程序是否在运行,但也可以自己编写一个简单的监控程序
  • 以非特权用户身份运行二进制文件
    • (如果需要的话)你也可以结合使用Docker

将程序放在public_html/domain.com/somefolder中是没有意义的,因为它不是公共的HTML代码。你希望将文件放在一个只有通过你创建的应用程序/二进制文件才能访问的地方。


对于没有提供整洁源链接的故事,我表示抱歉。然而,这似乎是最好的做法。


另一个重要的注意事项:
即使你的VPS运行的是Windows,你也可以将Linux二进制文件部署到Linux VPS上(价格要便宜得多)- 参考这个Stack Overflow的问题

英文:

Well, usually, you would:

  • Copy the binary you created + all resource files (html, css, images, ...)
    • (optionally the source code as well)
  • Have a way to ensure the program keeps running
    • crontab can be used to check if your program is alive, but a simple monitoring program would suffice as well (which you can write yourself)
  • Run the binary as a non-privileged user
    • (you can also combine it with something like Docker if you want)

It does not make sense to put it inside public_html/domain.com/somefolder, as it is not public html code. You'd want your files somewhere they cannot be accessed unless using the application/binary you created.


My apologies for not having neat source links to my story. However, this does seem like the best thing to do.


Another important note:
Even though your VPS may run Windows, you can also deploy linux binaries to a Linux VPS (which are drastically cheaper) - looking at this SO question.

答案2

得分: 0

我写了一篇关于在OSX上编写Golang应用并在Linux服务器上部署的简短笔记:http://kumargaurav.co/2016/08/10/deploy-go-lang-app-linux-server/

英文:

A short note I wrote on writing golang app on osx and deploying on Linux server: http://kumargaurav.co/2016/08/10/deploy-go-lang-app-linux-server/

huangapple
  • 本文由 发表于 2014年12月17日 12:35:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/27518407.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定