This time, I will show you how to deploy ** Go application ** on ** Alibaba Cloud ECS instance **.
In the previous article, I showed you how to deploy your local Java application directly to your Alibaba Cloud ECS instance. This time, I will show you how to deploy a Go application on an Alibaba Cloud Elastic Compute Service (ECS) instance.
Whether you compile a Go application that runs in the cloud or a Go application that runs locally, the coding method is the same. Therefore, in this article, we will explain how to deploy using a Go application that prints "Hello World" on a Web page as an example.
//Alibaba Cloud Toolkit. http://www.aliyun.com/product/cloudtoolkit
func setupRouter() *gin.Engine {
// Disable Console Color
// gin.DisableConsoleColor()
r := gin.Default()
// Ping test
r.GET("/ping", func(c *gin.Context) {
c.String(http.StatusOK, "Alibaba Cloud Toolkit: Hello World.")
})
return r
}
func main() {
r := setupRouter()
// Listen and Server in 0.0.0.0:8080
r.Run(":80")
}
You can download the source code from this link.
The above code is a standard Go project used to display the string "Hello World" on a web page.
Alibaba Cloud provides Eclipse-based plugins that allow developers to efficiently deploy applications written in their local IDE to ECS instances.
Plugin URL: https://www.aliyun.com/product/cloudtoolkit_en
The procedure for installing this Eclipse-based plug-in is similar to a typical plug-in, so we won't go into details here.
After installing the plugin, select it and configure the preferences.
Select Top Menu> Window> Preferences> Alibaba Cloud Toolkit> Account.
When the next page appears, set the AK and SK for your Alibaba Cloud account and you're done setting up your preferences (if you're using a RAM user account, enter the AK and SK for your RAM user) ).
Right-click on the project name in Eclipse and select Alibaba Cloud> Deploy to ECS from the shortcut menu. The following deployment screen will be displayed.
In the Placement Settings dialog box, set the placement parameters and click Placement to complete the initial placement.
--Deployment file: There are two options. --Maven Build: If you are using Maven to build your current project, you can use Alibaba Cloud Toolkit to build and deploy your application directly. --File Upload: If you are not using Maven to build your current project, or if you already have a locally packaged deployment file, you can select your local deployment file and upload it directly. --Select ECS to deploy: Select a region from the drop-down list and select the ECS instance to deploy to that region. --Specify deployment destination: Enter the deployment path on the ECS instance. --Command: Enter the application startup command. This parameter specifies the command to be executed after the application package is deployed. For Go programs, you typically enter a series of program launch commands.
source ~/.bash_profile
pkill -f 'go-demo'
mv /tmp/go-demo /root/go-demo
chmod 755 /root/go-demo
sh -c /root/go-demo
Recommended Posts