docker+zookeeper+mesos+marathon集群

 实验环境:

主机名 ip地址 运行服务 安装组件
docker-master1 192.168.20.210 zookeeper
mesos-master
marathon

mesos
marathon
mesosphere-zookeeper

jdk1.8

docker-master2 192.168.20.211 zookeeper
mesos-master
marathon

mesos
marathon
mesosphere-zookeeper

jdk1.8

docker-master3 192.168.20.212 zookeeper
mesos-master
marathon

mesos
marathon
mesosphere-zookeeper

jdk1.8

docker-slave1 192.168.20.213 mesos-slave 

mesos

docker-engine

docker-slave2 192.168.20.214 mesos-slave

mesos

docker-engine

一、 准备工作:
1.1   关闭Selinux
# setenforce 0

# sed -i '/^SELINUX=/c SELINUX=disabled'/etc/selinux/config

1.2   关闭防火墙
# systemctl stop firewalld

# systemctl disable firewalld

1.3   配置主机名解析
[root@docker-master1 ~]# vi /etc/hosts

192.168.20.210 docker-master1
192.168.20.211 docker-master2
192.168.20.212 docker-master3
192.168.20.213 docker-slave1
192.168.20.214 docker-slave2

1.4更新mesos、marathon源

rpm -ivh http://repos.mesosphere.com/el/7/noarch/RPMS/mesosphere-el-repo-7-1.noarch.rpm

二、 master节点配置

2.1 master节点安装JDK1.8

tar -zxvf /root/jdk-8u171-linux-x64.tar.gz -C /usr/local

cat >> /etc/profile << EOF

export JAVA_HOME=/usr/local/jdk1.8.0_171
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH

EOF

source /etc/profile

 

2.2 master 安装zookeeper(这里只以192.168.20.210为例)

2.2.1 解压zookeeper

tar zxf /root/zookeeper-3.4.8.tar.gz /usr/local

2.2.2创建zookeeper的日志目录和数据目录

mkdir /usr/local/zookeeper-3.4.8/{logs,data}

2.2.3修改zookeeper配置文件

touch /usr/local/zookeeper-3.4.8/conf/zoo.cfg

cat /usr/local/zookeeper-3.4.8/conf/zoo.cfg

tickTime=2000
dataDir=/usr/local/zookeeper-3.4.8/data
dataLogDir=/usr/local/zookeeper-3.4.8/logs
clientPort=2181
initLimit=5
syncLimit=2
server.1=192.168.20.210:2888:3888
server.2=192.168.20.211:2888:3888
server.3=192.168.20.212:2888:3888

1、2、3表示对应服务器上的myid,2888端口表示和leader通讯端口,3888端口表示选举端口

touch /usr/local/zookeeper-3.4.8/data/myid (每台主机上的myid是有zoo.cfg文件里的server后面的数字决定)

cat /usr/local/zookeeper-3.4.8/data/myid

1
cat >> /etc/profile << EOF
export PATH=$PATH:/usr/local/zookeeper-3.4.8/bin
EOF

source /etc/profile

2.2.4启动zookeeper

 zkServer.sh start

2.2.5 查看zookeeper状态

[root@docker-master1 zookeeper]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower

 

2.3 master节点安装mesos(这里只以192.168.20.210为例)

2.3.1安装mesos程序

yum install mesos -y

2.3.2配置mesos

vi /etc/mesos/zk

zk://192.168.20.210:2181,192.168.20.211:2181,192.168.20.212:2181/mesos
[root@docker-master1 ~]# cd /etc/mesos-master
[root@docker-master1 mesos-master]# cat cluster 
mesoscluster
[root@docker-master1 mesos-master]# cat hostname 
192.168.20.210
[root@docker-master1 mesos-master]# cat ip 
192.168.20.210
[root@docker-master1 mesos-master]# cat quorum 
2
[root@docker-master1 mesos-master]#  cat work_dir 
/var/lib/mesos

quorum表示zookeeper集群中 要求最少参加选举节点的数目,一般设置为zookeeper集群节点个数的一半多些(比如3个节点的话,可配置为2)

2.3.2 启动mesos服务

systemctl start mesos-master

 默认端口5050,访问地址:http://192.168.20.210:5050

2.4 master节点安装marathon(这里只以192.168.20.210为例) 

2.4.1 安装marathon程序

yum install -y marathon

2.4.1创建marathon配置文件目录(1.5版本之前)

mkdir -p /etc/marathon/conf
[root@docker-master1 conf]# ls
hostname  master  zk
[root@docker-master1 conf]# cat hostname 
192.168.20.210
[root@docker-master1 conf]# cat master 
zk://192.168.20.210:2181,192.168.20.211:2181,192.168.20.212:2181/mesos
[root@docker-master1 conf]# cat zk
zk://192.168.20.210:2181,192.168.20.211:2181,192.168.20.212:2181/marathon

1.5版本之后在/etc/default/marathon文件最下面增加如下两行

MARATHON_MASTER=zk://docker-master1:2181,docker-master2:2181,docker-master3:2181/mesos
MARATHON_ZK=zk://docker-master1:2181,docker-master2:2181,docker-master3:2181/marathon

 

2.4.2 启动marathon

systemctl start marathon

如果启动不了,查看/var/log/message,如有以下错误,

No start hook file found ($HOOK_MARATHON_START). Proceeding with the start script.

则可以在命令行直接启动marathon

nohup marathon --master zk://192.168.20.210:2181,192.168.20.211:2181,192.168.20.212:2181/mesos --zk zk://192.168.20.210:2181,192.168.20.211:2181,192.168.20.212:2181/marathon &

 默认8080端口,访问地址:http://192.168.20.210:8080/ui/#/apps

 

三、slave节点配置

 3.1 slave安装docker(这里只以192.168.20.213为例)

yum install docker

3.1.1 启动docker并且设置为开机自启动

systemctl enable docker.service

systemctl start docker.service

 

3.2 slave安装mesos(这里只以192.168.20.213为例)

3.2.1 安装mesos程序

yum install mesos -y

3.2.2配置mesos-slave

[root@docker-slave1 mesos-slave]# cd /etc/mesos-slave/
[root@docker-slave1 mesos-slave]# ls
attributes  containerizers  executor_registration_timeout  hostname  ip  work_dir
[root@docker-slave1 mesos-slave]# cat attributes 
rack_id:rack-1
[root@docker-slave1 mesos-slave]# cat containerizers 
docker,mesos
[root@docker-slave1 mesos-slave]# cat executor_registration_timeout 
15mins
[root@docker-slave1 mesos-slave]# cat hostname 
192.168.20.213
[root@docker-slave1 mesos-slave]# cat ip
192.168.20.213
[root@docker-slave1 mesos-slave]# cat work_dir 
/var/lib/mesos

3.2.3启动mesos-slave

systemctl start mesos-slave

mesos-slave默认端口为5051

 完成以上操作即完成了Mesos的DCOS集群搭建,下一章我们介绍《marathon的高可用服务自动发现和负载均衡》。

posted @ 2018-10-24 17:10  面对疾风  阅读(708)  评论(0编辑  收藏  举报