持續集成系列(1)------https私有docker倉庫harbor搭建
## 目標 gitlab+jenkins+docker+harbor+k8s初步實現持續集成
harbor簡介
Harbor是VMware公司開源的企業級Docker Registry項目,其目標是幫助用戶迅速搭建一個企業級的Docker registry服務。
環境準備
- 系統:Centos7.4
- docker v17.03
- ip:10.79.163.40
- 域名:hub.domain.com
docker安裝
#安裝依賴包
yum install -y yum-utils device-mapper-persistent-data lvm2
#添加docker源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
#安裝docker
yum install -y --setopt=obsoletes=0 \
docker-ce-17.03.1.ce-1.el7.centos \
docker-ce-selinux-17.03.1.ce-1.el7.centos
#切換國內hub
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://ef017c13.m.daocloud.io
#啓動
systemctl enable docker
systemctl start docker
#安裝docker-compose
yum install -y docker-compose
Harbor下載
cd /opt
wget https://storage.googleapis.com/harbor-releases/harbor-offline-installer-v1.5.2.tgz
tar xzvf harbor-offline-installer-v1.5.2.tgz
cd harbor
Harbor配置
vim harbor.cfg
修改如下內容
hostname = hub.domain.com
ui_url_protocol = https
customize_crt = off
ssl_cert = /opt/certs/hub.domain.com.cer
ssl_cert_key = /opt/certs/hub.domain.com.key
參數解釋
customize_crt:使用自簽名證書時設置爲on
ssl_cert&ssl_cert_key:ssl證書存放的路徑
ssl證書部署
自動申請免費ssl證書,這裏以阿里雲dns接口爲例,其它認證方式請參考官方文檔
acme腳本安裝
cd /opt
#下載Let's Encrypt免費證書自動申請腳本
git clone --depth=1 https://github.com/Neilpang/acme.sh.git
cd ./acme.sh/
./acme.sh --install
阿里雲dnskey獲取
#導入獲取的key
export Ali_Key="yourkey"
export Ali_Secret="yoursecret"
#申請ssl證書
./acme.sh --issue --dns dns_ali -d hub.domain.com
#部署證書
mkdir /opt/certs
./acme.sh --installcert -d hub.domain.com --key-file /opt/certs/hub.domain.com.key --fullchain-file /opt/certs/hub.domain.com.cer
Harbor運行
cd /opt/harbor && ./install.sh
- 更改域名解析指向服務器ip
- 訪問hub.domain.com
常用操作
默認使用db認證方式,初始用戶密碼爲admin/Harbor12345
- 登陸倉庫
docker login hub.domain.com
- 推送鏡像
#標記鏡像
docker tag SOURCE_IMAGE[:TAG] hub.domain.com/library/IMAGE[:TAG]
#推送鏡像到項目
docker push hub.domain.com/library/IMAGE[:TAG]
- 從倉庫拉取鏡像
docker pull hub.domain.com/library/IMAGE[:TAG]
- 配置修改後重啓
cd /opt/harbor
vim harbor.cfg
docker-compose down
./prepare.sh
docker-compose up -d
- 服務啓停
cd /opt/harbor
docker-compose stop
dokcer-compose start
思考
harbor高可用集羣
- mysql集羣
- 鏡像分佈式存儲
- session保持(多個harbor實例,通過nginx進行負載均衡)