安装artifactory

准备JDK

安装前需要确保JAVA_HOME有正确设置,可以修改 /etc/environment,加入JAVA_HOME:

  1. JAVA_HOME=/usr/lib/jvm/java-8-oracle

最新版本的artifactory会要求至少jdk1.8版本, 否则无法启动.如果遇到在安装好jdk8之后再安装jdk7一起安装的情况, 需要额外执行一次命令:

  1. sudo apt-get install oracle-java8-set-default

下载安装

https://www.jfrog.com/open-source/下载到最新的artifactory,将zip包解压。

注: 在linux上如果用wget命令直接下载会报错404,需要用浏览器先下载,得到具体下载地址之后再用wget命令下载。

将目录复制到/usr/lib,执行安装:

  1. sudo mv artifactory*** /usr/lib/
  2. cd /usr/lib/
  3. sudo mv artifactory*** artifactory
  4. cd artifactory/bin
  5. sudo ./installService.sh
  6. sudo systemctl start artifactory.service

安装成功后就可以通过http://localhost:8081访问artifactory的页面了,默认管理员账号和密码为admin/password。

安装设置

安全起见,登录后先修改admin密码,点击Admin -> Security -> Users -> User List -> admin,修改密码即可。

另外,Admin -> Security -> General Security Configuration, 取消”Allow Anonymous Access”。

nginx反代

为了方便访问,避免输入8081这样的端口号,考虑使用nginx做反代。

  1. /etc/nginx/sites-available目录下创建文件maven.dreamfly.io

    1. server {
    2. listen 80;
    3. server_name maven.dreamfly.io;
    4. location /
    5. {
    6. proxy_pass http://127.0.0.1:8081;
    7. proxy_redirect http://127.0.0.1:8081 $scheme://maven.dreamfly.io;
    8. }
    9. }
  2. /etc/nginx/sites-enabled目录下创建文件maven.dreamfly.io

    1. sudo ln -s ../sites-available/maven.dreamfly.io maven.dreamfly.io
    2. sudo service nginx restart
  3. 设置maven.dreamfly.io的域名解析到目标IP地址

设置maven

需要在maven的setttings文件中加入如下的 profile 设置, sudo vi /usr/share/maven3/conf/settings.xml

  1. <profile>
  2. <id>dreamfly</id>
  3. <activation>
  4. <activeByDefault>false</activeByDefault>
  5. </activation>
  6. <repositories>
  7. <repository>
  8. <id>dreamfly-release</id>
  9. <name>Dreamfly Release Repository</name>
  10. <releases>
  11. <enabled>true</enabled>
  12. <updatePolicy>never</updatePolicy>
  13. <checksumPolicy>warn</checksumPolicy>
  14. </releases>
  15. <snapshots>
  16. <enabled>false</enabled>
  17. </snapshots>
  18. <url>http://maven.dreamfly.io/artifactory/libs-release</url>
  19. <layout>default</layout>
  20. </repository>
  21. <repository>
  22. <id>dreamfly-snapshot</id>
  23. <name>Dreamfly Snapshot Repository</name>
  24. <releases>
  25. <enabled>false</enabled>
  26. </releases>
  27. <snapshots>
  28. <enabled>true</enabled>
  29. <updatePolicy>always</updatePolicy>
  30. <checksumPolicy>warn</checksumPolicy>
  31. </snapshots>
  32. <url>http://maven.dreamfly.io/artifactory/libs-snapshot</url>
  33. <layout>default</layout>
  34. </repository>
  35. </repositories>
  36. <pluginRepositories>
  37. <pluginRepository>
  38. <id>dreamfly-plugin-release</id>
  39. <name>Dreamfly Plugin Release Repository</name>
  40. <releases>
  41. <enabled>true</enabled>
  42. <updatePolicy>never</updatePolicy>
  43. <checksumPolicy>warn</checksumPolicy>
  44. </releases>
  45. <snapshots>
  46. <enabled>false</enabled>
  47. </snapshots>
  48. <url>http://maven.dreamfly.io/artifactory/plugins-release</url>
  49. <layout>default</layout>
  50. </pluginRepository>
  51. <pluginRepository>
  52. <id>dreamfly-snapshot</id>
  53. <name>Dreamfly Plugin Snapshot Repository</name>
  54. <releases>
  55. <enabled>false</enabled>
  56. </releases>
  57. <snapshots>
  58. <enabled>true</enabled>
  59. <updatePolicy>always</updatePolicy>
  60. <checksumPolicy>warn</checksumPolicy>
  61. </snapshots>
  62. <url>http://maven.dreamfly.io/artifactory/plugins-snapshot</url>
  63. <layout>default</layout>
  64. </pluginRepository>
  65. </pluginRepositories>
  66. </profile>

然后在activeProfiles中激活:

  1. <activeProfiles>
  2. <activeProfile>dreamfly</activeProfile>
  3. </activeProfiles>

deploy设置

再在<servers>中加入账号信息,注意id保持一致:

  1. <servers>
  2. ......
  3. <server>
  4. <id>dreamfly</id>
  5. <username>admin</username>
  6. <password>dreamfly.io</password>
  7. </server>
  8. </servers>

这样,在deploy时,就可以通过-DaltDeploymentRepository参数指定发布的目标地址,然后配合设置文件中的账号信息,完成deploy。

  1. mvn deploy -DaltDeploymentRepository=dreamfly::default::http://maven.dreamfly.io/artifactory/libs-snapshot