背景:

dev准备更新某个基础数据库表结构,为了评估影响范围和后续通知协作,需要找出使用此表的代码库。

思路:

  1. 查询数据库的连接IP,根据IP查询部署在上面的服务,根据服务找对应代码库。
    • 难点:
      • 并不是所有服务都会实时连接数据库,可能会漏掉;
      • 服务器上面部署的服务太多,还需要再做过滤。
    • 综上,这个思路否定。
  2. 直接通过关键字查询代码库源码来定位。
    • 难点:
      • 需要拥有大范围的代码库权限
      • 多目录文件查询涉及关键字文件
    • 解决方案:
      • 作为公司SCM权限不是问题
      • 使用OpenGrok来做关键字查询

参考链接:

实施步骤:

  1. 搭建OpenGrok:
    • 安装jdk-1.8
    • 安装tomcat-8
    • 安装Exuberant Ctags 下载地址
      1
      2
      3
      4
      5
      $ tar zxvf ctags-5.8.tar.gz
      $ cd ctags-5.8/
      $ ./configure
      $ make
      $ make install
    • 安装opengrok 下载地址 | 安装使用wiki
      1
      2
      3
      $ tar zxvf opengrok-1.1-rc16.tar.gz
      $ cd opengrok-1.1-rc16/bin/
      $ OPENGROK_TOMCAT_BASE=/path/to/my/tomcat/install ./OpenGrok deploy
  2. 下载代码
    • 创建一个公共代码库存放目录:
      1
      2
      $ mkdir -p /root/wwl/code/svn
      $ mkdir -p /root/wwl/code/git
    • 根据需要下载svn代码:
      1
      2
      $ cd /root/wwl/code/svn
      $ svn checkout svn_urls
    • 根据需要下载git代码:
      1
      2
      $ cd /root/wwl/code/git
      $ git clone git_urls
    • PS:如果要想查询所有分支代码
      • svn:直接checkout 包含branches目录url即可;
      • git:需要clone多次git_url到不同目录,然后cd到各自目录执行git checkout branch_name;
      • 建议只下载master/trunk和最新dev分支即可。
  3. 加载OpenGrok索引
    1
    2
    3
    $ ./OpenGrok index <absolute_path_to_your_SRC_ROOT>
    例如:
    ./OpenGrok index /root/wwl/code
    PS:如果代码文件很多的话,加载索引会很久。晚上执行第二天来看结果吧。
  4. 关键字查询
    • web端登陆:
      1
      <HOST>:<PORT>/source
    • 执行查询:
      logo

PS:

  1. OpenGrok还支持文件类型查询过滤等功能,各位可以自行尝试使用;
  2. 除了数据库表查询以外,常见的还有api调用查询;
  3. 这种方案是后置的,如果能在系统设计之初和迭代过程积极维护开发文档,形成系统整体调度架构图形的话,会另我们开发更加自信;
  4. 借此机会推动开发团队规范开发文档和产出系统调度架构图形。

Comment and share

背景:

公司之前使用nexus2.13.0版本的nexus,管理毕竟混乱。现搭建nexus3.6.0版本进行规范统一管理。

上篇记录nexus3搭建配置过程,本篇记录迁移nexus2.13.0版本库到nexus3.6.0版本过程。

迁移思路方法:

迁移范围:

仓库 类型 是否迁移
proxy 代理远端仓库 已经在nexus3.6.0版本配置增加,不需要迁移
hosted-3rd 本地内部仓库-第三方 之前没有使用,不需要迁移
hosted-Snapshots 本地内部仓库-快照版本 之前使用比较混乱沟通确认舍弃,不需要迁移
hosted-Releases 本地内部仓库-稳定版本 需要迁移

迁移方法:

如果原有hosted-Releases存放的jar包不多的话,可以考虑下载所有jar到本地,然后使用命令deploy到nexus3.6.0。

现状是原有库里面的jar包很多,groupId很多而且比较不规范(目录层级很复杂)。

参考链接:

升级方法:官方文档

根据官方升级文档说明nexus2.14.1(或者之后版本)才能直升nexus3.x。因为原有nexus版本为2.13.0,所有需要先升级到2.14.x后,再迁移到nexus3.6.0版本。

升级路径为:
nexus2.x – nexus2.14.x – nexus3.x

迁移步骤:

  1. 搭建nexus2.14.5
    • 官网下载 All platforms - Nexus Repository Manager OSS 2.x - bundle.zip
    • 解压缩、安装运行
    • ps:windows遇到的坑,需要使用管理员权限进行cmd安装
      logo
      logo
      logo
  2. 迁移原有nexus2.13.0仓库到nexus2.14.5
    • 仓库存放目录:sonatype-work\nexus\storage
    • 拷贝原nexus2.13.0的sonatype-work\nexus\storage\releases目录下的依赖文件
    • 覆盖nexus2.14.5的releases目录文件
    • 重启nexus2.14.5并刷新索引
      logo
      logo
      logo
  3. 迁移nexus2.14.5仓库到nexus3.6.0
    • 在nexus2.14.5上面配置Upgrade Agent
      logo
      logo
    • 在nexus3.6.0上面执行Upgrade
      logo
      logo
      logo
      logo
      logo
      logo
      logo
      logo
      logo
      logo

后续

使用这种方法,原有的release仓库迁移成功。
logo

但是同时原有nexus的Privileges、Roles、Users也会过来,需要后续进行调整。

当然此方法也可以用来全量升级nexus2.x到nexus3.x。

Comment and share

Nexus3搭建配置

in SCM

参考链接:

PS:

  • nexus分为nexus-repository-oss(免费版)和nexus-repository-pro(商业版)
  • 主要使用版本:2.x和3.x
  • 版本区别:官方文档

JAVA项目依赖管理方法:

  1. 所有依赖jar包都上传提交到代码库里面:
    • 优点:直接获取代码库代码就可以进行编译打包,不需要依赖外部网络(独立个人小项目)
    • 缺点:
      • 依赖包体积很大,导致代码获取推送太耗时和占用带宽;
      • 基础框架依赖包每个代码库都要存放一份(空间浪费);
      • 当前依赖包版本不明确。
  2. 依赖包编译过程中下载,不上传到代码库:
    • 优点:
      • 代码库干净,体积小;
      • 项目显性配置依赖包版本和引用阶段清晰明了。

私服的优点:

  1. 统一服务器代理外部依赖(节省外网带宽);
  2. 项目下载依赖通过内部网络的进行(更快);
  3. 托管内部项目依赖(协作更方便);
  4. 托管第三方依赖(例如:合作伙伴的依赖包)
    logo

搭建环境版本:

  • OS: Windows Server 2012 R2
  • JDK: 1.8.0_71
  • nexus-repository-oss 3.6.0-02

搭建步骤:

  1. 安装JDK
  2. 官网下载:nexus-3.6.0-02-win64.zip,解压缩
  3. 配置windows服务:官方文档
    1
    $install-dir/bin/nexus.exe /install <optional-service-name>
  4. 启动服务:
    1
    nexus.exe /start <optional-service-name>
  5. 网页端登陆配置Nexus
    • http://$ip:8081
    • 用户名/密码:admin/admin123

后台配置:

  1. data目录修改
    1
    2
    3
    4
    5
    $install-dir/bin/nexus.vmoptions

    -Dkaraf.data=../sonatype-work/nexus3
    -Djava.io.tmpdir=../sonatype-work/nexus3/tmp
    -XX:LogFile=../sonatype-work/nexus3/log/jvm.log
  2. 服务端口号修改:
    1
    2
    3
    4
    $data-dir/etc/nexus.properties

    # Jetty section
    application-port=8081
  3. jvm性能调优:
    1
    2
    3
    4
    5
    $install-dir/bin/nexus.vmoptions

    -Xms4G
    -Xmx4G
    -XX:MaxDirectMemorySize=4014M
    以上修改都需要重启服务生效。

前台配置:

使用管理员admin账号登陆

配置邮箱

logo

配置LDAP

logo
logo
logo

配置权限

logo
logo
logo

配置repositories

repositories分为三个种类:

  1. proxy 代理远端仓库
  2. hosted 本地内部仓库
  3. group 组合仓库
    logo

Maven依赖私服配置

修改~/.m2/settings.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<settings>
<servers>
<server>
<id>nexus</id>
<username>用户名</username>
<password>密码</password>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://$ip:8081/repository/maven-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>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>

内部项目上传jar包:

修改项目pom.xml文件增加

1
2
3
4
5
6
7
8
9
10
11
12
<distributionManagement>
<repository>
<id>nexus</id>
<name>Releases</name>
<url>http://$ip:8081/repository/maven-releases</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>Snapshot</name>
<url>http://$ip:8081/repository/maven-snapshots</url>
</snapshotRepository>
</distributionManagement>

然后执行:

1
mvn clean deploy

上传第三方jar包:

nexus3不能使用web端来上传第三方jar包,只能使用命令行:

1
2
mvn deploy:deploy-file -DgroupId=$groupId -DartifactId=$artifactId -Dversion=$version -Dpackaging=jar -Dfile=$path/XX.jar -Durl=http://$ip:8081/repository/$hosted_3rd/ -DrepositoryId=nexus

Comment and share

  • page 1 of 1
Author's picture

Weilong

    Write something about work-life:

PM


Shenzhen