如何搭建擁有服務(wù)發(fā)現(xiàn)能力的Mesosphere集群環(huán)境
有鑒于Docker集群技術(shù)如雨后春筍般不停涌現(xiàn),我來(lái)分享我自己在探索Mesosphere上的經(jīng)驗(yàn)和結(jié)果,我將告訴讀者如何在CentOS 7上基于Mesosphere搭建擁有服務(wù)發(fā)現(xiàn)能力的Docker集群。
我GitHub項(xiàng)目上的說(shuō)明:https://github.com/draculavlad/SetUpMesosphereOnCentos7WithServiceDiscovery
本人語(yǔ)死早,請(qǐng)諒解我的語(yǔ)言組織能力
搭建環(huán)境
CentOS 7
系統(tǒng)初始化
- yum update -y
- yum install bash curl wget tar zip unzip bzip2 telnet net-tools git -y
- yum groupinstall "Development Tools" –y
- yum -y install ntp ntpdate
- systemctl start ntpd
如果需要的話關(guān)閉防火墻。
- setenforce Permissive
- systemctl stop firewalld
- systemctl disable firewalld
添加yum源。
- rpm -Uvh 'http://repos.mesosphere.io/el/7/noarch/RPMS/mesosphere-el-repo-7-1.noarch.rpm'
- rpm -Uvh 'http://archive.cloudera.com/cdh4/one-click-install/redhat/6/x86_64/cloudera-c
安裝
- yum -y install mesos marathon mesosphere-zookeeper
啟動(dòng)haproxy
haproxy只有master節(jié)點(diǎn)才需要
- yum -y install haproxy && systemctl start haproxy
安裝啟動(dòng)docker
- rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
- yum install -y docker
預(yù)初始化
- systemctl disable mesos-master
- systemctl disable mesos-slave
- systemctl disable marathon
- systemctl disable zookeeper
ZooKeeper 配置和啟動(dòng)
只有master 節(jié)點(diǎn)需要如此操作。
設(shè)置文件[/var/lib/zookeeper/myid]為當(dāng)前mesos master節(jié)點(diǎn)的id,id必須為1-255之中的整數(shù),例如:1
添加所有的mesos master節(jié)點(diǎn)信息到文件[/etc/zookeeper/conf/zoo.cf],例如:
master_node_id為master節(jié)點(diǎn)id同該節(jié)點(diǎn)[/var/lib/zookeeper/myid]文件的配置,master_node_ip為master節(jié)點(diǎn)的ip地址:
- server.$master_node_id=$master_node_ip:2888:3888
啟動(dòng)ZooKeeper:
- systemctl start zookeeper
#p#
Mesos 配置和啟動(dòng)
master和slave節(jié)點(diǎn)都需要如此設(shè)置。添加所有的master節(jié)點(diǎn)到文件[/etc/mesos/zk],例如:
- zk://$first_master_node_ip:2181,$second_master_node_ip:2181,.../mesos
Mesos master 和 marathon的配置和啟動(dòng)
只有master節(jié)點(diǎn)需要如此配置,marathon節(jié)點(diǎn)與master節(jié)點(diǎn)不同,目前我是把marathon安裝在master節(jié)點(diǎn)。
設(shè)置文件[/etc/mesos-master/quorum]內(nèi)容為一個(gè)大于master節(jié)點(diǎn)數(shù)除以2的整數(shù)。
設(shè)置文件[/etc/mesos-master/ip]內(nèi)容為當(dāng)前master節(jié)點(diǎn)的ip
設(shè)置文件[/etc/mesos-master/hostname]內(nèi)容為當(dāng)前master節(jié)點(diǎn)的域名(必須可被其他節(jié)點(diǎn)解析)
- mkdir -p /etc/marathon/conf
- cp /etc/mesos/zk /etc/marathon/conf/master
- cp /etc/marathon/conf/master /etc/marathon/conf/zk
- sed –i 's|mesos|marathon|g' /etc/marathon/conf/zk
添加Mesosphere的服務(wù)發(fā)現(xiàn)功能
安裝在master節(jié)點(diǎn)。因?yàn)楣俜酵扑]的腳本和Haproxy1.5不兼容所以請(qǐng)使用我的腳本
- wget 'https://github.com/draculavlad/SetUpMesosphereOnCentos7/blob/master/haproxy-marathon-
設(shè)置文件[/etc/haproxy-marathon-bridge/marathons]:
- echo "$first_marathon_node_ip:8080" >> /etc/haproxy-marathon-bridge/marathons
- echo "$second_marathon_node_ip:8080" >> /etc/haproxy-marathon-bridge/marathons
- echo "$third_marathon_node_ip:8080" >> /etc/haproxy-marathon-bridge/marathons
執(zhí)行安裝腳本:
- chmod +x haproxy-marathon-bridge
- ./haproxy-marathon-bridge install_cronjob
啟動(dòng)mesos master和marathon服務(wù)
- systemctl start mesos-master
- systemctl start marathon
mesos slave 節(jié)點(diǎn)配置和啟動(dòng)
設(shè)置文件[/etc/mesos-slave/ip]內(nèi)容為當(dāng)前slave節(jié)點(diǎn)的ip地址
設(shè)置文件[/etc/mesos-slave/hostname]內(nèi)容為當(dāng)前slave節(jié)點(diǎn)的域名(必須可被其他節(jié)點(diǎn)解析)
使slave節(jié)點(diǎn)支持Docker:
- echo 'docker,mesos' > /etc/mesos-slave/containerizers
- echo '5mins' > /etc/mesos-slave/executor_registration_timeout
啟動(dòng)mesos slave:
- systemctl start mesos-slave
測(cè)試腳本
測(cè)試腳本來(lái)自于我參考的youtube視頻
- wget 'https://github.com/draculavlad/SetUpMesosphereOnCentos7WithServiceDiscovery/blob/master/launch.sh'
- wget 'https://github.com/draculavlad/SetUpMesosphereOnCentos7WithServiceDiscovery/blob/master/nginx-bridge.json'
- export marathon_node_ip=$your_marathon_node_ip
- chmod +x launch.sh
- ./launch.sh nginx-bridge.json