140 lines
5.0 KiB
Markdown
140 lines
5.0 KiB
Markdown
1、下载压缩包并解压:
|
||
|
||
```gitlab
|
||
cd /data/
|
||
wget https://download.sonatype.com/nexus/3/nexus-3.86.2-01-linux-x86_64.tar.gz
|
||
tar -zxf nexus-3.86.2-01-linux-x86_64.tar.gz
|
||
mv nexus-3.86.2-01-linux-x86_64 nexus
|
||
```
|
||
|
||
2、创建nexus用户、给权限、更改脚本使用nexus用户
|
||
|
||
```gitlab
|
||
useradd -M -r -s /bin/false nexus
|
||
chown -R nexus:nexus /data/nexus
|
||
cd /data/nexus
|
||
vim /data/nexus/bin/nexus
|
||
# user to execute as; optional but recommended to set
|
||
run_as_user='nexus'
|
||
```
|
||
|
||
3、创建systemctl
|
||
|
||
```gitlab
|
||
vim /etc/systemd/system/nexus.service
|
||
|
||
[Unit]
|
||
Description=Nexus Repository Manager
|
||
After=network.target
|
||
|
||
[Service]
|
||
Type=forking
|
||
LimitNOFILE=65536
|
||
|
||
User=nexus
|
||
Group=nexus
|
||
|
||
ExecStart=/data/nexus/bin/nexus start
|
||
ExecStop=/data/nexus/bin/nexus stop
|
||
Restart=on-abort
|
||
|
||
# JVM 内存你可根据机器调整 (默认 2G),在 nexus.vmoptions 修改,这里的路径要跟随实际解压出来的路径,或者是用本机的
|
||
Environment=JAVA_HOME=/data/nexus/jdk/temurin_17.0.13_11_linux_x86_64/jdk-17.0.13+11Environment=JAVA_HOME=/data/nexus/jdk
|
||
Environment=RUN_AS_USER=nexus
|
||
|
||
[Install]
|
||
WantedBy=multi-user.target
|
||
```
|
||
|
||
4、重载systemctl、启动、查看日志
|
||
|
||
```gitlab
|
||
systemctl daemon-reload
|
||
systemctl start nexus
|
||
systemctl status nexus -l
|
||
|
||
# 日志
|
||
tail -f /data/sonatype-work/nexus3/log/nexus.log
|
||
|
||
# 如果报错执行5:/data/nexus/bin/nexus: line 175: /data/sonatype-work/nexus3/nexus.pid: Permission denied
|
||
```
|
||
|
||
5、给工作目录权限
|
||
|
||
```gitlab
|
||
chown -R nexus:nexus /data/nexus
|
||
chown -R nexus:nexus /data/sonatype-work
|
||
chmod -R 755 /data/sonatype-work
|
||
|
||
# 重启查看
|
||
systemctl restart nexus
|
||
systemctl status nexus -l
|
||
|
||
# 端口占用8081
|
||
ss -ntl | grep 8081
|
||
|
||
# 自启
|
||
systemctl enable nexus
|
||
```
|
||
|
||
6、账号密码
|
||
|
||
```gitlab
|
||
默认账号:admin
|
||
密码:cat /data/sonatype-work/nexus3/admin.password
|
||
```
|
||
|
||
---
|
||
|
||
扩展 :
|
||
|
||
```gitlab
|
||
# Nexus 3 有两个目录:程序目录 + 数据目录
|
||
|
||
NEXUS_HOME(程序目录) 存放程序文件、脚本、jar /data/nexus/
|
||
NEXUS_DATA(数据目录) 存放仓库数据、配置、日志 /data/sonatype-work/nexus3/
|
||
|
||
/data/nexus/ # 下载官方tar包解压后改名的目录
|
||
├── bin/ # nexus 启动脚本
|
||
├── etc/ # 配置文件
|
||
├── deploy/
|
||
├── jdk/
|
||
├── *.txt
|
||
|
||
/data/sonatype-work/nexus3/ # 所有仓库的数据(比如 Maven 私服上传的 artifacts)都存这里
|
||
├── blobs/ # 仓库文件,所有上传的 jar 包都在这
|
||
├── db/ # 配置数据库
|
||
├── etc/ # 配置
|
||
├── log/ # 日志
|
||
├── cache/
|
||
└── nexus.pid # PID 文件
|
||
```
|
||
|
||
|
||
---
|
||
|
||
异常
|
||
|
||
```gitlab
|
||
查看日志报错:
|
||
tail -f /data/sonatype-work/nexus3/log/nexus.log
|
||
2025-11-21 12:06:34,120+0800 WARN [Timer-0] *SYSTEM java.util.prefs - Couldn't flush user prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.
|
||
2025-11-21 12:06:38,968+0800 INFO [qtp2016701496-114] *UNKNOWN org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler...
|
||
2025-11-21 12:06:38,985+0800 INFO [qtp2016701496-114] *UNKNOWN org.sonatype.nexus.internal.security.anonymous.AnonymousManagerImpl - Using default configuration: AnonymousConfigurationData{enabled=true, userId='anonymous', realmName='NexusAuthorizingRealm'}
|
||
2025-11-21 12:06:53,592+0800 INFO [quartz-14-thread-4] *TASK org.sonatype.nexus.quartz.internal.task.QuartzTaskInfo - Task 'Malicious Risk On Disk - Auto enable Health Check for proxy repositories on startup' [malicious-risk-on-disk-auto-enable-rhc] state change WAITING -> RUNNING
|
||
2025-11-21 12:06:53,594+0800 INFO [quartz-14-thread-4] *TASK com.sonatype.nexus.risk.riskondisk.MaliciousRiskOnDiskAutoEnableRHCTask - Starting malicious-risk-on-disk-auto-enable-rhc task
|
||
2025-11-21 12:06:53,594+0800 INFO [quartz-14-thread-4] *TASK com.sonatype.nexus.risk.riskondisk.MaliciousRiskOnDiskAutoEnableRHCTask - Found 2 proxy repositories
|
||
2025-11-21 12:06:53,673+0800 INFO [quartz-14-thread-4] *TASK com.sonatype.nexus.risk.riskondisk.MaliciousRiskOnDiskAutoEnableRHCTask - Completed malicious-risk-on-disk-auto-enable-rhc task
|
||
2025-11-21 12:06:53,674+0800 INFO [quartz-14-thread-4] *TASK org.sonatype.nexus.quartz.internal.task.QuartzTaskInfo - Task 'Malicious Risk On Disk - Auto enable Health Check for proxy repositories on startup' [malicious-risk-on-disk-auto-enable-rhc] state change RUNNING -> WAITING (OK)
|
||
2025-11-21 12:07:04,119+0800 WARN [Timer-0] *SYSTEM java.util.prefs - Could not lock User prefs. Unix error code 2.
|
||
2025-11-21 12:07:04,119+0800 WARN [Timer-0] *SYSTEM java.util.prefs - Couldn't flush user prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.
|
||
|
||
# 因为 Nexus 用 systemd 方式启动时,Java 会尝试写入,~/.java/.userPrefs/,但 nexus 用户没有对应目录,或者目录不可写
|
||
# 创建的nexus的家目录并给权限
|
||
mkdir -p /home/nexus/.java/.userPrefs
|
||
chown -R nexus:nexus /home/nexus/.java
|
||
# 如果 nexus 用户没有 home
|
||
usermod -d /home/nexus nexus
|
||
# 重启 nexus 服务
|
||
systemctl restart nexus
|
||
``` |