服务器架构
机器信息:
这里部属的机器为3个Master控制节点,3个slave运行节点,其中:
zookeeper、Mesos-master、marathon运行在Master端;Mesos-slave和docker运行在Slave端;需要修改zk的内容来保证slave能够被发现和管理
构建环境
配置mesos-master(3台master节点都要操作)
- # 关闭selinux
- [root@master-1 ~]# sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
- [root@master-1 ~]# setenforce 0
-
- # 关闭防火墙
- [root@master-1 ~]# systemctl stop firewalld.servic
- [root@master-1 ~]# systemctl disable firewalld.service
-
- # 添加mesos的yum源
- [root@master-1 ~]# rpm -Uvh http://repos.mesosphere.io/el/7/noarch/RPMS/mesosphere-el-repo-7-2.noarch.rpm
-
- # 安装mesos、marathon、zookeeper
- #安装依赖的JDK环境
- [root@master-1 ~]# yum install -y java-1.8.0-openjdk-devel java-1.8.0-openjdk
- [root@master-1 ~]# yum -y install mesos marathon mesosphere-zookeeper
-
- # 配置zookeeper
- # 设置文件/var/lib/zookeeper/myid为当前mesos-master节点的id,id必须为1-255中的整数
- # master-1机器id为"1"
- [root@master-1 ~]# echo 1 > /var/lib/zookeeper/myid
-
- # master-2机器id为"2"
- [root@master-2 ~]# echo 2 > /var/lib/zookeeper/myid
-
- # master-3机器id为"3"
- [root@master-3 ~]# echo 3 > /var/lib/zookeeper/myid
-
- # 修改zookeeper配置文件
- [root@master-1 ~]# cp /etc/zookeeper/conf/zoo.cfg /etc/zookeeper/conf/zoo.cfg.bak
- [root@master-1 ~]# vim /etc/zookeeper/conf/zoo.cfg
- # 单个客户端与单台服务器之间的连接数的限制,是ip级别的,默认是50,如果设置为0,那么表明不作任何限制。请注意这个限制的使用范围,仅仅是单台客户端机器与单台ZK服务器之间的连接数限制,不是针对指定客户端IP,也不是ZK集群的连接数限制,也不是单台ZK对所有客户端的连接数限制。
- maxClientCnxns=50
- # Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳
- tickTime=2000
- # Zookeeper的Leader 接受客户端(Follower)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过 5个心跳的时间(也就是tickTime)长度后 Zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是 5*2000=10 秒
- initLimit=10
- # 表示 Leader 与 Follower 之间发送消息时请求和应答时间长度,最长不能超过多少个tickTime 的时间长度,总的时间长度就是 2*2000=4 秒
- syncLimit=5
- # zookeeper数据文件存放目录
- dataDir=/var/lib/zookeeper
- # 客户端连接端口
- clientPort=2181
- # 数字1,2,3表示这个是第几号服务器(是上面myid文件里对应的数字);中间的是master主节点的ip地址
- # 第一个端口2888(这个端口可以自己定义)表示的是这个服务器与集群中的 Leader 服务器交换信息的端口
- # 第二个端口3888表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。
- server.1= 192.168.93.133:2888:3888
- server.2= 192.168.93.134:2888:3888
- server.3= 192.168.93.135:2888:3888
-
- [root@master-1 ~]# vim /etc/mesos/zk
- zk://192.168.93.133:2181,192.168.93.134:2181,192.168.93.135:2181/mesos
-
- # 设置文件/etc/master-/quorum内容为一个大于(master节点数除以2)的整数。即采用四舍五入,比如这里有3个master节点,那么3/2=1.5,四舍五入为2
- [root@master-1 ~]# echo 2 >/etc/mesos-master/quorum
- [root@master-1 ~]# cat /etc/mesos-master/quorum
- 2
-
- # 配置mesos和marathon
- # 主机名和ip要在hosts中写入,最好不要使用localhost,否则会出现slave不能识别,以及marathon任务下发不正常等现象。
-
- # master-1机器
- [root@master-1 ~]# mkdir -p /etc/marathon/conf
- [root@master-1 ~]# echo 192.168.93.133 > /etc/mesos-master/hostname
- [root@master-1 ~]# echo 192.168.93.133 > /etc/marathon/conf/hostname
- [root@master-1 ~]# hostnamectl --static set-hostname master-1.com
- [root@master-1 ~]# echo "192.168.93.133 master-1 master-1.com" >/etc/hosts
- [root@master-1 ~]# cat /etc/hosts
- 192.168.93.133 master-1 master-1.com
-
- # master-2机器
- [root@master-2 ~]# mkdir -p /etc/marathon/conf
- [root@master-2 ~]# echo 192.168.93.134 > /etc/mesos-master/hostname
- [root@master-2 ~]# echo 192.168.93.134 > /etc/marathon/conf/hostname
- [root@master-2 ~]# hostnamectl --static set-hostname master-2.com
- [root@master-2 ~]# echo "192.168.93.134 master-2 master-2.com" >/etc/hosts
- [root@master-2 ~]# cat /etc/hosts
- 192.168.93.134 master-2 master-2.com
-
- # master-3机器
- [root@master-3 ~]# mkdir -p /etc/marathon/conf
- [root@master-3 ~]# echo 192.168.93.135 > /etc/mesos-master/hostname
- [root@master-3 ~]# echo 192.168.93.135 > /etc/marathon/conf/hostname
- [root@master-3 ~]# hostnamectl --static set-hostname master-3.com
- [root@master-3 ~]# echo "192.168.93.135 master-3 master-3.com" >/etc/hosts
- [root@master-3 ~]# cat /etc/hosts
- 192.168.93.135 master-3 master-3.com
-
- [root@master-1 ~]# cp /etc/mesos/zk /etc/marathon/conf/master
- [root@master-1 ~]# cp /etc/mesos/zk /etc/marathon/conf/zk
- [root@master-1 ~]# sed -i 's|mesos|marathon|g' /etc/marathon/conf/zk
-
- # 启动mesos,marathon,zookeeper
- [root@master-1 ~]# systemctl enable zookeeper && systemctl enable mesos-master && systemctl enable marathon
- [root@master-1 ~]# systemctl start zookeeper && systemctl start mesos-master && systemctl start marathon
- [root@master-1 ~]# systemctl disable mesos-slave
-
- # 查看进程状态
- [root@master-1 ~]# systemctl status zookeeper
- [root@master-1 ~]# systemctl status mesos-master
- [root@master-1 ~]# systemctl status marathon
-
- [root@master-1 ~]# lsof -i:2181
- [root@master-1 ~]# lsof -i:5050
- [root@master-1 ~]# lsof -i:8080
-
- # 检查配置
- #配置过程中出错,为了方便检查对比各master配置,直接执行如下命令。
- [root@master-1 ~]# cat /var/lib/zookeeper/myid && grep -v "^#" /etc/zookeeper/conf/zoo.cfg && cat /etc/mesos/zk && cat /etc/mesos-master/quorum && cat /etc/mesos-master/hostname&& cat /etc/marathon/conf/hostname&& cat /etc/marathon/conf/master&&cat /etc/marathon/conf/zk
- 1
- maxClientCnxns=50
- tickTime=2000
- initLimit=10
- syncLimit=5
- dataDir=/var/lib/zookeeper
- clientPort=2181
- server.1= 192.168.93.133:2888:3888
- server.2= 192.168.93.134:2888:3888
- server.3= 192.168.93.135:2888:3888
- zk://192.168.93.133:2181,192.168.93.134:2181,192.168.93.135:2181/mesos
- 2
- 192.168.93.133
- 192.168.93.133
- zk://192.168.93.133:2181,192.168.93.134:2181,192.168.93.135:2181/mesos
- zk://192.168.93.133:2181,192.168.93.134:2181,192.168.93.135:2181/marathon
-
- # 以上操作后,master节点机不能ping通外网,是因为DNS解析文件被改变了,执行下面命令即可:
- [root@master-1 local]# echo "nameserver 114.114.114.114" >> /etc/resolv.conf
- [root@master-1 ~]# ping www.baidu.com
- PING www.a.shifen.com (180.97.33.108) 56(84) bytes of data.
- 64 bytes from 180.97.33.108 (180.97.33.108): icmp_seq=1 ttl=128 time=13.1 ms
- ...
配置slave节点(3台slave节点都要操作)
- # 关闭selinux
- [root@slave-1 ~]# sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
- [root@slave-1 ~]# setenforce 0
-
- # 关闭防火墙
- [root@slave-1 ~]# systemctl stop firewalld.servic
- [root@slave-1 ~]# systemctl disable firewalld.service
-
- # 安装并启动docker
- [root@slave-1 ~]# yum install -y docker
- [root@slave-1 ~]# systemctl enable docker
- [root@slave-1 ~]# systemctl start docker
-
- # 拉取镜像(三台slave节点机都需要下载镜像,因为在marathon界面里创建docker容器,是随机在slave节点机上读取镜像创建的)
- [root@slave-1 ~]# docker pull nginx
- [root@slave-1 ~]# docker pull tomcat
- [root@slave-1 ~]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- docker.io/nginx latest 2f7f7bce8929 6 days ago 107.5 MB
- docker.io/tomcat latest a2fbbcebd67e 11 days ago 333.9 MB
-
- # 添加mesos的yum源
- [root@slave-1 ~]# rpm -Uvh http://repos.mesosphere.io/el/7/noarch/RPMS/mesosphere-el-repo-7-2.noarch.rpm
-
- # 安装mesos
- [root@slave-1 ~]# yum -y install mesos
-
- # 配置master信息
- # slave-1机器
- [root@slave-1 ~]# echo 192.168.93.136 > /etc/mesos-slave/hostname
- [root@slave-1 ~]# hostnamectl --static set-hostname slave-1.com
- [root@slave-1 ~]# echo "192.168.93.136 slave-1 slave-1.com" >/etc/hosts
- [root@slave-1 ~]# cat /etc/hosts
- 192.168.93.136 slave-1 slave-1.com
-
- # slave-2机器
- [root@slave-2 ~]# echo 192.168.93.137 > /etc/mesos-slave/hostname
- [root@slave-2 ~]# hostnamectl --static set-hostname slave-2.com
- [root@slave-2 ~]# echo "192.168.93.137 slave-2 slave-1.com" >/etc/hosts
- [root@slave-2 ~]# cat /etc/hosts
- 192.168.93.137 slave-2 slave-2.com
-
- # slave-3机器
- [root@slave-3 ~]# echo 192.168.93.138 > /etc/mesos-slave/hostname
- [root@slave-3 ~]# hostnamectl --static set-hostname slave-3.com
- [root@slave-3 ~]# echo "192.168.93.138 slave-3 slave-1.com" >/etc/hosts
- [root@slave-3 ~]# cat /etc/hosts
- 192.168.93.138 slave-3 slave-3.com
-
- [root@slave-1 ~]# cat /etc/mesos/zk
- zk://192.168.93.133:2181,192.168.93.134:2181,192.168.93.135:2181/mesos
-
- # 配置marathon调用mesos运行docker容器
- [root@slave-1 ~]# echo 'docker,mesos' > /etc/mesos-slave/containerizers
-
- #启动slave(要保证mesos-slave启动后,读取的zk信息是那三个mesos-master的连接信息,否则mesos访问页面里就不会出现这个slave节点信息。ps -ef|grep mesos-slave,如果没有读取到zk信息,可以尝试重启服务器再查看)
- [root@slave-1 ~]# systemctl start mesos-slave && systemctl enable mesos-slave
- [root@slave-1 ~]# systemctl disable mesos-master
-
- # 以上操作后,slave节点机不能ping通外网,是因为DNS解析文件被改变了,执行下面命令即可:
- [root@slave-1 ~]#echo "nameserver 114.114.114.114" >> /etc/resolv.conf
- [root@slave-1 ~]# ping www.baidu.com
- PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
- 64 bytes from 14.215.177.38: icmp_seq=1 ttl=53 time=38.3 ms
- .......
-
- # 如果mesos-slave启动失败,可以如下检查:
- [root@slave-1 ~]# journalctl -f -u mesos-slave