网络视频直播系统 拓展培训公司 VMware post terminal 抖音 mtu原理 pagination vue开发 vue网站模板 支付网站建设 pmp教程 jquery事件绑定 移动端上传图片插件 nodejs后端开发 matlab自然对数 oracle行转列函数 java高级特性 java类 java实例 java开发学习 java课程 java接口的实例 linuxshell 在线手册 go2lan js刷新页面 python爬虫代码 瑞兹技能 语音分析软件 一键隐藏 游戏linux正则表达式 ios12录屏 pr加速视频 虚拟声卡驱动 renderto office2010免费版 冰冠堡垒单刷路线 ps画笔颜色 反转字符串
当前位置: 首页 > 学习教程  > 编程语言

多harbor实例共享后段存储

2020/8/11 19:00:34 文章标签:

多harbor实例共享后段存储

  • 一、环境准备
  • 二、安装mysql及redis
  • 三、修改harbor配置
  • 四、安装keepalived
  • 五、登陆验证

一、环境准备

机器用途

节点 IP 用途 VIP
harbor1 192.168.109.20 harbor1+keepalived主 192.168.109.30
harbor2 192.168.109.21 harbor2+keepalived备
harbor3 192.168.109.22 mysql+redis+nfs

nfs挂载
所有机器安装nfs
使用阿里云镜像源,这里不做描述

# yum -y install nfs-utils*

在harbor3上创建共享路径

# mkdir /data		#用于存放镜像仓库
# mkdir /db			#用于存放mysql及redis数据

将目录共享出来,并重启nfs

# vim /etc/exports
/data *(rw,no_root_squash)
/db *(rw,no_root_squash)
# systemctl restart nfs-server

在harbor1和harbor2上挂载共享路径

# mkdir /data
# vim /etc/fstab
192.168.109.22:/data    /data   nfs     defaults,_netdev        0 0
# mount -a

二、安装mysql及redis

在harbor3上创建docker-compose.yml

# vim /root/docker-compose.yml
version: '3'
services:
  mysql-server:
    hostname: mysql-server
    restart: always
    container_name: mysql-server
    image: mysql:5.7
    volumes:
      - /db/mysql:/var/lib/mysql
    command: --character-set-server=utf8
    ports:
      - '3306:3306'
    environment:
      MYSQL_ROOT_PASSWORD: 123456
#    logging:
#      driver: "syslog"
#      options:
#        syslog-address: "tcp://192.168.109.22:1514"
#        tag: "mysql"
  redis:
    hostname: redis-server
    container_name: redis-server
    restart: always
    image: redis:3
    volumes:
      - /db/redis:/data
    ports:
      - '6379:6379'
#    logging:
#      driver: "syslog"
#      options:
#        syslog-address: "tcp://192.168.109.22:1514"
#        tag: "redis"

其中的volumes路径,mysql的配置及密码可自行修改
提示:因为log容器为harbor中服务,当harbor暂未部署时,需要注释相关配置,harbor部署完毕后取消注释,然后重新up一次即可。

# docker-compose up -d
# docker-compose ps
    Name                  Command               State                 Ports              
-----------------------------------------------------------------------------------------
mysql-server   docker-entrypoint.sh --cha ...   Up      0.0.0.0:3306->3306/tcp, 33060/tcp
redis-server   docker-entrypoint.sh redis ...   Up      0.0.0.0:6379->6379/tcp           

解压harbor二进制包,将harbor自带的sql刷到mysql里

# tar xvf harbor-offline-installer-v1.5.0.tgz
# scp harbor/ha/registry.sql 192.168.109.22:/db/mysql   #将sql拷贝到mysql挂载目录下

从harbor3进入容器

# docker ps
CONTAINER ID        IMAGE
2a62e4f84958        mysql:5.7 
# docker exec -it 56a44d99c4c4 bash
root@mysql-server:/# cd /var/lib/mysql
root@mysql-server:/# mysql -uroot -p
mysql> set session sql_mode='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
mysql> source ./registry.sql

三、修改harbor配置

在harbor1上修改

# vim /root/harbor/harbor.cfg
 hostname = 192.168.109.30		#修改为VIP
 db_host = 192.168.109.22			#修改为mysql地址
 db_password = 123456				#修改mysql root密码
 db_port = 3306
 db_user = root
 redis_url = 192.168.109.22:6379	#修改为redis地址
 
# vim /root/harbor/prepare
empty_subj = "/C=/ST=/L=/O=/CN=/" 
修改为:
empty_subj = "/C=US/ST=California/L=Palo Alto/O=VMware, Inc./OU=Harbor/CN=notarysigner"
# cd /root/harbor
# ./prepare			渲染配置

harbor2也如上修改
验证结果

# cat ./common/config/ui/env
_REDIS_URL=192.168.109.22:6379
# cat ./common/config/adminserver/env | grep MYSQL
MYSQL_HOST=192.168.109.22
MYSQL_PORT=3306
MYSQL_USR=root
MYSQL_PWD=123456
MYSQL_DATABASE=registry

部署harbor

# cp ha/docker-compose.yml .
# vi docker-compose.yml
log
  ports:
  - 1514:10514		#只需修改log处配置即可
# ./install.sh

提示:由于redis和mysql采用外部部署,因此需要在docker-compose.yml中删除或注释redis和mysql的服务项,同时删除其他服务对其的依赖,官方自带的harbor中已经存在修改好的docker-compose文件,位于ha目录。
harbor2节点参考上述部署harbor即可。

四、安装keepalived

harbor1上安装所需yum包

# yum -y install gcc gcc-c++ make kernel-devel kernel-tools kernel-tools-libs kernel libnl libnl-devel libnfnetlink-devel openssl-devel
# tar -zxvf keepalived-2.0.8.tar.gz 	#解压keepalive包
# cd keepalived-2.0.8/
# ./configure --sysconf=/etc --prefix=/usr/local/keepalived
# make && make install		#编译安装keepalived

提示:harbor2节点如上即可
在harbor1上修改keepalived配置

# cp /root/harbor/ha/sample/active_active/keepalived_active_active.conf /etc/keepalived/keepalived.conf
# cp /root/harbor/ha/sample/active_active/check.sh /usr/local/bin/check.sh
# chmod u+x /usr/local/bin/check.sh
# vi /etc/keepalived/keepalived.conf
global_defs {
  router_id haborlb
}
vrrp_sync_groups VG1 {
  group {
    VI_1
  }
}
#Please change "ens160" to the interface name on you loadbalancer hosts.
#In some case it will be eth0, ens16xxx etc.
vrrp_instance VI_1 {
  interface ens33								#修改成自己的网卡

  track_interface {
    ens33											#修改成自己的网卡
  }

  state MASTER
  virtual_router_id 51
  priority 10

  virtual_ipaddress {
    192.168.109.30							#修改成VIP
  }
  advert_int 1
  authentication {
      auth_type PASS
    auth_pass d0cker
  }

}
########## Section for Harbor use HTTP protocol ######################
#Please change <change_to_VIP_address>, <harbor_node1_ip>, <harbor_node2_ip> to real ip address
virtual_server 192.168.109.30 80 {		#修改成VIP				
  delay_loop 15
  lb_algo rr
  lb_kind DR
  protocol TCP
  nat_mask 255.255.255.0
  persistence_timeout 10

  real_server 192.168.109.20 80 {		#修改成harbo1IP
    weight 10
    MISC_CHECK {
        misc_path "/usr/local/bin/check.sh 192.168.109.20"	#修改成harbo1IP
        misc_timeout 5
    }
  }

  real_server 192.168.109.21 80 {		#修改成harbo2IP
    weight 10
    MISC_CHECK {
            misc_path "/usr/local/bin/check.sh 192.168.109.21"	#修改成harbo2IP
        misc_timeout 5
    }
  }
}

harbor2如上修改,并修改主备模式

# vi /etc/keepalived/keepalived.conf
 state BACKUP
 priority 8

harbor1、2启动keepalive

# systemctl start keepalived.service
# systemctl enable keepalived.service

五、登陆验证

浏览器打开http://192.168.109.30,登陆harbor


本文链接: http://www.dtmao.cc/news_show_100049.shtml

附件下载

相关教程

    暂无相关的数据...

共有条评论 网友评论

验证码: 看不清楚?