逝者如斯夫

静而思之
数据加载中……

2013年11月3日

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 阅读(1270) | 评论 (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 阅读(5527) | 评论 (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 阅读(3235) | 评论 (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 阅读(566) | 评论 (0)编辑 收藏

ditaa

 

ditaa is a small command-line utility written in Java, that can
convert diagrams drawn using ascii art ('drawings' that contain
characters that resemble lines like | / - ), into proper
bitmap graphics. This is best illustrated by the following
example -- which also illustrates the benefits of using ditaa in
comparison to other methods :)

    +--------+   +-------+    +-------+
    |        | --+ ditaa +--> |       |
    |  Text  |   +-------+    |diagram|
    |Document|   |!magic!|    |       |
    |     {d}|   |       |    |       |
    +---+----+   +-------+    +-------+
        :                         ^
        |       Lots of work      |
        +-------------------------+
After conversion using ditaa, the above
file becomes:
round 		corner demo

ditaa interprets ascci art as a series of open and closed
shapes, but it also uses special markup syntax to increase the
possibilities of shapes and symbols that can be rendered.

ditaa is open source and free software (free as in free
speech), since it is released under the GPL license.

BUT WHY? Does this thing have any real use?

There are several reasons why I did this:

  1. Simply for hack value. I wanted to know if/how it could be
    done and how easily.
  2. Aesthetic reasons and legacy formats: there are
    several old FAQs with ascii diagrams lying out there. At this
    time and age ascii diagrams make my eyes hurt due to their
    ugliness. ditaa can be used to convert them to something
    nicer. Although ditaa would not be able to convert all of them
    (due to differences in drawing 'style' in each case), it could
    prove useful in the effort of modernising some of those
    documents without too much effort. I also know a lot of people
    that can make an ascii diagram easily, but when it gets to using
    a diagram program, they don't do very well. Maybe this utility
    could help them make good-looking diagrams easily/quickly.
  3. Embedding diagrams to text-only formats: There is a
    number of formats that are text-based (html, docbook, LaTeX,
    programming language comments), but when rendered by other
    software (browsers, interpreters, the javadoc tool etc), they
    can contain images as part of their content. If ditaa was
    intergrated with those tools (and I'm planning to do the javadoc
    bit myself soon), then you would have readable/editable diagrams
    within the text format itself, something that would make things
    much easier. ditaa syntax can currently be embedded to HTML.
  4. Reusability of "code": Suppose you make a diagram in
    ascii art and you render it with version 0.6b of ditaa. You keep
    the ascii diagram, and then version 0.8 comes out, which
    features some new cool effects. You re-render your old diagram
    with the new version of ditaa, and it looks better, with zero
    effort! In that sense ditaa is a diagram markup language, with
    very loose syntax.


Download

(((-intro-))) (((-download-))) (((-usage and syntax-))) (((-friends-))) (((-contact-)))

The latest version of ditaa can be obtained from its SourceForge project page.

You can checkout the code using:

   svn co https://ditaa.svn.sourceforge.net/svnroot/ditaa ditaa

You can also browse the code online.


Usage and syntax

(((-intro-))) (((-download-))) (((-usage and syntax-))) (((-friends-))) (((-contact-)))

Command line

You need the latest Java runtimes (JRE) to use ditaa. The best
anti-aliasing can be achieved using Java 1.5 or higher.

To start from the command line, type (where XXX is the version number):

java -jar ditaaXXX.jar

You will be presented with the command-line options help:

 -A,--no-antialias          Turns anti-aliasing off.
 -d,--debug                 Renders the debug grid over the resulting
                            image.
 -E,--no-separation         Prevents the separation of common edges of
                            shapes. You can see the difference below:
+---------+
| cBLU    |
|         |
|    +----+
|    |cPNK|
|    |    |
+----+----+
			
Before processingCommon edge
separation (default)
No separation
(with the -E option)
 -e,--encoding <ENCODING>   The encoding of the input file.
 -h,--html                  In this case the input is an HTML file. The
                            contents of the <pre class="textdiagram"> tags
                            are rendered as diagrams and saved in the
                            images directory and a new HTML file is
                            produced with the appropriate <img> tags.
                            See the HTML section.
    --help                  Prints usage help.
 -o,--overwrite             If the filename of the destination image
                            already exists, an alternative name is chosen.
                            If the overwrite option is selected, the image
                            file is instead overwriten.
 -r,--round-corners         Causes all corners to be rendered as round
                            corners.
 -s,--scale <SCALE>         A natural number that determines the size of
                            the rendered image. The units are fractions of
                            the default size (2.5 renders 1.5 times bigger
                            than the default).
 -S,--no-shadows            Turns off the drop-shadow effect.
 -t,--tabs <TABS>           Tabs are normally interpreted as 8 spaces but
                            it is possible to change that using this
                            option. It is not advisable to use tabs in
                            your diagrams.
 -v,--verbose               Makes ditaa more verbose.

Syntax

Round corners

If you use / and \ to connect corners, they are rendered as
round corners:

/--+
|  |
+--/
		  
round corner demo
Before processingRendered

Color

Color codes can be used to add color to the diagrams. The
syntax of color codes is

cXXX

where XXX is a hex number. The first digit of the number
represents the red compoment of the color, the second digit
represents green and the third blue (good ol' RGB). See below for
an example of use of color codes:

/----\ /----\
|c33F| |cC02|
|    | |    |
\----/ \----/

/----\ /----\
|c1FF| |c1AB|
|    | |    |
\----/ \----/
		  
color demo
Before processingRendered

This can become a bit tedious after a while, so there are (only
some for now) human readable color codes provided:

Color codes
/-------------+-------------\
|cRED RED     |cBLU BLU     |
+-------------+-------------+
|cGRE GRE     |cPNK PNK     |
+-------------+-------------+
|cBLK BLK     |cYEL YEL     |
\-------------+-------------/
color code
Before processingRendered

As you can see above, if a colored shape contains any text, the
color of the text is adjusted according to the underlying
color. If the undelying color is dark, the text color is changed
to white (from the default black).

Note that color codes only apply if they are within closed
shapes, and they have no effect anywhere outside.

Tags

ditaa recognises some tags that change the way a rectangular
shape is rendered. All tags are between { and }. See the table below:

NameOriginalRenderedComment
Document
+-----+
|{d}  |
|     |
|     |
+-----+
		  
Symbol representing a document.
Storage
+-----+
|{s}  |
|     |
|     |
+-----+
		  
Symbol representing a form of storage,
like a
database or a hard disk.
Input/Output
+-----+
|{io} |
|     |
|     |
+-----+
		  
Symbol representing input/output.

Dashed lines

Any lines that contain either at least one = (for horizontal
lines) or at least one : (for vertical lines) are rendered as
dashed lines. Only one of those characters can make a whole line
dashed, so this feature "spreads". The rationale behind that is
that you only have to change one character to switch from normal
to dashed (and vice versa), rather than redrawing the whole
line/shape. Special symbols (like document or storage symbols) can
also be dashed. See below:

----+  /----\  +----+
    :  |    |  :    |
    |  |    |  |{s} |
    v  \-=--+  +----+
Before processingRendered

Point markers

If * is encountered on a line (but not at the end of the
line), it is rendered as a special marker, called the point
marker (this feature is still experimental). See below:

*----*
|    |      /--*
*    *      |
|    |  -*--+
*----*
point marker demo
Before processingRendered

Text handling

(This section is still being written)

If the pattern ' o XXXXX' is encountered, where XXXXX is any
text, the 'o' is interpreted and rendered as a bullet point. Note
that there must be a space before the 'o' as well as after it. See
below:

/-----------------\
| Things to do    |
| cGRE            |
| o Cut the grass |
| o Buy jam       |
| o Fix car       |
| o Make website  |
\-----------------/
bullet point demo
Before processingRendered

 

HTML mode

When ditaa is run using the --html option, the input
is an HTML file. The contents of the <pre
class="textdiagram">
tags are rendered as diagrams and
saved in the images directory and a new HTML file is
produced with the appropriate <img> tags.

If the id parameter is present in the
<pre> tag, its value is used as the filename of the
rendered png. Otherwise a filename of the form
ditaa_diagram_X.png is used, where X is a
number. Similarly, if there is no output filename specified, the
converted html file is named in the form of
xxxx_processed.html, where xxxx is the filename of the
original file.

In this mode, files that exist are not generated again, they
are just skipped. You can force overwrite of the files using the
--overwrite option.

posted @ 2013-11-03 15:21 ideame 阅读(508) | 评论 (0)编辑 收藏

How to install ZXing in Xcode 4

  • April 2011
  • Posted By Yannick Loriot
  • 81 Comments

After an upgrading to Xcode 4, I have been having trouble compiling my own ZXing iOS project. That’s why I decided to explain you how to install easily ZXing with Xcode 4.

First of all (for those who don’t know), ZXing is an open-source library to read the 1D/2D barcodes. This library is available on many platforms such as the iOS, Android, Blackberry, ect. You can find it here: http://code.google.com/p/zxing/.

Before to start, be sure that you have the latest version of ZXing on your computer. If you don’t, you must download it via a SVN client here: http://zxing.googlecode.com/svn/trunk/.

 

To use ZXing into your project in Xcode 4 follow these steps:

  1. Firstly go to the “zxing/iphone/ZXingWidget/” and drag and drop the ZXingWidget.xcodeproj file onto your Xcode “Project navigator” sidebar. If a dialog appears uncheck the “Copy items” and verify that the “Reference Type” is “Relative to Project” before clicking “Add”.

  2. Now we are going to add ZXingWidget as a dependency of your project to allow Xcode to compile it whenever you compile the main project:
    1. First select your project file in the “Project navigator”.
    2. Then select the corresponding target.
    3. After choose the “Build Phases” tab and expand the “Target Dependencies” section.
    4. Click the “+” (add) button to display a dialog.
    5. To finish add the “ZXingWidget” target as shown above.

  3. Now we are going to link the ZXingWidget static library (libZXingWidget.a) to the project:
    1. Firstly choose the “Build Phases” tab and expand the “Link Binary With Libraries” section.
    2. Then click the “+” (add) button to display a dialog.
    3. To finish add the “libZXingWidget.a” which is located in the “Workspace” category as shown above.
    4. By the way add the following iOS frameworks too:
      • AddressBook
      • AddressBookUI
      • AudioToolbox
      • AVFoundation
      • CoreMedia
      • CoreVideo
      • libiconv.dylib

  4. Then you must configure the header search path of your project to allow Xcode to find the ZXingWidget headers. To do that:
    1. In the “Project navigator” select the main project (not the target).
    2. Go to the “Build Settings” tab and search the “Header Search Paths“.
    3. Double-click on it and add:
      • The full path of the “zxing/iphone/ZXingWidget/Classes” directory. Check the “recursive path“.
      • The full path of the “zxing/cpp/core/src/” directory. Uncheck the “recursive path“.

Now you just have to import the “ZXingWidgetController.h” and the “QRCodeReader.h” to your project and use them.
Attention: Make sure that the files in which you are using the ZXing headers have the .mm extension because they use c++ library files.

Voilà! Now all should be ok. I hope it’ll help you!

1 Star 2 Stars 3 Stars 4 Stars 5 Stars (33 votes, average: 4.55 out of 5)

http://yannickloriot.com/2011/04/how-to-install-zxing-in-xcode-4/

posted @ 2013-11-03 14:45 ideame 阅读(371) | 评论 (0)编辑 收藏