一键安装Harbor仓库(shell脚本)

一键安装Harbor仓库,支持在线和离线安装
前提是得有docker 和docker-compose环境
下载博主的脚本和安装包比在线下载安装快很多

请安装前修改正确的hostname 或者自己更换的端口

#!/bin/bash 

#域名设置
hostname=192.168.56.24
#端口
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

在网络条件不好的情况下建议离线安装,请先下载下面的包
离线的安装包
链接:https://pan.baidu.com/s/1X1JCDJktoQ1OCBgqZVMsyA
提取码:7ab5

你可能感兴趣的:(服务器,打包部署,linux,docker)