今年去參加Qcon上海2016開發者大會,發現大家都在講容器、微服務、深度學習這些高端的東西,所以抓緊時間學習和總結了一下,給大家吹吹牛,算是不虛此行吧。
容器
基于Linux內核中的Control Groups和namespace技術,對運行的進程做隔離和控制。Linux內核還在不斷創新中,《Unix 環境高級編程》沒有包含這些新技術,所以很多人對此一無所知。
不同于一般的虛擬化技術,在host中可以看到容器里面運行的進程。image和container的關系就像是可執行程序和進程的關系。
22957 ? Sl 0:00 | \_ docker-containerd-shim 9f4669fd46ab076cca3b71d67f697b1e9768e351bc40be3a85fa4e02eb92720a /var/run/docker/libcontainerd/9f4669fd46ab076cca3b
22971 pts/4 Ss 0:00 | | \_ sh -c service ssh start; bash
23029 ? Ss 0:00 | | \_ /usr/sbin/sshd
23032 pts/4 S+ 0:00 | | \_ bash
23593 ? Sl 29:49 | | \_ /usr/lib/jvm/java-7-openjdk-amd64/bin/java -Dproc_datanode -Xmx1000m -Djava.net.preferIPv4Stack=true -Dhadoop.log.dir=/usr/local/h
24149 ? Sl 36:09 | | \_ /usr/lib/jvm/java-7-openjdk-amd64/bin/java -Dproc_nodemanager -Xmx1000m -Dhadoop.log.dir=/usr/local/hadoop/logs -Dyarn.log.dir=/us
23065 ? Sl 0:00 | \_ docker-containerd-shim 1262b62afcac0c41ede4c28484a9697246e67c87c3945c1dd16cff3319689514 /var/run/docker/libcontainerd/1262b62afcac0c41ede4
23079 pts/5 Ss 0:00 | | \_ sh -c service ssh start; bash
23138 ? Ss 0:00 | | \_ /usr/sbin/sshd
23141 pts/5 S+ 0:00 | | \_ bash
23591 ? Sl 29:02 | | \_ /usr/lib/jvm/java-7-openjdk-amd64/bin/java -Dproc_datanode -Xmx1000m -Djava.net.preferIPv4Stack=true -Dhadoop.log.dir=/usr/local/h
24167 ? Sl 35:48 | | \_ /usr/lib/jvm/java-7-openjdk-amd64/bin/java -Dproc_nodemanager -Xmx1000m -Dhadoop.log.dir=/usr/local/hadoop/logs -Dyarn.log.dir=/us
但是容器看不到host和別的容器的信息。
root@hadoop-master:~# ps xf
PID TTY STAT TIME COMMAND
579 ? Sl 0:08 /usr/lib/jvm/java-7-openjdk-amd64/bin/java -Dproc_resourcemanager -Xmx1000m -Dhadoo
120 ? Ss 0:00 bash
904 ? R+ 0:00 \_ ps xf
93 ? Ss+ 0:00 bash
1 ? Ss 0:00 sh -c service ssh start; bash
31 ? Ss 0:00 /usr/sbin/sshd
34 ? S+ 0:00 bash
239 ? Sl 0:05 /usr/lib/jvm/java-7-openjdk-amd64/bin/java -Dproc_namenode -Xmx1000m -Djava.net.pre
428 ? Sl 0:03 /usr/lib/jvm/java-7-openjdk-amd64/bin/java -Dproc_secondarynamenode -Xmx1000m -Djav
有了docker,學習真的是一件很容易的事情。比如要搭建一個多節點的Hadoop集群,社區早有人做好了鏡像,pull下來就能跑得飛起。參考文章:基于Docker搭建Hadoop集群之升級版。例子中創建了三個容器,一個master(跑yarn),兩個slave(跑dfs),這樣就有了一個三節點的集群,然后把Hadoop集群跑起來。
還有比這更簡單的Hadoop搭建的學習環境嗎?
root@hadoop-master:~# ./run-wordcount.sh
16/11/08 12:28:32 INFO client.RMProxy: Connecting to ResourceManager at hadoop-master/172.20.0.2:8032
16/11/08 12:28:33 INFO input.FileInputFormat: Total input paths to process : 2
16/11/08 12:28:33 INFO mapreduce.JobSubmitter: number of splits:2
16/11/08 12:28:33 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1478607997885_0001
16/11/08 12:28:34 INFO impl.YarnClientImpl: Submitted application application_1478607997885_0001
16/11/08 12:28:34 INFO mapreduce.Job: The url to track the job: http://hadoop-master:8088/proxy/application_1478607997885_0001/
16/11/08 12:28:34 INFO mapreduce.Job: Running job: job_1478607997885_0001
16/11/08 12:28:43 INFO mapreduce.Job: Job job_1478607997885_0001 running in uber mode : false
16/11/08 12:28:43 INFO mapreduce.Job: map 0% reduce 0%
16/11/08 12:28:52 INFO mapreduce.Job: map 50% reduce 0%
16/11/08 12:28:53 INFO mapreduce.Job: map 100% reduce 0%
16/11/08 12:28:59 INFO mapreduce.Job: map 100% reduce 100%
16/11/08 12:28:59 INFO mapreduce.Job: Job job_1478607997885_0001 completed successfully
16/11/08 12:28:59 INFO mapreduce.Job: Counters: 49
File System Counters
FILE: Number of bytes read=56
FILE: Number of bytes written=352398
FILE: Number of read operations=0
FILE: Number of large read operations=0
FILE: Number of write operations=0
HDFS: Number of bytes read=258
HDFS: Number of bytes written=26
HDFS: Number of read operations=9
HDFS: Number of large read operations=0
HDFS: Number of write operations=2
Job Counters
Launched map tasks=2
Launched reduce tasks=1
Data-local map tasks=2
Total time spent by all maps in occupied slots (ms)=14221
Total time spent by all reduces in occupied slots (ms)=4203
Total time spent by all map tasks (ms)=14221
Total time spent by all reduce tasks (ms)=4203
Total vcore-milliseconds taken by all map tasks=14221
Total vcore-milliseconds taken by all reduce tasks=4203
Total megabyte-milliseconds taken by all map tasks=14562304
Total megabyte-milliseconds taken by all reduce tasks=4303872
Map-Reduce Framework
Map input records=2
Map output records=4
Map output bytes=42
Map output materialized bytes=62
Input split bytes=232
Combine input records=4
Combine output records=4
Reduce input groups=3
Reduce shuffle bytes=62
Reduce input records=4
Reduce output records=3
Spilled Records=8
Shuffled Maps =2
Failed Shuffles=0
Merged Map outputs=2
GC time elapsed (ms)=141
CPU time spent (ms)=1450
Physical memory (bytes) snapshot=798035968
Virtual memory (bytes) snapshot=2619658240
Total committed heap usage (bytes)=509607936
Shuffle Errors
BAD_ID=0
CONNECTION=0
IO_ERROR=0
WRONG_LENGTH=0
WRONG_MAP=0
WRONG_REDUCE=0
File Input Format Counters
Bytes Read=26
File Output Format Counters
Bytes Written=26
input file1.txt:
Hello Hadoop
input file2.txt:
Hello Docker
wordcount output:
Docker 1
Hadoop 1
Hello 2
aufs(Advanced multi layered unification filesystem)也是相當有意思。
~# docker pull xuyecan/ubuntu-shadowsocks
Using default tag: latest
latest: Pulling from xuyecan/ubuntu-shadowsocks
bf5d46315322: Already exists
9f13e0ac480c: Already exists
e8988b5b3097: Already exists
40af181810e7: Already exists
e6f7c7e5c03e: Already exists
64995ac659ee: Pull complete
Digest: sha256:0cfb5275581be3e6a5cce3f230ff9c3ef714f3c9291b76eb41e2f47d7362a994
Status: Downloaded newer image for xuyecan/ubuntu-shadowsocks:latest
Docker for Mac
Mac上使用Docker也是非常簡單的呢。首先下載并安裝https://download.docker.com/mac/stable/Docker.dmg,然后把App啟動起來。因為官方源比較慢,可以配置一下阿里云的鏡像:https://imuewcw.mirror.acs.aliyun.com。
配置完成之后,點擊下方Apply & Restart
就好了。以前想要在Linux環境下測試一些東西可麻煩了,現在有了Docker for Mac,在Mac上拉一個Ubuntu,用起來真的很方便。
[~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 05a60462f8ba 5 days ago 181.5 MB
ubuntu latest f753707788c5 4 weeks ago 127.2 MB
[~]$ docker run -ti f753707788c5
root@76cb78b38af5:/# cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
NAME="Ubuntu"
VERSION="16.04.1 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.1 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
UBUNTU_CODENAME=xenial
CoreOS
CoreOS是一個非常極端的Linux發行版,它沒有傳統的包管理系統,比如yum和apt-get,完全使用docker來做包管理。比如要使用gcc,那么需要去pull一個gcc的image,然后通過目錄共享的方式來編譯代碼。
CoreOS自帶了fleet做服務的管理,fleet大大方便了運維同學管理服務。CoreOS fleet之初體驗這篇文章通過一個demo較好地講述了fleet的使用。
阿里云與時俱進,也提供CoreOS鏡像。
微服務
這篇文章:微服務實戰(一):微服務架構的優勢與不足總結得非常到位。
深度學習
AWS 首席云計算技術顧問的AWS 首席云計算技術顧問介紹了一下深度學習的歷史及如何搭建環境。
騰訊孫子荀分享的新媒體與深度學習給我留下了深刻的印象。通過深度學習給出適合每個人的最佳推送時間、合理裁切圖片、分析文章質量等等。
目前有很多優秀的深度學習框架,比如Google開源的TensorFlow,被廣泛應用于各種場景。其實我也想總結點啥,但是實在說不出來,大家自行去學習莫煩 tensorflow 神經網絡 教程吧,這個TensorFlow的系列教程很贊。
Jupyter & TensorBoard對于初學者很有用。
阿里云
阿里云對容器有豐富的支持,包括Docker Registry、容器服務、HPC等等。阿里云使用Docker Swarm做服務編排。
輕松利用現有ECS實例大家容器服務集群。
云棲社區更是有大量關于TensorFlow的文章。
本系列將利用Docker和阿里云容器服務,幫助您上手TensorFlow的機器學習方案
第一篇:打造TensorFlow的實驗環境
第二篇:輕松搭建TensorFlow Serving集群
第三篇:打通TensorFlow持續訓練鏈路
服務編排
用戶只關心自己的服務,至于服務如何跑起來,并發和容錯就要交給編排工具去做了。目前比較流行的編排工具有Docker Swarm、Google Kubernetes、Apache Mesos。
通過基于Docker搭建單機版Mesos/Marathon這篇文章,可以理解一下Mesos的基本原理及使用。
通過鏡像創建 Nginx介紹了如何使用阿里云容器服務創建Nginx應用,可以了解一下Docker Swarm。把Nginx服務運行起來之后,可以到相應的機器上查看到對應的container。
root@cbb4515a0d85e4014b0a37d455793a89e-node1:~# docker ps -a | grep nginx
556348917c43 nginx:latest "nginx -g 'daemon off" 2 weeks ago Exited (0) 2 minutes ago nginx_nginx_1
推薦資料
- 書籍:《Docker技術入門與實踐》,鏈接:Docker — 從入門到實踐。
- 阿里云容器服務文檔。
- 云棲社區有很多關于容器、深度學習、阿里云容器服務的相關文章,值得閱讀。
- Mesos
- TensorFlow 官方文檔中文版
- Kubernetes入門指南
- Docker Machine 簡介