黑猴子的家:Maven 私服 Nexus3 在 Centos 安装

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_28652401/article/details/83552328

1、安装前准备

(1)安装好 jdk1.8
(2)安装好 maven
(3)上传 nexus-3.9.0-01-unix.tar.gz  到  Centos 7

2、解压

[victor@hadoop102 software]$ tar -xzvf nexus-3.9.0-01-unix.tar.gz -C ../module/

3、复制 nexus.properties 模板

[victor@hadoop102 nexus]$ cd etc/
[victor@hadoop102 etc]$ cp nexus-default.properties nexus.properties

4、设置环境变量

[victor@hadoop102 nexus]$ sudo vim /etc/profile
export NEXUS_HOME=/opt/module/nexus
//重新加载环境变量
[victor@hadoop102 nexus]$ source /etc/profile

5、启动nexus3

[victor@hadoop102 module]$ cd nexus-3.9.0-01/
//启动nexus
[victor@hadoop102 nexus-3.9.0-01]$ bin/nexus run &
[victor@hadoop102 nexus-3.9.0-01]$ bin/nexus start &

6、root用户运行,注意事项

[victor@hadoop102 module]$ cd nexus-3.9.0-01/
[victor@hadoop102 nexus-3.9.0-01]$ vim bin/nexus
RUN_AS_USER=root

注意:root用户运行,可能会报错,报上面错误时:需要修改运行的用户,修改运行文件 bin/nexus,命令:vim nexus,将RUN_AS_USER修改为root

7、启动成功

稍等一会(首次启动会比较慢),当出现以下日志的时候表示启动成功!

Started Sonatype Nexus OSS 3.9.0-01

8、开启远程访问端口

[root@MiWiFi-R3-srv bin]# firewall-cmd --zone=public --add-port=8081/tcp --permanent
[root@MiWiFi-R3-srv bin]# firewall-cmd –reload

9、web 查看

https://192.168.2.10*:8081
9193428-a1c892f181b916a3.png
9193428-acafc5057b42c723.png

10、nexus3 默认配置

nexus3默认端口是:8081
nexus3默认账号是:admin
nexus3默认密码是:admin123

11、设置开机自启动

[root@hadoop102 bin]# ln -s /opt/module/nexus-3.9.0-01/bin/nexus   /etc/init.d/nexus3
[root@hadoop102 bin]# chkconfig --add nexus3
[root@hadoop102 bin]# chkconfig nexus3 on

12、设置开机自启动(systemctl方式)

(1)创建一个服务

[root@hadoop102 ~]# vim /usr/lib/systemd/system/nexus.service

(2)填入相关内容

[Unit]
Description=nexus service

[Service]
Type=forking
LimitNOFILE=65536 #警告处理
ExecStart=/usr/local/nexus/nexus-3.9.1-01/bin/nexus start
ExecReload=/usr/local/nexus/nexus-3.9.1-01/bin/nexus restart
ExecStop=/usr/local/nexus/nexus-3.9.1-01/bin/nexus stop
Restart=on-failure

[Install]
WantedBy=multi-user.target

(3)将服务加入开机启动

[root@MiWiFi-R3-srv ~]# systemctl enable nexus.service

(4)重新加载配置文件

[root@MiWiFi-R3-srv ~]# systemctl daemon-reload

13、修改nexus3的运行用户为root

[root@hadoop102 bin]# vim nexus.rc
run_as_user="root"

14、修改nexus3启动时要使用的jdk版本

[victor@hadoop102 bin]# vim nexus
INSTALL4J_JAVA_HOME_OVERRIDE=/usr/local/java/jdk1.8.0_144

15、修改nexus3默认端口

[victor@hadoop102 ~]$ cd /opt/module/nexus-3.9.0-01/etc/
[victor@hadoop102 etc]$ vim nexus.properties 
//默认端口:8081
application-port=8081

16、修改nexus3数据以及相关日志的存储位置

[victor@hadoop102 ~]$ cd /usr/local/nexus-3.9.0-01/bin/
[victor@hadoop102 bin]$ vim nexus.vmoptions 

-XX:LogFile=./sonatype-work/nexus3/log/jvm.log
-Dkaraf.data=./sonatype-work/nexus3
-Djava.io.tmpdir=./sonatype-work/nexus3/tmp

17、配置本地maven的setting.xml文件

<mirrors>
    <mirror>
        <id>nexus</id>
        <mirrorOf>*</mirrorOf>
        <url>http://192.168.1.11:8081/repository/maven-public/</url>
    </mirror>
</mirrors>

18、nexus开启远程访问端口

关闭防火墙,并开启远程访问端口 8081

[root@hadoop102 ~]# vim /etc/sysconfig/iptables
//添加
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8081 -j ACCEPT

19、上传第三方jar包到nexus

(1)发布不带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。
默认情况下,maven会自动为jar包创建pom文件,如果只想保留独立jar包,可以使用参数关闭这个特性: -DgeneratePom=false

(2)发布带有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>

20、Maven settings.xml

<mirrors>
    <mirror>
    <!--This sends everything else to /public -->
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <url>http://192.168.2.140:8081/nexus/content/groups/public</url>
    </mirror>
</mirrors>

<profiles>
    <profile>
        <id>nexus</id>
        <!--Enable snapshots for the built in central repo to direct -->
        <!--all requests to nexus via the mirror -->
        <repositories>
            <repository>
                <id>central</id>
                <url>http://central</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>true</enabled></snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>central</id>
                <url>http://central</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>true</enabled></snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
</profiles>
<activeProfiles>
    <activeProfile>nexus</activeProfile>
</activeProfiles>

至此,nexus3_maven的私服就搭建完成了!!!

猜你喜欢

转载自blog.csdn.net/qq_28652401/article/details/83552328