英文:
How to deploy a go web application
问题
我有一些疑问,我正在Ubuntu上开发一个Go Web程序,但我的服务器是CentOS 7。
当开发完成后,我需要将其发布到我的CentOS服务器上。我可以直接在Ubuntu上打包,然后将可执行文件上传到服务器上运行,还是需要将源代码上传到服务器上,在服务器上安装Golang后再运行呢?
这是我对如何将Go Web程序发布到服务器上的问题,所以没有代码,抱歉。
英文:
I have some doubts, I am developing a go web program on ubuntu, but my server is centos7
When the development is completed, I need to publish it to my centos server. Can I package it directly on ubuntu, and then upload the executable file to the server to run, or do I need to upload the source code to the server, and then run it after installing golang on the server
This is a question I'm having on how to publish a go web program to a server, so no code, sorry
答案1
得分: 1
是的,你可以在你的Ubuntu机器上编译应用程序,然后将可执行文件复制到Centos服务器上。在服务器上不需要安装Go。
我说"可能"是因为这假设两台机器具有相同的架构/处理器(例如amd64
)。如果不是这种情况,你仍然可以在一台机器上编译,然后复制到另一台机器上,但在构建应用程序之前需要设置GOARCH
。实际上,如果你愿意,你甚至可以在Windows机器上构建应用程序(将GOOS
设置为linux
)。
我还假设你的Web服务器不会执行任何特别不寻常的操作(例如CGO或系统调用),因为这可能会导致问题。对于绝大多数应用程序来说,这并不是问题(我在Windows下编译应用程序,然后直接部署到运行OpenWRT Linux的具有MIPS CPU的RUT955上)。
可能会使情况复杂化的另一个因素是资源(html
、js
、css
等);如果你愿意,你可以将所有这些资源嵌入到可执行文件中。
英文:
Yes; you can probably compile the application on your Ubuntu box and just copy the executable to the Centos server. There is no need to install Go on the server.
I say probably because this assumes that the two machines have the same architecture/processor (e.g. amd64
). If that is not the case then you can still compile on one machine and copy to another but you need to set GOARCH
before building the app. In fact you can go a step further and build the app on a Windows box (with GOOS
set to linux
) if you so desire.
I'm also assuming that your web server does not do anything particularly unusual (i.e. CGO or system calls) because that might cause an issue. The is not the case for the vast majority of applications which will run just fine (I compile an app under windows and then deploy directly onto a RUT955 with a MIPS CPU running OpenWRT linux).
One additional factor that may complicate this is resources (html
, js
, css
etc); you can embed all of these into the executable if you want.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论