逝者如斯夫

静而思之
数据加载中……

2014年2月28日

Docker Registry 安装和运行

使用场景

  • 内部网络,无法访问 Docker Hub
  • 控制 image 的存储方式和存储位置
  • 控制 image 的部署流程
  • 内部开发流程需要集成控制 image 的部署和存储

应用逻辑示意图:

安装 Registry 服务

概要

Docker Registry 在 docker hub 的名称是 registry。v1 版本的源码地址 github.com/docker/docker-registry 已经废弃,v2 版本源码地址在 github.com/docker/distribution,对应的 API 是 Docker Registry HTTP API V2

以下安装没有使用 HTTPS 方式,启用 HTTPS 相关的证书配置参考这个文档:

官方文档参考:

最简安装(启动)

docker run -d -p 5000:5000 --name registry registry:2

以上命令未使用用户名密码登录策略。

启用登录密码

生成密码

登录密码可以通过 host 的文件传入,以下命令调用容器的 htpasswd 命令生成密码文件:

mkdir auth
docker run --entrypoint htpasswd registry:2 \
    -Bbn <USER_NAME> <PASSWORD> > auth/auth.htpasswd

启用密码

通过 –volume 参数传入密码文件:

docker run -d -p 5000:5000 --restart=always --name registry \
  --volume `PWD`/auth:/auth \
  --env "REGISTRY_AUTH=htpasswd" \
  --env "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
  --env REGISTRY_AUTH_HTPASSWD_PATH=/auth/auth.htpasswd \
  registry:2

修改镜像存储

默认镜像数据存储在 Docker Volume 中,可以通过 bind mount 进行修改,参数信息参考 Volume文档。下面的例子将本机目录 PWD/images 绑定到容器的 /var/lib/registry

docker run -d -p 5000:5000 \
    --name auth-registry \
    -v `PWD`/images:/var/lib/registry \
    -e SQLALCHEMY_INDEX_DATABASE=sqlite:////opt/docker-image/docker-registry.db \
    -e STORAGE_PATH=/opt/docker-image \
    --restart=always \
    docker.onestch.com:5000/admin/registry:0.1

默认的存储引擎为本地文件系统,可以修改文件的存储引擎为 Amazon S3 bucket、Google Cloud Platform 或其他引擎,可以通过配置 config.yml 的方式修改存储配置,更多信息参考 Docker Registry 存储配置文档

停止服务

停止 registry 容器并清理运行数据

docker stop registry && \
docker rm -v registry

验证

查看容器信息

docker ps --no-trunc

查看全部配置信息或部分信息

docker inspect <CONTAINER_ID> 

docker inspect <CONTAINER_ID> | grep -C3 -e "Volumes\":"
docker inspect <CONTAINER_ID> | grep -C2 Binds
docker inspect -f '{{ .Mounts }}' <CONTAINER_ID>

查看映射的详细信息

docker volume inspect 4496b0a257b966052ef8d0743014a4f63fc9924251c8de0df0e9c70fde4c45e6

发布镜像

登录服务

如果安装(启动)的 registry 服务需要登录访问时,执行:

docker login <REGISTRY_HOST>:<REGISTRY_PORT>

输入安装时设定的用户名密码。

目标地址

使用 docker tag 设定镜像的目标地址,镜像的目标地址包括三部分

<HOST_NAME>[:<HOST_PORT>]/<IMAGE_NAME>:<IMAGE_VERSION>
  • HOST_NAME : HOST_PORT

    目标 registry 服务地址,缺省时使用官方 docker hub 的地址 registry-1.docker.io,且不允许包含下划线

  • IMAGE_NAME 发布目标镜像名称

  • IMAGE_VERSION 发布目标镜像版本

例如:repo.company.com:3456/myapp:0.1

发布镜像

发布的镜像文件可以从 docker hub 中 Pull 或者本地使用 Dockerfile build 获得

Pull

docker pull registry

Build

docker build -t docker.onestch.com:5000/admin/registry:0.1 .

首先需要对镜像 tag 设定目标仓库,如果 build 的时候已经设置了目标地址,可以不用进行 tag 操作

docker tag registry:latest docker.onestch.com:5000/admin/registry:0.1

然后 Push

docker push docker.onestch.com:5000/admin/registry:0.1

验证

重新从私有仓库中获取镜像

docker pull localhost:5000/admin/registry:0.1

0.1: Pulling from admin/registry
Digest: sha256:d738e358b6910d3a53c9c7ff7bbb5eac490ab7a9b12ffb4c1c27f2c53aae9275
Status: Image is up to date for localhost:5000/admin/registry:0.1

安装 Registry UI

选择 registry ui,可选的有 atcol/docker-registry-uihyper/docker-registry-webkonradkleine/docker-registry-frontend

安装运行

针对 hyper/docker-registry-web,使用 BASIC 认证,未使用 HTTPS的情况

docker run -it -p 8080:8080 \
    --rm \
    --name registry-web \
    --link auth-registry \
    -e REGISTRY_URL=http://auth-registry:5000/v2 \
    -e REGISTRY_AUTH_ENABLED=false \
    -e REGISTRY_BASIC_AUTH=YWRtaW46MTIzNDU2 \
    -e REGISTRY_NAME=docker.onestch.com:5000 hyper/docker-registry-web

命令中 auth-registry 是自定的 registry 镜像。

使用 HTTPS 时需要传入 /config/auth.key 文件,或自定义 config.xml 配置,例如:
docker run -it -p 8080:8080 –name registry-web \
–link auth-registry \
-v $(pwd)/config.yml:/conf/config.yml:ro \
hyper/docker-registry-web

管理界面

建立了 registry 服务后,对 registry 的管理界面在本机的访问地址是http://localhost:8080,一般 ui 服务会和 registry 服务同样运行在私有网络,所以我们可以发布 registry ui 到 registry 服务器再运行。

docker tag docker.io/hyper/docker-registry-web docker.onestch.com:5000/admin/docker-registry-web

docker push docker.onestch.com:5000/admin/docker-registry-web

查看 UI 界面如下图

posted @ 2018-08-03 11:49 ideame 阅读(1268) | 评论 (0)编辑 收藏

Zookeeper Cli 常用命令

服务管理

  • 启动ZK服务: zkServer.sh start
  • 查看ZK状态: zkServer.sh status
  • 停止ZK服务: zkServer.sh stop
  • 重启ZK服务: zkServer.sh restart

终端操作

使用 zkCli 可以简单的对 ZooKeeper 进行访问,数据创建,数据修改等操作. 连接命令行如下:

zkCli.sh -server 127.0.0.1:2181

命令行工具常用操作:

  • 显示根目录下文件

    ls /              //查看当前节点数据
    ls2 /             //查看当前节点数据并能看到更新次数等数据
    
  • 创建文件, 并设置初始内容:

    create /config "test" //创建一个新的节点并设置关联值
    create /config “”     //创建一个新的空节点
    
  • 获取文件内容

    get /brokers      //获取节点内容
    
  • 修改文件内容

    set /zk "zkbak"   //对 zk 所关联的字符串进行设置
    
  • 删除文件

    delete /brokers  //删除节点
    rmr    /brokers  //删除节点及子节点
    

四字命令

ZooKeeper 支持某些特定的四字命令字母与其的交互,用来获取服务的当前状态及相关信息。在客户端可以通过 telnet 或 nc 向 ZooKeeper 提交相应的命令。命令行如下:

echo conf | nc 132.37.3.26 26181

ZooKeeper 常用四字命令:

  • conf

    输出相关服务配置的详细信息

  • cons

    列出所有连接到服务器的客户端的完全的连接 / 会话的详细信息。包括“接受 / 发送”的包数量、会话 id 、操作延迟、最后的操作执行等等信息

  • dump

    列出未经处理的会话和临时节点。

  • envi

    输出关于服务环境的详细信息(区别于 conf 命令)。

  • reqs

    列出未经处理的请求

  • ruok

    测试服务是否处于正确状态。如果确实如此,那么服务返回“ imok ”,否则不做任何相应

  • stat

    输出关于性能和连接的客户端的列表。

  • wchs

    列出服务器 watch 的详细信息

  • wchc

    通过 session 列出服务器 watch 的详细信息,它的输出是一个与 watch 相关的会话的列表

  • wchp

    通过路径列出服务器 watch 的详细信息。它输出一个与 session 相关的路径

posted @ 2016-10-10 17:54 ideame 阅读(5526) | 评论 (0)编辑 收藏

JMH(Java Micro Benchmark) 简介

     摘要: JMH简介本文由 ImportNew - hejiani 翻译自 java-performance。JMH是新的microbenchmark(微基准测试)框架(2013年首次发布)。与其他众多框架相比它的特色优势在于,它是由Oracle实现JIT的相同人员开发的。特别是我想提一下Aleksey Shipilev和他优秀的博客文章。JMH可能与最新的Oracle JRE同步,其结果可信度很高。JMH...  阅读全文

posted @ 2016-08-01 17:12 ideame 阅读(3234) | 评论 (0)编辑 收藏

如何将 SVN 源码库转换为 Mercurial

如何将 SVN 源码库转换为 Mercurial [1]

首先得安装 Subversion 库函数

				    wget http://mirrors.hust.edu.cn/apache/subversion/subversion-1.8.8.tar.gz

    tar xzf subversion-1.8.8.tar.bz2 

    cd subversion-1.8.8

    subversion-1.8.8 aliang$ ./autogen.sh 
        buildcheck: checking installation...
        buildcheck: autoconf not found.
                    You need autoconf version 2.59 or newer installed.

    brew install autoconf
        ==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/autoconf-2.69.mavericks.bottle.tar.gz
        #################################################### 100.0%
        ==> Pouring autoconf-2.69.mavericks.bottle.tar.gz
        🍺 /usr/local/Cellar/autoconf/2.69: 69 files, 2.0M

    ./autogen.sh 
        buildcheck: checking installation...
        buildcheck: autoconf version 2.69 (ok)
        buildcheck: autoheader version 2.69 (ok)
        buildcheck: libtool not found.
        You need libtool version 1.4 or newer installed

    brew install libtool
        Warning: A newer Command Line Tools release is available
        Update them from Software Update in the App Store.
        ==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/libtool-2.4.2.mavericks.bottle.2.tar.gz
        ##################################################### 100.0%
        ==> Pouring libtool-2.4.2.mavericks.bottle.2.tar.gz
        ==> Caveats
        In order to prevent conflicts with Apple''s own libtool we have prepended a "g"
        so, you have instead: glibtool and glibtoolize.
        ==> Summary
        🍺  /usr/local/Cellar/libtool/2.4.2: 66 files, 2.2M

    ./autogen.sh 
        buildcheck: checking installation...
        buildcheck: autoconf version 2.69 (ok)
        buildcheck: autoheader version 2.69 (ok)
        buildcheck: libtool version 2.4.2 (ok)
        Copying libtool helper: /usr/local/share/aclocal/libtool.m4
        Copying libtool helper: /usr/local/share/aclocal/ltoptions.m4
        Copying libtool helper: /usr/local/share/aclocal/ltsugar.m4
        Copying libtool helper: /usr/local/share/aclocal/ltversion.m4
        Copying libtool helper: /usr/local/share/aclocal/lt~obsolete.m4
        Creating build-outputs.mk...
        Creating svn_private_config.h.in...
        Creating configure...

        You can run ./configure now.

        Running autogen.sh implies you are a maintainer.  You may prefer
        to run configure in one of the following ways:

        ./configure --enable-maintainer-mode
        ./configure --disable-shared
        ./configure --enable-maintainer-mode --disable-shared
        ./configure --disable-optimize --enable-debug
        ./configure CUSERFLAGS='--flags-for-C' CXXUSERFLAGS='--flags-for-C++'

        Note:  If you wish to run a Subversion HTTP server, you will need
        Apache 2.x.  See the INSTALL file for details.

    brew install swig
        ==> Downloading http://downloads.sourceforge.net/project/swig/swig/swig-2.0.11/swig-2.0.11.tar.gz
        ######################################################################## 100.0%
        ==> ./configure --prefix=/usr/local/Cellar/swig/2.0.11
        ==> make
        ==> make install
        🍺  /usr/local/Cellar/swig/2.0.11: 597 files, 6.2M, built in 10.1 minutes 

    ./configure --with-swig=/usr/local/bin/swig
        configure: Configuring Subversion 1.8.8
        ... ...
        ==================================================================
        WARNING: You have chosen to compile Subversion with a different
                 compiler than the one used to compile Apache.

            Current compiler:  gcc
           Apache's compiler:  /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc

        This could cause some problems.
        ==================================================================
        ... ...

    make swig-py
    make install
    make check-swig-py        
    sudo make install-swig-py

    sudo cp -r /usr/local/lib/svn-python/ /Library/Python/2.7/site-packages/

		

执行转换命令

				    mkdir hgpath

    cd hgpath

    hg init

    hg convert -s svn -d hg ${local_path} ./hgpath

		

注意,这里转换的 SVN 目录只能是仓库目录而不是工作目录

posted @ 2014-02-28 11:25 ideame 阅读(565) | 评论 (0)编辑 收藏