Harbor私有仓库搭建
1、安装docker
yum install -y docker
systemctl start docker
systemctl enable docker
2、安装docker-compose
1、下载安装:
wget https://github.com/docker/compose/releases/download/1.16.0/docker-compose-Linux-x86_64
cp docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
2、验证:
docker-compose -versio
3、安装Harbor:
1、下载安装: wget https://github.com/vmware/harbor/releases/download/v1.1.2/harbor-online-installer-v1.1.2.tgz tar xvf harbor-online-installer-v1.1.2.tgz && cd harbor
2、修改harbor.cfg文件:
************************************ ## Configuration file of Harbor # hostname设置访问地址,可以使用ip、域名,不可以设置为127.0.0.1或localhost hostname = 192.168.73.68 # 访问协议,默认是http,也可以设置https,如果设置https,则nginx ssl需要设置on ui_url_protocol = https # mysql数据库root用户默认密码root123,实际使用时修改下 db_password = root123 max_job_workers = 3 customize_crt = on ssl_cert = /data/cert/server.crt ssl_cert_key = /data/cert/server.key secretkey_path = /data admiral_url = NA # 邮件设置,发送重置密码邮件时使用 email_identity = email_server = smtp.mydomain.com email_server_port = 25 email_username = sample_admin@mydomain.com email_password = abc email_from = admin <sample_admin@mydomain.com> email_ssl = false # 启动Harbor后,管理员UI登录的密码,默认是Harbor12345 harbor_admin_password = P@ssw0rd # 认证方式,这里支持多种认证方式,如LADP、本次存储、数据库认证。默认是db_auth,mysql数据库认证 auth_mode = db_auth # LDAP认证时配置项 #ldap_url = ldaps://ldap.mydomain.com #ldap_searchdn = uid=searchuser,ou=people,dc=mydomain,dc=com #ldap_search_pwd = password #ldap_basedn = ou=people,dc=mydomain,dc=com #ldap_filter = (objectClass=person) #ldap_uid = uid #ldap_scope = 3 #ldap_timeout = 5 # 是否开启自注册 self_registration = on # Token有效时间,默认30分钟 token_expiration = 30 # 用户创建项目权限控制,默认是everyone(所有人),也可以设置为adminonly(只能管理员) project_creation_restriction = everyone verify_remote_cert = on
2、创建认证:
mkdir -p /data/cert/
localdomain=server
openssl req -nodes -subj "/C=CN/ST=GuangDong/L=DongGuan/CN=$localdomain" -newkey rsa:2048 -keyout $localdomain.key -out $localdomain.csr
openssl x509 -req -days 3650 -in $localdomain.csr -signkey $localdomain.key -out $localdomain.crt
openssl x509 -req -in $localdomain.csr -CA $localdomain.crt -CAkey $localdomain.key -CAcreateserial -out $localdomain.crt -days 10000
3、安装启动:
./install.sh --with-notary #安装完成后就可以在浏览器访问
4、Harbor的使用:
1、两种方法:
1)、在web页面上增加项目之后,随便找一台装docker的机器,修改/etc/docker/daemon.json文件:
{ "insecure-registries":["192.168.73.63:5000","192.168.73.68","192.168.73.67:80"] } #支持多个仓库地址
2)、修改/etc/sysconfig/docker文件:
OPTIONS='--selinux-enabled=false --insecure-registry gcr.io --insecure-registry 192.168.73.68' #增加192.168.73.68
3)、修改/usr/lib/systemd/system/docker.service文件:
ExecStart=/usr/bin/dockerd \
--exec-opt native.cgroupdriver=systemd \
$DOCKER_OPT_BIP \
$DOCKER_OPT_IPMASQ \
$DOCKER_OPT_MTU \
-s=overlay \
--log-driver=json-file \
--insecure-registry=192.168.73.68
systemctl restart docker
注:1、对于http后面需要加端口,https后面不需要加端口(很重要) 2、用3增加了的话,再用2修改是不生效的,再用3修改的话会直接报错。
2、上传镜像:
docker login -u admin -p Harbor12345 192.168.73.68 #先登录
docker push 192.168.73.68/cheng/nginx #上传
docker pull 192.168.73.68/cheng/nginx #下载
3、重启harbor:
docker-compose down
docker-compose up -d
./prepare #重新配置文件