微服务架构【技术点2】--- centos+nexus搭建maven私服+idea联合发布使用

前言

一般产品到了一定规模内部的maven是必须要搭建的----当然,不到一定规模也可以搭建的,关键就看整个开发流程和团队配合了。
注意,这个搭建maven在网上已经一堆实践了的,跟着做即可。当然,假如有坑的话我也会先填上去的。

准备工作

分别先安装jdk及maven。

执行:
java -version
看看有没有安装java,服务器不要随便换环境。
假如没有的话就用:
yum install java
安装java。

这里写图片描述

服务器已经安装java,跳过这一步。

看看有没有安装maven,没有就安装,有就跳过。
mvn -version
安装maven:
yum install maven

这里写图片描述

刚好我没有安装,那么就安装先:

yum install maven

这里写图片描述

这里写图片描述

这里写图片描述

安装成功。

安装nexus

到官网下载页面看看:

这里写链接内容

可以看到:

这里写图片描述

好了忽略加入注册种种步骤,下载地址是:

https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.12.1-01-unix.tar.gz
在centos下下载:
wget https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.12.1-01-unix.tar.gz

这里写图片描述

保存成功。

解压缩
tar -zxvf nexus-3.12.1-01-unix.tar.gz -C /usr/local/

这里写图片描述

解压成功。

------重命名nexus文件夹
cd /usr/local
mv nexus-3.12.1-01 nexus3
创建软连接
sudo ln -s nexus3 nexus
创建 nexus 用户
# sudo useradd nexus -M -s /sbin/nologin
注意,这条命令后续会出问题的,在我上一篇文章已经将坑都排出来了:
https://blog.csdn.net/cdnight/article/details/80673110
所以,正式的命令是新建普通的账号:
sudo useradd nexus -m -s /bin/bash
授权
sudo chown -R nexus:nexus /usr/local/nexus
sudo chown -R nexus:nexus /usr/local/sonatype-work/

打开 /usr/local/nexus/bin/nexus.rc 文件, 去掉 run_as_user 变量的注释
sudo vim /usr/local/nexus/bin/nexus.rc
run_as_user="nexus"

安装nexus到系统服务

安装服务(本例以 systemd 为例)
创建服务文件

sudo vim /etc/systemd/system/nexus.service

添加如下内容

[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/usr/local/nexus/bin/nexus start
ExecStop=/usr/local/nexus/bin/nexus stop
User=nexus
Restart=on-abort
[Install]
WantedBy=multi-user.target

其中LimitNOFILE=65536用于调整文件描述符数量。

安装并启动服务
sudo systemctl daemon-reload
sudo systemctl enable nexus
sudo systemctl start nexus

查看服务
sudo systemctl status nexus

这里写图片描述

nexus3中央仓库改为阿里云

参考:这里写链接内容
找到中央仓库

这里写图片描述

然后修改成:
这里写图片描述

http://maven.aliyun.com/nexus/content/groups/public/

idea使用私服maven及对应配置

参考:
这里写链接内容

首先,新建一个maven项目—自己新建吧。

然后,
这里写图片描述

这里写图片描述

看到本机的maven 配置文件,
这里写图片描述

打开来,然后:
这里写图片描述
添加我们的maven私服及servers—用来发布类库的。

格式如下:



    
	
	      
          central  
          *  
          Central Repository  
          http://你仓库的地址/repository/maven-public/  
        
        
        
            alimaven
            central
            aliyun maven
            http://maven.aliyun.com/nexus/content/repositories/central/
        

        
        
            repo1
            central
            Human Readable Name for this Mirror.
            http://repo1.maven.org/maven2/
        

        
        
            repo2
            central
            Human Readable Name for this Mirror.
            http://repo2.maven.org/maven2/
        
    
	     
       
         nexus-releases  
         admin  
         你的密码  
       
       
         nexus-snapshots  
         admin  
         你的密码  
         
   

发布快照及正式版本

maven(15),快照与发布,RELEASE与SNAPSHOT

在pom.xml文件最后添加distributionManagement发布管理节点:

这里写图片描述

例如:

    
        
            nexus-releases
            Nexus Release Repository
            http://你的maven地址/repository/maven-releases/
        
        
            nexus-snapshots
            Nexus Snapshot Repository
            http://你的maven地址/repository/maven-snapshots/
        
    

注意一下

    net.funfunle
    baselib
    
    1.0.1-RELEASE

groupid这些,

    net.funfunle
    baselib
    
    1.0.1-RELEASE

决定发布的是正式版本release还是快照snapshot的是

    
    1.0.1-RELEASE

版本号及发布类型,有一点也需要注意,snapshot快照允许重复发布更新同一个版本,而release是不允许的,release每次发布版本号都要加的。

发布方式:
这里写图片描述

在mavenproject点击发布deploy。

新项目中引用发布的类库

maven2获取最新版本方式。

这里写链接内容
maven pom文件详解

这里写图片描述

这里写图片描述

这里写图片描述

maven3获取最新版本方式
这里写链接内容

Now I know this topic is old, but reading the question and the OP supplied answer it seems the Maven Versions Plugin might have actually been a better answer to his question:

In particular the following goals could be of use:

versions:use-latest-versions searches the pom for all versions which have been a newer version and replaces them with the latest version.
versions:use-latest-releases searches the pom for all non-SNAPSHOT versions which have been a newer release and replaces them with the latest release version.
versions:update-properties updates properties defined in a project so that they correspond to the latest available version of specific dependencies. This can be useful if a suite of dependencies must all be locked to one version.
The following other goals are also provided:

versions:display-dependency-updates scans a project's dependencies and produces a report of those dependencies which have newer versions available.
versions:display-plugin-updates scans a project's plugins and produces a report of those plugins which have newer versions available.
versions:update-parent updates the parent section of a project so that it references the newest available version. For example, if you use a corporate root POM, this goal can be helpful if you need to ensure you are using the latest version of the corporate root POM.
versions:update-child-modules updates the parent section of the child modules of a project so the version matches the version of the current project. For example, if you have an aggregator pom that is also the parent for the projects that it aggregates and the children and parent versions get out of sync, this mojo can help fix the versions of the child modules. (Note you may need to invoke Maven with the -N option in order to run this goal if your project is broken so badly that it cannot build because of the version mis-match).
versions:lock-snapshots searches the pom for all -SNAPSHOT versions and replaces them with the current timestamp version of that -SNAPSHOT, e.g. -20090327.172306-4
versions:unlock-snapshots searches the pom for all timestamp locked snapshot versions and replaces them with -SNAPSHOT.
versions:resolve-ranges finds dependencies using version ranges and resolves the range to the specific version being used.
versions:use-releases searches the pom for all -SNAPSHOT versions which have been released and replaces them with the corresponding release version.
versions:use-next-releases searches the pom for all non-SNAPSHOT versions which have been a newer release and replaces them with the next release version.
versions:use-next-versions searches the pom for all versions which have been a newer version and replaces them with the next version.
versions:commit removes the pom.xml.versionsBackup files. Forms one half of the built-in "Poor Man's SCM".
versions:revert restores the pom.xml files from the pom.xml.versionsBackup files. Forms one half of the built-in "Poor Man's SCM".
Just thought I'd include it for any future reference.

这里写图片描述

譬如:

这里写图片描述

配置优化及内存问题

nexus本身耗费的内存是非常大的。竟然到达了1g,对于小作坊是很致命的。

vim  /usr/local/nexus3/bin/nexus.vmoptions

默认配置如下

微服务架构【技术点2】--- centos+nexus搭建maven私服+idea联合发布使用_第1张图片

改为:

微服务架构【技术点2】--- centos+nexus搭建maven私服+idea联合发布使用_第2张图片

重启服务

忘记密码怎么办

nexus3忘记admin密码!!!

nexus3 这种东西,传完一次,再就少动了,很容易忘记密码。

然后我就搜了一下,nexus3忘记密码。

排在第一的是CSND的博客,https://blog.csdn.net/tianya6607/article/details/53305620

我按照上面说的,改了一下。

然后我就想告诉大家,千万不要试!千万不要试!千万不要试!

重要的话说三遍。

Nexus好像是通过内置的orientdb数据库管理的。需要进入到库里面修改密码。

如果直接去修改那个文件的话,他有文件校验,改完就GG了。

经过寻找,终于找到了方法(有事还得去官网找):

https://support.sonatype.com/hc/en-us/articles/213467158-How-to-reset-a-forgotten-admin-password-in-Nexus-3-x

基本流程就是先到你的安装目录下,那个带n.n.n的文件夹下。

linux :  java -jar ./lib/support/nexus-orient-console.jar
win :  java -jar lib\support\nexus-orient-console.jar
mac : .install4j/jre.bundle/Contents/Home/jre/bin/java -jar ./lib/support/nexus-orient-console.jar
这样进入OrientDB控制台

然后

connect plocal:../sonatype-work/nexus3/db/security admin admin
进入数据库

update user SET password="$shiro1$SHA-512$1024$NE+wqQq/TmjZMvfI7ENh/g==$V4yPw8T64UQ6GfJfxYq2hLsVrBY8D1v+bktfOxGdt4b/9BthpWPNUy/CBk6V9iA0nHpzYzJFWO8v/tZFtES8CA==" UPSERT WHERE id="admin"

这样就重置密码了

那个文章后面还有一些遇到问题的处理,我没仔细看,遇到问题去看一下吧。
--------------------- 
作者:ayuski 
来源:CSDN 
原文:https://blog.csdn.net/weixin_40011286/article/details/80996639 
版权声明:本文为博主原创文章,转载请附上博文链接!

实际上,官网介绍如下:

Shut down nexus, and backup your /db
Access the OrientDB console using these instructions.
Run the following command:
connect plocal:../sonatype-work/nexus3/db/security admin admin
You may need to adjust the path used in the connect statement depending on the location of your nexus data directory. It should be the path to the "db/security" directory in your data directory. An absolute path may be used.

After the connect command succeeds, issue this command in the console to update the admin user password to the default value:
update user SET password="$shiro1$SHA-512$1024$NE+wqQq/TmjZMvfI7ENh/g==$V4yPw8T64UQ6GfJfxYq2hLsVrBY8D1v+bktfOxGdt4b/9BthpWPNUy/CBk6V9iA0nHpzYzJFWO8v/tZFtES8CA==" UPSERT WHERE id="admin"

The query language is sql-like , but it is not SQL. See the OrientDB Command Reference.
At this point, the admin user should be able to authenticate if the default security realms are in still in place. Verify you can login as the admin user using your web browser.

Optional, if the admin user still fails to authenticate: If the default security realms were removed from the active list, the default admin user will still not be able to authenticate, despite resetting the password.

To reset the default security realms, enter this command at the karaf prompt:
delete from realm
After this command succeeds and Nexus is restarted, the default security realms will be activated and any custom activated realms will have been removed.

An admin user will then have to add back in any other security realms they had previously ( such as LDAP) using the Realms UI, to allow other users to authenticate.

Optional, if the admin user is missing the "nx-admin" role:
Check to see what roles the "admin" user has assigned to them:

select * from user_role_mapping where userID = "admin"
If they are missing "nx-admin" use this command at the karaf prompt to fix:

update user_role_mapping set roles = ["nx-admin"] where userID = "admin"  
Optional, check to see if the admin user is active:
Check to see if the "admin" user is active:

select status from user where id = "admin"
If they are not active, use this to make them active:

update user set status="active" upsert where id="admin"
To end the console session gracefully type "exit".

Start Nexus again using ./bin/nexus start or your regular service control command.

下面正式实践。

nexus3找回密码

1-关闭neuxs

systemctl stop nexus


2-打开nexus安装目录下面的nexus目录:

cd /usr/local/nexus

在这里插入图片描述

然后你会在

ls lib/support

下面看到这个jar程序,这就是我们需要用到的程序了。

在这里插入图片描述

执行

java -jar ./lib/support/nexus-orient-console.jar

在这里插入图片描述

在这里插入图片描述

然后再执行:

connect plocal:../sonatype-work/nexus3/db/security admin admin

在这里插入图片描述

然后更新密码:

update user SET password="$shiro1$SHA-512$1024$NE+wqQq/TmjZMvfI7ENh/g==$V4yPw8T64UQ6GfJfxYq2hLsVrBY8D1v+bktfOxGdt4b/9BthpWPNUy/CBk6V9iA0nHpzYzJFWO8v/tZFtES8CA==" UPSERT WHERE id="admin"

在这里插入图片描述

然后,重启nexus。

systemctl restart nexus


无法正常访问,报错:

java.io.FileNotFoundException: /usr/local/sonatype-work/nexus3/db/security/security.35.wal (Permission denied)
	at java.io.RandomAccessFile.open0(Native Method)
	at java.io.RandomAccessFile.open(RandomAccessFile.java:316)
	at java.io.RandomAccessFile.(RandomAccessFile.java:243)
	at com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSegmentV2.getRndFile(OLogSegmentV2.java:397)
	at com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSegmentV2.init(OLogSegmentV2.java:441)
	at com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog.(ODiskWriteAheadLog.java:279)
	at com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog.(ODiskWriteAheadLog.java:158)
	at com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage.initWalAndDiskCache(OLocalPaginatedStorage.java:586)
	at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.open(OAbstractPaginatedStorage.java:279)
	at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:259)
	at org.sonatype.nexus.orient.DatabaseManagerSupport.connect(DatabaseManagerSupport.java:143)
	at org.sonatype.nexus.orient.DatabaseInstanceImpl.doStart(DatabaseInstanceImpl.java:56)
	at org.sonatype.goodies.lifecycle.LifecycleSupport.start(LifecycleSupport.java:104)
	at org.sonatype.goodies.lifecycle.Lifecycles.start(Lifecycles.java:44)
	at org.sonatype.nexus.orient.DatabaseManagerSupport.createInstance(DatabaseManagerSupport.java:252)
	at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
	at org.sonatype.nexus.orient.DatabaseManagerSupport.instance(DatabaseManagerSupport.java:231)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291)
	at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool.helpComplete(ForkJoinPool.java:1870)
	at java.util.concurrent.ForkJoinPool.externalHelpComplete(ForkJoinPool.java:2467)
	at java.util.concurrent.ForkJoinTask.externalAwaitDone(ForkJoinTask.java:324)
	at java.util.concurrent.ForkJoinTask.doInvoke(ForkJoinTask.java:405)
	at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:734)
	at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:160)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:174)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
	at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:583)
	at org.sonatype.nexus.orient.restore.RestoreServiceImpl.doStart(RestoreServiceImpl.java:76)
	at org.sonatype.nexus.common.stateguard.StateGuardLifecycleSupport.start(StateGuardLifecycleSupport.java:67)
	at org.sonatype.nexus.orient.restore.RestoreServiceImpl$$EnhancerByGuice$$aa785730.CGLIB$start$4()
	at org.sonatype.nexus.orient.restore.RestoreServiceImpl$$EnhancerByGuice$$aa785730$$FastClassByGuice$$84b2bfc.invoke()
	at com.google.inject.internal.cglib.proxy.$MethodProxy.invokeSuper(MethodProxy.java:228)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:76)
	at org.sonatype.nexus.common.stateguard.MethodInvocationAction.run(MethodInvocationAction.java:39)
	at org.sonatype.nexus.common.stateguard.StateGuard$TransitionImpl.run(StateGuard.java:191)
	at org.sonatype.nexus.common.stateguard.TransitionsInterceptor.invoke(TransitionsInterceptor.java:56)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:77)
	at com.google.inject.internal.InterceptorStackCallback.intercept(InterceptorStackCallback.java:55)
	at org.sonatype.nexus.orient.restore.RestoreServiceImpl$$EnhancerByGuice$$aa785730.start()
	at org.sonatype.nexus.extender.NexusLifecycleManager.startComponent(NexusLifecycleManager.java:155)
	at org.sonatype.nexus.extender.NexusLifecycleManager.to(NexusLifecycleManager.java:95)
	at org.sonatype.nexus.extender.NexusContextListener.frameworkEvent(NexusContextListener.java:189)
	at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1429)
	at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
	at java.lang.Thread.run(Thread.java:748)



具体查看:

微服务架构【技术点2】--- centos+nexus搭建maven私服+idea联合发布使用_第3张图片

cat  sonatype-work/nexus3/log/nexus.log 

看到报错,然后,将文件权限赋值:

chown -R nexus:nexus /usr/local/sonatype-work/nexus3/db/security

重启:
微服务架构【技术点2】--- centos+nexus搭建maven私服+idea联合发布使用_第4张图片

访问:
微服务架构【技术点2】--- centos+nexus搭建maven私服+idea联合发布使用_第5张图片

大功告成。

你可能感兴趣的:(微服务,设计架构,后端,maven,nexus,微服务,研发模式及运维,idea,maven,nexus)