Docker方案选取背景[编辑]之前主服务器安装的是ubuntu系统,没有做容灾方案(运维方面擅长centos系统的服务器维护,而对ubuntu系统不如对centos系统那样熟悉),一旦机器出现故障,比如有一次停电导致硬盘损坏,平台停止运行很长时间,影响颇大。而直接在centos系统上部署stf,之前没有做过,因此有一些顾虑,担心不如在ubuntu上成熟稳定。最后决定采用一个折中的方案:选用安装有centos系统的机器作为宿主机,以ubuntu官方镜像为基础构建stf镜像,再用该镜像启动容器部署在宿主机上。Docker镜像制作[编辑]创建镜像通常会选用一个基础镜像,创建docker镜像主要有两种方式:1,commit方式;2,dockerfile方式。Commit方式[编辑]1,从远程仓库中搜寻合适的基础镜像,docker search ubuntu2,从远程仓库中拉取想要的基础镜像,docker pull ubuntu3,拉取镜像后,查看本地仓库中的镜像,docker images4,用拉取到的镜像启动一个新容器,docker run -it ubuntu,这个容器就相当于一个ubuntu操作系统环境5,之后就像普通ubuntu环境那样,搭建stf运行环境# apt-get update# apt-get install -y git# apt-get install -y lib32stdc++6# apt-get install -y yum# apt-get install -y build-essential# apt-get install -y android-tools-adb# apt-get install -y openjdk-8-jdk#apt-get install -y aapt#apt-get install -y unzip#apt-get install -y zip安装相应的软件软件列表:NodejsBowerGraphicsMagickLibsodiumZeromqProtobufRethinkdb(这个没有安装包)Nodejs安装方法一: 解压tar.gz包#tar fvxz node-v5.10.0.tar.gz#cd node-v5.10.0#./configure#make#make install#ln -s /usr/local/bin/node /usr/bin/node#ln -s /usr/local/bin/npm /usr/bin/npm下载链接:文件:Node-v5.10.0.tar.zip方法二:# apt-get install npm# apt install nodejs-legacy检查是否正常安装#node -vUbuntu的node版本比较低,建议用第一种方法bower 安装#npm install bower -g检查是否正常安装# bower -versionGraphicsMagick安装# tar fvxz GraphicsMagick-1.3.24.tar.bz2# cd GraphicsMagick-1.3.24#./configure#make#make install检查是否正常安装#whereis gmroot@stf-test:~# whereis gmgm: /usr/local/bin/gm下载链接 文件:GraphicsMagick-1.3.24.tar.ziplibsodium安装tar fvxz libsodium-1.0.8.tar.gzcd libsodium-1.0.8./configuremakemake install检查是否安装成功 使用命令whereis libsodium下载链接文件:Libsodium-1.0.9.tar.zipzeromq安装# tar fvxz zeromq-4.1.4.tar.gz# cd zeromq-4.1.4#./configure# make# make install文件:Zeromq-4.2.0.tar.zipprotobuf安装# tar fvxz protobuf-cpp-3.0.0-alpha-3.tar.gz#cd protobuf-cpp-3.0.0-alpha-3#./configure --prefix=/usr/local/protobuf# make# make install# vi /etc/profile/etc/profile配置在上面配置已经加上了,直接使用命令source /etc/profile就能生效#protoc --version文件:Protobuf-cpp-3.1.0.zip建议用apt-get的方法安装apt-get install protobuf-compilerpkg-config安装#apt-get install pkg-configrethinkdb安装# source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt xenial main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list |wget -qO- http://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -(以上是一条命令,一定要把选择xenial 或者wily版本的rethink,不然后面启动STF时会报错)#apt-get update#apt-get install rethinkdbstf安装 使用git 命令下载master版本#git clone https://github.com/openstf/stf.git当然也可以下载stf的tgz包下来解压 进入stf目录,安装node_module的组件#npm install#npm link安装完成 检查是否能启动stf#rethinkdb &#stf local --public-ip= ip地址Dockerfile方式[编辑]dockerfile创建镜像的步骤大致为:先创建dockerfile文件,再编辑该文件,加上符合dockerfile语法的命令,最后用docker build命令生成镜像。dockerfile语法FROM:指定镜像基于哪个基础镜像创建。FROM ubuntuMAINTAINER:用来指定维护者的姓名和联系方式。MAINTAINER <author name email>RUN:相当于运行shell命令。RUN apt-get updateCOPY:复制文件指令,将本地文件copy到镜像中。COPY node-v5.10.0 /home/ly/node-v5.10.0编辑好dockerfile文件后,创建镜像docker build -t cloud:stf .dockerfile文件在/home/ly/路径下Docker环境的部署和镜像维护[编辑]因为网络这一块我们不太熟悉,所以镜像制作好后是请运维部门的同事代为部署的。docker环境ip为192.168.196.203,宿主机ip为192.168.196.201,宿主机目录/data/g_data1/挂载到容器目录/var/stf/,从宿主机进入到docker环境的命令docker exec -it stf /bin/bash在使用过程中,会安装新的模块或其它工具,docker环境也会随之变化,因此docker容器和其刚开始部署时已有很大不同。如果有删除容器、重新部署容器的需求,需将当前运行的容器commit成新的镜像,作为下次部署容器时的依据。最开始制作镜像时采用的是dockerfile方式,容器运行后,采用的是用容器commit成镜像的方式来维护更新镜像。空间清理,日志删除[编辑]因为存储有限,需要定理清理磁盘空间。/var/stf/file文件夹下保存着大量测试生成的日志文件和用户上传的apk,占用空间较大,需要定期清理/var/stf下的cleanlog.sh是用来清理日志和apk的脚本,清除30天以前的日志./cleanlog.sh 31 清除19天以前的日志./cleanlog.sh 20