文章目录
一、下载地址
官网下载地址如下:
https://help.sonatype.com/en/download.html
或者直接下载最新版
wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz
二、直接安装
1. 将文件上传到目标文件夹/opt/nexus下解压
cd /opt/nexus
tar -zxvf nexus-3.69.0-02-java17-unix.tar.gz
2.配置
默认端口是8081,想改的话可以改成自己的
vi /opt/nexus/nexus-3.69.0-02/etc/nexus-default.properties
如果要允许root账户启动的话,将run_as_root改为false
vi /opt/nexus/nexus-3.69.0-02/bin/nexus
刷新一下配置
source /etc/profile
如果要修改内存的话
vi /opt/nexus/nexus-3.69.0-02/bin/nexus.vmoptions
3. 加入系统服务
创建用户和组
groupadd -r nexus-user
useradd -M -r -g nexus-user nexus-user
chown nexus-user:nexus-user /opt/nexus
vi /etc/systemd/system/nexus.service
[Unit]
Description=nexus
After=network.target
[Service]
User=root
Type=forking
Environment="JAVA_HOME=/etc/graalvm-ce-java17-22.3.1"
ExecStart=/opt/nexus/nexus-3.69.0-02/bin/nexus start
ExecStop=/opt/nexus/nexus-3.69.0-02/bin/nexus stop
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable nexus
systemctl start nexus
三、docker 安装
- 安装
docker run -d --restart=always --name nexus -p 8081:8081 -v /etc/nexus:/nexus-data sonatype/nexus3
- 查找初始密码
find / -name admin.password
cat /var/lib/docker/volumes/1298675c5f3433bed00ff321e8e0be74ef6dcedf7341cc86b5db2e8ad3f2c5a9/_data/admin.password
显示的就是初始密码
四、将本地仓库jar批量上传到nexus
1.编写脚本放到本地仓库目录下
mavenimport.sh
#!/bin/bash
# copy and run this script to the root of the repository directory containing files
# this script attempts to exclude uploading itself explicitly so the script name is important
# Get command line params
while getopts ":r:u:p:" opt; do
case $opt in
r) REPO_URL="$OPTARG"
;;
u) USERNAME="$OPTARG"
;;
p) PASSWORD="$OPTARG"
;;
esac
done
find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;
2. 在当前目录打开git,输入以下内容执行
./mavenimport.sh -u admin -p 123456 -r http://192.168.101.222/repository/maven-releases/
等待执行完即可