在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

如何通过puppet管理远程docker容器并配置puppet和实现变更

227次阅读
没有评论

共计 6708 个字符,预计需要花费 17 分钟才能阅读完成。

这篇文章将为大家详细讲解有关如何通过 puppet 管理远程 docker 容器并配置 puppet 和实现变更,丸趣 TV 小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

前提准备:

1.master 和 docker 节点上分别安装好 puppet master 和 puppet agent;

2.docker 节点上安装好 docker1.2.0、nsenter(被脚本用于连接容器),并 pull 一个镜像:training/webapp

master 上的准备工作:

创建 docker 模块:

mkdir -p /etc/puppet/modules/docker/{manifests,files,templates}
vi /etc/puppet/modules/docker/manifests/init.pp
#编写 docker 类
class docker {
 exec {  dockerlaunch  :
 command =   /usr/bin/docker run -d -p 1000:5000 --name webbase training/webapp python app.py   /usr/bin/docker run -d -p 2000:5000 --name web1 --link webbase:webbase training/webapp python app.py ,
 }
 
 exec {  dockerlogs  :
 command =   /bin/mkdir -p /var/log/dockerlaunch   /usr/bin/docker inspect webbase   /var/log/dockerlaunch/webbase.log   /usr/bin/docker inspect web1   /var/log/dockerlaunch/web1.log ,
 }
 
 file {  /root/status.log  :
 ensure =  file,
 mode =   740 ,
 content =   docker container is running:webbase and web1 please use broswer access the ip address of docker.hzg.com and the 1000 or the 2000 port.You can use the control.sh script help you to manage the container ,
 }
 
 file {  /root/control.sh  :
 ensure =  file,
 mode =   1777 ,
 source =   puppet:///modules/docker/control.sh ,
 }
 
 notify {  Docker container is running on node $fqdn ! : }
}

编写管理脚本,并放置到 /etc/puppet/modules/docker/files 目录中:

vi control.sh
#脚本如下
#!/bin/bash
#used for access the specific container
#written by Hochikong
while true
read -p  What you want to do?try input  help  to get some tips(please input the words in ):   what
if [ $what =  help  ];
 echo  ################################################################################################################################ 
 echo   The helping information about this script  
 echo  ################################################################################################################################ 
 echo  COMMAND INFO  
 echo  ################################################################################################################################ 
 echo  status  get the info about the running containers.  
 echo  access  access the specific contianer.  
 echo  manage  manage the contianer,such as  start , stop  and  delete .  
 echo  exit  exit this script.  
 echo  statusa  show the infomation about all containers.   
 echo  statusl  show the latest infomation about container.  
 echo  ################################################################################################################################ 
 echo  MAINCOMMAND SUBCOMMAND INFO  
 echo  ################################################################################################################################ 
 echo  manage   start  launch a exist contianer  
 echo  manage   stop  stop a running container  
 echo  manage   delete  detele a not-running container  
 echo  manage   status  get the info about the running containers  
 echo  manage   statusa  show the infomation about all containers.  
 echo  manage   statusl  show the latest infomation about container.  
 echo  ################################################################################################################################ 
fi 
 
if [ $what =  status  ];
 echo  The running containers are:\n 
 docker ps;
if [ $what =  statusa  ];
then 
 echo  All containers s status:\n 
 docker ps -a;
if [ $what =  statusl  ];
 echo  The latest infomation about containers:\n 
 docker ps -l;
if [ $what =  access  ];
 read -p  Please input the specific container s name:  name;
 CPID=$(docker inspect --format  {{.State.Pid}}  $name);
 nsenter --target $CPID --mount --uts --ipc --net --pid;
if 
 [ $what =  manage  ];
 while true
 read -p  Please input the container name which you want to manage,or  exit ,or  help ?:   name2;
 if [ $name2 =  help  ];
 then
  echo  ############################################################################################################# 
 echo   SUBCOMMAND INFO  
 echo  ############################################################################################################# 
 echo    start  launch a exist contianer  
 echo    stop  stop a running container  
 echo    delete  detele a not-running container  
 echo    status  get the info about the running containers  
 echo    statusa  show the infomation about all containers.  
 echo    statusl  show the latest infomation about container.  
 echo  ############################################################################################################# 
 break;
 if [ $name2 =  status  ];
 then 
  echo  Running container: 
 docker ps;continue;
 if [ $name2 =  exit  ];
 then 
  echo  Exiting 
  break;
 if [ $name2 =  statusa  ];
 then 
  echo  All infomation about containers:\n 
 docker ps -a;continue;
 elif [ $name2 =  statusl  ];
 then
  echo  The latest infomation about containers:\n 
 docker ps -l;continue;
 read -p  Do you want to  start  or  stop  or  delete  your container?:   what2;
 if [ $what2 =  start  ];
 then
 echo  Notice:Please make sure this container is not running 
 docker start $name2;continue
 elif [ $what2 =  stop  ];
 then
 echo  Notice:container is stopping 
 docker stop $name2;continue;
 elif [ $what2 =  delete  ];
 then
 echo  Notice:You cannot delete a running container,if the container is running,please stop it first! 
 docker rm $name2;continue;
 else
  echo  Error:Command Error,no such command! continue;
 fi 
 }

done

编辑 /etc/puppet/manifests/nodes/docker.hzg.com.pp, 加载 docker 类:

node  docker.hzg.com  { include docker}

编辑 /etc/puppet/manifests/site.pp, 加载 docker 节点的配置,增加这么一行:

import  nodes/docker.hzg.com.pp

编辑 /etc/puppet/fileserver.conf,授权 docker 对 modules 和 files 的访问,添加内容:

[files]
 path /etc/puppet/files
 allow docker.hzg.com
# allow *.example.com
# deny *.evil.example.com
# allow 192.168.0.0/24
[files]
 path /etc/puppet/modules
 allow *.hzg.com

编辑 /etc/puppet/puppet.conf,在 [main] 那一段增加以下内容(可?。?/p>

modulepath = /etc/puppet/modules

PS:因为我使用 puppet kick 实现配置,要为 agent 做点配置工作:

agent 上:

编辑 puppet.conf,在 [agent] 那段增加以下内容(可选):

listen = true

实现配置:

master 上:

root@workgroup:~# puppet kick docker.hzg.com
Warning: Puppet kick is deprecated. See http://links.puppetlabs.com/puppet-kick-deprecation
Warning: Failed to load ruby LDAP library. LDAP functionality will not be available
Triggering docker.hzg.com
Getting status
status is success
docker.hzg.com finished with exit code 0
Finished

因为我没有配置 LDAP,所以有些警告内容。

检查 docker 节点上的信息:

root@docker:~# ls
BACKUPDockerfile control.sh Dockerfile hzg.sh init.pp status.log test2.sh test.py util-linux-2.24
root@docker:~# cd /var/log/dockerlaunch/
root@docker:/var/log/dockerlaunch# ls
web1.log webbase.log
root@docker:/var/log/dockerlaunch# cd ~
root@docker:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
050ebb07cf25 training/webapp:latest  python app.py  About a minute ago Up About a minute 0.0.0.0:2000- 5000/tcp web1 
0ef5d56e4c89 training/webapp:latest  python app.py  About a minute ago Up About a minute 0.0.0.0:1000- 5000/tcp web1/webbase,webbase

  可以看到相应的东西都创建了。

关于“如何通过 puppet 管理远程 docker 容器并配置 puppet 和实现变更”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-25发表,共计6708字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 欧美日韩综合高清一区二区 | 综合久久一区二区三区 | 欧美一级毛片免费播放器 | 亚洲精品影视 | 日本一级淫片a的一级欧美 日本一级淫片a免费播放 | 亚洲午夜久久久精品影院 | 狠狠干福利视频 | 天堂亚洲网 | 午夜片神马影院福利 | 亚洲精品无码专区 | 尤物网址在线观看 | 国产在线一区二区三区四区五区 | 国产日韩欧美在线观看 | 欧美色aⅴ欧美综合色 | 色拍拍噜噜噜aⅴ在线观看 色拍拍在精品视频69影院在线 | 性感美女一级毛片 | 亚洲精品国产第一区二区图片 | 2o2o天天看夜夜看狠狠看 | 国产精品爽黄69天堂a | 91夜夜人人揉人人捏人人添 | 国产精品天天狠天天看 | 九九影院午夜理论片少妇 | 玖玖精品视频在线观看 | 四虎永久在线精品波多野结衣 | 精品国产免费一区二区三区五区 | 天美麻花果冻视频大全英文版 | 四虎成人免费电影 | 香蕉影视在线观看 | 久久精品无码一区二区三区 | 无码国产69精品久久久孕妇 | 成人高辣h视频一区二区在线观看 | 国产精品视频在这里有精品 | 一个人看的ww免费视频 | 午夜国产视频 | 亚洲视频欧洲视频 | 少妇性荡欲午夜性开放视频剧场 | 色老头一区二区三区 | 日本真人边吃奶边做爽电影 | 亚洲涩网 | 精品国产97在线观看 | 亚洲精品久久区二区三区蜜桃臀 |