安装docker-compose
# 安装docker-compose
curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# 添加docker-compose执行权限
chmod +x /usr/local/bin/docker-compose
# 查看版本
docker-compose --version
安装 habor
wget https://github.com/vmware/harbor/releases/download/v2.4.3/harbor-online-installer-v2.4.3.tgz
tar xvf harbor-online-installer-v2.4.3.tgz
mkdir -p /var/lib/docker/habor/data
cp ./harbor/harbor.yml.tmpl ./harbor/harbor.yml
# https://www.cnblogs.com/wjlv/p/10772888.html
# 【0,/待替换内容/s/待替换内容/替换内容/】 只替换一个找到的匹配项
# sed -i "0,/https:/s/https:/#https:/" ./harbor/harbor.yml
# sed -i "0,/ port: 443/s/ port: 443/# port: 443/" ./harbor/harbor.yml
# ### 正式环境
# 阿里 8045412__cdsjty.com_chain.crt 和 8045412__cdsjty.com_public 合并 chain内容放在public中的后面 https://www.jianshu.com/p/18decb471817
# sed -i "s# certificate: /your/certificate/path# certificate: /etc/cdsjty_cert/8045412__cdsjty.com_public_chain.crt#g" ./harbor/harbor.yml
# sed -i "s# private_key: /your/private/key/path# private_key: /etc/cdsjty_cert/8045412__cdsjty.com.key#g" ./harbor/harbor.yml
# sed -i "s/reg.mydomain.com/harbor.cdsjty.com/g" ./harbor/harbor.yml
# sed -i "s#data_volume: /data#data_volume: /var/lib/docker/habor/data#g" ./harbor/harbor.yml
# 开发环境
sed -i "0,/https:/s/https:/#https:/" ./harbor/harbor.yml
sed -i "0,/ port: 443/s/ port: 443/# port: 443/" ./harbor/harbor.yml
sed -i "s/reg.mydomain.com/192.168.10.211/g" ./harbor/harbor.yml
sed -i "s#data_volume: /data#data_volume: /var/lib/docker/habor/data#g" ./harbor/harbor.yml
# 执行安装命令
# 优先注释https访问方式 :https://blog.csdn.net/zhengzaifeidelushang/article/details/110781033
bash ./harbor/install.sh
# 设置harbor开机启动,不设置这个会因为harbor各服务启动顺序不同导致无法正常使用harbor
# 3. https://blog.csdn.net/weixin_43784341/article/details/121466222
cat > /usr/lib/systemd/system/harbor.service << EOF
[Unit]
Description=Harbor
After=docker.service systemd-networkd.service systemd-resolved.service
Requires=docker.service
Documentation=http://github.com/vmware/harbor
[Service]
Type=simple
Restart=on-failure
RestartSec=5
ExecStart=/usr/local/bin/docker-compose -f /root/harbor/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f /root/harbor/docker-compose.yml down
[Install]
WantedBy=multi-user.target
EOF
# 服务配置说明 https://blog.csdn.net/linux_yyp/article/details/106209812
echo"
# [Unit]部分主要是对这个服务的说明,内容包括Description和After
# Description用于描述服务,After用于描述服务启动依赖
[Unit]
Description=Harbor
After=docker.service systemd-networkd.service systemd-resolved.service
Requires=docker.service
Documentation=http://github.com/vmware/harbor
# [Service]部分是服务的关键,是服务的一些具体运行参数的设置,这里
# Type=forking 是后台运行的形式,!这里用的 simple
# PIDFile为存放PID的文件路径,!这里没有
# ExecStart为服务的具体运行命令,
# ExecReload为重启命令,ExecStop为停止命令,
# PrivateTmp=True表示给服务分配独立的临时空间
# 注意:[Service]部分的启动、重启、停止命令全部要求使用绝对路径,使用相对路径则会报错!
[Service]
Type=simple
Restart=on-failure
RestartSec=5
ExecStart=/usr/local/bin/docker-compose -f /root/harbor/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f /root/harbor/docker-compose.yml down
# [Install]部分是服务安装的相关设置,可设置为多用户的
[Install]
WantedBy=multi-user.target
"
# 设置harbor开机自启动
systemctl daemon-reload
systemctl enable harbor
systemctl start harbor
docker login -u admin -p Harbor12345 172.18.76.112
默认账号密码
admin
Harbor12345
账号密码 admin 123456
deployer 123456
jenkins 123456
参考资料
- https://zhuanlan.zhihu.com/p/265913747
- https://zhuanlan.zhihu.com/p/31483386
- https://blog.csdn.net/weixin_43784341/article/details/121466222
异常 ERROR: network harbor_harbor is ambiguous (2 matches found based on name)
docker network ls
#
# NETWORK ID NAME DRIVER SCOPE
# 905014581a6c bridge bridge local
# 85c67a2abe2f harbor_harbor bridge local
# d36e9902b9da harbor_harbor bridge local
# cabf13df4faf host host local
# e6c901e0193f none null local
#
# 删除报错的网络
docker network rm 85c
docker network rm d36e
参考资料
更换harbor证书
- 检查harborcompose.yml文件中nginx模块的证书所在文章
- 将获取到的nginx证书替换harborcompose.yml文件中nginx模块的证书所在位置
- 若下载下来的证书是.pem后缀,则直接改成.crt后缀
参考资料:
https://blog.csdn.net/wzy_168/article/details/109577638
<https://blog.csdn.n et/aligeter/article/details/132477671>