1. 程式人生 > >龍芯Fedora21平臺portainer部署方案

龍芯Fedora21平臺portainer部署方案

http://ask.loongnix.org/?/article/90

 

一、下載portainer官方映象
  1.在loongnix上下載映象

[[email protected] ~]# docker pull docker.io/portainer/portainer:1.14.3
Using default tag: 1.14.3
Trying to pull repository docker.io/portainer/portainer ... 
unauthorized: authentication required

  2.根據控制檯反饋結果unauthorized: authentication required,提示無許可權,因為該映象不支援       mips64el,所以無法下載映象到本地,可使用X86機器進行下載該映象

[[email protected] ~]# docker pull docker.io/portainer/portainer:1.14.3

  3.提示下載成功,檢視本地映象

[[email protected] ~]# docker images
REPOSITORY                       TAG   IMAGE ID  
docker.io/portainer/portainer   1.14.3 457fb8fa57b0

  4.確認本地映象docker.io/portainer/portainer已存在,執行該映象

[[email protected] ~]# docker run -i -t docker.io/portainer/portainer:1.14.3


  5.使用Docker export命令匯出當前映象建立的容器為tar包

[[email protected] ~]# docker export 36ceef361070 > loongson-portainer.tar

  6.將loongson-portainer.tar包拷貝到loongson機器上,這裡使用scp命令進行拷貝

[[email protected]
~]# scp loongson-portainer.tar [email protected]:/root/portainer/

  7.在loongnix機器上解壓loongson-portainer.tar

[[email protected] portainer]# tar xf loongson-portainer.tar

  8.經分析,需要重新編譯的二進位制檔案為portainer

[[email protected] portainer]# file portainer 
portainer: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped


    接下來,從github下載portainer原始碼,重新編譯portainer
二、從github下載portainer原始碼
  1.設定GO語言引數—GOPATH

export GOPATH=/usr/share/gocode

  2.使用go get 從github中下載原始碼

[[email protected] portainer]# go get github.com/portainer/portainer

package github.com/portainer/portainer: no buildable Go source files in /usr/share/gocode/src/github.com/portainer/portainer



    這裡出現了錯誤提示,但是沒有關係,go get 命令相當於先下載,再安裝兩個步驟,上面的提示是安裝失敗,我們需要的是原始碼,因此可以忽略此提示
3.開啟原始碼所在資料夾

[[email protected] portainer]# cd $GOPATH/src/github.com/portainer/portainer

  4.因為只需要編譯原始碼中的api部分所以將此資料夾下的其他內容全部刪除

[[email protected] portainer]# rm -rf app assets bower.json build build.sh codefresh.yml CODE_OF_CONDUCT.md CONTRIBUTING.md gruntfile.js index.html LICENSE package.json README.md test vendor.yml distribution

  5.因為go語言檔案中的的目錄的相對路徑和原始碼中的相對路徑不同,所以需要對原始碼的相對路徑做調整

[[email protected] portainer]# cp -rf api/* $GOPATH/src/github.com/portainer/portainer

  6.刪除原始碼中的api資料夾

[[email protected] portainer]# rm -rf api/

三、編譯portainer原始碼
  1.開啟main.go所在目錄

[[email protected] portainer]# cd $GOPATH/src/github.com/portainer/portainer/cmd/portainer

  2.執行go build 命令,開始進行程式碼編譯

[[email protected] portainer]# go build main.go 
../../../../../gopkg.in/alecthomas/kingpin.v2/usage.go:10:2: cannot find package "github.com/alecthomas/template" in any of:
	/usr/lib/golang/src/github.com/alecthomas/template (from $GOROOT)


  3.根據提示需要載入github.com/alecthomas/template

[[email protected] portainer]# go get github.com/alecthomas/template

  4.再次執行go build 命令,開始進行程式碼編譯

[[email protected] portainer]# go build main.go 
../../../../../gopkg.in/alecthomas/kingpin.v2/parsers.go:9:2: cannot find package "github.com/alecthomas/units" in any of:
	/usr/lib/golang/src/github.com/alecthomas/units (from $GOROOT)
	/usr/share/gocode/src/github.com/alecthomas/units (from $GOPATH)


  5.根據提示需要載入github.com/alecthomas/units

[[email protected] portainer]# go get github.com/alecthomas/units

  6.再次執行go build 命令,開始進行程式碼編譯

[[email protected] portainer]# go build main.go 
../../http/handler/auth.go:11:2: cannot find package "github.com/asaskevich/govalidator" in any of:
	/usr/lib/golang/src/github.com/asaskevich/govalidator (from $GOROOT)
	/usr/share/gocode/src/github.com/asaskevich/govalidator (from $GOPATH)


  7.根據提示需要載入github.com/asaskevich/govalidator

[[email protected] portainer]# go get github.com/asaskevich/govalidator

  8.再次執行go build 命令,開始進行程式碼編譯

[[email protected]  portainer]# go build main.go 
../../bolt/datastore.go:8:2: cannot find package "github.com/boltdb/bolt" in any of:
	/usr/lib/golang/src/github.com/boltdb/bolt (from $GOROOT)
	/usr/share/gocode/src/github.com/boltdb/bolt (from $GOPATH)


  9.根據提示需要載入github.com/boltdb/bolt

[[email protected]  portainer]# go get github.com/boltdb/bolt
# github.com/boltdb/bolt
../../../../boltdb/bolt/db.go:101: undefined: maxMapSize
../../../../boltdb/bolt/db.go:101: invalid array bound maxMapSize


  10.根據提示缺少變數maxMapSize,那麼接下來建立變數,首先開啟boltdb所在目錄

[[email protected]  portainer]# cd $GOPATH/src/github.com/boltdb/bolt

  11.建立適用於mips64el平臺的bolt

[[email protected]n  bolt]# cp bolt_amd64.go bolt_mips64el.go

  12.開啟main.go所在目錄

[[email protected] bolt]# cd $GOPATH/src/github.com/portainer/portainer/cmd/portainer/

  13.再次執行go build 編譯檔案

[[email protected] portainer]# go build main.go 
../../jwt/jwt.go:9:2: cannot find package "github.com/dgrijalva/jwt-go" in any of:
	/usr/lib/golang/src/github.com/dgrijalva/jwt-go (from $GOROOT)
	/usr/share/gocode/src/github.com/dgrijalva/jwt-go (from $GOPATH)


  14.根據提示需要載入github.com/dgrijalva/jwt-go

[[email protected] portainer]# go get github.com/dgrijalva/jwt-go

  15.再次執行go build 命令,開始進行程式碼編譯

[[email protected] portainer]# go build main.go 
../../http/handler/auth.go:12:2: cannot find package "github.com/gorilla/mux" in any of:
	/usr/lib/golang/src/github.com/gorilla/mux (from $GOROOT)
	/usr/share/gocode/src/github.com/gorilla/mux (from $GOPATH)


  16.根據提示需要載入github.com/gorilla/mux

[[email protected] portainer]# go get github.com/gorilla/mux

  17.再次執行go build 命令,開始進行程式碼編譯

[[email protected] portainer]# go build main.go 
../../jwt/jwt.go:10:2: cannot find package "github.com/gorilla/securecookie" in any of:
	/usr/lib/golang/src/github.com/gorilla/securecookie (from $GOROOT)
	/usr/share/gocode/src/github.com/gorilla/securecookie (from $GOPATH)









  18.根據提示需要載入github.com/gorilla/securecookie

[[email protected] portainer]# go get github.com/gorilla/securecookie

  19.再次執行go build 命令,開始進行程式碼編譯

[[email protected] portainer]# go build main.go 
../../http/proxy/manager.go:7:2: cannot find package "github.com/orcaman/concurrent-map" in any of:
	/usr/lib/golang/src/github.com/orcaman/concurrent-map (from $GOROOT)
	/usr/share/gocode/src/github.com/orcaman/concurrent-map (from $GOPATH)









  20.根據提示需要載入github.com/orcaman/concurrent-map

[[email protected] portainer]# go get github.com/orcaman/concurrent-map

  21.再次執行go build 命令,開始進行程式碼編譯

[[email protected] portainer]# go build main.go 
../../cron/watcher.go:5:2: cannot find package "github.com/robfig/cron" in any of:
	/usr/lib/golang/src/github.com/robfig/cron (from $GOROOT)
	/usr/share/gocode/src/github.com/robfig/cron (from $GOPATH)









  22.根據提示需要載入github.com/robfig/cron

[[email protected] portainer]# go get github.com/robfig/cron

  23.再次執行go build 命令,開始進行程式碼編譯

[[email protected] portainer]# go build main.go 
../../crypto/crypto.go:4:2: cannot find package "golang.org/x/crypto/bcrypt" in any of:
	/usr/lib/golang/src/golang.org/x/crypto/bcrypt (from $GOROOT)
	/usr/share/gocode/src/golang.org/x/crypto/bcrypt (from $GOPATH)
../../http/handler/websocket.go:21:2: cannot find package "golang.org/x/net/websocket" in any of:
	/usr/lib/golang/src/golang.org/x/net/websocket (from $GOROOT)
	/usr/share/gocode/src/golang.org/x/net/websocket (from $GOPATH)









  24.根據提示需要載入golang.org/x/crypto/bcrypt和golang.org/x/net/websocket
  注意:$GOPATH的路徑已經不再是/usr/share/gocode/src/github.com/...
       而是/usr/share/gocode/src/golang.org/x/...
       所以需要先建立資料夾

[[email protected] portainer]# mkdir -p $GOPATH/src/golang.org/x/

  25.切換至該資料夾下

[[email protected] portainer]# cd $GOPATH/src/golang.org/x/

  26.載入golang.org/x/crypto/bcrypt

[[email protected] x]# git clone https://github.com/golang/crypto.git

27.載入golang.org/x/net/websocket

[[email protected] x]# git clone https://github.com/golang/net.git

28.切換至main.go所在目錄

[[email protected] x]# cd $GOPATH/src/github.com/portainer/portainer/cmd/portainer/

  29.再次執行go build 命令,開始進行程式碼編譯

[[email protected] portainer]# go build main.go

  30.編譯完成,當前目錄生成檔名為main的二進位制可執行檔案,下面需要拷貝到loongson-portainer.tar 解壓目錄,替換掉二進位制檔案portainer
 
四、loongson-portainer.tar二進位制檔案替換
  1.修改編譯完成後二進位制檔案的檔名

[[email protected] portainer]# mv main portainer

  2.拷貝loongson-portainer.tar 解壓目錄,替換掉二進位制檔案portainer

[[email protected] portainer]# cp -f portainer /root/portainer/

  3.切換至loongson-portainer.tar 解壓目錄

[[email protected] portainer]# cd /root/portainer/

  4.執行二進位制檔案portainer

[[email protected] portainer]# ./portainer

  5.開啟瀏覽器,輸入網址http://localhost:9000

1.png


  6.切換至loongson-portainer.tar 解壓目錄的上級目錄

[[email protected] portainer]# cd /root/

  7.壓縮整個portainer資料夾

[[email protected] ~]# tar -cvf portainer.tar portainer/

五、製作portainer映象
  1.在loongnix上下載fedora21-tools基礎映象

[[email protected] ~]# docker pull docker.io/huangxg20171010/feodra21-tools
REPOSITORY                                     TAG  
docker.io/huangxg20171010/fedora21-tools       latest 









  2.執行feodra21-tools基礎映象

[[email protected] ~]# docker run -i -t docker.io/huangxg20171010/fedora21-tools

  3.基礎映象執行成功後,會自動進入映象控制檯,由[[email protected] ~]變成[[email protected] /],說明容器建立成功,下面切換目錄至root下

[[email protected] /]# cd /root/

  4.將第四節第7步壓縮的portainer.tar拷貝到當前容器的root目錄下

[[email protected] ~]# scp [email protected]:/root/portainer.tar /root/

  5.將portainer.tar解壓到當前目錄

[[email protected] ~]# tar xvf portainer.tar

  6.刪除壓縮檔案portainer.tar

[[email protected] ~]# rm -f portainer.tar

  7.切換至portainer目錄下

[[email protected] ~]# cd /root/portainer

  8.建立執行檔案run-portainer.sh

[[email protected] ~]# vi /root/portainer/run-portainer.sh

  9.run-portainer.sh檔案內容如下

#!/bin/bash
export LC_ALL=zh_CN.UTF-8
export LANG=zh_CN.UTF-8
cd /root/portainer
./portainer









  10.修改run-portainer.sh檔案許可權

[[email protected] ~]#chmod +x /root/portainer/run-portainer.sh

  11.建立portainer所需資料夾

[[email protected] ~]#mkdir -p /data/tls

  12.退出當前容器

[[email protected] ~]# exit

  13.展示所有已建立容器

[[email protected] /]# docker ps -a
CONTAINER       IMAGE                 
1cb....         docker.io/huangxg20171010/fedora21-tools  









  14.使用Docker commit生成一個新映象

[[email protected] /]# docker commit --change='CMD ["/root/portainer/run-portainer.sh"]' 1cb98e167e49 portainer









  15.檢視製作的新映象

[[email protected] /]# docker images
REPOSITORY   TAG     IMAGE ID         CREATED   
portainer   latest  085a675a35d7   12 seconds ago 









六、上傳portainer映象
  1.申請docker hub 帳號
    開啟 docker hub官網:https://hub.docker.com 進行註冊
 
 

2.png


  2.郵件啟用後登入docker hub 點選 Create --> Create repository 建立一個倉庫
 

3.png


  3.本機登入Docker hub帳號

[[email protected] /]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: jiangxinshang
Password: 
Login Succeeded









  4.將本機已經存在的映象名稱做格式化,保證和倉庫名稱:jiangxinshang/portainer 一致,操作如下:

[[email protected] /]# docker tag portainer:latest jiangxinshang/portainer

  5.使用 docker push 將映象上傳至hub上,操作如下:

[[email protected] /]# docker push jiangxinshang/portainer
The push refers to a repository [docker.io/jiangxinshang/portainer]
572868387250: Pushed 









  6.檢視所上傳映象

[[email protected] /]# docker search jiangxinshang/portainer

  

4.png


 
七、下載並執行portainer映象
  1.下載portainer映象

[[email protected] /]# docker pull jiangxinshang/portainer

  2.檢視已下載映象

[[email protected] /]# docker images
 REPOSITORY                           TAG   
docker.io/jiangxinshang/portainer   latest









  3.執行該映象

[[email protected] /]# docker run -i -t --name portainer -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock docker.io/jiangxinshang/portainer

  4.開啟瀏覽器,輸入網址http://localhost:9000
 

5.png


==================================================================================
 X86版本的portainer官方映象docker.io/portainer/portainer 已更新版本,可通過docker pull portainer/portainer:1.14.3來獲取映象,portainer的github原始碼請下載版本v1.14.3
                                                                                                           文章更新日期:2017年10月24日

1.png