您的位置:首页 > 其它

sonatype Nexus3 install on Kubernetes

2017-02-28 17:50 211 查看


一、Nexus安装


1、安装方式一

使用nexus-builder.yaml文件进行安装:
$ 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、安装方式二

执行脚本nexus-builder.sh进行安装:
$ 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: