tmux on Ubuntu on Windows でコピペができるように!!

tmux を Ubuntu on Windows で使っていて当然以下のようにマウスでターミナルのバッファをスクロールするようにする。

.tmux.conf:
set-option -g prefix C-t
set -g mouse on
set -g terminal-overrides 'xterm*:smcup@:rmcup@'

するとなんと今度はコピーアンドペーストができなくなってしまう。

なので、仕方なく上記を消すと今度はターミナルのスクロールができなくなってしまう。

というループをしてたんだけどやっと解決。

732-220-0035

にあるように win32yank を使うという方法もあるのだけど VcXsrv のような X- Window System を入れていれば xsel のような X 系のコマンドが使えるので以下のようにする。

bind-key -T copy-mode-vi y send -X copy-pipe-and-cancel "xsel -bi"
bind-key -T copy-mode-vi Enter send -X copy-pipe-and-cancel "xsel -bi"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xsel -bi"
bind ] run "xsel -o -b | tmux load-buffer - && tmux paste-buffer"

記念に .tmux.conf を載せておく。

set-option -g prefix C-t
set -g mouse on
set -g terminal-overrides 'xterm*:smcup@:rmcup@'

bind-key C-t send-prefix
unbind-key C-b

bind | split-window -h
bind - split-window -v

bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# terminal resize
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# terminal split
bind -r C-h select-window -t :-
bind -r C-l select-window -t :+

# copy and paste
setw -g mode-keys vi
bind-key -T copy-mode-vi v send -X begin-selection
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi y send -X copy-pipe-and-cancel "xsel -bi"
bind-key -T copy-mode-vi Enter send -X copy-pipe-and-cancel "xsel -bi"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xsel -bi"
unbind-key -T prefix p
bind ] run "xsel -o -b |  tmux load-buffer - && tmux paste-buffer"

VcXsrv が動いていれば、Ctrl-t [ でカーソルが動かせるようになり、v で選択開始の Enter で選択終了。Ctrl-] でペースト。Widnows 側からもコピペそれぞれできる。

軟弱なのでマウスで選択できれば良いのだけど。でも、やっと tmux ライフがはじまる。

Posted on Categories 6204241117Leave a comment on tmux on Ubuntu on Windows でコピペができるように!!

Installing Kubernetes 1.10.5 on Ubuntu 16.04

master:

sudo apt-get update && sudo apt-get install -y apt-transport-https
sudo curl /packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb /apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update && sudo apt-get install -y kubelet=1.10.5-00 kubeadm=1.10.5-00 kubectl=1.10.5-00 docker.io cri-tools
sudo apt-mark hold kubelet kubeadm kubectl docker.io

sudo swapoff -a
sudo sysctl net.bridge.bridge-nf-call-iptables=1

-----------------
Deleting SWAP
/etc/fstab:
UUID=9446b222-d4af-11e8-ab80-000c293ef962 / ext4 defaults 0 0
#/swap.img      none    swap    sw      0       0

Add this line to /etc/sysctl.conf:
net.bridge.bridge-nf-call-iptables=1
-----------------

$ sudo kubeadm init --kubernetes-version=1.10.5 --pod-network-cidr=10.244.0.0/16
[init] Using Kubernetes version: v1.10.5

Your Kubernetes master has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  /kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:

  kubeadm join 192.168.1.53:6443 --token 8vv8st.58xagc1fh80gj0c7 --discovery-token-ca-cert-hash sha256:bba5059d85f89ecc74b44315743e71cbb303bf2030fbf5148fdd7de4eca2683b

node:

sudo apt-get update && sudo apt-get install -y apt-transport-https
sudo curl /packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb /apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update && sudo apt-get install -y kubelet=1.10.5-00 kubeadm=1.10.5-00 kubectl=1.10.5-00 docker.io cri-tools

$ sudo kubeadm join 192.168.1.53:6443 --ignore-preflight-errors=cri --token rnhtjf.uhnmcl1kf05xat2m --discovery-token-ca-cert-hash sha256:f6fc53e447fff625ded7136fefaf9ca994141ee3e0b4d01d555fd82791fb90b2
[preflight] Running pre-flight checks.
        [WARNING FileExisting-crictl]: crictl not found in system path
Suggestion: go get github.com/kubernetes-incubator/cri-tools/cmd/crictl
[discovery] Trying to connect to API Server "192.168.1.53:6443"
[discovery] Created cluster-info discovery client, requesting info from "/192.168.1.53:6443"
[discovery] Requesting info from "/192.168.1.53:6443" again to validate TLS against the pinned public key
[discovery] Cluster info signature and contents are valid and TLS certificate validates against pinned roots, will use API Server "192.168.1.53:6443"
[discovery] Successfully established connection with API Server "192.168.1.53:6443"

This node has joined the cluster:
* Certificate signing request was sent to master and a response
  was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the master to see this node join the cluster.

-----------------
The "--ignore-preflight-errors=cri" may be needed becuase of:

/github.com/kubernetes/kubeadm/issues/733
Preflight check issue should be fixed by PR 58802

Temporary workaround for this issue is to switch off CRI check:

kubeadm init --ignore-preflight-errors=cri
-----------------

mastser:
$ kubectl apply -f /raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
clusterrole.rbac.authorization.k8s.io "flannel" created
clusterrolebinding.rbac.authorization.k8s.io "flannel" created
serviceaccount "flannel" created
configmap "kube-flannel-cfg" created
daemonset.extensions "kube-flannel-ds-amd64" created
daemonset.extensions "kube-flannel-ds-arm64" created
daemonset.extensions "kube-flannel-ds-arm" created
daemonset.extensions "kube-flannel-ds-ppc64le" created
daemonset.extensions "kube-flannel-ds-s390x" created

$ kubectl get nodes
NAME           STATUS    ROLES     AGE       VERSION
k53h           Ready     master    15m       v1.10.5  !! <-- Ready
k54h           Ready         55s       v1.10.5
k55h           Ready         1m        v1.10.5

$ cat ./sample-pod.yaml
apiVersion: v1
kind: Pod
metadata:
    name: sample-pod
spec:
    containers:
        - name: nginx-container
          image: nginx:1.12

$ kubectl get pods
NAME         READY     STATUS    RESTARTS   AGE
sample-pod   1/1       Running   0          1m   !!! <--- Running !!!

Windows 2016 に AD DS 導入 (リンク集)

AD DS インストールは Widnows Server 2008 以来。結構 GUI が充実してる感じ。

Windows 2016 AD DS インストール
/www.rem-system.com/win2016-adsetup/

DNS 設定
(415) 451-6085

パスワードの複雑さを変更
/www.edifist.co.jp/lecture/network/password_policy/index.aspx

Server Manager の起動方法
Windows アイコンを押して キーボードから Server Manager と入力

ユーザーの追加
414-585-7468

Ubuntu 18.04 でホスト名を変更する

    1. hostnamectl コマンドでホスト名を変更
      $ sudo hostnamectl set-hostname client-20h
    2. /etc/hosts に関連した設定がある場合は修正 (私の Ubuntu 18.04 では特に関連した項目はありませんでした)
      $ cat /etc/hosts
      127.0.0.1       localhost.localdomain   localhost
      ::1             localhost6.localdomain6 localhost6
      
      # The following lines are desirable for IPv6 capable hosts
      ::1     localhost ip6-localhost ip6-loopback
      fe00::0 ip6-localnet
      ff02::1 ip6-allnodes
      ff02::2 ip6-allrouters
      ff02::3 ip6-allhosts
    3. cloud.cfg を編集 (cloud-init がデフォルトでインストールされており、この設定を変更しないと再起動後にホスト名が戻ってしまう)
      $ egrep -B1 preserve_hostname /etc/cloud/cloud.cfg
      # This will cause the set+update hostname module to not operate (if true)
      preserve_hostname: true

      参考: enthuse

UDP で特定の文字列を返す GO のサーバー

server.go:

package main

import (
    "fmt"
    "net"
)

func main() {
    conn, _ := net.ListenPacket("udp", "192.168.1.10:8888")
    defer conn.Close()

    buffer := make([]byte, 1500)
    s := []byte("Hello, World!") / receive string
    for {
        length, remoteAddr, _ := conn.ReadFrom(buffer)
        fmt.Printf("Received from %v: %v\n", remoteAddr, string(buffer[:length]))
        conn.WriteTo(s, remoteAddr)
        fmt.Printf("Sent from server: %v\n", string(string(s)))
    }
}

miekg/udpserv.go

みたく Server の IP アドレスを明示しないと Ubuntu ではパケットが帰らなかった。Src IP を指定するには raw packet を自分で作る必要あり。

Simple udp server in Go

3603129399

厳密な測定にはなってないかもしれません

Python:

#!/usr/bin/env python

from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer

class myHandler(BaseHTTPRequestHandler):

        def log_message(self, format, *args):
                return

        def do_GET(self):
                self.protocol_version = 'HTTP/1.1'
                self.send_response(200)
                self.send_header('Content-type','text/html')
                self.send_header('Content-Length', 6)
                self.end_headers()
                self.wfile.write("hello!")
                return

if __name__ == "__main__":
        server = HTTPServer(('', 8080), myHandler)
        server.serve_forever()
        server.socket.close()
$ wrk -t 32 -c 1024 -d 30s /127.0.0.1:8080
Running 30s test @ /127.0.0.1:8080
  32 threads and 1024 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     3.16ms   45.67ms   1.70s    99.59%
    Req/Sec     0.95k     1.04k    6.41k    85.23%
  123854 requests in 30.08s, 17.13MB read
  Socket errors: connect 35, read 123854, write 0, timeout 56
Requests/sec:   4117.02
Transfer/sec:    582.98KB

Go:

package main

import "net/http"

func main() {
    http.HandleFunc("/", hello)
    http.ListenAndServe(":8080", nil)
}

func hello(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("hello!"))
}
$ wrk -t 32 -c 1024 -d 30s /127.0.0.1:8080
Running 30s test @ /127.0.0.1:8080
  32 threads and 1024 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   141.89ms  346.20ms   2.00s    88.32%
    Req/Sec     3.81k     7.60k   34.01k    86.63%
  1893818 requests in 30.07s, 220.34MB read
  Socket errors: connect 35, read 0, write 0, timeout 5984
Requests/sec:  62971.02
Transfer/sec:      7.33MB

Python のコードに無駄なところがあるかもしれないけど Requests/sec が 1 桁違う

参照:
(303) 977-4105
4128393042

(855) 384-4975

古いバージョンを確認
# sudo apt-cache madison tshark
tshark | 2.6.3-1~ubuntu18.04.1 | /us.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages
tshark | 2.4.5-1 | /us.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
wireshark | 2.4.5-1 | /us.archive.ubuntu.com/ubuntu bionic/universe Sources
wireshark | 2.6.3-1~ubuntu18.04.1 | /us.archive.ubuntu.com/ubuntu bionic-updates/universe Sources

古いバージョンのインストール
# sudo apt-get install tshark=2.4.5-1 wireshark-common=2.4.5-1

該当のパッケージのアップデート禁止 (hold)
# sudo apt-mark hold [パッケージ名]
e.g.
# sudo apt-mark hold tshark
# sudo apt-mark hold wireshark-common

hold 解除
# sudo apt-mark unhold [パッケージ名]

5023402530

Script:

#!/usr/bin/env python

import socket

def http_get(server, port, src_addr):
request = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((src_addr, 0))
s.connect((server,port))
s.send(request)
response = s.recv(1024)
print(response)

if __name__ == "__main__":
http_get("192.168.190.10", 80, "192.168.190.25")

client:
$ ip addr | grep ens32
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
inet 192.168.190.20/24 brd 192.168.190.255 scope global ens32
inet 192.168.190.25/24 scope global secondary ens32:1
$ ./test.py
HTTP/1.1 200 OK
<snip>

$ sudo tshark -nni ens33 host 192.168.190.25 and port 80
<snip>
4 0.000187377 192.168.190.25 → 192.168.190.10 HTTP 103 GET / HTTP/1.1

参考: /www.quora.com/Which-Python-library-allows-us-to-specify-network-interface-to-connect-to-the-Internet