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"