Windows files packaged and uploaded to Linux

1. Write a test demo

package main

import (
	"fmt"
	"net/http"
)

func main() {
    
    
	http.HandleFunc("/", hello)
	server := &http.Server{
    
    
		Addr: ":8888",
	}
	fmt.Println("server startup...")
	if err := server.ListenAndServe(); err != nil {
    
    
		fmt.Printf("server startup failed, err:%v\n", err)
	}
}

func hello(w http.ResponseWriter, _ *http.Request) {
    
    
	w.Write([]byte("hello golang.com!"))
}

2. Compile into executable file demo

write in makefile

.PHONY: all build run gotool clean help

BINARY="appdemo"

all: gotool build

build:
#这个应该是mac上的命令,我们用win,用下面即可
#    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o ./bin/${
      
      BINARY}
	set CGO_ENABLED=0
	set GOOS=linux
	set GOARCH=amd64
	go build -ldflags "-s -w" -o ./bin/${
    
    BINARY}

The directory structure is as follows, the command line make in the current project directory can generate appdemo files, Linux executable files without suffix

insert image description here

Windows files packaged and uploaded to Linux

You can also drag and drop in xshell (used for a single file). Multiple file uploads will be packaged. The packaging steps are as follows:

1.在win先用把文件打包成xxx.tar
2.再把xxx.tar打包成xxx.tar.gz
3.用xshell将文件上传到Linux
4.解压文件
1、压缩命令:
	命令格式:
	tar -zcvf 压缩文件名 .tar.gz 被压缩文件名
	可先切换到当前目录下,压缩文件名和被压缩文件名都可加入路径。
2、压缩命令:
tar -zxvf xxx.tar.gz -C /xxx/
	-z是使用gzip来解压或者压缩文件
	-x是释放文件,或者说叫解压文件
	-v是报告文件详情信息,如果不加这一条的话,就不会一直滚动的信息条了,建议加上,如果出了错还是会更加直观的看出来是什么原因
	-f是指定名字
	后续跟的是要解压的文件名,-C是指定目录,后续跟的也就是目标目录
3、解压缩命令:
	命令格式:
	tar -zxvf 压缩文件名.tar.gz
	解压缩后的文件只能放在当前的目录。
4、运行程序
打开腾讯云安全组 --自定义 --tcp --8888
设置appdemo权限
chmod 777 ./appdemo
运行程序:Linux程序没有后缀,执行./文件路径即可
./appdemo

Close terminal without stopping

sudo nohup ./bin/appdemo  > nohup_appdemo.log 2>&1 &

insert image description here

Solve miscellaneous problems
How to solve the problem that the Linux port is occupied

FirewallD is not running causes and solutions

Guess you like

Origin blog.csdn.net/weixin_46356409/article/details/127060519