美文网首页运维
一起学习微服务和容器4-Maven Repo Center (S

一起学习微服务和容器4-Maven Repo Center (S

作者: cxj_hit | 来源:发表于2019-02-12 18:08 被阅读66次

简述

我们采用Nexus OSS作为私有的Maven仓库中心。OSS版本已足够使用,如果是企业的话,可以购买PRO版本。如果是单兵作战,此章节非必须,如果项目比较大,服务比较多,建议构建下私有仓库中心。

环境准备

Host List

IP Address Hosts Disk Comment
192.168.0.25 nexus 1TB

OS

我们采用CentOS作为宿主机操作系统,版本请升级为最新稳定版7.6。(CentOS7即可,建议升级到最新稳定版7.6)
升级方式,请参考本人的另一篇文章:https://www.jianshu.com/p/3e3bc1f51332

并将内核升级到最新稳定版本4.20.

[root@localhost ~]# uname -sr
Linux 4.20.0-1.el7.elrepo.x86_64
[root@localhost ~]# 
[root@localhost ~]# 

安装步骤

下载Nexus OSS安装包。

从Nexus官网下载即可,个人偏好,还是最新稳定版。
https://www.sonatype.com/download-oss-sonatype

image.png

安装 Nexus

前置条件

Nexus由于依赖于Java环境,所以我们还是需要先把JDK安装下,鉴于Nexsus官网推荐使用Oracle JDK,我们还是需要把Oracle的JDK给安装下。
访问Oracle官网,找到JDK的下载路径,鉴于后续版本Oracle的JDK可能会有各种商业条款限制,还是推荐使用1.8的版本。

image.png

下载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下创建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启动

进入到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 安装,默认应该是:/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=
......

修改监听端口

Nexus默认的端口为8081,如果需要更改,可以通过如下文件调整。

[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
......

修改文件存储路径

一般情况下,nexus会把文件存放在安装路径中,而我们的数据盘一般都是和应用盘分处不同的盘符中,故修改一下。视自己情况而定,亦可不做变动。
注意下,本文中,修改了三个部分:

  • LOG日志,请注意日志更换到/var/log下,nexus不会自动创建目录,需要自己在/var/log下创建nexus3目录,否则将不会有日志打出。
  • 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启动

[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

加入开机自启动

[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 ~]# 

尝试启动Nexus

重新装载下系统配置参数。

[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# 

启动Nexus。

[root@localhost ~]# systemctl restart nexus
[root@localhost ~]# 

检测Nexus启动状态

检测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目录创建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已安装设置完毕,最后一步,登录到Portal上去,用默认admin和密码登录(默认密码为:admin123),修改下admin的密码就可以啦。

相关文章

网友评论

    本文标题:一起学习微服务和容器4-Maven Repo Center (S

    本文链接:https://www.haomeiwen.com/subject/rcwrsqtx.html