最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Linux環(huán)境下編譯并運行go項目的全過程

 更新時間:2023年11月16日 11:18:52   作者:臨風賞月  
Go語言是Google的開源編程語言,廣泛應用于云計算、分布式系統(tǒng)開發(fā)等領域,在Linux上也有大量的應用場景,這篇文章主要給大家介紹了關于Linux環(huán)境下編譯并運行go項目的相關資料,需要的朋友可以參考下

拿了一個GitHub的go采集namenode指標的項目,修改了一下,本地調測正常,記錄一下在Linux環(huán)境編譯并運行的過程。

1.安裝go環(huán)境

[root@hadoop1011 ~]# yum install go -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package golang.x86_64 0:1.18.9-1.el7 will be installed
--> Processing Dependency: golang-bin = 1.18.9-1.el7 for package: golang-1.18.9-1.el7.x86_64
--> Processing Dependency: golang-src = 1.18.9-1.el7 for package: golang-1.18.9-1.el7.x86_64
--> Running transaction check
---> Package golang-bin.x86_64 0:1.18.9-1.el7 will be installed
---> Package golang-src.noarch 0:1.18.9-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================================================================
 Package                                         Arch                                        Version                                             Repository                                 Size
=================================================================================================================================================================================================
Installing:
 golang                                          x86_64                                      1.18.9-1.el7                                        epel                                      685 k
Installing for dependencies:
 golang-bin                                      x86_64                                      1.18.9-1.el7                                        epel                                      105 M
 golang-src                                      noarch                                      1.18.9-1.el7                                        epel                                      9.1 M

Transaction Summary
=================================================================================================================================================================================================
Install  1 Package (+2 Dependent packages)

Total download size: 115 M
Installed size: 420 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): golang-1.18.9-1.el7.x86_64.rpm                                                                                                                                     | 685 kB  00:00:00     
(2/3): golang-src-1.18.9-1.el7.noarch.rpm                                                                                                                                 | 9.1 MB  00:00:02     
(3/3): golang-bin-1.18.9-1.el7.x86_64.rpm                                                                                                                                 | 105 MB  00:00:14     
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                            8.2 MB/s | 115 MB  00:00:14     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : golang-src-1.18.9-1.el7.noarch                                                                                                                                                1/3 
  Installing : golang-1.18.9-1.el7.x86_64                                                                                                                                                    2/3 
  Installing : golang-bin-1.18.9-1.el7.x86_64                                                                                                                                                3/3 
  Verifying  : golang-bin-1.18.9-1.el7.x86_64                                                                                                                                                1/3 
  Verifying  : golang-1.18.9-1.el7.x86_64                                                                                                                                                    2/3 
  Verifying  : golang-src-1.18.9-1.el7.noarch                                                                                                                                                3/3 

Installed:
  golang.x86_64 0:1.18.9-1.el7                                                                                                                                                                   

Dependency Installed:
  golang-bin.x86_64 0:1.18.9-1.el7                                                                golang-src.noarch 0:1.18.9-1.el7                                                               

Complete!

2.嘗試編譯,發(fā)現(xiàn)失敗

[root@hadoop1011 ~]# go build namenode_exporter.go 
namenode_exporter.go:9:2: no required module provides package github.com/prometheus/client_golang/prometheus: go.mod file not found in current directory or any parent directory; see 'go help mo
dules'namenode_exporter.go:10:2: no required module provides package github.com/prometheus/log: go.mod file not found in current directory or any parent directory; see 'go help modules'

3. 更改GOPROXY依賴下載代理為國內的地址

[root@hadoop1011 ~]# go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/golang"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.9"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build820474747=/tmp/go-build -gno-record-gcc-switches"

[root@hadoop1011 go_pkg]# go env -w GOPROXY=https://mirrors.aliyun.com/goproxy,direct

4.編譯項目

[root@hadoop1011 go_pkg]# go build namenode_exporter.go 
go: downloading github.com/prometheus/log v0.0.0-20151026012452-9a3136781e1f
go: downloading github.com/prometheus/client_golang v0.8.0
go: downloading github.com/Sirupsen/logrus v1.0.6
go: downloading github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273
go: downloading github.com/golang/protobuf v1.2.0
go: downloading github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e
go: downloading github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973
go: downloading github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910
go: downloading golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8
go: downloading golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b
go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.1
[root@hadoop1011 go_pkg]# ls
go.mod  go.sum  LICENSE  namenode_exporter  namenode_exporter.exe  namenode_exporter.go  README.md  resourcemanager_exporter.go
[root@hadoop1011 go_pkg]# ll
total 20936
-rw-r--r-- 1 root root     1033 Apr 19 19:43 go.mod
-rw-r--r-- 1 root root     4526 Apr 19 19:43 go.sum
-rw-r--r-- 1 root root    11357 Apr 19 19:43 LICENSE
-rwxr-xr-x 1 root root 10570414 Apr 19 19:56 namenode_exporter
-rw-r--r-- 1 root root 10808832 Apr 19 19:30 namenode_exporter.exe
-rw-r--r-- 1 root root    13704 Apr 19 19:43 namenode_exporter.go
-rw-r--r-- 1 root root      944 Apr 19 19:43 README.md
-rw-r--r-- 1 root root     9586 Apr 19 19:43 resourcemanager_exporter.go

5.啟動進程

[root@hadoop1011 go_pkg]# nohup ./namenode_exporter &
[1] 4361
[root@hadoop1011 go_pkg]# nohup: ignoring input and appending output to ‘nohup.out'

[root@hadoop1011 go_pkg]# ll
total 20940
-rw-r--r-- 1 root root     1033 Apr 19 19:43 go.mod
-rw-r--r-- 1 root root     4526 Apr 19 19:43 go.sum
-rw-r--r-- 1 root root    11357 Apr 19 19:43 LICENSE
-rwxr-xr-x 1 root root 10570414 Apr 19 19:56 namenode_exporter
-rw-r--r-- 1 root root 10808832 Apr 19 19:30 namenode_exporter.exe
-rw-r--r-- 1 root root    13704 Apr 19 19:43 namenode_exporter.go
-rw------- 1 root root      108 Apr 19 19:56 nohup.out
-rw-r--r-- 1 root root      944 Apr 19 19:43 README.md
-rw-r--r-- 1 root root     9586 Apr 19 19:43 resourcemanager_exporter.go
[root@hadoop1011 go_pkg]# cat nohup.out 
time="2023-04-19T19:56:22+08:00" level=info msg="Starting Server: :9070" file=namenode_exporter.go line=395
[root@hadoop1011 go_pkg]# ll
total 20940
-rw-r--r-- 1 root root     1033 Apr 19 19:43 go.mod
-rw-r--r-- 1 root root     4526 Apr 19 19:43 go.sum
-rw-r--r-- 1 root root    11357 Apr 19 19:43 LICENSE
-rwxr-xr-x 1 root root 10570414 Apr 19 19:56 namenode_exporter
-rw-r--r-- 1 root root 10808832 Apr 19 19:30 namenode_exporter.exe
-rw-r--r-- 1 root root    13704 Apr 19 19:43 namenode_exporter.go
-rw------- 1 root root      108 Apr 19 19:56 nohup.out
-rw-r--r-- 1 root root      944 Apr 19 19:43 README.md
-rw-r--r-- 1 root root     9586 Apr 19 19:43 resourcemanager_exporter.go

6.檢測進程是否存在

[root@hadoop1011 go_pkg]# ss -tlnp|grep 9070
LISTEN     0      128         :::9070                    :::*                   users:(("namenode_export",pid=4361,fd=3))
[root@hadoop1011 go_pkg]# 

總結 

到此這篇關于Linux環(huán)境下編譯并運行go項目的文章就介紹到這了,更多相關Linux編譯運行go項目內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • go原子級內存操作實現(xiàn)

    go原子級內存操作實現(xiàn)

    原子級內存操作是在多線程并發(fā)執(zhí)行時,能夠確保某個內存操作是不可中斷的操作,本文主要介紹了go原子級內存操作實現(xiàn),具有一定的參考價值,感興趣的可以了解一下
    2024-02-02
  • Golang二維切片初始化的實現(xiàn)

    Golang二維切片初始化的實現(xiàn)

    這篇文章主要介紹了Golang二維切片初始化的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-04-04
  • Go語言基礎學習之map的示例詳解

    Go語言基礎學習之map的示例詳解

    哈希表是常見的數(shù)據(jù)結構,有的語言會將哈希稱作字典或者映射,在Go中,哈希就是常見的數(shù)據(jù)類型map,本文就來聊聊Golang中map的相關知識吧
    2023-04-04
  • go打包aar及flutter調用aar流程詳解

    go打包aar及flutter調用aar流程詳解

    這篇文章主要為大家介紹了go打包aar及flutter調用aar流程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-03-03
  • 一文吃透Go的內置RPC原理

    一文吃透Go的內置RPC原理

    這篇文章主要為大家詳細介紹了Go語言中內置RPC的原理。說起?RPC?大家想到的一般是框架,Go?作為編程語言竟然還內置了?RPC,著實讓我有些吃鯨,本文就來一起聊聊吧
    2023-03-03
  • 在Go中創(chuàng)建自定義錯誤的方式總結

    在Go中創(chuàng)建自定義錯誤的方式總結

    在程序開發(fā)中錯誤處理是至關重要的,下面這篇文章主要給大家介紹了關于在Go中創(chuàng)建自定義錯誤的方式,文中通過代碼介紹的非常詳細,對大家學習或者使用Go具有一定的參考借鑒價值,需要的朋友可以參考下
    2024-01-01
  • Golang中map數(shù)據(jù)類型的使用方法

    Golang中map數(shù)據(jù)類型的使用方法

    這篇文章主要介紹了Golang中map數(shù)據(jù)類型的使用方法,文章圍繞主題展開詳細的內容戒殺,具有一定的參考價值,需要的朋友可以參考一下
    2022-09-09
  • Go語言單線程運行也會有的并發(fā)問題解析

    Go語言單線程運行也會有的并發(fā)問題解析

    這篇文章主要為大家介紹了Go語言單線程運行的并發(fā)問題解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-12-12
  • 詳解Go中的高效切片拼接和Go1.22提供的新方法

    詳解Go中的高效切片拼接和Go1.22提供的新方法

    在?Go?語言中,切片拼接是一項常見的操作,但如果處理不當,可能會導致性能問題或意外的副作用,本文將詳細介紹幾種高效的切片拼接方法,希望對大家有所幫助
    2024-01-01
  • 如何用golang運行第一個項目

    如何用golang運行第一個項目

    這篇文章主要介紹了如何用golang運行第一個項目,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-03-03

最新評論

鹿邑县| 宜君县| 团风县| 九龙坡区| 海原县| 墨江| 双鸭山市| 双峰县| 灵台县| 万荣县| 朝阳县| 江源县| 搜索| 嘉善县| 南陵县| 永和县| 彩票| 且末县| 九龙坡区| 天峨县| 舒城县| 西乌珠穆沁旗| 阿克陶县| 云阳县| 漠河县| 措勤县| 商南县| 河源市| 建宁县| 隆尧县| 巴南区| 万荣县| 珠海市| 沿河| 镇平县| 景泰县| 蒲江县| 土默特左旗| 汶川县| 将乐县| 韶山市|