sonatype Nexus3 install on Kubernetes

一、Nexus安装

1、安装方式一

$ kubectl create -f ./nexus-builder.yaml
namespace "nexus" created
deployment "nexus3" created
service "nexus3" created
  • 安装完成后,查找对应端口进行访问:
$ kubectl describe svc -n nexus nexus3 | grep 'NodePort:'
NodePort:               <unset> 32139/TCP
$ hostname -i
192.168.56.11
  • 恭喜你,已完成Nexus3的安装,接下来你就可以进行访问了192.168.56.11:32139

Note:如果页面无法访问,请等待几分钟后再刷新页面。

2、安装方式二

$ kubectl create -f ./run.sh
namespace "nexus" created
deployment "nexus3" created
service "nexus3" created
Now Nexus running on k8s-worker2 : 192.168.56.11:32139
Note:If the page can't be accessed,please wait a few minutes and refresh the page.

参考资料:sonatype/nexus3 - Docker Hub

二、用户操作界面

1、用户登录

  • 根据上面的地址打开用户界面。点击右上角Sign in登陆,默认账号admin,密码admin123

2、修改用户密码

  • 为了系统的安全性考虑,请及时修改密码,下面我们以默认账号admin为例进行修改,在配置页面,选择Security - User,点击用户列表admin

  • 进入后选择More - Change password进行密码修改。

3、创建maven仓库

  • 在配置界面,选择Repository - repositories,图中红色选线框着的是默认仓库。点击Create repository

  • 我们的目的仅仅管理自己开发的组件,选择maven2(hosted)即可。

  • 填写仓库配置,Deployment policy选择Allow redeploy

version policy,可以选Release或Snapshot,如果仓库开放给所有人,那选Release比较好,如果公司内部或自己用,其中一个都可以。

  • 仓库Hand-repository创建完毕

4、创建角色

  • 在配置页面,选择Security - Roles,点击Nexus role
  • 填写角色配置,根据所需的权限进行添加权限,然后点击Create role

5、创建用户

  • 在配置页面,选择Security - User,点击Create user

  • 填写用户信息,再点击最底下的Create user即可创建用户,注意如果启用此帐号,Status选择Active


  • 创建HandUser用户后,可以Sign out,用HandUser账号登陆了。

三、工作空间设置

1、给单一项目设置远程仓库

  • 在Maven project中的pom.xml文件添加以下信息
<repositories>
    <repository>
        <id>nexus</id>
        <name>Nexus3 Repository</name>
        <!-- 此为仓库地址,应用 group 类型可以相当于同时添加多个仓库地址 -->
        <url>http://192.168.56.11:32139/repository/maven-public/</url>
    </repository>
</repositories>
  • 代码中url标签的路径在Repositories中选择需要的仓库,点击URL字段下的copy进行复制。

2、设置所有项目远程仓库

全局配置文件在Maven安装目录conf文件夹中settings.xml,当前用户配置文件在本地仓库中的settings.xml

若更改当前用户配置信息无效,则修改全局配置信息。

(1)、在本地仓库文件夹下,给settings.xml文件添加以下信息
  • 此种方法如果远程仓库关闭或意外退出,在maven构建时会到中央仓库去查找jar包
<profiles>
    <profile>
      <id>NexusRepo</id>
      <repositories>
        <repository>
          <id>nexus</id>
          <name>Nexus3 Repository</name>
          <url>http://192.168.56.11:32139/repository/maven-public/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <!-- snapshots默认是关闭的,需要手动开启 -->
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>    
</profiles>
<!-- 只有激活后才生效,此代码为激活代码  -->
<activeProfiles>
      <activeProfile>NexusRepo</activeProfile>
</activeProfiles>
(2)、在本地仓库文件夹下,给settings.xml文件添加以下信息
  • 添加此配置信息后,上面(1)中的配置将失效
  • Maven构建时可能会出现报错信息,尝试更新索引文件
  <!-- 工厂的镜像,只要mirrorOf中的工厂要被访问,都会自动来找镜像,如果无法访问就不会再去中央工厂,推荐这个配置 -->
  <mirrors>
    <mirror>
      <id>nexusMirror</id>
      <!-- *号代表所有仓库,此处也可以单独设置,以逗号隔开 -->
      <mirrorOf>*</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://192.168.56.11:32139/repository/maven-public/</url>
    </mirror>
  </mirrors>

3、Maven默认是无法下载中央仓库snapshots版本jar包的,通过以下设置即可下载

<profiles>
    <profile>
      <id>NexusRepo</id>
      <repositories>
        <repository>
          <id>central</id>
          <name>Central Repository</name>
          <url>https://repo.maven.apache.org/maven2</url>
          <layout>default</layout>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>    
</profiles>
<!-- 只有激活后才生效,此代码为激活代码  -->
<activeProfiles>
   <activeProfile>NexusRepo</activeProfile>
</activeProfiles>

三、发布jar包

  • 配置pom.xml文件,添加以下代码:
<distributionManagement>
    <repository>
        <id>maven-releases</id>
        <name>maven releases</name>
        <url>http://192.168.56.11:32139/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>maven-snapshots</id>
        <name>maven snapshots</name>
        <url>http://192.168.56.11:32139/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>
  • 配置settings.xml文件添加以下代码:
<servers>
    <server>
      <id>maven-releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>maven-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
</servers>
  • 执行clean deploy语句,进行构建上传。

Nexus相关信息

这里简单介绍下几种repository的类型:

  • hosted,本地仓库,通常我们会部署自己的构件到这一类型的仓库。比如公司的第二方库。
  • proxy,代理仓库,它们被用来代理远程的公共仓库,如maven中央仓库。
  • group,仓库组,用来合并多个hosted/proxy仓库,当你的项目希望在多个repository使用资源时就不需要多次引用了,只需要引用一个group即可。

Nexus搭建代码清单

nexus-builder.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: nexus
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  labels:
    app: nexus3
  name: nexus3
  namespace: nexus
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nexus3
  template:
    metadata:
      labels:
        app: nexus3
    spec:
      containers:
      - name: nexus3
        image: registry.saas.hand-china.com/tools/nexus3:3.2.0
        ports:
        - containerPort: 8081
          protocol: TCP
        volumeMounts:
        - name: nexus-data
          mountPath: /nexus-data
      volumes:
        - name: nexus-data
          hostPath:
            path: /vagrant/nexus-data
---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: nexus3
  name: nexus3
  namespace: nexus
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 8081
  selector:
    app: nexus3
nexus-builder.sh
#!/bin/bash

cat > nexus-builder.yaml << EOF
apiVersion: v1
kind: Namespace
metadata:
  name: nexus
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  labels:
    app: nexus3
  name: nexus3
  namespace: nexus
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nexus3
  template:
    metadata:
      labels:
        app: nexus3
    spec:
      containers:
      - name: nexus3
        image: registry.saas.hand-china.com/tools/nexus3:3.2.0
        ports:
        - containerPort: 8081
          protocol: TCP
        volumeMounts:
        - name: nexus-data
          mountPath: /nexus-data
      volumes:
        - name: nexus-data
          hostPath:
            path: /vagrant/nexus-data
---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: nexus3
  name: nexus3
  namespace: nexus
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 8081
  selector:
    app: nexus3
EOF

kubectl create -f ./nexus-builder.yaml

HostIP=`hostname -i`
EndPort=`kubectl describe svc -n nexus nexus3 | grep 'NodePort:' | awk '{print $3}'`
HostName=`kubectl get pods -n nexus -o wide | grep 'nexus3' | awk '{print $7}'`
echo "Now Nexus running on ${HostName}:${HostIP} : ${EndPort%/*}"
echo "Note:If the page can't be accessed,please wait a few minutes and refresh the page."

sudo rm -f ./nexus-builder.yaml
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 195,980评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,422评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,130评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,553评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,408评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,326评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,720评论 3 386
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,373评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,678评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,722评论 2 312
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,486评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,335评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,738评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,283评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,692评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,893评论 2 335

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,510评论 18 139
  • 搭建 nexus 私服(centos6.7) 备注:Centos 6.7 、 nexus-2.12.1-01-bu...
    逐暗者阅读 2,482评论 3 9
  • 首先私服是一种衍生出来的特殊的Maven远程仓库,构建私服的好处请看3.5私服 可以帮助大家建立私服的仓库管理软件...
    zlcook阅读 10,516评论 0 32
  • 在每一个下雨的瞬间, 在每一个夕阳西下的傍晚, 在每一个星星为伴的夜间, 思念是瞬间的泪涌, 是鸟儿归巢后留下的落...
    半夏未满阅读 219评论 0 0
  • ajax无刷新页面同时改变url
    lmem阅读 312评论 0 0