Chinaunix首页 | 论坛 | 博客
  • 博客访问: 140879
  • 博文数量: 34
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 252
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-27 20:04
文章分类

全部博文(34)

文章存档

2018年(1)

2017年(23)

2016年(10)

我的朋友

分类: Python/Ruby

2017-05-13 16:38:45

简介

本文当用于智城云系统发布中的基础设施建设,包括redisfdfsmariadbmongorabbitmq

发布机器配置

单机测试系统需要

cpu

mem

disk

OS

>=4

>=8

50GB

CentOS 6.8

文件准备

  • 使用 10.112.80.1 机器作为运维部署服务器
  • 安装resilio sync 并同步软件到10.112.80.1
  • 同步目录必须和下表一致
  • 关闭防火墙

同步目录

简介

rslsync key

/opt/3rd/funcs

python fabric写好的模块

B33Z4ASZ4RHWQMOXJIP6BVUSQ56B7KXQR

/opt/software

发布用的程序文件

B7QERSPFRTHNA5OJJOKE7LHT573NCK5VU

  • rslsync主要用于同步数据目录,非常方便, 相关参考
  • 安装步骤可参考:

发布过程

机器和网络准备

  • SSH可以直接登陆服务器,并且拥有root权限
  • 关闭所有机器的防火墙
  • 所有机器可以访问公网
  • 机器规划列表,如果是测试系统,可以都在一台系统里面

机器

系统服务

10.112.80.1

cdh jdk

10.112.80.2

jdk

10.112.80.3

jdk mariadb mq zk redis fdfs mongo

10.112.80.4

jdk

10.112.80.5

jdk

10.112.80.6

jdk

fabric文件修改

  • 下面的文件放在/opt目录下,
  • 这个文件是调用 /opt/3rd以及/opt/software
  • 里面的ip地址需要按照当前环境进行修改
  • 里面的ip地址我已经按照国美现状修改完成,里面必须需要修改的是t1_t6root密码

#!/usr/bin/python

# -*- coding: utf-8 -*

from fabric.api import *

from fabric.context_managers import *

from fabric.contrib.console import confirm

from fabric.contrib.files import *

from fabric.contrib.project import rsync_project

import fabric.operations

import time,os

import logging

import base64

from getpass import getpass

import json

import sys

execfile("/opt/3rd/funcs/addons.py")

execfile("/opt/3rd/funcs/basic.py")

execfile("/opt/3rd/funcs/cdh.py")

execfile("/opt/3rd/funcs/fdfs.py")

execfile("/opt/3rd/funcs/haproxy.py")

execfile("/opt/3rd/funcs/kafka.py")

execfile("/opt/3rd/funcs/keepalived.py")

execfile("/opt/3rd/funcs/mariadb.py")

execfile("/opt/3rd/funcs/mgmt.py")

execfile("/opt/3rd/funcs/mongo.py")

execfile("/opt/3rd/funcs/rabbitmq.py")

execfile("/opt/3rd/funcs/redis.py")

execfile("/opt/3rd/funcs/zookeeper.py")

execfile("/opt/3rd/funcs/shell.py")

 

 

# 如果需要打印log,取消下行的注释

logging.basicConfig(level=logging.WARN)

 

# 定义三台服务器

 

## 基础设施服务_root

 

t_1="root@10.112.80.1:22"

t_2="root@10.112.80.2:22"

t_3="root@10.112.80.3:22"

t_4="root@10.112.80.4:22"

t_5="root@10.112.80.5:22"

t_6="root@10.112.80.6:22"

 

## 业务服务_machtalk

m_1="machtalk@10.112.80.1:22"

m_2="machtalk@10.112.80.2:22"

m_3="machtalk@10.112.80.3:22"

m_4="machtalk@10.112.80.4:22"

m_5="machtalk@10.112.80.5:22"

m_6="machtalk@10.112.80.6:22"

 

 

# define the comment for each machine 

#env.comments = {

#  t: "managent server",

#}

 

# 必须修改 t1_t6root密码

env.passwords = {

    t_1:"pwd",

    t_2:"pwd",

    t_3:"pwd",

    t_4:"pwd",

    t_5:"pwd",

    t_6:"pwd",

    m_1:"GVk2qWUTW7kP2hwQ",

    m_2:"GVk2qWUTW7kP2hwQ",

    m_3:"GVk2qWUTW7kP2hwQ",

    m_4:"GVk2qWUTW7kP2hwQ",

    m_5:"GVk2qWUTW7kP2hwQ",

    m_6:"GVk2qWUTW7kP2hwQ"

}

 

env.roledefs = {

        'basic': [t_1,t_2,t_3,t_4,t_5,t_6],

        'fdfs': [m_3],

        'redis': [m_3],

        'mongo': [ m_3],

        'rabbitmq': [m_3],

        'zookeeper': [m_3],

        'mariadb':[m_3],

        'cdh': [t_1]

        }

 

# 定义一些环境变量,没有也无所谓,小细节

#env.sdir="/data/soft/soft/"

#env.ddir="/opt/machtalk/"

env.disable_known_hosts=True

env.abort_on_prompts=True

env.skip_bad_hosts = True

env.remote_interupt = True

env.warn_only = True

env.eagerly_disconnect = True

env.key_filename="./key"

#env.gateway=t

env.keepalive = 1

 

# 定义一些常量

## 本地软件目录

env.local_softdir="/opt/software/"

## 远端软件目录

env.remote_softdir="/opt/software/"

## 远端家目录

env.remote_dir="/opt/machtalk/"

 

# 需要一个json,描述场景中的变量

confJson = {

  'clusterName': "gomeTest",

  'clusterType': "cluster",

  'servers': [ 'x.x.x.x', 'x.x.x.x.', 'x.x.x.x', 'x.x.x.x' ],

  #'rootpass': '',

  #'managementServer': "x.x.x.x",

  'services': {

          'basic': {

            'normalUserName': 'machtalk',

            'normalUserPass': 'GVk2qWUTW7kP2hwQ'

          },

          'zookeeper': {

            'servers': [ '10.112.80.3' ],

            'usrname': 'machtalk',

            'pwd': 'dJIccFRHS8oGbda9',

            'useroot': 0,

            'zkclientport': '1812'

          },

          'mariadb': {

            'servers': [ '10.112.80.3' ],

            'usrname': 'machtalk',

            'pwd': 'dJIccFRHS8oGbda9',

            'useroot': 0,

            'usrname_replication': 'repli',

            'pwd_replication': 'repli'

          },

          'redis' :{

            'servers': [ '10.112.80.3' ],

            'pwd': "dJIccFRHS8oGbda9",

            'pwd_masterauth': "dJIccFRHS8oGbda9",

          },

          'rabbitmq': {

            'servers': [ '10.112.80.3' ],

            'usrname': "machtalk",

            'pwd': "dJIccFRHS8oGbda9",

          },

          'fdfs': {

            'servers': [ '10.112.80.3' ],

            'storages': [

                        [ '10.112.80.3' ],

                      ],

            'trackers': [ '10.112.80.3' ],

            'nginxs': [ '10.112.80.3' ]

          },

          'mongo': { },

          'cdh': {

              'servers': [ "10.112.80.1" ],

              'dbip': "10.112.80.3",

              'dbusrname': "machtalk",

              'dbpwd': "dJIccFRHS8oGbda9"

          }

  }

}

 

# json unicode转成str的函数

def byteify(input):

    if isinstance(input, dict):

        return {byteify(key):byteify(value) for key,value in input.iteritems()}

    elif isinstance(input, list):

        return [byteify(element) for element in input]

    elif isinstance(input, unicode):

        return input.encode('utf-8')

    else:

        return input

 

print json.dumps(confJson,ensure_ascii=False).encode('utf-8')

env.info = json.loads(json.dumps(confJson,ensure_ascii=False),encoding='utf-8')

env.info = byteify(env.info)

开始发布

# 进入fabric 沙箱环境

source /opt/software/fabAnsible/bin/activate

# 进入 fabricfile.py 目录

cd /opt

# 查看已有的fabric命令

fab list

# 按顺序执行以下列表的中的命令

安装软件

执行命令

备注

basic

fab basic_deploy

建立账户,调整参数等

fdfs

fab fdfs_deploy


redis

fab redis_deploy


zookeeper

fab zookeeper_putfile; fab zookeeper_deploy


rabbitmq

fab rabbitmq_putfile; fab rabbitmq_deploy


mariadb

fab mariadb_putfile; fab mariadb_deploy


rabbitmq

fab rabbitmq_putfile; fab rabbitmq_deploy


mongodb

fab mongo_single_deploy


cdh

fab cdh_putfile; fab cdh_deploy


 

---------------------------------------------------------------------------
集群可以把脚本中json换成以下:
confJson = {
  'clusterName': "gomeProd",
  'clusterType': "cluster",
  'servers': [ 'x.x.x.x', 'x.x.x.x.', 'x.x.x.x', 'x.x.x.x' ],
  #'rootpass': '',
  #'managementServer': "x.x.x.x",
  'services': {
          'basic': {
            'normalUserName': 'machtalk',
            'normalUserPass': 'GVk2qWUTW7kP2hwQ'
          },
          'zookeeper': {
            'servers': [ '10.112.73.32','10.112.73.33','10.112.73.34' ],
            'usrname': 'machtalk',
            'pwd': 'dJIccFRHS8oGbda9',
            'useroot': 0,
            'zkclientport': '1812'
          },
          'mariadb': {
            'servers': [ '10.112.73.38','10.112.73.39' ],
            'usrname': 'machtalk',
            'pwd': 'dJIccFRHS8oGbda9',
            'useroot': 0,
            'usrname_replication': 'repli',
            'pwd_replication': 'repli'
          },
          'fdfs': {
            'servers': [ '10.112.73.40','10.112.73.41'],
            'storages': [
                        [ '10.112.73.40','10.112.73.41' ],
                      ],
            'trackers': [ '10.112.73.40','10.112.73.41' ],
            'nginxs': [ '10.112.73.40','10.112.73.41' ]
          },
          'mongo': {
        'usrname': 'machtalk',
            'pwd': 'dJIccFRHS8oGbda9',
            'useroot': 0,
            'usrname_view': 'xcloud',
            'pwd_view': 'dJIccFRHS8oGbda9',
            # For 监控调用
            'port': '20000',
            # # [0]-代表configserver [1]-代表mongos_server [2]-代表shards_server [3]-代表所有服务器,用于分配hosts
            'servers': [
                    [ '10.112.73.35','10.112.73.36','10.112.73.37' ], # config server
                    [ '10.112.73.35','10.112.73.36','10.112.73.37' ], # mongos
                    [ '10.112.73.35','10.112.73.36','10.112.73.37' ], # shard server
                    [ '10.112.73.35','10.112.73.36','10.112.73.37' ]  # all server
            ],
            'shardtotal': 3,
      },
          'cdh': {
              'servers': [ '10.112.73.29','10.112.73.30','10.112.73.31' ],
              'dbip': "10.112.73.38",
              'dbusrname': "machtalk",
              'dbpwd': "dJIccFRHS8oGbda9"
          }
  }
}

阅读(1517) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~