centos7搭建harbor私有镜像仓库
1.准备工作
1.1更换软件源
#更换阿里yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
#更换阿里docker源
yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
1.2 修改主机名
hostnamectl set-hostname harbor
#修改/etc/hosts,同步到使用私有镜像库的每个节点
echo "192.168.153.139 docker.io" >>/etc/hosts
1.3 同步时间
yum install chrony ntpdate -y
sed "s/^server/#server/g" /etc/chrony.conf
echo 'server tiger.sina.com.cn iburst' >> /etc/chrony.conf
echo 'server ntp1.aliyun.com iburst' >> /etc/chrony.conf
systemctl enable chronyd ; systemctl start chronyd
ntpdate tiger.sina.com.cn
1.4 安装docker和docker-compose
安装docker
yum install docker-ce -y
systemctl start docker
systemctl enable docker
安装docker-compose
#1.下载Docker Compose的可执行文件。可以使用以下命令下载最新版本:
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
#2.赋予可执行权限给下载的二进制文件:
sudo chmod +x /usr/local/bin/docker-compose
#3.创建一个符号链接,将docker-compose命令链接到/usr/bin目录,以便可以全局访问
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
#4.验证安装是否成功
docker-compose --version
1.5 下载harbor离线安装包
去harbor github下载离线安装包,版本可自行选择。下载完成后解压。
[root@localhost ~]# tar xzvf harbor-offline-installer-v2.10.3.tgz
harbor/harbor.v2.10.3.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/common.sh
harbor/harbor.yml.tmpl
2.配置harbor
切换至解压目录后,修改harbor.yml文件。
cp harbor.yml.tmpl harbor.yml # 注意文件名必须是harbor.yml
最主要的是更改标红内容,除hostname外,其余的都可以保持默认。
如果仅测试环境不需要启用https的话,可以把https的所有内容注释掉。
3.执行安装命令
[root@localhost harbor]# ./install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 26.1.4
[Step 1]: checking docker-compose is installed ...
Note: Docker Compose version v2.27.1
[Step 2]: loading Harbor images ...
...
[Step 5]: starting Harbor ...
WARN[0000] /root/harbor/docker-compose.yml: `version` is obsolete
[+] Running 10/10
✔ Network harbor_harbor Created 0.3s
✔ Container harbor-log Started 0.5s
✔ Container harbor-portal Started 1.2s
✔ Container registry Started 1.2s
✔ Container harbor-db Started 1.3s
✔ Container registryctl Started 1.1s
✔ Container redis Started 1.3s
✔ Container harbor-core Started 1.5s
✔ Container nginx Started 2.4s
✔ Container harbor-jobservice Started 2.2s
✔ ----Harbor has been installed and started successfully.----
如果你配置的harbor使用http协议,则需要编辑docker主配置文件daemon.json加入insecure-registries,centos目录为/etc/docker/daemon.json
[root@harbor ~]# cat /etc/docker/daemon.json
{
"insecure-registries":["http://docker.io"]#替换为你的域名
}
更改后重启docker
# 重载配置文件
systemctl daemon-reload
# 重启docker
systemctl restart docker
# 停止所有容器
docker-compose down -v
# 启动所有容器
docker-compose up -d
#配置开机自启
chmod +x /etc/rc.d/rc.local
echo "/usr/bin/docker-compose -f /你的路径/docker-compose.yml up -d" >> /etc/rc.d/rc.local
4.测试
访问harbor服务器地址,看到截图说明搭建成功
#命令行登录到仓库
docker login 你的harbor地址