Nexus號稱是世界上最流行的私服管理軟件(The world's most popular repository),能夠搭建幾乎目前全部常見的倉庫如npm,maven,yum等,Nexus3更是增長了對docker倉庫的支持 ,應該是搭建私服的惟一選擇.css
Nexus有兩個版本 Nexus Repository OSS和Nexus Repository Pro,其中OSS版本是免費,Pro專業版須要收費.OSS對於平常的倉庫管理已經足夠用.html
Nexus OSS支持二進制文件安裝和docker安裝,這裏選擇docker安裝,簡單方便.java
運行如下命令便可完成安裝mysql
$ docker run -d -p 8081:8081 sonatype/nexus3 #能夠掛載本地目錄作數據持久化 $ mkdir /some/dir/nexus-data && chown -R 757 /some/dir/nexus-data $ docker run -d -p 8081:8081 -v /some/dir/nexus-data:/nexus-data sonatype/nexus3
在nexus3官方docker倉庫說明文檔裏掛載目錄設置的權限爲200
但實際安裝的時候沒法啓動,權限不夠,錯誤以下:linux
mkdir: cannot create directory '../sonatype-work/nexus3': Permission denied mkdir: cannot create directory '../sonatype-work/nexus3': Permission denied Java HotSpot(TM) 64-Bit Server VM warning: Cannot open file ../sonatype-work/nexus3/log/jvm.log due to Permission denied Warning: Cannot open log file: ../sonatype-work/nexus3/log/jvm.log Warning: Forcing option -XX:LogFile=/tmp/jvm.log Unable to update instance pid: Unable to create directory /nexus-data/instances /nexus-data/log/karaf.log (Permission denied) Unable to update instance pid: Unable to create directory /nexus-data/instances Exception in thread "Thread-2" java.lang.SecurityException: Could not lock User prefs. Lock file access denied. at java.util.prefs.FileSystemPreferences.checkLockFile0ErrorCode(FileSystemPreferences.java:937) at java.util.prefs.FileSystemPreferences.lockFile(FileSystemPreferences.java:925) at java.util.prefs.FileSystemPreferences.sync(FileSystemPreferences.java:729) at java.util.prefs.FileSystemPreferences.flush(FileSystemPreferences.java:824) at java.util.prefs.FileSystemPreferences.syncWorld(FileSystemPreferences.java:464) at java.util.prefs.FileSystemPreferences.access$1200(FileSystemPreferences.java:50) at java.util.prefs.FileSystemPreferences$4$1.run(FileSystemPreferences.java:442)
修改成757
後正常啓動.等待啓動完,訪問http://host:8081
測試是否安裝成功.sql
Nextus3倉庫都有三種類型docker
http://host:8081
登錄,默認用戶名密碼admin/admin123Repository->Blob Stores->Create blob store
建立本地存儲Type:file Name:definesys-docker-store Path:/nexus-data/blobs/definesys-docker-store
由於要存儲鏡像請保證該目錄下有足夠空間,能夠掛在NAS到該目錄下.npm
Repositories->Create repositories->docker(hosted)
建立本地倉庫Name(倉庫名稱):definesys-docker-repo Http(倉庫開放端口):8001 Docker Registry API Support:必須選上 Storage:選擇剛建立的definesys-docker-store 其他選項默認便可
這樣就完成一個docker私有倉庫的建立,過程仍是很簡單的.json
Repositories->Create repositories->docker(proxy)
建立代理倉庫Name(倉庫名稱):definesys-docker-proxy Http(倉庫開放端口):8002 Docker Registry API Support:必須選上 Proxy->remote storage:https://registry-1.docker.io/ Docker index選擇Use Docker Hub Storage:選擇剛建立的definesys-docker-store這樣就能夠和hosted共用一個存儲實現本地優先本地拉取本地找不到再從遠程倉庫拉取 其他選項默認便可
Name(倉庫名稱):definesys-docker-group Http(倉庫開放端口):8003 Docker Registry API Support:必須選上 Storage:選擇剛建立的definesys-docker-store Group: definesys-docker-repo definesys-docker-proxy 其他選項默認便可
daemon.json
文件$ vi /etc/docker/daemon.json { "insecure-registries": [ "http://localhost:7001", "http://localhost:7002", "http://localhost:7003" ], "disable-legacy-registry": true }
$ systemctl restart docker
$ docker run -d -p 8081:8081 -p 8001:8001 -p 8003:8003 -p 8002:8002 -v /root/u01/nexus-data:/nexus-data sonatype/nexus3
4.分別登錄三個倉庫ubuntu
$ docker login -u admin -p admin123 http://localhost:8001 $ docker login -u admin -p admin123 http://localhost:8002 $ docker login -u admin -p admin123 http://localhost:8003
Nexus會將登錄信息記錄在~/.docker/config.json
,這樣下次就不用再次登錄:
{ "auths": { "http://localhost:8003": { "auth": "YWRtaW46YWRtaW4xMjM=" }, "http://localhost:8001": { "auth": "YWRtaW46YWRtaW4xMjM=" }, "http://localhost:8002": { "auth": "YWRtaW46YWRtaW4xMjM=" } } }
$ docker tag docker.io/ubuntu:15.10 localhost:8001/defiensys-ubuntu:15.10 $ docker push localhost:8001/defiensys-ubuntu:15.10
#拉取docker hub上鏡像 $ docker pull localhost:8003/mysql #拉取私服鏡像 $ docker pull localhost:8003/defiensys-ubuntu:15.10
待續...
待續...
$ docker push localhost:8003/oraclelinux:v1.0 The push refers to a repository [localhost:8003/oraclelinux] 3b431d8f4cd1: Preparing error parsing HTTP 404 response body: invalid character '<' looking for beginning of value: "\n<!DOCTYPE html>\n<html>\n<head>\n <title>404 - Nexus Repository Manager</title>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n\n\n <!--[if lt IE 9]>\n <script>(new Image).src=\"http://localhost:8003/favicon.ico?3.13.0-01\"</script>\n <![endif]-->\n <link rel=\"icon\" type=\"image/png\" href=\"http://localhost:8003/favicon-32x32.png?3.13.0-01\" sizes=\"32x32\">\n <link rel=\"mask-icon\" href=\"http://localhost:8003/safari-pinned-tab.svg?3.13.0-01\" color=\"#5bbad5\">\n <link rel=\"icon\" type=\"image/png\" href=\"http://localhost:8003/favicon-16x16.png?3.13.0-01\" sizes=\"16x16\">\n <link rel=\"shortcut icon\" href=\"http://localhost:8003/favicon.ico?3.13.0-01\">\n <meta name=\"msapplication-TileImage\" content=\"http://localhost:8003/mstile-144x144.png?3.13.0-01\">\n <meta name=\"msapplication-TileColor\" content=\"#00a300\">\n\n <link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8003/static/css/nexus-content.css?3.13.0-01\"/>\n</head>\n<body>\n<div class=\"nexus-header\">\n <a href=\"http://localhost:8003\">\n <div class=\"product-logo\">\n <img src=\"http://localhost:8003/static/images/nexus.png?3.13.0-01\"/>\n </div>\n <div class=\"product-id\">\n <div class=\"product-id__line-1\">\n <span class=\"product-name\">Nexus Repository Manager</span>\n </div>\n <div class=\"product-id__line-2\">\n <span class=\"product-spec\">OSS 3.13.0-01</span>\n </div>\n </div>\n </a>\n</div>\n\n<div class=\"nexus-body\">\n <div class=\"content-header\">\n <img src=\"http://localhost:8003/static/rapture/resources/icons/x32/exclamation.png?3.13.0-01\"/>\n <span class=\"title\">Error 404</span>\n <span class=\"description\">Not Found</span>\n </div>\n <div class=\"content-body\">\n <div class=\"content-section\">\n Not Found\n </div>\n </div>\n</div>\n</body>\n</html>\n\n"