1. 程式人生 > >harbor安裝實操筆記

harbor安裝實操筆記

![file](https://img2020.cnblogs.com/other/268922/202012/268922-20201230222324927-1214202540.png)
紙上得來終覺淺,實操一遍吧!

把所有開發的後端服務先在打成映象,傳到私有映象倉庫;

然後在任意的遠端機器拉取映象,然後可採用docker或者docker-compose的方式執行,本節先按照docker的方式執行;

後面補充docker-compose和k8s的方式執行映象;

| 問題 | 回答 | | --- | --- | | where are we?現狀 | 簡單的聽說過harbor並未實操,不知道里面的坑 | | where are we go? 目標 | 實際使用harbor,把完整的產品映象(前後端中介軟體)上傳到映象倉庫,得到軟體製品; | | how can we go there?路徑 | 先安裝harbor
然後推送程式映象到harbor
最後在任意機器上拉取映象執行; |

# 安裝docker和docker-compose
當前的docker版本不夠高,需要升級;

先刪除docker;
```shell rpm -qa | grep docker //刪除查詢到的所有跟docker相關的東西; yum reomove xxx ```
安裝指定版本: ```shell yum install docker-ce-18.06.3.ce-3.el7 -y # 啟動docker systemctl start docker # 設定為開啟啟動 systemctl enable docker ```

安裝docker-compose ```shell yum install docker-compose ```
解壓安裝包之後得到的檔案目錄如下:
![file](https://img2020.cnblogs.com/other/268922/202012/268922-20201230222325244-593043211.png)

複製配置檔案模板,並修改host和埠;
```shell cp harbor.yml.tmpl harbor.yml vim harbor.yml # 配置host和埠; # 註釋掉htts埠的配置; ```
![file](https://img2020.cnblogs.com/other/268922/202012/268922-20201230222325869-987814702.png)
執行安裝: ```shell sh install.sh ```
安裝完畢之後成功截圖:
![file](https://img2020.cnblogs.com/other/268922/202012/268922-20201230222326565-1902357362.png)
# 登入Harbor管理後臺

入口:[http://47.115.100.100:8000/](http://47.115.100.100:8000/)


賬號:admin


密碼:Harbor12345


![file](https://img2020.cnblogs.com/other/268922/202012/268922-20201230222326961-404015562.png)

# 推送映象到harbor
製作映象的Dockerfile
``` FROM java:8 MAINTAINER lifuchun VOLUME /tmp ADD config config ADD app-file.jar app.jar ADD skywalking-agent.jar skywalking-agent.jar ADD application.properties application.properties EXPOSE 8881 RUN bash -c 'touch /app.jar' ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.cloud.nacos.discovery.server-addr=47.113.126.86:8848","-Dspring.cloud.nacos.discovery.namespace=test","-javaagent:/skywalking-agent.jar","-Dskywalking.agent.service_name=app-file","-Dcollector.backend_service=47.115.100.100:11800","-Dspring.application.name=app-file","-jar","/app.jar"] ```
製作映象指令: ```shell echo '構建app-file映象並啟動' docker build -t app-file . echo '執行app-file' docker run --name app-file -v /data/var/log:/data/var/log -m 1024M -d -p 8881:8080 app-file ```
得到映象之後,需要推送映象到harbor倉庫;

如果推送到harbor倉庫提示https錯誤; ```shell docker push 47.115.100.100:8000/cloudpivot/app-file:latest The push refers to repository [47.115.100.100:8000/cloudpivot/app-file] Get https://47.115.100.100:8000/v2/: http: server gave HTTP response to HTTPS client ```
需要設定本地的docker接受不安全的註冊中心:
![file](https://img2020.cnblogs.com/other/268922/202012/268922-20201230222327290-1105403743.png)


然後重啟docker;


登入倉庫:
```shell docker login 47.115.100.100:8000 # 輸入賬號,密碼 ```
本地映象打tag:
```shell docker tag app-file 47.115.100.100:8000/cloudpivot/app-file:latest ```
推送映象:
```shell docker push 47.115.100.100:8000/cloudpivot/app-file:latest ```

推送進度:

![file](https://img2020.cnblogs.com/other/268922/202012/268922-20201230222327671-255116369.png)

介面觀察映象:

![file](https://img2020.cnblogs.com/other/268922/202012/268922-20201230222328100-1461956811.png)

# 從harbor拉取映象執行 需要編輯docker的配置檔案:
```shell vim /etc/docker/daemon.json # 插入配置資訊 ``` 配置資訊如下: ```json {"insecure-registries":["ip:port"]} ```
然後重啟docker:
```shell systemctl restart docker ```

拉取映象: ```shell docker pull 47.115.100.100:8000/cloudpivot/app-file:latest ```
進度如下:
![file](https://img2020.cnblogs.com/other/268922/202012/268922-20201230222328285-400179165.png)
執行映象:
```shell docker run --name app-file -v /data/var/log:/data/var/log -m 1024M -d -p 8881:8080 app-file ``` 然後檢視日誌:
```shell docker logs -f app-file ```
或者直接在掛載的日誌目錄中檢視日誌:
```shell tail -f /data/var/log/app-file.log ```
![file](https://img2020.cnblogs.com/other/268922/202012/268922-20201230222328901-2041038086.png)
# 小結
一句話概括本文做的事情: 先安裝docker和docker-compose,然後安裝完harbor,找了一個後端服務本地上傳映象,遠端伺服器直接使用映象使用docker的方式執行起來了。

> 原創不易,關注誠可貴,轉發價更高!轉載請註明出處,讓我們互通有無,共同進步,歡迎溝通