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>