CentOS7中搭建nexus3私服
安装jdk1.8
安装教程导航:https://lushunde.blog.csdn.net/article/details/104280861
安装maven
安装教程导航:https://lushunde.blog.csdn.net/article/details/104281476
安装nexus3
下载nexus-3.6.0-02-unix.tar.gz
官网下载地址:https://www.sonatype.com/download-oss-sonatype
创建安装文件夹
[root@iZ4zeaehxxqhrn553tblkkZ /]# mkdir /home/work/nexus
上传
[root@iZ4zeaehxxqhrn553tblkkZ nexus]# rz
解压
[root@iZ4zeaehxxqhrn553tblkkZ /]# cd /home/work/nexus
[root@iZ4zeaehxxqhrn553tblkkZ maven]# tar -zxvf nexus-3.6.0-02-unix.tar.gz
启动nexus3
[root@iZ4zeaehxxqhrn553tblkkZ /]# cd /home/work/nexus/nexus-3.6.0-02/bin/
[root@iZ4zeaehxxqhrn553tblkkZ bin]# ./nexus run &
出现以下日志的时候表示启动成功,第一次启动比较慢。
-------------------------------------------------
Started Sonatype Nexus OSS 3.6.0-02
-------------------------------------------------
开启远程访问端口
nexus 默认web端口8081
[root@iZ4zeaehxxqhrn553tblkkZ bin]# firewall-cmd --zone=public --add-port=8081/tcp --permanent
[root@iZ4zeaehxxqhrn553tblkkZ bin]# firewall-cmd --reload
测试
默认端口:8081
默认账号:admin/admin123
安装完成后常用配置整理
设置开机自启动(systemctl方式)
创建一个服务
[root@iZ4zeaehxxqhrn553tblkkZ bin]# vim /usr/lib/systemd/system/nexus.service
内容如下:
[Unit]
Description=nexus service
[Service]
Type=forking
LimitNOFILE=65536 #警告处理
ExecStart=/home/work/nexus/nexus-3.6.0-02/bin/nexus start
ExecReload=/home/work/nexus/nexus-3.6.0-02/bin/nexus restart
ExecStop=/home/work/nexus/nexus-3.6.0-02/bin/nexus stop
Restart=on-failure
[Install]
WantedBy=multi-user.target
加入开机启动
[root@iZ4zeaehxxqhrn553tblkkZ bin]# systemctl enable nexus.service
重新加载配置文件
[root@iZ4zeaehxxqhrn553tblkkZ bin]# systemctl daemon-reload
修改nexus3的运行用户为root
[root@iZ4zeaehxxqhrn553tblkkZ bin]# vim nexus.rc
run_as_user="root"
修改nexus3启动时指定jdk版本
···
[root@iZ4zeaehxxqhrn553tblkkZ bin]# vim nexus
···
修改内容:
···
INSTALL4J_JAVA_HOME_OVERRIDE=/home/work/java/jdk1.8.0_144
···
修改nexus3默认端口
[root@iZ4zeaehxxqhrn553tblkkZ bin]# cd /home/work/nexus/nexus-3.6.0-02/etc/
[root@iZ4zeaehxxqhrn553tblkkZ etc]# vim nexus-default.properties
修改内容:
application-port=8081
修改数据、日志的存储位置
[root@iZ4zeaehxxqhrn553tblkkZ etc]# cd /usr/local/nexus-3.6.0-02/bin/
[root@iZ4zeaehxxqhrn553tblkkZ bin]# vim nexus.vmoptions
修改内容:
-XX:LogFile=./sonatype-work/nexus3/log/jvm.log
-Dkaraf.data=./sonatype-work/nexus3
-Djava.io.tmpdir=./sonatype-work/nexus3/tmp
配置本地maven的setting.xml文件
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.0.123:8081/repository/maven-public/</url>
</mirror>
</mirrors>
上传第三方jar包到nexus
发布不带pom文件的独立jar包:
mvn deploy:deploy-file -DgroupId=<group-id> \
-DartifactId=<artifact-id> \
-Dversion=<version> \
-Dpackaging=<type-of-packaging> \
-Dfile=<path-to-file> \
-DrepositoryId=<id-to-map-on-server-section-of-settings.xml> \
-Durl=<url-of-the-repository-to-deploy>
- -DrepositoryId的值即为在setttings.xml里面配置的server id。
- -DgeneratePom=false 默认情况下,maven会自动为jar包创建pom文件,如果只想保留独立jar包,可以使用参数关闭这个特性
发布带有pom的jar包
mvn deploy:deploy-file -DpomFile=<path-to-pom> \
-Dfile=<path-to-file> \
-DrepositoryId=<id-to-map-on-server-section-of-settings.xml> \
-Durl=<url-of-the-repository-to-deploy>