亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

拿了一個GitHub的go采集namenode指標(biāo)的項目,修改了一下,本地調(diào)測正常,記錄一下在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依賴下載代理為國內(nèi)的地址

[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.啟動進(jìn)程

[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.檢測進(jìn)程是否存在

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

總結(jié) 

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

相關(guān)文章

  • Golang Printf,Sprintf,Fprintf 格式化詳解

    Golang Printf,Sprintf,Fprintf 格式化詳解

    這篇文章主要介紹了Golang Printf,Sprintf,Fprintf 格式化詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03
  • GO語言中ni,零值與空結(jié)構(gòu)體的使用

    GO語言中ni,零值與空結(jié)構(gòu)體的使用

    Go語言為Java開發(fā)者帶來了一些新概念,如零值、nil和空結(jié)構(gòu)體,理解這些概念有助于Go語言的學(xué)習(xí)和應(yīng)用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-10-10
  • Go語言輕量級線程Goroutine用法實例

    Go語言輕量級線程Goroutine用法實例

    這篇文章主要介紹了Go語言輕量級線程Goroutine用法,實例分析了goroutine使用技巧,需要的朋友可以參考下
    2015-02-02
  • 一文搞懂Golang中的內(nèi)存逃逸

    一文搞懂Golang中的內(nèi)存逃逸

    內(nèi)存逃逸是 Go 語言中一個重要的概念,涉及到程序的性能優(yōu)化和內(nèi)存管理,了解內(nèi)存逃逸可以幫助我們編寫更高效的代碼,本文將從基本概念入手,深入講解 Go 語言中的內(nèi)存逃逸現(xiàn)象,以及如何避免,需要的朋友可以參考下
    2023-12-12
  • go本地環(huán)境配置及vscode go插件安裝的詳細(xì)教程

    go本地環(huán)境配置及vscode go插件安裝的詳細(xì)教程

    這篇文章主要介紹了go本地環(huán)境配置及vscode go插件安裝的詳細(xì)教程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-05-05
  • Golang Copier入門到入坑探究

    Golang Copier入門到入坑探究

    這篇文章主要為大家介紹了Golang Copier入門到入坑探究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • GoFrame?gtree樹形結(jié)構(gòu)的使用技巧示例

    GoFrame?gtree樹形結(jié)構(gòu)的使用技巧示例

    這篇文章主要為大家介紹了GoFrame?gtree樹形結(jié)構(gòu)的使用技巧示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-06-06
  • goland最新激活辦法

    goland最新激活辦法

    這篇文章主要介紹了goland最新激活辦法,激活方法真的超級簡單,只需要把腳本內(nèi)容復(fù)制到對應(yīng)文件,并運行該腳本就可以了,需要的朋友可以參考下
    2021-12-12
  • golang簡單獲取上傳文件大小的實現(xiàn)代碼

    golang簡單獲取上傳文件大小的實現(xiàn)代碼

    這篇文章主要介紹了golang簡單獲取上傳文件大小的方法,涉及Go語言文件傳輸及文件屬性操作的相關(guān)技巧,需要的朋友可以參考下
    2016-07-07
  • 解決Go gorm踩過的坑

    解決Go gorm踩過的坑

    這篇文章主要介紹了解決Go gorm踩過的坑,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04

最新評論