移除XQuartz

launchctl unload /Library/LaunchAgents/org.macosforge.xquartz.startx.plist && \
sudo launchctl unload /Library/LaunchDaemons/org.macosforge.xquartz.privileged_startx.plist && \
sudo rm -rf /opt/X11* /Library/Launch*/org.macosforge.xquartz.* /Applications/Utilities/XQuartz.app /etc/*paths.d/*XQuartz  && \
sudo pkgutil --forget org.macosforge.xquartz.pkg  && \
rm -rf ~/.serverauth* && rm -rf ~/.Xauthorit* && rm -rf ~/.cache && rm -rf ~/.rnd && \
rm -rf ~/Library/Caches/org.macosforge.xquartz.X11 && rm -rf ~/Library/Logs/X11

refer: https://gist.github.com/pwnsdx/d127873e24cef159d4d603accaf37ee4

經測試,可移除使用dmg安裝的XQuartz

修改docker0網段

其中10.172.254.254是Getway,不要自作主張改成 192.168.1.0/24 or 10.172.0.0之類的..

yum install bridge-utils -y

service docker stop
ip link set dev docker0 down
brctl delbr docker0
iptables -t nat -F POSTROUTING


brctl addbr docker0
ip addr add 10.172.254.254/16 dev docker0
ip link set dev docker0 up


cat << EOF > /etc/docker/daemon.json
{
  "bip": "10.172.254.254/16"
}
EOF

systemctl daemon-reload
systemctl restart docker.service
reboot #如果有k8s則需要重開機

refer: https://blog.yowko.com/docker-172-17-ip/

tensorflow 初測

#TAG=latest-py3
TAG=latest-gpu-py3

#準備資料
rm -rf $PWD/test
mkdir -p $PWD/test
cd $PWD/test
git clone https://github.com/purocean/tensorflow-simple-captcha.git
cd tensorflow-simple-captcha

#前處理
docker run \
  --runtime=nvidia \
  -it --rm \
  -v $PWD:/data \
  -w /data \
  tensorflow/tensorflow:$TAG python3 prepare.py

#訓練
time docker run \
  --runtime=nvidia \
  -it --rm \
  -v $PWD:/data \
  -w /data \
  tensorflow/tensorflow:$TAG python3 train.py

#測試
docker run \
  --runtime=nvidia \
  -it --rm \
  -v $PWD:/data \
  -w /data \
  tensorflow/tensorflow:$TAG bash -c 'python3 work.py < test.jpg'

在centos 7上安裝nvidia docker

#安裝 docker-ce
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce-18.06.0.ce -y
systemctl enable docker && systemctl start docker


# 移除舊版nvidia-docker
docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f
sudo yum remove nvidia-docker

# 加入repositories
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.repo | sudo tee /etc/yum.repos.d/nvidia-docker.repo

# 安裝 nvidia-docker2
sudo yum install -y nvidia-docker2
sudo pkill -SIGHUP dockerd

# 測試
docker run --runtime=nvidia --rm nvidia/cuda:9.0-base nvidia-smi

refer: https://github.com/NVIDIA/nvidia-docker

k8s安裝ingress nginx

ingress-nginx最新版已經不包含default-http-backend.
因此安裝0.20.0

#安裝ingress-nginx
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.20.0/deploy/mandatory.yaml
sed -i 's/serviceAccountName: nginx-ingress-serviceaccount/hostNetwork: true\n      serviceAccountName: nginx-ingress-serviceaccount/g' mandatory.yaml
kubectl apply -f mandatory.yaml
rm -f mandatory.yaml*
kubectl get pod --all-namespaces

#修改ingress-nginx
NODE_COUNT=$(kubectl get nodes | grep -v master | grep -v STATUS | wc -l)
echo $NODE_COUNT
if [ $NODE_COUNT -gt 1 ] ; then
kubectl -n ingress-nginx patch deployment default-http-backend --patch $(echo "{\"spec\":{\"replicas\":$NODE_COUNT}}")
kubectl -n ingress-nginx patch deployment nginx-ingress-controller --patch $(echo "{\"spec\":{\"replicas\":$NODE_COUNT}}")
fi
kubectl get pods -n ingress-nginx -o wide

#更換自製 http-backend image
DOMAIN=ssl.cbe.tw
kubectl -n ingress-nginx patch deployment default-http-backend --patch "{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"default-http-backend\",\"resources\":{\"limits\":{\"cpu\":\"100m\",\"memory\":\"200Mi\"},\"requests\":{\"cpu\":\"100m\",\"memory\":\"200Mi\"}},\"image\":\"slanla/apache-defaultbackend\",\"ports\":[{\"containerPort\":8080,\"protocol\":\"TCP\"}],\"env\":[{\"name\":\"LETSENCRYPT_PROXYPASS_URL\",\"value\":\"http://$DOMAIN/.well-known/acme-challenge/ connectiontimeout=15 timeout=30\"},{\"name\":\"LETSENCRYPT_PROXYPASSREVERSE_URL\",\"value\":\"http://$DOMAIN/.well-known/acme-challenge/\"}],\"livenessProbe\":{\"httpGet\":{\"path\":\"/healthz\",\"port\":8080,\"scheme\":\"HTTP\"},\"initialDelaySeconds\":30,\"timeoutSeconds\":5,\"periodSeconds\":10,\"successThreshold\":1,\"failureThreshold\":3}}]}}}}"
kubectl get pods -n ingress-nginx -o wide

用docker編譯latex文件

最近打開在寫技術報告,寫到一半覺得word弄出來的文件非常難看.
因此興起了用latex寫文件的念頭.

因為已經兩三年沒寫latex,連安裝基本上都沒有了.
稍微搜尋一下安裝方法,又分為MacOS/Windows.
想說太麻煩了!
乾脆用docker來跑latex編譯的工作.

下列就是用docker建立一個latex編譯環境:
1.首先我們需要建立一個image

mkdir -p $PWD/latex_temp/fonts
cat <<EOF > $PWD/latex_temp/Dockerfile
FROM slanla/ubuntu

MAINTAINER slanla slanla@slanla.com
RUN DEBIAN_FRONTEND=noninteractive \
    apt-get update && \
    apt-get upgrade -y && \
    apt-get -f install && \
    apt-get install -y \
      fontconfig \
      texlive-xetex \
      texlive-publishers \
      texlive-latex-extra \
      texlive-latex-recommended \
      latex-cjk-* \
      language-pack-zh-hant \
      language-pack-zh-hant-base

COPY fonts /usr/share/fonts
ENV LANG zh_TW.UTF-8  
ENV LANGUAGE zh_TW:zh  
ENV LC_ALL zh_TW.UTF-8  
EOF

docker build -t slanla/latex $PWD/latex_temp/

2.接著之後有需要編譯*.tex文件的話,例如是main.tex,
只需要在main.tex所在目錄下執行下列指令就可以編譯出main.pdf.

docker rm -f latex || echo 1 
docker run \
    -d \
    --name latex \
    -v $file_path:/data \
    -w /data \
    slanla/latex \
    xelatex main.tex
docker logs -f latex

這邊可以看到我是用-d,並加上docker logs來查看log,而非用-it –rm.主要避免latex出錯時,整個終端機會無法控制使用的問題.

3.有了步驟2的指令,我們就可以跟Sublime Text來做整合.
(a)首先打開Sublime Text
(b)開啟Tools->Build System->New Build System
(c)輸入下列json資料:

{
  "encoding": "utf8",
  "working_dir": "$file_path",
  "shell_cmd": "(rm -f $file_path/*.aux $file_path/*.bbl $file_path/*.blg $file_path/*.lof $file_path/*.log $file_path/*.toc) && (docker rm -f latex || echo 1 ) && docker run -d --name latex -v $file_path:/data -w /data dkr.tw/latex bash -c 'xelatex $file_base_name;bibtex $file_base_name;xelatex $file_base_name' && docker logs -f latex"
}

如此一來只需要用Sublime Text編輯main.tex後,按下CMD+B就可以編譯成PDF檔案了.