使用JFrog Artifactory Open Source 搭建私服

團結發表於2016-06-25

之前使用Nexus搭建過私服,可惜做完後沒怎麼用就重灌系統了。這次想搭建私服時想起Jcenter和Spring都使用Artifactory私服,看著介面也比Nexus漂亮、順眼,所以就選擇Artifactory作為私服工具了。
本文主要參考:Install Artifactory on CentOS官方使用者指南

安裝手冊

Artifactory有多種安裝選擇,我選擇了其中的Service Installation。

Artifactory服務安裝說明

Artifactory 是一個內建tomcat的zip包,擁有一個完整的linux服務安裝指令碼。

當作為一個服務執行Artifactory ,安裝指令碼建立一個名為Artifactory的使用者,並且這個使用者必須有安裝的目錄的執行和執行許可權。因此,建議下載安裝zip到一個授權所有使用者執行、執行的資料夾,如/opt。

  1. 下載jfrog-artifactory-oss-4.8.2.zip到/opt

  2. 解壓jfrog-artifactory-oss-4.8.2.zip,unzip jfrog-artifactory-oss-4.8.2.zip

  3. 修改JVM執行引數,$ARTIFACTORY_HOME/etc/default:“

  4. 在vim模式下查詢檔案內容:按下斜線(/),游標會跑到訊息行,然後vim會顯示斜線。在輸入你要查詢的文字後,按下Enter鍵。要繼續查詢同一個單詞,按下n鍵,表示下一個。

  5. 修改JVM執行引數後,需要重啟artifactory服務

  6. 實際上沒有在$ARTIFACTORY_HOME/etc/下找到default檔案,反而在$ARTIFACTORY_HOME/bin/下找到了artifactory.default檔案,暫且修改這個(如果不生效,再查詢其他資料)

  7. 修改artifactory.default檔案,export ARTIFACTORY_HOME=/opt/artifactory-oss-4.8.2 ;export ARTIFACTORY_USER=artifactory ;START_TMO=60

安裝Artifactory

跳轉到$ARTIFACTORY_HOME/bin,以root執行下面的命令:

$ARTIFACTORY_HOME/bin/installService.sh [USER [GROUP]]

實際執行:

bin/installService.sh 

Installing artifactory as a Unix service that will run as user artifactory
Installing artifactory with home /opt/artifactory-oss-4.8.2
Creating user artifactory...creating... DONE

Checking configuration link and files in /etc/opt/jfrog/artifactory...
Moving configuration dir /opt/artifactory-oss-4.8.2/etc /opt/artifactory-oss-4.8.2/etc.original...creating the link and updating dir... DONE
Creating environment file /etc/opt/jfrog/artifactory/default...creating... DONE
** INFO: Please edit the files in /etc/opt/jfrog/artifactory to set the correct environment
Especially /etc/opt/jfrog/artifactory/default that defines ARTIFACTORY_HOME, JAVA_HOME and JAVA_OPTIONS

Initializing artifactory service with chkconfig...
注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置資料可能被原生 systemd 配置覆蓋。 
      如果您想列出 systemd 服務,請執行 `systemctl list-unit-files`。
      欲檢視對特定 target 啟用的服務請執行
      `systemctl list-dependencies [target]`。

artifactory        0:關    1:關    2:開    3:開    4:開    5:開    6:關
 DONE

Setting file permissions... DONE

************ SUCCESS ****************
Installation of Artifactory completed

Please check /etc/opt/jfrog/artifactory, /opt/artifactory-oss-4.8.2/tomcat and /opt/artifactory-oss-4.8.2 folders
Please check /etc/init.d/artifactory startup script

you can now check installation by running:
> service artifactory check (or /etc/init.d/artifactory check)

Then activate artifactory with:
> service artifactory start (or /etc/init.d/artifactory start)

看執行結果,有很多需要設定而為設定的項。

執行Artifactory無許可權

以非root使用者執行報錯:

service artifactory start
/bin/java
Starting Artifactory tomcat as user artifactory...
/etc/init.d/artifactory: line 80: ulimit: open files: cannot modify limit: Operation not permitted
WARNING: Max number of open files 1024 is too small!
You should add:
artifactory soft nofile 32000
artifactory hard nofile 32000
to your /etc/security/limits.conf file.
Password: 

成功執行Artifactory服務

root使用者執行:

service artifactory start
/bin/java
Starting Artifactory tomcat as user artifactory...
Max number of open files: 32000
Using ARTIFACTORY_HOME: /opt/artifactory-oss-4.8.2
Using ARTIFACTORY_PID: /opt/artifactory-oss-4.8.2/run/artifactory.pid
Using CATALINA_BASE:   /opt/artifactory-oss-4.8.2/tomcat
Using CATALINA_HOME:   /opt/artifactory-oss-4.8.2/tomcat
Using CATALINA_TMPDIR: /opt/artifactory-oss-4.8.2/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/artifactory-oss-4.8.2/tomcat/bin/bootstrap.jar:/opt/artifactory-oss-4.8.2/tomcat/bin/tomcat-juli.jar
Using CATALINA_PID:    /opt/artifactory-oss-4.8.2/run/artifactory.pid
Tomcat started.
Artifactory Tomcat started in normal mode

瀏覽器訪問,http://localhost:8081/artifactory/

停止Artifactory服務

service artifactory stop
Stopping Artifactory Tomcat...
Max number of open files: 1024
Using ARTIFACTORY_HOME: /opt/artifactory-oss-4.8.2
Using ARTIFACTORY_PID: /opt/artifactory-oss-4.8.2/run/artifactory.pid
Using CATALINA_BASE:   /opt/artifactory-oss-4.8.2/tomcat
Using CATALINA_HOME:   /opt/artifactory-oss-4.8.2/tomcat
Using CATALINA_TMPDIR: /opt/artifactory-oss-4.8.2/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/artifactory-oss-4.8.2/tomcat/bin/bootstrap.jar:/opt/artifactory-oss-4.8.2/tomcat/bin/tomcat-juli.jar
Using CATALINA_PID:    /opt/artifactory-oss-4.8.2/run/artifactory.pid
Tomcat stopped.
Artifactory Tomcat stopped

檢視Artifactory服務的狀態

Artifactory安裝後,可以使用下面的命令檢視Artifactory服務的狀態:

service artifactory check

如果,Artifactory服務正在執行,你可以檢視它的pid:

service artifactory check
Artifactory is running, on pid=5319

如果,Artifactory服務沒有啟動,你可以看到它的執行引數:

service artifactory check
Checking arguments to Artifactory: 
ARTIFACTORY_HOME     =  /opt/artifactory-oss-4.8.2
ARTIFACTORY_USER     =  artifactory
TOMCAT_HOME          =  /opt/artifactory-oss-4.8.2/tomcat
ARTIFACTORY_PID      =  /opt/artifactory-oss-4.8.2/run/artifactory.pid
JAVA_HOME            =  
JAVA_OPTIONS         =  -server -Xms512m -Xmx2g -Xss256k -XX:+UseG1GC -Djruby.compile.invokedynamic=false -Dfile.encoding=UTF8 -Dartdist=zip -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

/bin/java

檢視Artifactory日誌

可以使用下面的命令檢視Artifactory日誌:

tail -f $ARTIFACTORY_HOME/logs/artifactory.log

實際執行時,沒有找到ARTIFACTORY_HOME環境變數,暫以絕對路徑檢視:

tail -f /opt/artifactory-oss-4.8.2/logs/artifactory.log 
2016-06-25 17:22:30,034 [localhost-startStop-2] [INFO ] (o.a.s.ArtifactoryApplicationContext:301) - Destroying org.artifactory.repo.service.InternalRepositoryService
2016-06-25 17:22:30,035 [localhost-startStop-2] [INFO ] (o.a.s.ArtifactoryApplicationContext:301) - Destroying org.artifactory.schedule.TaskService
2016-06-25 17:22:30,039 [localhost-startStop-2] [INFO ] (o.a.s.ArtifactoryApplicationContext:301) - Destroying org.artifactory.state.model.ArtifactoryStateManager
2016-06-25 17:22:30,043 [localhost-startStop-2] [INFO ] (o.a.s.ArtifactoryApplicationContext:301) - Destroying org.artifactory.config.InternalCentralConfigService
2016-06-25 17:22:30,044 [localhost-startStop-2] [INFO ] (o.a.s.ArtifactoryApplicationContext:301) - Destroying org.artifactory.config.ConfigurationChangesInterceptors
2016-06-25 17:22:30,044 [localhost-startStop-2] [INFO ] (o.a.s.ArtifactoryApplicationContext:301) - Destroying org.artifactory.repo.interceptor.StorageInterceptors
2016-06-25 17:22:30,044 [localhost-startStop-2] [INFO ] (o.a.s.ArtifactoryApplicationContext:301) - Destroying org.artifactory.storage.db.DbService
2016-06-25 17:22:30,045 [localhost-startStop-2] [INFO ] (o.a.s.ArtifactoryApplicationContext:301) - Destroying org.artifactory.md.MetadataDefinitionService
2016-06-25 17:22:30,046 [localhost-startStop-2] [INFO ] (o.a.s.ArtifactoryApplicationContext:315) - Closing Artifactory: startup date [Sat Jun 25 17:20:37 CST 2016]; root of context hierarchy
2016-06-25 17:22:30,054 [localhost-startStop-2] [INFO ] (o.a.s.ArtifactorySchedulerFactoryBean:765) - Shutting down Quartz Scheduler

安全相關

When installing from an RPM or Debian distribution, Artifactory is generally started as root and will su internally to the $ARTIFACTORY_USER user.

For reasons of security, it is not recommended to leave the $ARTIFACTORY_USER variable undefined with Artifactory running as the current user, especially if the current user is root.

安裝指令碼的執行順序

The following table describes the sequence of commands performed by the install script

建立使用者

建立一個名為artifactory的使用者,也可以通過修改/etc/opt/jfrog/artifactory/default中的ARTIFACTORY_USER改變預設使用者。
另外,也可以在啟動命令中設定預設使用者,方法是把user作為第一個引數,也可以在設定user的同時設定group。

etc 配置

建立一個資料夾 /etc/opt/jfrog/artifactory,複製配置檔案到資料夾下並建立一個軟連線到$ARTIFACTORY_HOME/etc。
Creates the folder /etc/opt/jfrog/artifactory, copies the configuration files there and creates a soft link in$ARTIFACTORY_HOME/etc

etc 預設設定

Creates the file /etc/opt/jfrog/artifactory/default containing the main environment variables needed for Artifactory to run:JAVA_HOME, ARTIFACTORY_USER, ARTIFACTORY_HOME, JAVA_OPTIONS,…
The /etc/opt/jfrog/artifactory/default is included at the top of artifactoryctl and can include any settings.
To modify your JVM parameters modify JAVA_OPTIONS in /etc/opt/jfrog/artifactory/default

init.d

複製服務指令碼檔案artifactory到/etc/init.d/artifactory

Logs 資料夾

Creates the folder $ARTIFACTORY_HOME/logs, makes it writable for the user ARTIFACTORY_USER and creates a soft link $ARTIFACTORY_HOME/logs.
The $ARTIFACTORY_HOME/tomcat/logs folder is linked to $ARTIFACTORY_HOME/logs/catalina.

Backup 資料夾

Creates the folder $ARTIFACTORY_HOME/backup, so you must create a link if you want this folder to point to a different place (such as /var/backup/artifactory for example). The script makes $ARTIFACTORY_HOME/backup writable for the user ARTIFACTORY_USER

Data folder

Creates the folder $ARTIFACTORY_HOME/data, so you must create a link if you want this folder to point to somewhere else. The script makes it writable for the user ARTIFACTORY_USER.

chkconfig calls

The script calls add and list (you can see the output), and then activates the Artifactory service

一些配置

參考:Artifactory的搭建與使用簡介
[用artifactory搭建maven2內部伺服器 .
](http://blog.csdn.net/madun/article/details/8961659)
預設管理員:admin/password

相關文章