问题
需要在EC2机器上面安装私有maven库。
步骤
更新OS
sudo yum update -y
JDK11
# 安装JDK11
sudo yum install java-11-amazon-corretto
# 查询jdk11位置
sudo alternatives --config java
内容如下:
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
*+ 1 /usr/lib/jvm/java-17-amazon-corretto.aarch64/bin/java
2 /usr/lib/jvm/java-11-amazon-corretto.aarch64/bin/java
Enter to keep the current selection[+], or type selection number:
nexus安装包
cd /opt
# 下载
sudo wget https://download.sonatype.com/nexus/3/nexus-3.67.0-03-java11-unix.tar.gz
# 解压
sudo tar -xvf nexus-3.67.0-03-java11-unix.tar.gz
这里解压出来是在两个文件夹,如下:
drwxr-xr-x. 10 root root 181 Apr 8 11:10 nexus-3.67.0-03
-rw-r--r--. 1 root root 228889361 Apr 2 06:18 nexus-3.67.0-03-java11-unix.tar.gz
drwxr-xr-x. 3 root root 20 Apr 8 11:10 sonatype-work
添加nexus用户和用户组
sudo useradd --system --home /home/nexus --shell /sbin/nologin --comment "nexus user" --user-group nexus
配置目录权限
sudo chown -R nexus:nexus /opt/nexus-3.67.0-03
sudo chown -R nexus:nexus /opt/sonatype-work
设置nexus运行用户
sudo vim /opt/nexus-3.67.0-03/bin/nexus.rc
设置如下内容:
run_as_user="nexus"
配置JDK11
sudo vim /opt/nexus-3.67.0-03/bin/nexus
添加如下内容:
INSTALL4J_JAVA_HOME_OVERRIDE=/usr/lib/jvm/java-11-amazon-corretto.aarch64
SysV设置
sudo vim /etc/systemd/system/nexus.service
内容如下:
[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
LimitNPROC=65536
LimitNOFILE=65536
ExecStart=/opt/nexus-3.67.0-03/bin/nexus start
ExecStop=/opt/nexus-3.67.0-03/bin/nexus stop
User=nexus
Group=nexus
Restart=on-abort
[Install]
WantedBy=multi-user.target
启动nexus
sudo systemctl daemon-reload
sudo systemctl start nexus.service
sudo systemctl status nexus.service
sudo systemctl enable nexus.service
后面放开8081端口,访问web页面即可,效果如下:
第一次登录
这里获取admin密码:
cat /opt/sonatype-work/nexus3/admin.password
修改完密码后,重启nexus,如下:
sudo systemctl restart nexus
总结
到此为止就nexus maven私库的手动sysv方式安装。
参考
- Installation Methods
- Download
- Run as a Service
- Sonatype Nexus Repository System Requirements
- systemd.exec 中文手册
- Amazon Corretto 11 安装说明