• Harbor私有镜像仓库(下)


    七,Harbor HA:环境准备

    • 全新安装两台harbor,但不要着急执行./install(如果用旧的要清理下数据)
    • 要做Harbor高可用,我们需要准备一台NFS服务器共享2台harbor的数据存储目录,在生产环境中,我们可以选则Ceph或者Glusterfs
    • 我们需要一台Postgres数据库给Harbor的clair漏洞扫描组件使用
    • 我们需要一台MySQL数据库给Harbor使用
    • 我们需要一台redis数据库给session使用
    主机IP用途VIP
    harbor-master 192.168.200.70 Harbor镜像仓库-主 192.168.200.244
    harbor-slave 192.168.200.109 Harbor镜像仓库-备  
    dns-nfs 192.168.200.1110 DNS服务器和NFS服务器端(harbor HA文件存储)  
     

    (1)在dns-nfs上搭建nfs服务端 ip4转发开开

    为了省事儿把nfs服务端装在DNS服务器上

    echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf

    sysctl -p

    mkdir -p /data/nfs

    yum -y install nfs-utils

    vim /etc/exports

    cat /etc/exports

     
    1. /data/nfs 192.168.200.0/24(rw,no_root_squash)
    2. #默认root用户存的东西不降权

    systemctl start nfs

    image_1d0r3cm4497e86odnp1fg61811p.png-169.1kB


    image_1d0r3feik17en17691hhn19ph1eg31m.png-152.5kB

     

    (2)在harbor主和备上创建数据挂载目录,并安装nfs节点支持包(主备操作都一样)

    yum -y install nfs-utils

    mkdir -p /data/storage

    mount 192.168.200.110:/data/nfs /data/storage

    df -hT | grep /data/nfs

    image_1d0r3h8j61g4ujjj18mm14c9ata23.png-158kB


    image_1d0r3hh32r99j881bf51cg42vt2g.png-158.6kB

     

    (3)在LDNS-NFS(NFS服务器端)启动一个redis容器

     

    下载一个redis镜像(apline系统目前docker领域很火,因为它容量很小,比centos小很多)

    docker pull redis:alpine

    docker images

    image_1d0r7ol8p1kogmdrc6pqvd10dk3t.png-46.2kB

     

    启动redis镜像,映射端口

    docker run -dit --name redis_test -p 6379:6379 redis:alpine

    docker ps -a

    image_1d0r7qb62rltm3712p6138kf704q.png-29.2kB

     

    (4) 在LDNS-NFS(NFS服务器端)启动一个postgreSQL数据库容器

     

    下载postgres

    docker pull postgres

    docker images

    docker run -dit --name postgres_test -p 5432:5432 -e POSTGRES_PASSWORD=123123 postgres

    docker ps -a

    image_1d0r7tdsfjhv1p674rm1nt4f2057.png-109.4kB

     

    (5) 在LDNS-NFS(NFS服务端)启动一个MySQL数据容器

     

    下载MySQL 5.6版镜像

    docker pull mysql:5.6

    docker images

    docker run -dit --name mysql_test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123123 mysql:5.6 --character-set-server=utf8

    docker ps -a

    image_1d0r8i23hq3k1m9tqav1go35l8k.png-111.3kB

     

    (6)最后按照用途,我们分别给数据库改一下名称

    docker ps -a

    docker rename postgres_test clair_db

    docker rename mysql_test harbor_db

    docker rename redis_test session

    docker ps -a

    image_1d0r8ki3h1cd414436p92b0jlpa4.png-71.3kB

     

    八,Harbor HA:修改配置

     

    8.1 Harbor-Master向mysql_db容器里导入数据表(192.168.200.110)

     

    再解压后的harbor的ha目录下的registry.sql表导入到我们之前在NFS服务端上创建的MySQL容器里

    cd /data/install/harbor

    ls

    tree ha

     
    1. ha
    2. ├── docker-compose.clair.tpl
    3. ├── docker-compose.clair.yml
    4. ├── docker-compose.tpl
    5. ├── docker-compose.yml #需要修改的配置文件
    6. ├── registry.sql #需要导入的mysql表格
    7. └── sample
    8. ├── active_active
    9.    ├── check.sh
    10.    └── keepalived_active_active.conf
    11. └── active_standby
    12. ├── check_harbor.sh
    13. └── keepalived_active_standby.conf
    14. 3 directories, 9 files

    image_1d0r8p77d1mt13g91hheaa51k1bah.png-56.8kB

     

    Harbor-master本地安装mysql客户端连接程序

    yum -y install mysql

    which mysql

    image_1d0r8uevb16jlqk41pm1uk1cence.png-122.5kB

     

    远程连接到192.168.200.110(NFS服务器端)的3306端口 导入表registry.sql

    mysql -uroot -p123123 -h192.168.200.110 -P3306

    show databases;

    source ha/registry.sql

    show databases;

    image_1d0r948b4lk3h2nfpf4nv1t7jfp.png-82.1kB


    image_1d0r94mia12ii3eg1tbd138fg35g6.png-84.9kB

     

    特别提示:如果导入表格出现如下错误

    Specified key was too long; max key length is 767 bytes

    这是因为导入的表格建立的索引超过mysql默认上线767bytes >=254 因此我们需要修改导入的表

    cat -n ha/registry.sql | sed -n '220p;291p'

     
    1. 220 repository varchar(256) NOT NULL, #将256改成254
    2. 291 resource_name varchar(256), #将256改成254
    3. #改完之后在进行表格导入就不会报错了

    vim ha/registry.sql

    cat -n ha/registry.sql | sed -n '220p;291p'

    image_1d0r9ejuj1b3q1ttetl5n891lnfn2.png-30.2kB

     

    再次导入表registry.sql

    mysql -uroot -p123123 -h192.168.200.110 -P3306

    show databases;

    source ha/registry.sql

    show databases;

    image_1d0r9i3vveuc1fl71r53t3sv6gnf.png-79.6kB


    image_1d0r9igrn1iggli49ps18fh1j66ns.png-61.3kB

     

    8.2 修改配置文件

     

    修改/data/install/ha/docker-compose.yml配置文件(备库也要改!!)

    cat -n ha/docker-compose.yml | sed -n '19p'

     
    1. 19 /data/registry:/storage:z

    vim ha/docker-compose.yml

    cat -n ha/docker-compose.yml | sed -n '19p'

     
    1. 19 /data/storage:/storage:z #修改成我们的nfs共享目录

    image_1d0r9lik6f91eco15i4n27eepp9.png-22.7kB


    image_1d0r9p42r1c5d124nsfamkd1n2qr9.png-23.6kB

     

    修改/data/install/harharbor.cfg文件

    cat -n harbor.cfg | sed -n '7p;11p;23p;24p;68p;130p;133p;136p;139p;145p;150p;154p;157p;160p;163p'

     
    1. 7 hostname = reg.mydomain.com #harbor的访问域名
    2. 11 ui_url_protocol = http #web访问连接方式
    3. 23 ssl_cert = /data/cert/server.crt #ca证书路径
    4. 24 ssl_cert_key = /data/cert/server.key #ca密钥路径
    5. 68 harbor_admin_password = Harbor12345 #harbor默认初始密码
    6. 130 db_host = mysql #harbor连接的mysql_db的IP
    7. 133 db_password = root123 #MySQL连接密码
    8. 136 db_port = 3306 #MySQL连接端口
    9. 139 db_user = root #MySQL连接用户
    10. 145 redis_url = redis:6379 #session连接的redis数据库路径
    11. 150 clair_db_host = postgres #clair漏洞检测组件连接的数据库IP
    12. 154 clair_db_password = password #postgres数据库连接密码
    13. 157 clair_db_port = 5432 #postgres数据库连接端口
    14. 160 clair_db_username = postgres #默认的连接用户名
    15. 163 clair_db = postgres #默认的库名
     

    修改成如下所示(主备都一样)

    vim harbor.cfg

    scp harbor.cfg 192.168.200.109:/data/install/harbor/

    cat -n harbor.cfg | sed -n '7p;11p;23p;24p;68p;130p;133p;136p;139p;145p;150p;154p;157p;160p;163p'

     
    1. 7 hostname = www.yunjisuan.com
    2. 11 ui_url_protocol = https
    3. 23 ssl_cert = /etc/ssl/harbor/www.yunjisuan.com.crt
    4. 24 ssl_cert_key = /etc/ssl/harbor/www.yunjisuan.com.key
    5. 68 harbor_admin_password = Harbor12345
    6. 130 db_host = 192.168.200.110
    7. 133 db_password = 123123
    8. 136 db_port = 3306
    9. 139 db_user = root
    10. 145 redis_url = 192.168.200.110:6379
    11. 150 clair_db_host = 192.168.200.110
    12. 154 clair_db_password = 123123
    13. 157 clair_db_port = 5432
    14. 160 clair_db_username = postgres
    15. 163 clair_db = postgres

    image_1d0rbfa0ntk1lhctffp6l1cfn19.png-76.2kB


    image_1d0rbfirq1lp715a74117a05fg1m.png-54.6kB

     

    九,Harbor HA:启动Harbor

    把证书信任给主,备,DNS-NFS 三台都得信任 ,信任之后都得重启docker!

    mkdir -p /etc/ssl/harbor --->提前在nfs服务器创建目录

     

    在主上把证书信任,并都发送给备和nfs,信任之后重启docker

    cd /data/ssl/

    cp www.yunjisuan.com.crt www.yunjisuan.com.key /etc/ssl/harbor

    cp www.yunjisuan.com.crt /etc/pki/ca-trust/source/anchors/

    scp www.yunjisuan.com.crt www.yunjisuan.com.key 192.168.200.109:/etc/ssl/harbor

    scp www.yunjisuan.com.crt www.yunjisuan.com.key 192.168.200.110:/etc/ssl/harbor

    update-ca-trust enable

    update-ca-trust extract

    systemctl restart docker

    image_1d0rco7dj3m1530b0i1t0s2m.png-76kB

     

    在备上把证书信任,信任之后重启docker

    cd /etc/ssl/harbor

    cp www.yunjisuan.com.crt /etc/pki/ca-trust/source/anchors/

    update-ca-trust enable

    update-ca-trust extract

    systemctl restart docker

    image_1d0rcttit1qnb19jv1it01cns22c3p.png-24.8kB

     

    在nfs上把证书信任,信任之后重启docker

    cd /etc/ssl/harbor

    cp www.yunjisuan.com.crt /etc/pki/ca-trust/source/anchors/

    update-ca-trust enable

    update-ca-trust extract

    systemctl restart docker

    image_1d0rcu7bg6nh1eej1m40104c1h646.png-28.1kB

     

    DNS-NFS上的docker进程开启 (重启之后就关了)

    docker ps -a

    docker start harbor_db

    docker startclair_db

    docker start session

    docker ps -a

    image_1d0rd06rc877p5v138ve897lh4j.png-73kB

     

    启动harbor-master

    cd /data/install/harbor

    ./install.sh --with-clair --ha

    因为使用了自定义存储路径,安装途中需要yes确认

    主和备两台最好一个一个的启动,免得冲突

    image_1d0rd2j1f1e71v11qi412eflui50.png-42.4kB

     

    进行Harbor-master的IP浏览器进行访问测试

    https://192.168.200.70

    image_1d0rda7vr1ojdro4k3h158o1v6u6g.png-92.1kB

     

    在DNS-NFS上进行上传测试

     

    修改映射

    cat /etc/hosts

     
    1. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
    2. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
    3. 192.168.200.70 www.yunjisuan.com

    image_1d0rdc0lm1fsg1oje14vnn3c1bca7d.png-21.2kB

    image_1cu1d9gtqlvbqu8610er71dn59.png-233.6kB


    image_1cu1da7tid1pbff98gmc3kjrm.png-106.6kB

     

    上传一个镜像进行测试

    docker login -uadmin -pHarbor12345 www.yunjisuan.com

    docker images

    docker tag redis:alpine www.yunjisuan.com/library/redis:v1

    docker push www.yunjisuan.com/library/redis:v1

    image_1d0rdohel1ure1785odv1ati1kud8q.png-81.6kB


    image_1d0rdscepbva1eqfqceokb1f9han.png-91.5kB

     

    在主上查看测试结果

    ls /data/storage

    image_1d0rdsk0evh3f0m1u1718dn1in6b4.png-11.8kB

     

    启动harbor-slave

    cd /data/install/harbor

    ./install.sh --with-clair --ha

    因为使用了自定义存储路径,安装途中需要yes确认

    image_1d0rdtr2l1d6amftk70nrf1e2vbh.png-42.4kB

     

    进行Harbor-slave的IP浏览器进行访问测试

    https://192.168.200.109

    image_1d0re8ssr1t3vbpidm04rslinde.png-92.7kB

     

    安装keepalived(域名映射在VIP上即可)

    image_1cu1dpb2r1oei107q1cc1jd3dfu13.png-239.8kB


    image_1cu1dpqk01ieb13nl1q9n1bb36911g.png-133.3kB

  • 相关阅读:
    hdu-2841 Visible Trees---容斥定理
    hdu-4135 Co-prime---容斥定理经典&&求1-m中与n互质的数目
    hdu-1796 How many integers can you find---容斥定理
    hdu-2837 Calculation---指数循环节
    FZU-1759 Super A^B mod C---欧拉降幂&指数循环节
    指数循环节&欧拉降幂
    hdu-3074 Multiply game---线段树+单点更新
    hdu-1792 A New Change Problem---数论&剩余系
    POJ-2429 GCD & LCM Inverse---给出gcd和lcm求原来两个数
    hdu-2685 I won't tell you this is about number theory---gcd和快速幂的性质
  • 原文地址:https://www.cnblogs.com/linyaonie/p/11238385.html
Copyright © 2020-2023  润新知