製品倉庫系統有不少,例如Artifactory、Archiva、Sonatype Nexus、Eclipse Package Drone,其中Artifactory擁有不少強大的企業級特性和人性化的用戶接口,擁有衆多客戶羣。不少大型的公司都在使用它,經過如下的Google趨勢圖能夠看出,它愈來愈受青睞。功能對比在此:Binary Repository Manager Feature Matrixjavascript
官方正版license,3個 License 25900美圓(16.7萬人民幣)一年,貴的離譜。本文以實驗學習爲主使用最新破解版4.7.4,破解也很是容易就不贅述了。商業用途,請使用正版。css
Artifactory集羣須要如下硬件設備:html
集羣中全部的節點最好處於同一局域網內,節點之間使用固定端口傳輸數據。java
本文使用阿里雲ECS服務器,申請三臺阿里雲ECS服務器分別取名artifactory-master,artifactory-slave,artifactory-nfs。node
artifactory會部署在artifactory-master和artifactory-slave上,須要安裝所需的軟件。mysql
安裝JDK 8。nginx
apt-get install software-properties-common add-apt-repository ppa:webupd8team/java apt-get update apt-get install oracle-java8-installer
編輯.bashrc文件vi ~/.bashrc
在文件尾加入如下內容:git
if [ -f ~/.bash_env ]; then . ~/.bash_env fi
建立.bash_env
文件touch ~/.bash_env
並添加JAVA_HOME環境變量:github
export JAVA_HOME=/usr/lib/jvm/java-8-oracle export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib export PATH=$JAVA_HOME/bin:$PATH
上傳artifactory-pro-4.7.4.zip到artifactory-master和artifactory-slave服務器/opt
目錄並解壓,並生成兩個不一樣的artifactory.lic
許可證,分別放在/opt/artifactory-pro-4.7.4/etc目錄下。web
scp artifactory-pro-4.7.4.zip root@<ip>:/opt
分別在artifactory兩個節點設置artifactory環境變量,編輯.bash_env
文件。
export ARTIFACTORY_HOME=/opt/jfrog/artifactory-pro-4.7.4 export JAVA_HOME=/usr/lib/jvm/java-8-oracle export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib export PATH=$JAVA_HOME/bin:$PATH
安裝artifactory as service。
sh installService.sh passwd artifactory <new password>
NFS配置須要在artifactory-nfs上安裝NFS服務端,須要在artifactory-master和artifactory-salve上安裝NFS客戶端。
在artifactory-nfs服務器上安裝nfs-kernel-server。
apt-get install nfs-kernel-server
在/etc/exports文件裏增長一行。
/artifactory/cluster-home *(rw,sync,no_root_squash,no_subtree_check)
在artifactory-master和artifactory-salve分別安裝NFS客戶端。
apt-get install nfs-common portmap
在artifactory-master和artifactory-salve分別建立NFS待掛載目錄/artifactory/cluster-home。
mkdir /artifactory/cluster-home mount <artifactory-nfs' IP>:/artifactory/cluster-home /artifactory/cluster-home
將NFS目錄分配權限。
chown -R artifactory:artifactory /artifactory/cluster-home
在artifactory-nfs上安裝MySQL。
安裝MySQL。
apt-get install mysql-server mysql-client mysql> CREATE DATABASE artdb CHARACTER SET utf8 COLLATE utf8_bin; CREATE USER artifactory IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON *.* TO 'artifactory'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; FLUSH PRIVILEGES;
容許MySQL遠程訪問。修改雲主機上的/etc/mysql/my.cnf 文件,註釋掉 bind_address=127.0.0.1就能夠了,而後重啓MySQL。
在/artifactory/cluster-home
下建立一下目錄:
mkdir ha-etc mkdir ha-data mkdir ha-backup
在./ha-etc
下建立文件cluster.properties
,內容爲:
##隨機生成的token,保證惟一就行 security.token=4n4tpxip7spQQu2pKf3811S2W7GY46Yb
在./ha-etc
下建立文件storage.properties
,內容爲:
type=mysql driver=com.mysql.jdbc.Driver url=jdbc:mysql://<artifactory-nfs' IP>:3306/artdb?characterEncoding=UTF-8&elideSetAutoCommits=true username=artifactory password=password
複製artifactory.system.properties
和mimetypes.xml
文件
mv /opt/jfrog/artifactory-pro-4.7.4/etc/artifactory.system.properties /artifactory/cluster-home/ha-etc mv /opt/jfrog/artifactory-pro-4.7.4/etc/mimetypes.xml /artifactory/cluster-home/ha-etc
在/opt/artifactory-pro-4.7.4/etc目錄下建立ha-node.properties
文件,內容以下:
node.id=art1 cluster.home=/artifactory/cluster-home context.url=http://<artifactory-master's IP>:8081/artifactory membership.port=10001 primary=true
在.bash_env
文件添加$CLUSTER_HOME環境變量。
export ARTIFACTORY_HOME=/opt/jfrog/artifactory-pro-4.7.4 export CLUSTER_HOME=/artifactory/cluster-home export JAVA_HOME=/usr/lib/jvm/java-8-oracle export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib export PATH=$JAVA_HOME/bin:$PATH
注意:對於每一個artifactory集羣節點使用的artifactory.lic是不同的,否者將會報錯。
在/opt/artifactory-pro-4.7.4/etc目錄下建立ha-node.properties
文件,內容以下:
node.id=art2 cluster.home=/artifactory/cluster-home context.url=http://<artifactory-slave's IP>:8081/artifactory membership.port=10001 primary=false
在.bash_env文件添加$CLUSTER_HOME
環境變量。
export ARTIFACTORY_HOME=/opt/jfrog/artifactory-pro-4.7.4 export CLUSTER_HOME=/artifactory/cluster-home export JAVA_HOME=/usr/lib/jvm/java-8-oracle export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib export PATH=$JAVA_HOME/bin:$PATH
Nginx也支持粘性會話如使用ip_hash
等,可是最好的方案是藉助第三份中間件例如Redis來存儲session,使用Nginx+Tomcat+Redis組合。在此我使用最簡單的ip_hash
方法。Nginx的/etc/nginx/nginx.conf文件配置:
##/etc/nginx/nginx.conf user www-data; worker_processes 8; error_log /var/log/nginx/error.log crit; pid /run/nginx.pid; events { use epoll; worker_connections 8192; } http { include /etc/nginx/mime.types; default_type application/octet-stream; charset utf-8; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; keepalive_timeout 30; sendfile on; tcp_nopush on; tcp_nodelay on; # gzip壓縮功能設置 gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/json application/xml application/x-javascript text/css text/xml text/javascript; gzip_vary on; #容許客戶端請求的最大的單個文件字節數 client_max_body_size 10m; #緩衝區代理緩衝用戶端請求的最大字節數 client_body_buffer_size 128k; #跟後端服務器鏈接的超時時間_發起握手等候響應超時時間 proxy_connect_timeout 600; #鏈接成功後_等候後端服務器響應時間_其實已經進入後端的排隊之中等候處理 proxy_read_timeout 600; #後端服務器數據回傳時間_就是在規定時間以內後端服務器必須傳完全部的數據 proxy_send_timeout 600; #代理請求緩存區_這個緩存區間會保存用戶的頭信息以供Nginx經行規則處理_通常只要能保存下頭信息便可 proxy_buffer_size 16k; #Nginx保存單個用的幾個Buffer及最大用多大空間 proxy_buffers 4 32k; #若是系統很忙的時候能夠申請最大的proxy_buffers proxy_busy_buffers_size 64k; #proxy緩存臨時文件的大小 proxy_temp_file_write_size 64k; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
##/etc/nginx/site-available/default upstream artifactory { ip_hash; server <ip>:<port>; server <ip>:<port>; } server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.html index.htm; # Make site accessible from http://localhost/ server_name localhost; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } location /artifactory { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Url-Scheme $scheme; proxy_redirect off; proxy_pass http://artifactory; } # Media: images, icons, video, audio, HTC location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc| woff)$ { expires 1M; access_log off; add_header Cache-Control "public"; proxy_pass http://artifactory; } # CSS and Javascript location ~* \.(?:css|js)$ { expires 1M; access_log off; add_header Cache-Control "public"; proxy_pass http://artifactory; } }
su - artifactory service artifactory start
Artifactory容許支持不一樣地區不一樣項目之間artifactory實例複製。帶來的好處有如下幾點:
用於本地倉庫,上傳到某個artifactory實例的某個本地倉庫可以同步到其餘遠程artifactory倉庫裏面。
用於遠程倉庫,將遠程artifactory倉庫同步到本地artifactory某個倉庫。
服務器有限,在artifactory-master上安裝Mission Control。
wget https://akamai.bintray.com/84/842469ab2f8d53dcd01e99c1f96b39b7580571a20096f741446e5c789ff2bca5?__gda__=exp=1462285257~hmac=76ab0b04df1b8b374bd539b83e246f8fe00ad8be57d7d7e47138b9ffb1b13a78&response-content-disposition=attachment%3Bfilename%3D%22jfrog-mission-control-1.1.deb%22&response-content-type=application%2Fx-debian-package apt-get install net-tools dpkg -i jfrog-mission-control-1.1.deb
在artifactory-slave上安裝Jenkins
wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt-get update sudo apt-get install jenkins
安裝jenkins packer plugin
apt-get install docker.io
把jenkins用戶加入到docker的group裏面。
gpasswd -a jenkins docker
apt-get install openssl mkdir /etc/nginx/ssl openssl genrsa -out "/etc/nginx/ssl/artifactory.key" 2048 openssl req -new -key "/etc/nginx/ssl/artifactory.key" -out "/etc/nginx/ssl/artifactory.csr" openssl x509 -req -days 365 -in "/etc/nginx/ssl/artifactory.csr" -signkey "/etc/nginx/ssl/artifactory.key" -out "/etc/nginx/ssl/artifactory.crt"
upstream artifactory { ip_hash; server <IP>:<PORT>; server <IP>:<PORT>; } server { listen 80; server_name <IP>; if ($http_x_forwarded_proto = '') { set $http_x_forwarded_proto $scheme; } rewrite ^/$ /artifactory/webapp/ redirect; rewrite ^/artifactory/?(/webapp)?$ /artifactory/webapp/ redirect; location /artifactory/ { proxy_read_timeout 900; proxy_pass_header Server; proxy_cookie_path ~*^/.* /; proxy_pass http://artifactory/artifactory/; proxy_set_header X-Artifactory-Override-Base-Url $http_x_forwarded_proto://$host:$server_port/artifactory; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server { listen 443 ssl; server_name <IP>; ssl on; ssl_certificate /etc/nginx/ssl/artifactory.crt; ssl_certificate_key /etc/nginx/ssl/artifactory.key; ssl_session_cache shared:SSL:1m; ssl_prefer_server_ciphers on; if ($http_x_forwarded_proto = '') { set $http_x_forwarded_proto $scheme; } rewrite ^/$ /artifactory/webapp/ redirect; rewrite ^/artifactory/?(/webapp)?$ /artifactory/webapp/ redirect; location /artifactory/ { proxy_read_timeout 900; proxy_pass_header Server; proxy_cookie_path ~*^/.* /; proxy_pass http://artifactory/artifactory/; proxy_set_header X-Artifactory-Override-Base-Url $http_x_forwarded_proto://$host:$server_port/artifactory; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }