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

1.停止服务

    # ./nexus stop
        Shutting down nexus

2.进入OrientDB控制台(OrientDB是不一开源NoSql数据库)

    #cd ../nexus-3.19.1-01/lib/support

    # ls
    nexus-orient-console.jar
    加载jar包
    #java -jar ./lib/support/nexus-orient-console.jar
    提示错误:Exception in thread "main" java.lang.UnsupportedClassVersionError: org/sonatype/nexus/orient/console/Main : **Unsupported major.minor version 52.0**

    查看JAVA版本是否过低
    # java -version
        java version "1.7.0_80"
        Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
        Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

        解决方法:安装JAVA1.8以上版本
        orientdb> 
            连接数据库格式:connect   []
            WHERE:
                * url               The url of the remote server or the database to connect to in the format ':'
                * user              User name
                * password          User password (optional)

3 进入数据库

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

Connecting to database [plocal:/home/cqs/data/nexus/sonatype-work/nexus3/db/security] with user 'admin'...
2020-03-17 18:21:19:075 WARNI Not enough physical memory available for DISKCACHE: 1,490MB (heap=361MB direct=361MB). Set lower Maximum Heap (-Xmx setting on JVM) and restart OrientDB. Now running with DISKCACHE=256MB [OMemoryAndLocalPaginatedEnginesInitializer]OK

orientdb {db=security}

查看用户名是否存在admin

 > > select * from user where id = "admin"

+----+-----+------+-----+------+--------+-----------+---------------+---------------------------------------------------------------------------------------------------+
|#   |@RID |@CLASS|id   |status|lastName|firstName  |email          |password                                                                                           |
+----+-----+------+-----+------+--------+-----------+---------------+---------------------------------------------------------------------------------------------------+
|0   |#15:0|user  |admin|active|User    |Administ...|admin@exampl...|$shiro1$SHA-512$1024$ksGQUj3R+CuvzLNvrTWm5A==$OJSYDLBq47rESaV+NJ3hMCc/D+j/UEdW9gD1fpo15nJ5mAwyHw...|
+----+-----+------+-----+------+--------+-----------+---------------+---------------------------------------------------------------------------------------------------+

1 item(s) found. Query executed in 0.008 sec(s).
orientdb {db=security}>

4 重置密码

    将admin用户密码重置为admin123,具体执行如下:
    #update user SET password="$shiro1$SHA-512$1024$NE+wqQq/TmjZMvfI7ENh/g==$V4yPw8T64UQ6GfJfxYq2hLsVrBY8D1v+bktfOxGdt4b/9BthpWPNUy/CBk6V9iA0nHpzYzJFWO8v/tZFtES8CA==" UPSERT WHERE id="admin"

5 启动服务

# ./nexus start