如何搭建擁有服務發現能力的Mesosphere集群環境
有鑒于Docker集群技術如雨后春筍般不停涌現,我來分享我自己在探索Mesosphere上的經驗和結果,我將告訴讀者如何在CentOS 7上基于Mesosphere搭建擁有服務發現能力的Docker集群。
我GitHub項目上的說明:https://github.com/draculavlad/SetUpMesosphereOnCentos7WithServiceDiscovery
本人語死早,請諒解我的語言組織能力
搭建環境
CentOS 7
系統初始化
- 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
如果需要的話關閉防火墻。
- 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
啟動haproxy
haproxy只有master節點才需要
- yum -y install haproxy && systemctl start haproxy
安裝啟動docker
- rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
- yum install -y docker
預初始化
- systemctl disable mesos-master
- systemctl disable mesos-slave
- systemctl disable marathon
- systemctl disable zookeeper
ZooKeeper 配置和啟動
只有master 節點需要如此操作。
設置文件[/var/lib/zookeeper/myid]為當前mesos master節點的id,id必須為1-255之中的整數,例如:1
添加所有的mesos master節點信息到文件[/etc/zookeeper/conf/zoo.cf],例如:
master_node_id為master節點id同該節點[/var/lib/zookeeper/myid]文件的配置,master_node_ip為master節點的ip地址:
- server.$master_node_id=$master_node_ip:2888:3888
啟動ZooKeeper:
- systemctl start zookeeper
#p#
Mesos 配置和啟動
master和slave節點都需要如此設置。添加所有的master節點到文件[/etc/mesos/zk],例如:
- zk://$first_master_node_ip:2181,$second_master_node_ip:2181,.../mesos
Mesos master 和 marathon的配置和啟動
只有master節點需要如此配置,marathon節點與master節點不同,目前我是把marathon安裝在master節點。
設置文件[/etc/mesos-master/quorum]內容為一個大于master節點數除以2的整數。
設置文件[/etc/mesos-master/ip]內容為當前master節點的ip
設置文件[/etc/mesos-master/hostname]內容為當前master節點的域名(必須可被其他節點解析)
- 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的服務發現功能
安裝在master節點。因為官方推薦的腳本和Haproxy1.5不兼容所以請使用我的腳本
- wget 'https://github.com/draculavlad/SetUpMesosphereOnCentos7/blob/master/haproxy-marathon-
設置文件[/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
執行安裝腳本:
- chmod +x haproxy-marathon-bridge
- ./haproxy-marathon-bridge install_cronjob
啟動mesos master和marathon服務
- systemctl start mesos-master
- systemctl start marathon
mesos slave 節點配置和啟動
設置文件[/etc/mesos-slave/ip]內容為當前slave節點的ip地址
設置文件[/etc/mesos-slave/hostname]內容為當前slave節點的域名(必須可被其他節點解析)
使slave節點支持Docker:
- echo 'docker,mesos' > /etc/mesos-slave/containerizers
- echo '5mins' > /etc/mesos-slave/executor_registration_timeout
啟動mesos slave:
- systemctl start mesos-slave
測試腳本
測試腳本來自于我參考的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