簡述
我們采用Nexus OSS作為私有的Maven倉庫中心。OSS版本已足夠使用,如果是企業(yè)的話,可以購買PRO版本。如果是單兵作戰(zhàn),此章節(jié)非必須,如果項(xiàng)目比較大,服務(wù)比較多,建議構(gòu)建下私有倉庫中心。
環(huán)境準(zhǔn)備
Host List
| IP Address | Hosts | Disk | Comment |
|---|---|---|---|
| 192.168.0.25 | nexus | 1TB |
OS
我們采用CentOS作為宿主機(jī)操作系統(tǒng),版本請升級為最新穩(wěn)定版7.6。(CentOS7即可,建議升級到最新穩(wěn)定版7.6)
升級方式,請參考本人的另一篇文章:http://www.itdecent.cn/p/3e3bc1f51332
并將內(nèi)核升級到最新穩(wěn)定版本4.20.
[root@localhost ~]# uname -sr
Linux 4.20.0-1.el7.elrepo.x86_64
[root@localhost ~]#
[root@localhost ~]#
安裝步驟
下載Nexus OSS安裝包。
從Nexus官網(wǎng)下載即可,個(gè)人偏好,還是最新穩(wěn)定版。
https://www.sonatype.com/download-oss-sonatype

安裝 Nexus
前置條件
Nexus由于依賴于Java環(huán)境,所以我們還是需要先把JDK安裝下,鑒于Nexsus官網(wǎng)推薦使用Oracle JDK,我們還是需要把Oracle的JDK給安裝下。
訪問Oracle官網(wǎng),找到JDK的下載路徑,鑒于后續(xù)版本Oracle的JDK可能會(huì)有各種商業(yè)條款限制,還是推薦使用1.8的版本。

下載Oracle JDK8
[root@localhost ~]# wget --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm
--2019-02-01 10:32:34-- https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm
Resolving download.oracle.com (download.oracle.com)... 23.58.216.130
Connecting to download.oracle.com (download.oracle.com)|23.58.216.130|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm [following]
--2019-02-01 10:32:35-- https://edelivery.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm
Resolving edelivery.oracle.com (edelivery.oracle.com)... 23.10.0.83, 2600:1417:a000:29f::366, 2600:1417:a000:288::366
Connecting to edelivery.oracle.com (edelivery.oracle.com)|23.10.0.83|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm?AuthParam=1548988480_9c35a33007884935cdd41ab3dcf556c0 [following]
--2019-02-01 10:32:40-- http://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm?AuthParam=1548988480_9c35a33007884935cdd41ab3dcf556c0
Connecting to download.oracle.com (download.oracle.com)|23.58.216.130|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://101.96.8.157/download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm?AuthParam=1548988480_9c35a33007884935cdd41ab3dcf556c0 [following]
--2019-02-01 10:32:41-- http://101.96.8.157/download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm?AuthParam=1548988480_9c35a33007884935cdd41ab3dcf556c0
Connecting to 101.96.8.157:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm?AuthParam=1548988480_9c35a33007884935cdd41ab3dcf556c0 [following]
--2019-02-01 10:32:41-- https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm?AuthParam=1548988480_9c35a33007884935cdd41ab3dcf556c0
Connecting to download.oracle.com (download.oracle.com)|23.58.216.130|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 176209195 (168M) [application/x-redhat-package-manager]
Saving to: ‘jdk-8u201-linux-x64.rpm’
100%[====================================================================>] 176,209,195 1.49MB/s in 98s
2019-02-01 10:34:19 (1.72 MB/s) - ‘jdk-8u201-linux-x64.rpm’ saved [176209195/176209195]
[root@localhost ~]#
安裝Oracle JDK8
rpm 安裝 Oracle JDK8.
[root@localhost ~]# rpm -ivh jdk-8u201-linux-x64.rpm
warning: jdk-8u201-linux-x64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:jdk1.8-2000:1.8.0_201-fcs ################################# [100%]
Unpacking JAR files...
tools.jar...
plugin.jar...
javaws.jar...
deploy.jar...
rt.jar...
jsse.jar...
charsets.jar...
localedata.jar...
[root@localhost ~]#
解壓安裝Nexus.
我們在/usr/local下創(chuàng)建nexus的安裝目錄。
[root@localhost ~]# mkdir -p /usr/local/nexus
[root@localhost ~]#
[root@localhost ~]# tar -zxvf nexus-3.15.2-01-unix.tar.gz -C /usr/local/nexus
nexus-3.15.2-01/.install4j/9d17dc87.lprop
nexus-3.15.2-01/.install4j/MessagesDefault
配置Root啟動(dòng)
進(jìn)入到nexus的安裝目錄,bin目錄下,修改nexus.rc.
[root@localhost bin]# pwd
/usr/local/nexus/nexus-3.15.2-01/bin
[root@localhost bin]# vi nexus.rc
run_as_user="root"
修改JDK的Home
找到剛才安裝的Oracle JDK的路徑。如果是RPM 安裝,默認(rèn)應(yīng)該是:/usr/java/jdk1.8.0_xxxxx.
[root@localhost bin]# vi nexus
#!/bin/sh
# chkconfig: 2345 75 15
......
# Uncomment the following line to override the JVM search sequence
INSTALL4J_JAVA_HOME_OVERRIDE=/usr/java/jdk1.8.0_102
# Uncomment the following line to add additional VM parameters
# INSTALL4J_ADD_VM_PARAMS=
......
修改監(jiān)聽端口
Nexus默認(rèn)的端口為8081,如果需要更改,可以通過如下文件調(diào)整。
[root@localhost ~]# vi /usr/local/nexus/nexus-3.15.2-01/etc/nexus-default.properties
......
# Jetty section
application-port=9881
application-host=0.0.0.0
......
修改文件存儲(chǔ)路徑
一般情況下,nexus會(huì)把文件存放在安裝路徑中,而我們的數(shù)據(jù)盤一般都是和應(yīng)用盤分處不同的盤符中,故修改一下。視自己情況而定,亦可不做變動(dòng)。
注意下,本文中,修改了三個(gè)部分:
- LOG日志,請注意日志更換到/var/log下,nexus不會(huì)自動(dòng)創(chuàng)建目錄,需要自己在/var/log下創(chuàng)建nexus3目錄,否則將不會(huì)有日志打出。
- Dkaraf.data。
- Djava.io.tmpdir。
[root@localhost ~]# vi /usr/local/nexus/nexus-3.15.2-01/bin/nexus.vmoptions
-Xms1200M
-Xmx1200M
-XX:MaxDirectMemorySize=2G
-XX:+UnlockDiagnosticVMOptions
-XX:+UnsyncloadClass
-XX:+LogVMOutput
-XX:LogFile=/var/log/nexus3/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=/home/nexus/data/sonatype-work/nexus3
-Djava.io.tmpdir=/home/nexus/data/sonatype-work/nexus3/tmp
-Dkaraf.startLocalConsole=false
配置Service啟動(dòng)
[root@localhost ~]# vi /usr/lib/systemd/system/nexus.service
[Unit]
Description = nexus service
After = network.target
[Service]
Type = forking
LimitNOFILE = 65536
ExecStart = /usr/local/nexus/nexus-3.15.2-01/bin/nexus start
ExecReload= /usr/local/nexus/nexus-3.15.2-01/bin/nexus restart
ExecStop = /usr/local/nexus/nexus-3.15.2-01/bin/nexus stop
Restart = on- abort
[Install]
WantedBy = multi-user.target
加入開機(jī)自啟動(dòng)
[root@localhost ~]# systemctl enable nexus
Created symlink from /etc/systemd/system/multi-user.target.wants/nexus.service to /usr/lib/systemd/system/nexus.service.
[root@localhost ~]#
嘗試啟動(dòng)Nexus
重新裝載下系統(tǒng)配置參數(shù)。
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]#
啟動(dòng)Nexus。
[root@localhost ~]# systemctl restart nexus
[root@localhost ~]#
檢測Nexus啟動(dòng)狀態(tài)
檢測Nexus端口
[root@localhost ~]# netstat -an|grep 9881
tcp 0 0 0.0.0.0:9881 0.0.0.0:* LISTEN
[root@localhost ~]#
防火墻放行
[root@localhost ~]# firewall-cmd --zone=public --add-port=9881/tcp --permanent
success
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]#
更新 nexus 索引
在nexus目錄創(chuàng)建plugin目錄用來存放nexus需要更新的索引。
在http://repo.maven.apache.org/maven2/.index/下載
nexus-maven-repository-index.gz
nexus-maven-repository-index.properties
[root@localhost ~]# cd /home
[root@localhost home]# cd nexus/
[root@localhost nexus]# ls -al
total 0
drwxr-xr-x. 3 root root 17 Feb 1 11:29 .
drwxr-xr-x. 4 root root 31 Feb 1 11:29 ..
drwxr-xr-x. 3 root root 34 Feb 1 11:34 data
[root@localhost nexus]# mkdir plugin
[root@localhost nexus]#
[root@localhost nexus]# cd plugin/
[root@localhost plugin]# wget http://repo.maven.apache.org/maven2/.index/nexus-maven-repository-index.gz
--2019-02-01 11:47:53-- http://repo.maven.apache.org/maven2/.index/nexus-maven-repository-index.gz
Resolving repo.maven.apache.org (repo.maven.apache.org)... 151.101.40.215
Connecting to repo.maven.apache.org (repo.maven.apache.org)|151.101.40.215|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 615207556 (587M) [application/x-gzip]
Saving to: ‘nexus-maven-repository-index.gz’
100%[====================================================================>] 615,207,556 330KB/s in 41m 44s
2019-02-01 12:29:48 (240 KB/s) - ‘nexus-maven-repository-index.gz’ saved [615207556/615207556]
[root@localhost plugin]#
[root@localhost plugin]# wget http://repo.maven.apache.org/maven2/.index/nexus-maven-repository-index.properties
--2019-02-01 11:51:16-- http://repo.maven.apache.org/maven2/.index/nexus-maven-repository-index.properties
Resolving repo.maven.apache.org (repo.maven.apache.org)... 151.101.24.215
Connecting to repo.maven.apache.org (repo.maven.apache.org)|151.101.24.215|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1130 (1.1K) [text/plain]
Saving to: ‘nexus-maven-repository-index.properties’
100%[====================================================================>] 1,130 --.-K/s in 0s
2019-02-01 11:51:26 (58.9 MB/s) - ‘nexus-maven-repository-index.properties’ saved [1130/1130]
[root@localhost plugin]# wget http://central.maven.org/maven2/org/apache/maven/indexer/indexer-cli/6.0.0/indexer-cli-6.0.0.jar
--2019-02-01 11:53:08-- http://central.maven.org/maven2/org/apache/maven/indexer/indexer-cli/6.0.0/indexer-cli-6.0.0.jar
Resolving central.maven.org (central.maven.org)... 151.101.196.209
Connecting to central.maven.org (central.maven.org)|151.101.196.209|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 14914610 (14M) [application/java-archive]
Saving to: ‘indexer-cli-6.0.0.jar’
100%[====================================================================>] 14,914,610 91.2KB/s in 5m 57s
2019-02-01 11:59:06 (40.8 KB/s) - ‘indexer-cli-6.0.0.jar’ saved [14914610/14914610]
[root@localhost plugin]#
[root@localhost plugin]# java -jar indexer-cli-6.0.0.jar -u nexus-maven-repository-index.gz -d indexer
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Index Folder: /home/nexus/plugin
Output Folder: /home/nexus/plugin/indexer
Total time: 6 min 2 sec
Final memory: 80M/440M
[root@localhost plugin]#
[root@localhost plugin]#
[root@localhost nexus]# cd plugin/
[root@localhost plugin]# ls -al
total 615380
drwxr-xr-x. 3 root root 4096 Feb 1 13:37 .
drwxr-xr-x. 4 root root 42 Feb 1 11:47 ..
drwxr-xr-x. 2 root root 8192 Feb 1 13:43 indexer
-rw-r--r--. 1 root root 14914610 Nov 28 2017 indexer-cli-6.0.0.jar
-rw-r--r--. 1 root root 615207556 Jan 28 14:42 nexus-maven-repository-index.gz
-rw-r--r--. 1 root root 1130 Jan 28 14:42 nexus-maven-repository-index.properties
[root@localhost plugin]# cd indexer/
[root@localhost indexer]# mv * /home/nexus/data/sonatype-work/nexus3/indexer/central-ctx/
[root@localhost indexer]#
重啟Nexus
[root@localhost plugin]# systemctl stop nexus
[root@localhost plugin]# systemctl start nexus
[root@localhost plugin]#
至此Nexus已安裝設(shè)置完畢,最后一步,登錄到Portal上去,用默認(rèn)admin和密碼登錄(默認(rèn)密碼為:admin123),修改下admin的密碼就可以啦。