怎么从marathon中使用docker启动nginx

51次阅读
没有评论

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

这篇文章主要介绍“怎么从 marathon 中使用 docker 启动 nginx”,在日常操作中,相信很多人在怎么从 marathon 中使用 docker 启动 nginx 问题上存在疑惑,丸趣 TV 小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么从 marathon 中使用 docker 启动 nginx”的疑惑有所帮助!接下来,请跟着丸趣 TV 小编一起来学习吧!

如果程序一直 deploy 说明一定有问题
mac 安装

brew install mesos
brew upgrade mesos

启动 zookeeper 启动 master

HOST_IP=100.80.128.98
sudo /usr/local/Cellar/mesos/1.4.1/sbin/mesos-master --ip=${HOST_IP} \
 --log_dir=/Users/lifei/dockerproject/mesos/master/log --work_dir=/Users/lifei/dockerproject/mesos/master/work \
 --ZK=zk://${HOST_IP}:2181/mesos --quorum=1

启动 slave(注意端口,如果 marathon 中用到 80 等端口,需要将 ports 范围足够大)

/usr/local/Cellar/mesos/1.4.1/sbin/mesos-slave --help  查看帮助
启动第一个 slave
sudo /usr/local/Cellar/mesos/1.4.1/sbin/mesos-slave --master=${HOST_IP}:5050 \
--log_dir=/Users/lifei/dockerproject/mesos/slave/log --work_dir=/Users/lifei/dockerproject/mesos/slave/work \
--containerizers=docker,mesos --no-hostname_lookup --ip=${HOST_IP} --resources= ports:[1-32000];  
启动第二个 slave
sudo /usr/local/Cellar/mesos/1.4.1/sbin/mesos-slave --master=${HOST_IP}:5050 \
--log_dir=/Users/lifei/dockerproject/mesos/slave/log2 --work_dir=/Users/lifei/dockerproject/mesos/slave/work2 \
--containerizers=docker,mesos --no-hostname_lookup --ip=${HOST_IP} --resources= ports:[1-32000];

测试 task

/usr/local/Cellar/mesos/1.4.1/bin/mesos-execute --master=localhost:5050 --name=hellomesos --command= echo  hello,mesos

启动 marathon

sudo ./bin/start --http_port 8088 --master ${HOST_IP}:5050 --zk zk://${HOST_IP}:2181/marathon -h ${HOST_IP}

测试 marathon

Command
while [ true ] ; do echo  Hello Marathon  ; sleep 5 ; done

从 marathon 中使用 docker 启动 nginx

{
  type :  DOCKER ,
  volumes : [],
  docker : {
  image :  library/nginx ,
  network :  BRIDGE ,
  portMappings : [
 {
  containerPort : 80,
  hostPort : 0,
  servicePort : 2000,
  protocol :  tcp ,
  labels : {}
 }
 ],
  privileged : false,
  parameters : [],
  forcePullImage : false
 }
使用 docker inspect containerid,查看动态分配的 hostport
ps: 在 container 里边,  这个 web 服务运行的端口是 8080(containerPort 的值)。在 container 外,Marathon 会分配一个随机端口(hostPort 设置是 0)

marathon-lb 安装

 采用 bridge 方式,host 方式失败,不明白问题在哪儿 **********
  id :  /marathon-lb ,
  cmd : null,
  cpus : 1,
  mem : 128,
  disk : 0,
  instances : 1,
  constraints : [
 [
  hostname ,
  UNIQUE 
 ]
 ],
  container : {
  type :  DOCKER ,
  volumes : [
 {
  containerPath :  /var ,
  hostPath :  /Users/lifei/dockerproject/marathon/marathon-lb-var ,
  mode :  RW 
 },
 {
  containerPath :  /tmp ,
  hostPath :  /Users/lifei/dockerproject/marathon/marathon-lb-tmp ,
  mode :  RW 
 }
 ],
  docker : {
  image :  docker.io/mesosphere/marathon-lb ,
  network :  BRIDGE ,
  portMappings : [
 {
  containerPort : 80,
  hostPort : 80,
  servicePort : 10001,
  protocol :  tcp ,
  labels : {}
 },
 {
  containerPort : 9090,
  hostPort : 9090,
  servicePort : 10002,
  protocol :  tcp ,
  labels : {}
 }
 ],
  privileged : true,
  parameters : [],
  forcePullImage : false
 }
 },
  portDefinitions : [
 {
  port : 10001,
  protocol :  tcp ,
  labels : {}
 },
 {
  port : 10002,
  protocol :  tcp ,
  labels : {}
 }
 ],
  args : [
  sse ,
  -m ,
  http://100.80.128.98:8088 ,
  --group ,
  external 
 ]
}

测试 marathon-lb

{
  id :  /test-lb-nginx ,
  cmd : null,
  cpus : 0.2,
  mem : 20,
  disk : 0,
  instances : 2,
  container : {
  type :  DOCKER ,
  volumes : [],
  docker : {
  image :  docker.io/nginx ,
  network :  BRIDGE ,
  portMappings : [
 {
  containerPort : 80,
  hostPort : 0,
  servicePort : 80,
  protocol :  tcp ,
  labels : {}
 }
 ],
  privileged : false,
  parameters : [],
  forcePullImage : false
 }
 },
  healthChecks : [
 {
  path :  / ,
  protocol :  HTTP ,
  portIndex : 0,
  gracePeriodSeconds : 300,
  intervalSeconds : 60,
  timeoutSeconds : 20,
  maxConsecutiveFailures : 3,
  ignoreHttp1xx : false
 }
 ],
  labels : {
  HAPROXY_GROUP :  external ,
  HAPROXY_0_VHOST :  nginx.marathon.mesos 
 },
  portDefinitions : [
 {
  port : 80,
  protocol :  tcp ,
  labels : {}
 }
 ]
}

测试 url

http://100.80.128.98:9090/haproxy?stats
http://100.80.128.98

到此,关于“怎么从 marathon 中使用 docker 启动 nginx”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注丸趣 TV 网站,丸趣 TV 小编会继续努力为大家带来更多实用的文章!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-16发表,共计3640字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)