概述
Harbor是一个开源的企业级Docker Registry管理工具,它提供了一个安全、可靠、可扩展的平台,用于存储、管理和分发Docker镜像。Harbor可以帮助组织和团队更好地管理Docker镜像,并提高应用程序构建和部署的效率。
Harbor 架构
前期准备
下载harbor安装包
下载地址:Releases · goharbor/harbor · GitHub
harbor-offline-installer-v1.2.0.tgz
安装docker-compose
sudo yum install -y yum-utils sudo yum-config-manager --add-repo sudo yum install docker-compose docker-compose -v
一键安装脚本installHarbor.sh
#!/bin/bash
#域名设置
hostname=121.43.36.87
#端口
port=80
#禁止用户注册
self_registration=off
#设置只有管理员可以创建项目
project_creation_restriction=adminonly
#登录密码
harbor_admin_password=Harbor12345
# 当前目录
CURRENT_DIR=$(
cd "$(dirname "$0")"
pwd
)
#检测docker是否安装
if ! which docker >/dev/null ; then
echo -e "\033[31m 请先安装docker \033[0m"
exit
fi
#检测 docker-compose是否安装
if ! which docker-compose >/dev/null ; then
echo -e "\033[31m 请先安装docker-compose \033[0m"
exit
fi
##Install
if which docker-compose1 >/dev/null; then
echo "检测到 Docker Compose 已安装,跳过安装步骤"
else
if [[ -f "$CURRENT_DIR/harbor-offline-installer-v1.2.0.tgz" ]]; then
echo "... 离线安装 harbor"
tar zxf harbor-offline-installer-v1.2.0.tgz
cd harbor
filePath="$CURRENT_DIR/harbor/harbor.cfg"
host=1
if [ $port == "80" ]
then
host=$hostname
else
host=$hostname":"$port
fi
sed -i "s/hostname = reg.mydomain.com/hostname = ${host}/g" $filePath
sed -i "s/self_registration = on/self_registration = ${self_registration}/g" $filePath
sed -i "s/project_creation_restriction = everyone/project_creation_restriction = ${project_creation_restriction}/g" $filePath
sed -i "s/harbor_admin_password = Harbor12345/harbor_admin_password = ${harbor_admin_password}/g" $filePath
sed -i "s/80:80/${port}:80/" ./docker-compose.yml
./prepare && ./install.sh
echo "... 离线安装 harbor 成功"
else
echo "... 在线安装 Harbor"
cd $CURRENT_DIR
wget https://github.com/vmware/harbor/releases/download/v1.2.0/harbor-online-installer-v1.2.0.tgz
tar zxf harbor-online-installer-v1.2.0.tgz
cd harbor
filePath="$CURRENT_DIR/harbor/harbor.cfg"
host=1
if [ $port == "80" ]
then
host=$hostname
else
host=$hostname":"$port
fi
sed -i "s/hostname = reg.mydomain.com/hostname = ${host}/g" $filePath
sed -i "s/self_registration = on/self_registration = ${self_registration}/g" $filePath
sed -i "s/project_creation_restriction = everyone/project_creation_restriction = ${project_creation_restriction}/g" $filePath
sed -i "s/harbor_admin_password = Harbor12345/harbor_admin_password = ${harbor_admin_password}/g" $filePath
sed -i "s/80:80/${port}:80/" ./docker-compose.yml
chmod +x install.sh
./install.sh || exit
docker-compose ps
echo "... 在线安装 Harbor 成功"
fi
fi
注意:需要修改脚本中的hostname,改为自己服务器的外网IP
安装
sh installHarbor.sh docker ps //查看harbor容器进程
访问
账号/密码:admin/Harbor12345