如何在CentOS 7上安装JFrog Artifactory

时间:2020-02-23 14:30:44  来源:igfitidea点击:

本指南将引导我们完成在CentOS 7上安装JFrog Artifactory的步骤。JFrog Artifactory是世界上最先进的存储库管理器,它完全支持以任何语言或者使用任何工具创建的软件。

JFrog Artifactory旨在与大多数持续集成和交付工具集成,以提供端到端自动化解决方案,以跟踪从开发到生产的工件。提供了许多开放源代码插件,使我们可以轻松地扩展Artifactory的功能并与其他工具集成。例如Jenkins,TeamCity,Bamboo,Maven,Bower和Gradle等。

有两种在CentOS 7上安装Artifactory的方法:使用Docker从RPM软件包安装

方法1:使用Docker安装JFrog Artifactory

对于Docker安装,以下是使用步骤:

安装Docker Engine

使用我们之前的指南安装Docker:如何在Ubuntu/Debian/Fedora/Arch/CentOS上安装Docker CE

下载JFrog Artifactory Docker镜像

拉取JFrog Artifactory的最新Docker镜像。

docker pull docker.bintray.io/jfrog/artifactory-oss:latest

对于CE版:

docker pull docker.bintray.io/jfrog/artifactory-cpp-ce

确认Docker镜像:

$docker images
REPOSITORY                                   TAG                 IMAGE ID            CREATED             SIZE
docker.bintray.io/jfrog/artifactory-cpp-ce   latest              24d943a892ac        43 hours ago        582MB
docker.bintray.io/jfrog/artifactory-oss      latest              58d49856785f        43 hours ago        582MB

建立资料目录

在主机系统上创建数据目录,以确保容器上使用的数据是持久性的。

sudo mkdir -p /jfrog/artifactory
sudo chown -R 1030 /jfrog/

启动JFrog Artifactory容器

要启动Artifactory容器,请使用以下命令:

docker run --name artifactory -d -p 8081:8081 \
  -v /jfrog/artifactory:/var/opt/jfrog/artifactory \
  docker.bintray.io/jfrog/artifactory-oss:latest

我们可以使用EXTRA_JAVA_OPTIONS将Java系统属性传递给运行Artifactory的JVM。在Docker setuplink上查看更多信息。参见下面的示例。

$docker run --name artifactory -d -p 8081:8081 \
   -v /jfrog/artifactory:/var/opt/jfrog/artifactory \
   -e EXTRA_JAVA_OPTIONS='-Xms512m -Xmx2g -Xss256k -XX:+UseG1GC' \
   docker.bintray.io/jfrog/artifactory-oss:latest

使用docker ps命令查看容器信息。

使用Systemd运行JFrog Artifactory容器

Systemd是CentOS 7的默认初始化系统。我们可以使用它来管理JFrog Artifactory容器。

创建Artifactory服务单元文件。

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

添加:

[Unit]
Description=Setup Systemd script for Artifactory Container
After=network.target

[Service]
Restart=always
ExecStartPre=-/usr/bin/docker kill artifactory
ExecStartPre=-/usr/bin/docker rm artifactory
ExecStart=/usr/bin/docker run --name artifactory -p 8081:8081 \
  -v /jfrog/artifactory:/var/opt/jfrog/artifactory \
  docker.bintray.io/jfrog/artifactory-oss:latest
ExecStop=-/usr/bin/docker kill artifactory
ExecStop=-/usr/bin/docker rm artifactory

[Install]
WantedBy=multi-user.target

重新加载systemd。

sudo systemctl daemon-reload

然后使用systemd启动Artifactory容器。

sudo systemctl start artifactory

启用它以在系统引导时启动。

sudo systemctl enable artifactory

可以通过以下方式检查状态:

sudo systemctl status artifactory

还要检查服务绑定:

$ss -tunelp | grep 8081

访问Artifactory Web界面

可以使用以下URL访问Artifactory:

http://SERVERIP_OR_DOMAIN:8081/artifactory

请遵循以下安装说明。

选择要为其创建默认存储库的软件包类型。

以后可以跳过设置。

单击完成按钮以完成安装。

配置Nginx反向代理(可选)

如果我们想将Nginx用作SSL代理,请查看以下指南:

在Nginx反向代理后面配置JFrog Artifactory,并让SSL加密

方法2:使用RPM安装JFrog Artifactory

这是从RPM软件包在CentOS 7上安装JFrog Artifactory所需的步骤。

安装Java

使用以下命令在CentOS上安装Java:

sudo yum -y install java-1.8.0-openjdk  java-1.8.0-openjdk-devel
sudo alternatives --config java
java -version

第2步:设置JAVA_HOME

安装Java之后,设置JAVA_HOME环境变量。

在CentOS/RHEL/Fedora上设置JAVA_HOME

安装和配置数据库服务器

安装MariaDB数据库服务器:

在CentOS 7上安装MariaDB Server

添加JFrog Artifactory RPM存储库

JFrog Artifactory软件包可在官方资料库中获得。通过运行添加它:

curl -sL https://bintray.com/jfrog/artifactory-rpms/rpm | sudo tee /etc/yum.repos.d/bintray-jfrog-artifactory-rpms.repo

该存储库适用于Artifactory CE和Artifactory OSS版本。

在CentOS 7上安装JFrog Artifactory

安装JFrog Artifactory只需运行yum命令并指定要安装的Artifactory版本。

安装JFrog Artifactory OSS:

sudo yum -y install jfrog-artifactory-oss wget

安装JFrog Artifactory CE:

sudo yum -y install jfrog-artifactory-cpp-ce wget

设置" ARTIFACTORY_HOME"。

echo "export ARTIFACTORY_HOME=/opt/jfrog/artifactory" | sudo tee -a /etc/profile
source /etc/profile
env | grep ARTIFACTORY_HOME

文件和文件夹位置:

从RPM发行版安装时,Artifactory保留FHS(文件系统层次结构标准)格式:

Tomcat home/opt/jfrog/artifactory/tomcatartifactory (root for sub dirs)
Artifactory startup script/etc/init.d/artifactoryroot
Artifactory logs/var/opt/jfrog/artifactory/logsartifactory
Artifactory home/var/opt/jfrog/artifactoryartifactory
Artifactory etc/etc/opt/jfrog/artifactoryartifactory
Artifactory env variables/etc/opt/jfrog/artifactory/defaultartifactory
Artifactory binary/opt/jfrog/artifactoryroot

配置Artifactory以使用MariaDB

1.复制Artifactory数据库配置模板。

sudo mkdir /var/opt/jfrog/artifactory/etc
sudo cp /opt/jfrog/artifactory/misc/db/mariadb.properties /var/opt/jfrog/artifactory/etc/db.properties

2.运行MariaDB配置脚本。

sudo /opt/jfrog/artifactory/bin/configure.mysql.sh

提供root密码并设置Artifactory用户密码,然后同意下载Artifactory。

########################################################
# Welcome to the Artifactory MySQL configuration tool! #
########################################################

Please enter the MySQL server admin username [root]: <Enter root password>

Please enter the MySQL server admin password: <Set ArtifactoryAdminPassoword>
Please enter the Artifactory database username [artifactory]: 

Please enter the Artifactory database password [password]: 
Creating the Artifactory MySQL user and database...

No MySQL JDBC connector found. Download or copy one needed.
Does the current server has access to the Internet? [Y/n] y

Downloading mysql-connector-java-5.1.24.jar to /opt/jfrog/artifactory/tomcat/lib...

Configuration completed successfully!
You can now start up the Artifactory service to use Artifactory with MySQL.
Press enter to exit...

启动Artifactory服务:

sudo systemctl start artifactory.service
sudo systemctl enable artifactory.service

检查服务状态:

$sudo systemctl status  artifactory.service
 ● artifactory.service - Setup Systemd script for Artifactory in Tomcat Servlet Engine
    Loaded: loaded (/usr/lib/systemd/system/artifactory.service; enabled; vendor preset: disabled)
    Active: active (running) since Wed 2019-04-10 10:31:16 CEST; 36s ago
   Process: 5091 ExecStop=/opt/jfrog/artifactory/bin/artifactoryManage.sh stop (code=exited, status=0/SUCCESS)
   Process: 5164 ExecStart=/opt/jfrog/artifactory/bin/artifactoryManage.sh start (code=exited, status=0/SUCCESS)
  Main PID: 5213 (java)
    CGroup: /system.slice/artifactory.service
            ‣ 5213 /usr/bin/java -Djava.util.logging.config.file=/opt/jfrog/artifactory/tomcat/conf/logging.properties -Djava.util.logging.manager=or…
 Apr 10 10:31:16 artifactory artifactoryManage.sh[5164]: + runReplicator
 Apr 10 10:31:16 artifactory artifactoryManage.sh[5164]: + '[' '' == true ']'
 Apr 10 10:31:16 artifactory artifactoryManage.sh[5164]: + return 1
 Apr 10 10:31:16 artifactory artifactoryManage.sh[5164]: + startMetadata
 Apr 10 10:31:16 artifactory artifactoryManage.sh[5164]: + runMetadata
 Apr 10 10:31:16 artifactory artifactoryManage.sh[5164]: + '[' '' == true ']'
 Apr 10 10:31:16 artifactory artifactoryManage.sh[5164]: + return 1
 Apr 10 10:31:16 artifactory artifactoryManage.sh[5164]: + '[' 0=0 ']'
 Apr 10 10:31:16 artifactory artifactoryManage.sh[5164]: + exit 0
 Apr 10 10:31:16 artifactory systemd[1]: Started Setup Systemd script for Artifactory in Tomcat Servlet Engine.

访问Artifactory Web界面

可以使用以下URL访问Artifactory:

http://SERVERIP_OR_DOMAIN:8081/artifactory

我们应该看到Artifactory欢迎页面。