从零开始安装部署Harbor(Docker+Docker-compose+Harbor)
1.安装docker
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io
systemctl start docker
查看docker版本
docker -v
2.安装docker-compose
1)配置阿里的epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
2)安装并升级Python-pip
yum install python-pip -y
pip install --upgrade pip
3)安装docker-compose
pip install docker-compose
4)查看docker-compose版本
docker-compose -v
3.安装harbor
1)自己上传harbor的压缩包
harbor-offline-installer-v2.0.1
提取码:2022
2)自己解压压缩包
tar -zxvf harbor-offline-installer-v2.0.1.tgz
3)进入到相对应的目录下
cd harbor
4)修改harbor的配置文件(如果只想能够运行起来的话,只需要修改hostname即可,改成你机器的ip;
)
cp harbor.yml.tmpl harbor.yml
mkdir -p /opt/application/harbor //用于存放harbor的持久化数据
harbor.yml配置文件主要修改参数如下:
hostname: 192.168.205.129 //设置访问地址,可以使用ip、域名,不可以设置为127.0.0.1或localhost。默认情况下,harbor使用的端口是80,若使用自定义的端口,除了要改docker-compose.yml文件中的配置外,这里的hostname也要加上自定义的端口,否则在docker login、push时会报错
#http配置
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 80
#https配置(如不需要可不配置,注释掉)
# https related config
#https:
# https port for harbor, default is 443
#port: 443
# The path of cert and key files for nginx
#certificate: /your/certificate/path
#private_key: /your/private/key/path
#external_url: https://reg.mydomain.com:8433 //如果要启用外部代理,比如外层的NGINX、LB等,请取消注释external_url,当它启用时,hostname将不再使用。
harbor_admin_password: Harbor12345 //admin密码
#数据库配置
database:
# The password for the root user of Harbor DB. Change this before any production use.
password: root123
# The maximum number of connections in the idle connection pool. If it <=0, no idle connections are retained.
max_idle_conns: 50
# The maximum number of open connections to the database. If it <= 0, then there is no limit on the number of open connections.
# Note: the default number of connections is 100 for postgres.
max_open_conns: 100
#持久化数据目录
data_volume: /opt/application/harbor
5)修改Docker的配置文件
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://cyowm7vy.mirror.aliyuncs.com"]
"insecure-registries":["192.168.205.129:80"]
}
systemctl daemon-reload
重新启动Docker后台服务: systemctl restart docker
6)修改配置后docker-compose down
停止所有服务,删除当前配置目录:rm -rf ./common/config/*
下配置清单,重新执行install.sh
生成配置
docker-compose down
rm -rf ./common/config/*
./install.sh
4,Harbor如何停止与启动
# cd soft/harbor //切换到harbor安装包目录
# docker-compose stop //停止Harbor
# docker-compose start //启动Harbor
部分代码如下(可以直接打成一个简易命令包执行就行!):
vi dockers.sh
#i
#!/bin/bash
# docker
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io
systemctl start docker
docker -v
# docker-compose
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install python-pip -y
pip install --upgrade pip
pip install docker-compose
docker-compose -v
chmod 777 dockers.sh #赋权
./dockers.sh #执行权限
感谢大家,点赞,收藏,关注,评论!