Sharing

2022年9月4日 星期日

Test

 



葉氏盃全國大賽四強下半第一牌,南北方一路氣勢磅礡的叫到大滿貫,在 18 IMP 的領先下實在是不樂見如此大牌。你坐在西家,首攻什麼?

古往今來眾所皆知,對抗大滿貫最好消極首攻,若非單張王一律建議敲王,但在機械化的敲王之前,先來描繪看看南北方的牌情吧。


測試 iframe:




BBO handviewer editor
https://www.bridgebase.com/tools/handviewer.html?editor=y


2014年12月31日 星期三

2014 Study Target

Python

Linux

Design Pattern

重構 (Re-factoring)

    • 重構 - 改善既有程式的設計 (Refactoring: Improving The Design of Existing code) Martin Fowler著,侯捷/熊節 譯
    • Java重構 結城浩 著,江珮齡/王元綱 譯
    • 重構 - 向範式前進 (Refactoring to Pattterns) Joshua Kerievsky 著,侯捷/陳裕城 譯

Storage

Hypervisor

Cloud

演算法

Programming Language

NoSQL



    2014年3月26日 星期三

    MAAS

    Official Site


    http://maas.ubuntu.com/docs/
    https://launchpad.net/maas



    Installation


    Precise 上預設的是 1.2 版, 裝起來後問題不少, 所以決定直接改用 Saucy (13.10) 安裝1.4 版, 安裝過程在文件上寫的滿清楚的, 還附圖, maas-dhcp/maas-dns 則是 optional, 就看環境中是否已經有存在的 dhcp/dns

    http://maas.ubuntu.com/docs/install.html

    每個 node 有一整個 life cycle, 在 /usr/share/pyshared/maasserver/enum.py 裡可以找到
    class NODE_STATUS:
        # A node starts out as READY.
        DEFAULT_STATUS = 0
        #: The node has been created and has a system ID assigned to it.
        DECLARED = 0
        #: Testing and other commissioning steps are taking place.
        COMMISSIONING = 1
        #: Smoke or burn-in testing has a found a problem.
        FAILED_TESTS = 2
        #: The node can't be contacted.
        MISSING = 3
        #: The node is in the general pool ready to be deployed.
        READY = 4
        #: The node is ready for named deployment.
        RESERVED = 5
        #: The node is powering a service from a charm or is ready for use with
        #: a fresh Ubuntu install.                                                                                                          
        ALLOCATED = 6                                                                                                                       
        #: The node has been removed from service manually until an admin
        #: overrides the retirement.
        RETIRED = 7
    


    Configuration

    Proxy Server

    在 MAAS 裡面, 預設是一定有 http proxy, 從 /etc/maas/preseeds/generic 可以看的出來

    {{if http_proxy }}
    d-i     mirror/http/proxy string {{http_proxy}}
    {{else}}
    d-i     mirror/http/proxy string http://{{server_host}}:8000/
    {{endif}}
    

    如果環境中沒有 http proxy, 處理方式可能有兩個, 第一種就是把 proxy 的設定全都拿掉, 以下這些檔案都需要修改

    /etc/maas/templates/commissioning-user-data/user_data_config.template
    /etc/maas/preseeds/enlist_userdata
    /etc/maas/preseeds/curtin_userdata
    /etc/maas/preseeds/generic
    

    第二種則是可以把 MAAS 內建的 squid-deb-proxy 打開來, 其實也會有一些好處, 下載 .deb 檔會快不少

    update-rc.d  squid-deb-proxy defaults
    

    打開 squid-deb-proxy 後, 可能要看一下 /etc/squid-deb-proxy 是否有滿足你的網路環境
    另外如果需要連結額外的 repository server, 則需要在 mirror-dstdomain.acl.d 內加 server
    http://www.garron.me/en/blog/ubuntu-deb-proxy-cache.html

    /etc/maas/import_pxe_files


    設定你需要的 RELEASE 以及 ARCHES, 但 i386 一定要留著, 因為有些地方的預設值是 i386, 沒有的話會出問題, 如果要加自己定義的 RELEASE, 也是加在這裡, 這邊我自己加了一個 precise04, 是要安裝 Ubuntu Precise 12.04 但 kernel 是 3.11.

    RELEASES="precise04 saucy precise"
    #RELEASES="precise quantal raring saucy"
    ARCHES="amd64/generic i386/generic"
    #ARCHES="amd64/generic i386/generic armhf/highbank armhf/generic"
    

    /usr/lib/python2.7/dist-packages/maasserver/enum.py


    如果有加自己定義的 RELEASE, 請加上新的 enum, UI 上就會看到了

    class DISTRO_SERIES:
        precise04 = 'precise04'
        
    DISTRO_SERIES_CHOICES = (
        (DISTRO_SERIES.precise04, 'Ubuntu 12.04 LTS "Precise Pangolin with 3.11 Kernel"')
    )
    

    /usr/sbin/maas-import-pxe-files


    抓 image 的主要程式在這隻檔案內, 配合前面新增的 precise04, 我修改了以下幾個地方

    compose_installer_base_url


    compose_installer_base_url() {
        local arch=$1 release=$2
        case $arch in
            amd64/*|i386/*)
                if [ "$release" = "precise04" ]; then
                    local installer_url="$MAIN_ARCHIVE/dists/precise-updates/main/installer-${arch%%/*}"
                else
                    local installer_url="$MAIN_ARCHIVE/dists/${release}-updates/main/installer-${arch%%/*}"
                fi
                echo "$installer_url/current/images/"
                ;;
        ...
    }
    

    compose_installer_download_url_postfix

    compose_installer_download_url_postfix() {
        local arch=$1
        local release=$2
        case $arch in
            amd64/*|i386/*)
                if [ "$release" = "precise04" ]; then
                    echo "saucy-netboot/ubuntu-installer/${arch%%/*}/"
                else
                    echo "netboot/ubuntu-installer/${arch%%/*}/"
                fi
                ;;
        ...
    }
    

    凡是有用到 compose_installer_download_url_postfix 的地方都加上第二個參數

    compose_installer_download_url_postfix $arch $release
    


    update_install_files

    update_install_files() {
            ...
            filename_in_md5sums_file=./$file_prefix$file
            ...
    }
    


    完成之後就執行 /usr/sbin/maas-import-pxe-files, 就可以看到結果啦~

    root@ops-maas3:/var/lib/maas/tftp# find . | grep initrd.gz
    ./amd64/generic/precise/install/initrd.gz
    ./amd64/generic/saucy/install/initrd.gz
    ./amd64/generic/precise04/install/initrd.gz
    ./i386/generic/precise/install/initrd.gz
    ./i386/generic/saucy/install/initrd.gz
    ./i386/generic/precise04/install/initrd.gz
    



    Preseed Configuration


    其實每個下載下來的 initrd.gz 內, 都有一個 preseed.cfg, 裡面會指明要安裝的 kernel 版本
    d-i     base-installer/kernel/altmeta   string lts-saucy 
    

    /etc/maas/preseeds/preseed_master

    如果按照原本的設定, 反而可能會裝錯 kernel, 把以下兩行改掉
    #d-i     base-installer/kernel/image     string linux-server
    d-i debian-installer/allow_unauthenticated string true
    

    VMWare Issue


    /etc/maas/templates/commissioning-user-data/snippets/maas_ipmi_autodetect_tool.py


    判斷是否是 VMware
    def detect_ipmi():
        # XXX: andreserl 2013-04-09 bug=1064527: Try to detect if node
        # is a Virtual Machine. If it is, do not try to detect IPMI.
        with open('/proc/cpuinfo', 'r') as cpuinfo:
            for line in cpuinfo:
                if line.startswith('model name') and 'QEMU' in line:
                    return (False, None)
        with open('/var/log/dmesg', 'r') as dmesg:
            for line in dmesg:
                if 'Hypervisor detected' in line and 'VMware' in line:
                    return (False, None)
    


    Use E1000 NIC under Curtin Installing


    不知道為什麼如果用 VMXNET3, 在 pxeboot 後 /sys/class/net/eth0/operstate 內的狀態會是 "Unknown".
    這會造成 deploy 的過程中會有誤判, 所以請使用 E1000


    類似的 Issue
    https://www.vmware.com/support/vsphere5/doc/vsp_esxi50_u3_rel_notes.html#resolvedissuesnetworking

    Preseed Order


    /usr/share/pyshared/maasserver/preseed.py

    {prefix}_{node_architecture}_{node_subarchitecture}_{release}_{node_name}
        {prefix}_{node_architecture}_{node_subarchitecture}_{release}
        {prefix}_{node_architecture}_{node_subarchitecture}
        {prefix}_{node_architecture}
        {prefix}
        'generic'
    

    Trouble Shooting


    During Commission Stage

    有個方法可以加入 backdoor 這個帳號, 就可以登入
    https://maas.ubuntu.com/docs/troubleshooting.html

    During Debian Installing

    http://www.informit.com/articles/article.aspx?p=1757616&seqNum=2

    The installer itself runs on virtual console 1. If you switch to console 2 by pressing Alt-F2, you'll be able to activate the console by hitting Enter and land in a minimalistic (busybox) shell. This will let you explore the complete installer environment and take some matters into your own hands if necessary. You can switch back to the installer console by pressing Alt-F1. Console 4 contains a running, noninteractive log file of the installation, which you can inspect by pressing Alt-F4. Finally, it's sometimes useful to be able to connect to another server during installation, perhaps to upload a log file or to gain access to your mailbox or other communication. By default, the shell on console 2 will not provide you with an ssh client, but you can install one by running anna-install openssh-client-udeb after the installer has configured the network. Now you can use the ssh and scp binaries to log in or copy data to the server of your choice.

    Reference


    Compare Razor/Crowbar/MAAS

    http://www.chenshake.com/design-of-the-razor/