0
点赞
收藏
分享

微信扫一扫

10、NEXUS私有仓库

NEXUS私有仓库

Nexus 是一个强大的Maven和其它仓库的管理器,它极大地简化了自己内部仓库的维护和外部仓库的访问.
官网:https://www.sonatype.com/

安装NEXUS建议内存至少4G以上

nexus安装脚本

[root@ubuntu2004 ~]#cat install_nexus.sh 
#!/bin/bash

NEXUS_URL="https://download.sonatype.com/nexus/3/nexus-3.39.0-01-unix.tar.gz"
#NEXUS_URL="https://download.sonatype.com/nexus/3/nexus-3.36.0-01-unix.tar.gz"
#NEXUS_URL="https://download.sonatype.com/nexus/3/nexus-3.29.2-02-unix.tar.gz"
INSTALL_DIR=/usr/local/nexus

HOST=`hostname -I|awk '{print $1}'`
GREEN="echo -e \E[32;1m"
END="\E[0m"

. /etc/os-release

color () {
    RES_COL=60
    MOVE_TO_COL="echo -en \\033[${RES_COL}G"
    SETCOLOR_SUCCESS="echo -en \\033[1;32m"
    SETCOLOR_FAILURE="echo -en \\033[1;31m"
    SETCOLOR_WARNING="echo -en \\033[1;33m"
    SETCOLOR_NORMAL="echo -en \E[0m"
    echo -n "$1" && $MOVE_TO_COL
    echo -n "["
    if [ $2 = "success" -o $2 = "0" ] ;then
        ${SETCOLOR_SUCCESS}
        echo -n $"  OK  "    
    elif [ $2 = "failure" -o $2 = "1"  ] ;then 
        ${SETCOLOR_FAILURE}
        echo -n $"FAILED"
    else
        ${SETCOLOR_WARNING}
        echo -n $"WARNING"
    fi
    ${SETCOLOR_NORMAL}
    echo -n "]"
    echo 
}


install_jdk() {
    if [ $ID = "centos" -o  $ID = "rocky" ];then
        yum  -y install java-1.8.0-openjdk || { color "安装JDK失败!" 1; exit 1; } 
    else
        apt update
        apt -y install openjdk-8-jdk  || { color "安装JDK失败!" 1; exit 1; } 
    fi
    color "安装JDK完成!" 0
    java -version
}

install_nexus() {
    if [  -f ${NEXUS_URL##*/} ];then
        cp ${NEXUS_URL##*/} /usr/local/src
    else 
        wget -P /usr/local/src/ $NEXUS_URL || { color  "下载失败!" 1 ;exit ; }
    fi
    tar xf /usr/local/src/${NEXUS_URL##*/} -C /usr/local
    ln -s /usr/local/nexus-*/ ${INSTALL_DIR}
    ln -s ${INSTALL_DIR}/bin/nexus /usr/bin/
}

start_nexus (){
cat   > /lib/systemd/system/nexus.service <<EOF
[Unit]
Description=nexus service
After=network.target

[Service]
Type=forking
LimitNOFILE=65536
ExecStart=${INSTALL_DIR}/bin/nexus start
ExecStop=${INSTALL_DIR}/bin/nexus stop
User=root
#User=nexus
Restart=on-abort

[Install]
WantedBy=multi-user.target

EOF
    systemctl daemon-reload 
    systemctl enable --now  nexus.service
    if [ $? -eq 0 ] ;then 
        color "nexus 安装成功" 0  
    echo "-------------------------------------------------------------------"
        echo -e "访问链接: \c"
    ${GREEN}"http://$HOST:8081/"${END}
    while [ ! -f ${INSTALL_DIR}/../sonatype-work/nexus3/admin.password ];do
        sleep 1
    done
    PASS=`cat ${INSTALL_DIR}/../sonatype-work/nexus3/admin.password`
    echo -e "用户和密码: \c"
    ${GREEN}"admin/$PASS"$END
    else 
        color "nexus 安装失败!" 1
        exit 1
    fi 
}


install_jdk
install_nexus
start_nexus

二进制包安装

NEXUS默认端口8081
maven仓库
更新缓存
[root@ubuntu2004 ~]#apt update
#安装JDK
[root@ubuntu2004 ~]#apt install openjdk-8-jdk -y
下载NEXUS安装包:
[root@ubuntu2004 ~]#wget https://download.sonatype.com/nexus/3/nexus-3.41.1-01- unix.tar.gz
将下载好的包解压缩
[root@ubuntu2004 ~]#tar xf nexus-3.41.1-01-unix.tar.gz -C /usr/local/
创建软链接
[root@ubuntu2004 ~]#cd /usr/local/
[root@ubuntu2004 local]#ls
apache-tomcat-9.0.65  etc    include  jdk1.8.0_341  man              sbin   sonatype-work  tomcat
bin                   games  jdk      lib           nexus-3.41.1-01  share  src
[root@ubuntu2004 local]#ln -s nexus-3.41.1-01/ nexus
[root@ubuntu2004 local]#ls nexus/
bin  deploy  etc  lib  NOTICE.txt  OSS-LICENSE.txt  PRO-LICENSE.txt  public  replicator  system

修改运行身份
[root@ubuntu2004 local]#vim /usr/local/nexus/bin/nexus.rc
run_as_user="root"

查看配置文件,可以在此文件中修改端口等配置
[root@ubuntu2004 ]#cat /usr/local/nexus/etc/nexus-default.properties 
## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
## 
# Jetty section 
application-port=8081 
application-host=0.0.0.0 
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml 
nexus-context-path=/ 

# Nexus section 
nexus-edition=nexus-pro-edition 
nexus-features=\ 
nexus-pro-feature
nexus.hazelcast.discovery.isEnabled=true

查看JVM配置文件(优化相关)
[root@ubuntu2004 ]#cat /usr/local/nexus/bin/nexus.vmoptions

创建service文件
[root@ubuntu2004 local]#vim /lib/systemd/system/nexus.service
[Unit] 
Description=nexus serviceAfter=network.target 

[Service] Type=forking LimitNOFILE=65536 ExecStart=/usr/local/nexus/bin/nexus start ExecStop=/usr/local/nexus/bin/nexus stop 
User=root 
#User=nexus 
Restart=on-abort 

[Install]WantedBy=multi-user.target
重新加载
[root@ubuntu2004 local]#systemctl daemon-reload 
开机自启
[root@ubuntu2004 local]#systemctl enable --now nexus.service 
去浏览器访问10.0.0.100:8081
点击sign in登录
用户名admin,密码在提示的目录里:
Your admin user password is located in
/usr/local/sonatype-work/nexus3/admin.password on the server.
去服务器上查看密码:
[root@ubuntu2004 local]#cat /usr/local/sonatype-work/nexus3/admin.password
6576897c-ac1c-42b9-b4e4-a9c6c70ac331
进入后直接提示修改新密码
匿名下载选第一个,输入密码下载选第二个
下一步即可使用nexus仓库

验证默认仓库

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

Maven的仓库优化配置(MAVEN编译源代码需要的依赖包由nexus去拉取)

默认仓库maven-central使用国外仓库地址,可修改为如下的国内镜像地址进行加速
http://maven.aliyun.com/nexus/content/groups/public

点击齿轮图形进行设置--repositories

10、NEXUS私有仓库_NEXUS私有仓库

点击maven-central,将Remote storage地址修改为https://maven.aliyun.com/repository/central

10、NEXUS私有仓库_NEXUS私有仓库_02

将nexus的URL地址配置在maven的配置文件中

将此路径配置到maven仓库
[root@ubuntu2004 ~]#vim /conf/maven/settings.xml 
  <mirror> 
      <id>nexus-aliyun</id> 
      <mirrorOf>*</mirrorOf> 
      <name>Nexus aliyun</name> 
      <url>http://10.0.0.100:8081/repository/maven-central/</url> 
  </mirror> 
</mirrors>前面

此时再下载依赖包mvn clean install package -Dmaven.test.skip=true
就是走的私有仓库http://10.0.0.100:8081/repository/maven-central/

nexus搭建yum仓库

自定义存储仓库数据目录
[root@ubuntu2004 local]#mkdir /data/blobs -p

到网站nexus去配置 点击blob stores-create blob stores-FILE

10、NEXUS私有仓库_NEXUS私有仓库_03

10、NEXUS私有仓库_NEXUS私有仓库_04

Type:file Name:blob-yum-zabbix-centos7 Path:/data/blob/blob-yum-zabbix-centos7

10、NEXUS私有仓库_NEXUS私有仓库_05

创建yum仓库 :repositories--create repository

10、NEXUS私有仓库_NEXUS私有仓库_06

选择yum(proxy)

10、NEXUS私有仓库_NEXUS私有仓库_07

代理直到清华源,把清华源上关于centos7系统zabbix安装包的URL路径输上

10、NEXUS私有仓库_NEXUS私有仓库_08

并指定安装包存储位置,并创建

10、NEXUS私有仓库_NEXUS私有仓库_09

进入仓库,复制仓库路径,找一台centos7服务器,并在服务器上配置YUM仓库

10、NEXUS私有仓库_NEXUS私有仓库_10

服务器上配置Yum仓库
vim /etc/yum.repos.d/base.repo
[zabbix]
baseurl=http://10.0.0.100:8081/repository/yum-zabbix5.0/
gpgcheck=0
enabled=1

yum clean all
yum repolist
更新仓库后,去nexus服务器/data/blob/blob-yum-zabbix-centos7/目录下,可看到数据

10、NEXUS私有仓库_NEXUS私有仓库_11

当在centos7服务器上装包后,安装包便存在nexus中

[root@centos7 ~]#yum list |grep zabbix
[root@centos7 ~]#yum install zabbix-agent

10、NEXUS私有仓库_NEXUS私有仓库_12

nexus配置apt仓库

点击blob stores-create blob stores-FILE

10、NEXUS私有仓库_NEXUS私有仓库_13

创建apt仓库 :repositories--create repository,选择apt(proxy)

10、NEXUS私有仓库_NEXUS私有仓库_14

选择目录后创建

10、NEXUS私有仓库_NEXUS私有仓库_15

进入复制路径

10、NEXUS私有仓库_NEXUS私有仓库_16

开启ubuntu服务器,并把路径写道配置文件中

vim /etc/apt/sources.list
把路径替换成nexus路径
更新仓库
apt update

nexus配置邮件通知

10、NEXUS私有仓库_NEXUS私有仓库_17


举报

相关推荐

0 条评论