- 适用环境
Ubuntu-1804
Docker:5:19.03.12~3-0~ubuntu-bionic
Harbor:1.7.6
Docker-Compose:1.26.2
- 需要修改的内容
IPADDR: Harbor主机的地址
HARBOR_ADMIN_PASSWORD: 管理员密码
- 脚本
#!/bin/bash
COLOR="echo -e \033[1;31m"
END="\033[0m"
DOCKER_VERSION="5:19.03.12~3-0~ubuntu-bionic"
HARBOR_VERSION="1.7.6"
IPADDR=`hostname -I | awk '{print $1}'`
HARBOR_ADMIN_PASSWORD=000000
install_docker(){
apt update
apt -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt update
${COLOR}"5秒后即将安装: docker-"${DOCKER_VERSION}"版本......"${END}
${COLOR}"如果想安装其他版本Docker, 请按ctrl+c键退出, 修改版本再执行"${END}
sleep 5
apt -y install docker-ce=${DOCKER_VERSION} docker-ce-cli=${DOCKER_VERSION}
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-EOF
{
"registry-mirrors": ["https://odzb6i12.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl enable --now docker
docker version && ${COLOR}"Docker 安装成功"${END} || ${COLOR}"Docker 安装失败"${END}
}
install_docker_compose(){
#!/bin/bash
COLOR="echo -e \033[1;31m"
END="\033[0m"
DOCKER_VERSION="5:19.03.12~3-0~ubuntu-bionic"
HARBOR_VERSION="1.7.6"
IPADDR=`hostname -I | awk '{print $1}'`
HARBOR_ADMIN_PASSWORD=000000
install_docker(){
apt update
apt -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt update
${COLOR}"5秒后即将安装: docker-"${DOCKER_VERSION}"版本......"${END}
${COLOR}"如果想安装其他版本Docker, 请按ctrl+c键退出, 修改版本再执行"${END}
sleep 5
apt -y install docker-ce=${DOCKER_VERSION} docker-ce-cli=${DOCKER_VERSION}
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-EOF
{
"registry-mirrors": ["https://odzb6i12.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl enable --now docker
docker version && ${COLOR}"Docker 安装成功"${END} || ${COLOR}"Docker 安装失败"${END}
}
install_docker_compose(){
${COLOR}"开始安装 Docker Compose......"${END}
sleep 1
cp -a docker-compose-Linux-x86_64 docker-compose && mv docker-compose /usr/sbin && chmod +x /usr/sbin/docker-compose
docker-compose --version && ${COLOR}"Docker Compose 安装完成"${END} || ${COLOR}"Docker Compose 安装失败"${END}
}
install_harbor(){
${COLOR}"开始安装 Docker Harbor......"${END}
sleep 1
mkdir /apps
tar xf harbor-offline-installer-v1.7.6.tgz -C /apps
sed -i.bak -e "s/^hostname =.*/hostname = "${IPADDR}"/" -e "s/^harbor_admin_password = .*/harbor_admin_password = "$HARBOR_ADMIN_PASSWORD"/" /apps/harbor/harbor.cfg
apt -y install python
/apps/harbor/install.sh && ${COLOR}"Harbor 安装完成"${END} || ${COLOR}"Harbor 安装失败"${END}
}
create_harbor_service(){
cat > /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/sbin/docker-compose -f /apps/harbor/docker-compose.yml up
ExecStop=/usr/sbin/docker-compose -f /apps/harbor/docker-compose.yml down
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now harbor &> /dev/null
}
dpkg -s docker-ce &> /dev/null && ${COLOR}"Docker已安装"${END} || install_docker
docker-compose --version &> /dev/null && ${COLOR}"Docker Compose 已经安装"${END} || install_docker_compose
install_harbor
create_harbor_service
网友评论