欢迎您光临本小站。希望您在这里可以找到自己想要的信息。。。

(原创)利用Saltstack完成elasticsearch自动部署

Linux water 3983℃ 0评论

注意:
  本部署工具依赖saltstack工具,最好要安装es的服务器上都安装了salt

  salt-ssh 是 0.17.0 新出现的一个功能,它是依赖ssh 来进行远程命令执行的工具,
  好处就是不需要在客户端安装minion,也不需要安装master(直接安装 salt-ssh 这个包即可),
  有些时候你还真的需要salt-ssh(例如:条件不允许安装minion、不用长期管理某台minion),
  最重要的是salt-ssh 并不只是单纯的ssh 工具,它支持salt 大部分的功能,如grains、modules、state 等
  需要注意的是salt-ssh并没有继承原来的通讯架构 (ZeroMQ),也就是说它的执行速度啥的都会比较慢

操作步骤
  1.把deploy_es.tar.gz 上传到salt-master服务器上

  2.把deploy_es.tar.gz解压到服务器根目录下
    tar -zxvf deploy_es.tar.gz -C /

  3.需要配置要部署es的服务器的名称和角色
    /srv/pillar/ip.sls

    10.144.37.108:
        name: 'search1'
        role: 'master'
    10.144.48.33:
        name: 'search2'
         role: 'data'

  4.分别修改master、data的配置文件目录
    /srv/salt/elasticsearch/files/data/elasticsearch.yml
    /srv/salt/elasticsearch/files/master/elasticsearch.yml

  5.修改分配内存
    /srv/salt/elasticsearch/files/elasticsearch
   
    ES_HEAP_SIZE=1g

  6.把ip.sls同步到所有机器上

  salt '*' saltutil.refresh_pillar

 

  7.修改完成之后执行以下命令把文件传到其他服务器并自动完

    成所有es服务器配置
      salt '*' state.highstate

  8.最后查看执行结果

  9.最后调起所有es服务器

     salt '*' cmd.run '/gomeo2o/app/elasticsearch-1.5.1/bin/elasticsearch -d'
     注:好像salt中不能执行别名

下面是工具自动完成的配置

  1.修改机器名称
    vim /etc/hosts
    ip    search10

  2.禁用内存锁定
    vim /etc/security/limits.conf
    – memlock unlimited
    执行  ulimit -l unlimited

  3.禁用交换分区
    vim /etc/fstab
    注释掉swap分区
    执行swapoff -a

  4.创建目录
    mkdir -p /gomeo2o/work/
    mkdir -p /gomeo2o/data/es/
    mkdir -p /gomeo2o/logs/es/

  5创建别名
    echo "alias es_start=/gomeo2o/nfs/data/elasticsearch-1.5.1/bin/elasticsearch -d && tail -100f /gomeo2o/logs/es/gomeo2o.log'" >> ~/.bash_profile
    echo "alias es_log='tail -100f /gomeo2o/logs/es/gomeo2o.log'" >> ~/.bash_profile

    source ~/.bash_profile

下面是

 /srv/pillar/ip.sls

10.144.37.108:
  name: 'search1'
  role: 'master'
10.144.48.33:
  name: 'search2'
  role: 'data'

/srv/pillar/top.sls   

 base:
   '*':
     - ip

/srv/salt/top.sls

base:
  '*':
    - elasticsearch.init

/srv/salt/elasticsearch/config.sls

myconfig:
  cmd.run:
   {%set ip = grains['ipv4'][0]%}
    - names:
        - echo {{ip}}"    "{{pillar[ip]['name']}} >> /etc/hosts
        - echo "- memlock unlimited " >> /etc/security/limits.conf
        - mkdir -p /gomeo2o/work/
        - mkdir -p /gomeo2o/data/es/
        - mkdir -p /gomeo2o/logs/es/
        - alias es_start='/gomeo2o/app/elasticsearch-1.5.1/bin/elasticsearch -d && tail -100f /gomeo2o/logs/es/gomeo2o.log'
        - alias es_log='tail -100f /gomeo2o/logs/es/gomeo2o.log'
        - echo "alias es_start='/gomeo2o/app/elasticsearch-1.5.1/bin/elasticsearch -d && tail -100f /gomeo2o/logs/es/gomeo2o.log'" >> ~/.bash_profile
        - echo "alias es_log='tail -100f /gomeo2o/logs/es/gomeo2o.log'" >> ~/.bash_profile
        - sed -i 's/^.*swap/#&/' /etc/fstab
myrun:
  cmd.run:
    - names:
        - swapoff -a
        - ulimit -l unlimited
        - source ~/.bash_profile
    - require:
        - cmd: myconfig

/srv/salt/elasticsearch/init.sls

include:
  - elasticsearch.install
  - elasticsearch.config

/srv/salt/elasticsearch/install.sls

#elasticsearch.tar.gz
es_source:
  cmd.run:
    - cwd: /
    - names:
        - mkdir -p /gomeo2o/app/
    - unless: test -d /gomeo2o/app/
  file.managed:
    - name: /gomeo2o/app/elasticsearch-1.5.1.tar.gz
    - unless: test -e /gomeo2o/app/elasticsearch-1.5.1.tar.gz
    - source: salt://elasticsearch/files/elasticsearch-1.5.1.tar.gz
    - require:
        - cmd: es_source


#extract

extract_es:
  cmd.run:
    - cwd: /gomeo2o/app
    - names:
        - tar -zxvf elasticsearch-1.5.1.tar.gz
    - unless: test -d /gomeo2o/app/elasticsearch-1.5.1
    - require:
        - file: es_source

del_config:
  cmd.run:
    - names:
        - rm -rf /gomeo2o/app/elasticsearch-1.5.1/config/elasticsearch.yml
        - rm -rf /gomeo2o/app/elasticsearch-1.5.1/bin/elasticsearch
    - require:
        - cmd: extract_es

load_config:
  file.managed:
    - name: /gomeo2o/app/elasticsearch-1.5.1/config/elasticsearch.yml
    - unless: test -e /gomeo2o/app/elasticsearch-1.5.1/config/elasticsearch.yml
    {% set ip = grains['ipv4'][0] %}
    {% set role = pillar[ip]['role'] %}
    {% if 'master' in role %}
    - source: salt://elasticsearch/files/master/elasticsearch.yml
    {% else %}
    - source: salt://elasticsearch/files/data/elasticsearch.yml
    {% endif %}
    - require:
        - cmd: del_config

load_es:
  file.managed:
    - name: /gomeo2o/app/elasticsearch-1.5.1/bin/elasticsearch
    - unless: test -e /gomeo2o/app/elasticsearch-1.5.1/bin/elasticsearch
    - source:  salt://elasticsearch/files/elasticsearch
    - require:
        - cmd: del_config

add_exe:
   cmd.run:
     - name: chmod +x /gomeo2o/app/elasticsearch-1.5.1/bin/elasticsearch
     - require:
         - file: load_es

需要demo 的可以联系博主索取密码

    链接: http://pan.baidu.com/s/1c00OEx6

转载请注明:学时网 » (原创)利用Saltstack完成elasticsearch自动部署

喜欢 (3)or分享 (0)

您必须 登录 才能发表评论!